# MimeTeX

## Questions answered by this recipe

- Can PmWiki be used to display mathematical formulas?

## Solution

- mimetex-vc.phpΔ - PmWiki cookbook script (to rename mimetex.php)
- http://www.forkosh.com/mimetex.html - mimeTeX package

## See also

- Cookbook /
- AMmathjax Add markup to embed math using ASCII MATH by MathJax. (Stable)
- ASCIIMath Display MathML rendered ascii formula into PmWiki 2.x pages (Stable)
- Formula Lightweight rendering of mathematical formulas in wiki pages (Beta)
- JsMath Add markup to display and embed mathematical formulas in wiki pages using TeX. (Obsolete - use MathJax)
- LaTeXMathJax MathJax support for PmWiki (stable)
- LaTeXMathML Translating LaTeX math notation dynamically to Presentation MathML (Stable)
- LinuxTex Enable TeX markup
- LuaExecute Lets Lua scripts dynamically generate parts of your wiki page (Beta)
- MathJax Add markup to embed math using TeX syntax. (Stable)
- Mathtex Add markup to display and embed several lines of mathematical formulas in wiki pages (testing)
- SageCell This allows you to embed an interactive SageCell into your webpage. Sage is an open source alternative to MathLab, Mathematica, and Maple. (Stable)
- SimpleJsMath Notes on modifying the jsMath for a skin (not a complete recipe)
- TrueLatex Enables interpretation and rendering of real LaTeX markups in PmWiki. Support for XeLaTex included in v1.8. (Working perfectly. Very simple to use, customizable and comes with lots of options.)

## Discussion

The mimeTeX utility from John
Forkosh Associates, Inc., along with the *mimetex.php* script above, 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 $}`

produces

More complex formulas can be generated--for example:

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

becomes

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

## Installation

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 -DAA mimetex.c gifsave.c -lm -o mimetex.cgi

(you can download the compiled version for linux directly on : [(approve links) edit diff] )

2. Place the mimetex-vc.phpΔ script in your *cookbook/* subdirectory and rename it mimetex.php)

3. If you want to have PmWiki simply use MimeTeX as an external CGI script and do no caching of its own, you can place the following lines in your *local/config.php* (change the URL for *mimetex.cgi* as necessary):

$MimetexUrl = '/cgi-bin/mimetex.cgi'; include_once('cookbook/mimetex.php');

4. If you want PmWiki to call MimeTeX directly and cache the resulting images, then create a directory called *pub/cache* for the 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;`

.) Then add the following to your *local/config.php*:

$MimetexCmd = '/filesystem/path/to/mimetex.cgi'; include_once('cookbook/mimetex.php');

That should do it! Whenever *mimetex.php* encounters the {$ ... $} markup, it automatically generates a call to mimetex.cgi and displays the resulting image. If PmWiki is being used to cache the images, then the images are kept in *pub/cache/* to avoid regenerating them on future page accesses. A WikiAdministrator can delete the image files in *pub/cache/* at any time and MimeTeX will automatically regenerate them as needed.

MimeTeX itself now has an optional built-in cachine mechanism, which is enabled by compiling mimetex.cgi with the `-DCACHEPATH=\"path/\"`

switch (where `path/`

is a directory relative to mimetex.cgi where images will be cached. This can be used in conjunction with #3 above and still provide caching.

5. If you have a wikifarm installed, you need an extra `$FarmD`

in mimetex.php.

--- mimetex.php.orig +++ mimetex.php -SDV($ImgCacheDir,"pub/cache"); +SDV($ImgCacheDir,"$FarmD/pub/cache");

Also add `$FarmD`

in config.php

` include_once('``$FarmD`

/cookbook/mimetex.php');

## Contributors

- Pm
- Christian RidderstrÃ¶m
- John Forkosh Associates, Inc. -- mimeTeX utility

## MimeTeX Sandbox

{$$ f_X(x_1, \dots, x_N) = \frac

{1} {(2\pi)^{N/2} \left|\Sigma\right|^{1/2}}

\exp \left(

-\frac{1}{2} ( x - \mu)^\top \Sigma^{-1} (x - \mu)

\right)$$}

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

{$\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}\] $

,

AB

}

This is some text wrapped around the formula to see how it behaves.

Some examples used from another Wiki:

Some weird examples... probably a bug. Only one of the formulas below should produce ...

`* {$ -\bar a_{c 3} \cos \Phi \sin \rho $}` |

Ben: I found a similar bug. If you insert \. (which does nothing) at the beginning of each of these, then MimeTeX formats the image correctly. I would guess it is a bug with MimeTeX. Typing the following should work:

`* {$\. -\bar a_{c 3} \cos \Phi \sin \rho $}` |

return "<img class='mimetex' src='$ImgCacheUrl/$imgname' alt='".

to

return "<img ALIGN='absMIDDLE' class='mimetex' src='$ImgCacheUrl/$imgname' alt='".

This causes the images to be centered with the center line of the text. It works in IE and Firefox. It still is not perfect at displaying all images, but I think it looks a lot better.

Other options for aligning are available (see http://www.w3.org/MarkUp/Test/Img/imgtest.html). I think the absmiddle does the best job.

`* {$ -\bar a_{c 3} \cos \Phi \sin \rho $}` |

I'm trying to make this work but I keep getting the error message: Warning: Cannot modify header information - headers already sent by (output started at /home6/jcarter/public_html/pmwiki/cookbook/mimetex.php:4) in /home6/jcarter/public_html/pmwiki/pmwiki.php on line 871.

any suggestions???

That worked! thanks!

I'm looking for markup that I can use for text that will allow me to place alternative strings directly above and below eachother (without using preformatted text). For example, with preformatted text, the result would be like this:

(ago) A: (e) ache moyuba

Using frac (and avoiding Q&A):

A: (e) moyuba

Using large and frac:

A: (e) moyuba

Using large and relstack:

Using \\:

A: (e) moyuba

------

i'm wondering if and how can this plugin works under windows iis..

Folks can't get it to work config.php has

$MimetexUrl = '/cgi-bin/mimetex.cgi'; include_once('cookbook/mimetex.php');

"cgi-bin" is a subdirectory in the "pmwiki-2.1.26" directory. mimetex.cgi is there, still it shows only the typed symbols, not the one I want to display.

Thanks for suggestion <<<<<<<

mw <math>\sqrt{1-e^2}</math> ltx =======

<math>\sqrt{1-e^2}</math> >>>>>>>

http://meta.wikimedia.org/wiki/Help:Formula

{$S_{new} = S_{old} - \frac{ \left( 5-T \right) ^2} {2}*}

abcd

27-Feb-2007

## Attachement problem

24-Jul-2007

mimetex.phpΔ attachment seems to be corrupted. Can it be restored please ??

18-Nov-2007

try to copy content of mimetex-vc.phpΔ to your mimetex.php. It works

**User notes** +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.