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> and Metapost.i18n.php</tt> respectively, in that directory.

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
 * $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

 * 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 extension tries to counteract this by using a few ulimit statements, with wfShellExec, 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.
 * Version 0.9.3:External Python script now rewritten in PHP.