Note: The recipes here are for PmWiki versions 0.6 and 1.0 only. For PmWiki 2.0 recipes, see Cookbook.


Add markup to display and embed mathematical formulas in wiki pages.



The mimeTeX utility from John Forkosh Associates, Inc., along with the mimetex.php script below, makes it easy to embed mathematical formulas in wiki pages using the LaTeX math expression syntax. Once installed, the markup {$ and $} can be used to embed a formula in a wiki page. For example, the markup

{$ x^2 + y^2 = z^2 $}


{$ x^2 + y^2 = z^2 $}

More complex formulas can be generated--for example:

{$ e^x=\relstack{\rm lim}{n\rightar\infty}\(1+\frac xn\)^n $}


{$ e^x=\relstack{\rm lim}{n\rightar\infty}\(1+\frac xn\)^n $}

See the full mimeTeX manual [forkosh.com] for more details.


To install MimeTeX, perform the following steps:

1. Download and install the mimeTeX package from http://www.forkosh.com/mimetex.html. You can use the installation instructions given in the README file included with the mimeTeX package; on pmichaud.com we simply unzipped the archive into a mimetex/ directory and executed the command

    cc -DGIF mimetex.c gifsave.c -lm -o mimetex.cgi

2. Place the Attach:mimetex.php script in your local/ subdirectory, then add the following lines to your local configuration:

    $MimetexCmd = '/path/to/mimetex.cgi';

3. Create a subdirectory called 'pub/cache' where MimeTeX can cache the formula images, and give the webserver write permissions to this subdirectory. (On Unix systems this is typically done via the command mkdir pub/cache; chmod 777 pub/cache; .)

That should do it! Whenever mimetex.php encounters the {$ ... $} markup, it automatically generates a formula image file in the pub/cache/ directory (if needed) and returns the appropriate reference to the image. The images in the pub/cache/ directory are kept to avoid regenerating them on future page accesses. However, a WikiAdministrator can delete the image files in pub/cache/ at any time and MimeTeX will automatically regenerate them as needed.


{$ \bold \hspace{20} \atop{\raise{-11}{\fs3\swarr} \compose{\circle(140,30)}{\rm Have a nice day!}}{\vspace1} $}

MimeTeX examples

See MimeTeX-Examples for more examples.

Notes and MimeTeX Sandbox

{$\array{CCC$\Large f=b_\0+\frac{a_\1}{b_\1+\frac{a_2}{b_2+\frac{a_3}{b_3+a_4}}} & \hspace{10} {\small\rm{Notes and\atop mimeTeX Sandbox}} \hspace{10} } \Large \scrJ^{ij}=\frac12\vareps_{ijk}\[\array{cc$\sig_k&0\\0&\sig_k}\] $}

isn't there a plugin for pmwiki that uses an existing latex installation on the server ... i think the quality of the images MimeTex produces is quite poor. what was used here? (this is pmwiki right? but i think the images look much better):http://www.lyx.org/~chr/wiki/pmwiki.php?pagename=Math.Math ==> i started working on something like this, i'll add it as soon as it is usable --JanSchumacher

Feel free to use the space below to test various mimeTeX formula markups.

{$\large \Bigint\limits_^{-1$\infty} e^{-x^2} dx\ =\ \frac{\sqrt\pi}2$}

{$ \LaTeX{} {\TeX} $} - the CamelCase collides with the latex-source? :(

{$ WikiWord $} - should be fixed now (22-Mar-2004). --Pm


Please disable the WikiWords in latex-code, because the latexwords in .gif's are not usable. (click the "?" above, behind "TeX" for example). I think it's easy, if the mimetex2gif-conversion are done before the wikiwords where analyzed.

I did this already (22-Mar-2004). --Pm

but from where the "?" and the "[]" came from in {$ \LaTeX{} $} = {$ \LaTeX{} $}. the WikiWord is only disabled in {$ LaTeX{} $} = {$ LaTeX{} $} (without "\").

Apparently the mimeTeX package itself adds the question mark, and it's not anything PmWiki is doing. Jump to http://www.forkosh.com/mimetex.html, and enter the latex-source in the query box and you'll see that you get the same results. Also, note that {$ \Foo $} does the same thing ({$ \Foo $}) even though "Foo" isn't a WikiWord. --Pm, 24-Mar-2004.

aaah, my fault. i'm relieved to read that. it's not a bug, it's a feature. *g*

Yes, it's just an embedded error message indicating an unrecognized escape sequence. For example {$\varphi=\sqrt2$} gives the expected {$\varphi=\sqrt2$}. But if you happen to misspell it, or something, then {$\vaphi=\sqrt2$} gives {$\vaphi=\sqrt2$}, hopefully clueing you in to what needs fixing. Since mimetex recognizes neither {$\TeX$} nor {$\LaTeX$} because they're not mathmode symbols, it renders them both as errors. Unfortunately, that got a little confusing here, where you (mis)interpreted it as some kind of weird WikiWord collision.

By the way, if you'd prefer not to cache a lot of images that may accumulate after prolonged mimetex use, the short script below can be used in place of the original mimetex.php

$DoubleBrackets['/\\{\\$(.*?)\\$\\}/e'] = "Mimetex('$1')";
function Mimetex($tex) {
{$ \hspace{10} $}global $MimetexCmd;
{$ \hspace{10} $}$tex = trim($tex);
{$ \hspace{10} $}return "<img src=\"$MimetexCmd?$tex\" align=absmiddle>";

It will incur a little extra computational overhead on your server in exchange for slightly simpler site maintenance.

Also, you might want to try compiling as

    cc -DAA mimetex.c gifsave.c -lm -o mimetex.cgi

that is, try the anti-aliasing -DAA option rather than the non-antialiased -DGIF option. Typically produces more pleasing renderings, but, of course, it's a matter of taste. (Meanwhile, thanks for your efforts plugging mimetex into PmWiki.)

{$ 1+\frac{1+\frac{1+\frac{a}{b}}{c}}{d} $}

If you have problems getting this to work, and you use the above suggested version of "mimetex.php" to disable the cache and it still doesn't work, your system() function may be disabled on your web server. Check a phpinfo() output, or simply use the instructions on this page:

[(approve links) edit diff]

It worked for me. Disadvantage - no cache, so more overhead on the server to generate math.

The latest version of mimeTeX discusses it's new optional built-in caching mechanism, which you turn on with the compile line switch -DCACHEPATH=\"path/\", where path/ (relative to mimetex.cgi) is the directory where images will be cached. So you can either turn mimetex's caching on and use the "simple script" above, or leave mimetex's caching off (which is the default) and use the original pmwiki mimetex script. Actually, if you compile with -DCACHEPATH=\"path/\" and path/ doesn't exist or isn't writeable, then mimetex will just emit images without caching them. So there's no penalty for compiling with -DCACHEPATH even if you don't want to use it.

That will hopefully simplify writing future mimetex plugin scripts. Since all the existing scripts I know about cache mimetex's images, I thought it would be easier to implement that in one place rather than re-inventing the same wheel for every plugin. Also, I'm hoping to eventually get a super-sampling anti-aliasing algorithm working (in place of the current low-pass filter algorithm), which should render mimetex's built-in fonts better. But super-sampling will be more compute intensive, so image caching will become an even better idea than it is now.


{$e^{2\pi i}-1 =0 $} pmwiki-2.3.8 -- Last modified by {{Petko}}

from IP: ip should be disabled by default for security reasons