User:Tommy Ekola/Metapost

For version tested with 1.11.0 see Metapost 0.9.1

Metapost is an extension that renders MetaPost code included in the wikitext as SVG (or a PNG picture if SVG isn't supported by the browser). This extension defines a new tag   and between this tag and its end tag a user can include MetaPost code.

Example
If you include the following lines in the wikitext

then the result will be this graphics:


 * [[Image:mpexample.png]]

Note that it is only the graphics created in beginfig(1) that gets rendered.

Install software on the wikiserver
 Install a TeX-system on your wikiserver. See, for example, this site. Install imagemagick. Install pdf2svg 

Save the code
Create the directory $IP/extensions/Metapost and save the code in the files Metapost.php, Metapost.body.php</tt>, Metapost.i18n.php</tt> and bin/mprend.py</tt>, respectively, in that directory. The Python script mprend.py</tt> should also be made executable to the webserver process (e.g. by writing something like chmod u+x mprend.py</tt> on a unix system).

Create an image directory
You need to create a directory where the SVG and PNG files will be stored. For example, $IP/images/metapost</tt>. The webserver process also needs to have read and write access to this directory (e.g., by writing something like chmod u+rw images/metapost</tt> on a unix system).

Configure the extension
Add the following lines at the end of the file $IP/LocalSettings.php</tt>

where
 * $wgMprend</tt> is the path of the Python script mprend</tt>.
 * $wgMetapostDirectory</tt> is the full path of the directory where all SVG and PNG files will be stored.
 * $wgMetapostPath</tt> is path of $wgMetapostDirectory</tt> on the webserver.

Bugs and future improvements

 * Rewrite mprend.py in php.
 * This extension might be unsafe to use in a public wiki since MetaPost is a full-fledged programming language and it is easy, for example, to write a infinite loop. The script mprend</tt> tries to counteract this by using a few ulimit statements but it is not clear if this is a robust solution.
 * The included graphics might not display on older browsers.

History

 * Version 0.9:Initial version
 * Version 0.9.1:German translation of messages. (Thanks to Ruedi Seiler)
 * Version 0.9.2:Adjusted for use with MediaWiki 1.21.