MediaWiki and LaTeX on a host with shell access

Three methods for including LaTeX in mediawiki are presented. Examples can be seem in LaTeX Rendering Method Examples.

Install mediawiki
Installation of mediawiki proceeds with instructions such as these: How to Install MediaWiki on Hostmonster

The simplest and universal option: mathtex.cgi
Using mathTeX you can test out LaTeX in your wiki almost immediately, using the generosity of forkosh.dreamhost.com to render the PNG images for you. See the advice in the section mathTeX web services. After that step is successful, you can gradually move to using LaTeX on your account.

To have functioning LaTeX within your wiki, you will need this file (and embedded instructions):   tags.

$wgExtensionFunctions[] = "wfMtag";

function wfMtag { global $wgParser; $wgParser->setHook( "m", "returnMtagged" ); }

function returnMtagged( $code, $argv) {

$txt='';
 * 1) if you have mathtex.cgi installed in your DocumentRoot:
 * 2) $txt='';
 * 3) OR if you want to temporarily test a public mathtex.cgi:

return $txt; }

?>

mathtex.cgi is independent of mediawiki; hence it is referred to as universal. For example, a similar short macro file could use your mathtex.cgi in the MoinMoin wiki engine:
 * 1) DESCRIPTION: convert LaTeX into PNG in MoinMoin wiki using mathtex.cgi
 * 2) Drop this file into data/plugin/macro as M.py
 * 3) Example usage in MoinMoin wiki:
 * 4) <>

def execute(macro, args): str="""""" % (args) return str or " "
 * 1) If you have mathtex.cgi installed in your DocumentRoot:
 * 2)       str="""""" % (args)
 * 3) OR if you want to temporarily test a public mathtex.cgi:

Install LaTeX
Particularly helpful for 64-bit servers is Installing LaTeX on hostmonster, with one exception. The exception is to NOT put a trailing slash (as appears on 12 July 2008): ./configure --prefix=/home/username/local/teTeX/ Instead, the correct line should be: ./configure --prefix=/home/username/local/teTeX

Getting LaTeX
From your command line:

wget ftp://tug.ctan.org/tex-archive/systems/unix/teTeX/current/distrib/tetex-src-3.0.tar.gz

wget ftp://tug.ctan.org/tex-archive/systems/unix/teTeX/current/distrib/tetex-texmf-3.0.tar.gz

I find 127 binaries installed in /home/youraccount/local/teTeX/bin/x86_64-unknown-linux-gnu If I use the trailing / in the --prefix, I get 119. If you read the QuickInstall included with the distro, you will see the advice to ./configure --prefix=/usr/local/teTeX >& configure.log You should probably include the  >& configure.log </tt> in the advice from Burad's blog.

Compiling your own mathtex.cgi
You may want to allow for certain LaTeX commands as defined in your personal style file. Suppose you have a style file mystyle.sty</tt> with the command definitions. Depending on where your teTeX is installed, you should find many directories containing .sty</tt> files in: /home/myaccount/local/teTeX/share/texmf-dist/tex/latex

Within that directory, mkdir mystyle</tt> and then move your mystyle.sty</tt> into mystyle</tt>.

In order for LaTeX to find the newly created mystyle</tt>, you need to simply run texhash</tt> from the command line.

Here is an example script to compile mathtex</tt>, which can be kept in an executable file named compilemathtex</tt>:

cc mathtex.c -DLATEX=\"$(which latex)\" \ -DDVIPNG=\"$(which dvipng)\" \ -DDVIPS=\"$(which dvips)\" \ -DCONVERT=\"$(which convert)\" \ -DPNG -DUSEPACKAGE=\"mylittlefile\" \ -DREFERER=\"mydomain,myotherdomain"\" \   -o mathtex.cgi

And within mylittlefile</tt>, there could be just one line: "\\usepackage{mystyle}\n"

The traditional
There is a Readme</tt> file inside the math</tt> subdirectory of your mediawiki distro. In addition to the requirements you needed for mathtex</tt>, you will also need texvc</tt> and ocaml</tt>.

ocaml and texvc
You will likely need to compile texvc</tt>. Simply uploading a binary, as described at MediaWiki with math in HostMonster, might not work, especially if your server is 64-bit. To compile <tt>texvc</tt>, you will need <tt>ocaml</tt>, obtained from http://caml.inria.fr/. Compiling <tt>ocaml</tt> will take some time, and some 64-bit issues may arise in the <tt>make</tt> process. But after it compiles, and with the binary <tt>ocaml</tt> in your path (for example, residing in <tt>/home/youraccount/local/bin</tt>) the make process for <tt>texvc</tt> may proceed quickly. After <tt>texvc</tt> is compiled, it is quite possible that you will never use ocaml again.

If the server is a flavour of Debian Linux, there is a package that may be installed by the host maintainers which provides a binary of texvc (in ) installed using the Advanced Packaging Tool command.

wikitex
If you want to extend your LaTeX with AMS-LaTeX or other styles, an alternative to <tt>mathtex</tt> is <tt>wikitex</tt>, available from http://wikisophia.org/wiki/Wikitex. Suppose you want to extend <tt>wikitex</tt> with your own styles, similar to what was described above for <tt>mathtex</tt>. Here is an example of using <tt> <ma>...</ma> </tt> tags for that purpose:

<tt>'ma'  => 'strMa',</tt> function strMa($str) { global $objRend; return $objRend->strRend($str, array('class' => 'ma')); }
 * 1) <tt>cp wikitex.math.inc.tex wikitex.ma.inc.tex </tt>
 * 2) add your command definitions within the preamble of <tt>wikitex.ma.inc.tex</tt>
 * 3) alternatively add your package to the list within <tt>\usepackage{...</tt>
 * 4) Within <tt>wikitex.inc.php</tt>, add this line to the definition of <tt>$arrRend</tt>:
 * 1) Within <tt>wikitex.php</tt>, add this function

It is possible that when the webserver invokes LaTeX, the webserver won't have permissions to make missing fonts, and you will see an error message. In the <tt>tmp</tt> directory within <tt>wikitex</tt> you may find long file names, for example <tt>cd02e2b844e50595b3d569247d533cc9</tt> without the corresponding <tt>cd02e2b844e50595b3d569247d533cc91.png</tt>. Entering the shell command <tt>latex cd02e2b844e50595b3d569247d533cc9</tt> may give some messages about the missing fonts, and then make the missing fonts. The wiki invocation may now be able to render the PNG.

In order to render a page full of PNGs <tt>wikitex</tt> will call <tt>wikitex.sh</tt> for each PNG. A shared host may be very slow in completing the many calls to <tt>wikitex.sh</tt>, perhaps deliberately by its configuration. PHP may then time out. Use of <tt>mathtex</tt> avoids this problem.