Mediawiki and LaTeX on a host with shell access

From briki

Jump to: navigation, search

This page was the original draft of the version now at mediawiki.org , which is the one you should visit if you want to make a contribution, or to read the latest contributions.

Three methods for including LaTeX in mediawiki are presented.

Examples can be seem in LaTeX Rendering Method Examples

Contents

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):

<?php
# Place this file in extension directory as Mtag.php
# Add the following line to LocalSettings.php:
# include './extensions/Mtag.php';
# Mediawiki will render as LaTeX the code within <m> </m> tags.

$wgExtensionFunctions[] = "wfMtag";

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

function returnMtagged( $code, $argv)
{

# if you have mathtex.cgi installed in your DocumentRoot:
# $txt='<img src="/mathtex.cgi?'.$code.'">';
# OR if you want to temporarily test a public mathtex.cgi:
 $txt='<img src="http://www.forkosh.dreamhost.com/mathtex.cgi?'.$code.'">';

 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:

#DESCRIPTION: convert LaTeX into PNG in MoinMoin wiki using mathtex.cgi
# Drop this file into data/plugin/macro as M.py
# Example usage in MoinMoin wiki:
# <<M(\int_0^\infty e^{-x^2}dx)>>

def execute(macro, args):
# If you have mathtex.cgi installed in your DocumentRoot:
#       str="""<img src="/mathtex.cgi?%s">""" % (args)
# OR if you want to temporarily test a public mathtex.cgi:
        str="""<img src="http://www.forkosh.dreamhost.com/mathtex.cgi?%s">""" % (args)
        return str or " "

Install LaTeX

Getting LaTeX (teTeX distro)

With shell access from the server, do 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

unpacking

In your home directory,

 
gunzip tetex-src-3.0.tar.gz 

tar xvf tetex-src-3.0.tar.gz 


This produces a directory tetex-src-3.0. There is a file QuickInstall within, which your should probably read. Here is another summary of installation, a little bit less cryptic.

mkdir -p /home/username/local/teTeX/share/texmf-dist

Then move the massive tetex-texmf-3.0.tar.gz to that directory, gunzip it and untar it, then either delete it or move it back out. This step has installed a bunch of files that are independent of the compilation step. The compilation step comes next, and that will fill out the teTeX directory that you have created.

compiling

If uname -a reveals that you are on a 32-bit server, try within tetex-src-3.0 executing

./configure --prefix=/home/username/local/teTeX -without-texinfo -with-x=no

At hostgator, you will find that your jailshell access does not allow access to gcc, so may need to ship off the directory to your local linux PC and attempt the compilation there. The ./configure step may reveal you need to install packages for flex, bison, byacc, libncurses5-dev before the next step is successful:

make world

That above step will take several (many) minutes. If it is successful (and, if need be, you have shipped the directory back to the server) then finish the installation on the server with:

make all install

final configuration

texconfig

The usual advice to finish an installation of LaTeX is to run texconfig, which brings up an interactive menu. But if you are installing LaTeX on a webserver, for the purpose of making little PNGs, you may not need to change anything with texconfig.

texhash

If you have your own personal style file, say titled myown.sty. Then

cd /home/username/local/teTeX/share/texmf-dist/tex/latex

Make a directory there: mkdir myown and drop myown.sty into it. Then run texhash, so that LaTeX can find the new style file. Even without installing a style file, I believe the usual installation advice is to run texhash.

VARTEXFONTS

Execution of texhash may also reveal an attempt to access /var/tmp/texfonts. At hostgator, that presents a problem, at hostmonster it does not. If a problem arises (or even before arises) you may want to:

grep VARTEXFONTS  /home/username/local/teTeX/share/texmf/web2c/texmf.cnf 

You should see a line

VARTEXFONTS  = /var/tmp/texfonts

You can remedy this with

mkdir /home/username/texfonts
texconfig font vardir /home/username/texfonts

grep should now reveal VARTEXFONTS = /home/username/texfonts .

Or follow this teTeX advice, and change VARTEXFONTS before compilation.

64-bit servers

For 64-bit servers, the ./configure step will need to be:

CC="gcc ${BUILD64}" CXX="g++ ${BUILD64}" USE_ARCH=64 \
./configure --prefix=/home/username/local/teTeX \
–enable-shared \
–without-texinfo \
–with-x=no \
–with-system-ncurses \
–with-system-zlib &&
[ -f texk/libtool ] && sed -i “/sys_lib_search_path_spec=/s:/lib:&64:g” texk/libtool;

That step can be found at 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


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 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 with the command definitions. Depending on where your teTeX is installed, you should find many directories containing .sty files in:

/home/myaccount/local/teTeX/share/texmf-dist/tex/latex

Within that directory, mkdir mystyle and then move your mystyle.sty into mystyle.

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

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

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, there could be just one line:


"\\usepackage{mystyle}\n"

The traditional <math>

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

ocaml and texvc

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


wikitex

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

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


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 tmp directory within wikitex you may find long file names, for example cd02e2b844e50595b3d569247d533cc9 without the corresponding cd02e2b844e50595b3d569247d533cc91.png. Entering the shell command latex cd02e2b844e50595b3d569247d533cc9 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 wikitex will call wikitex.sh for each PNG. A shared host may be very slow in completing the many calls to wikitex.sh, perhaps deliberately by its configuration. PHP may then time out. Use of mathtex avoids this problem.