Texvc allows to insert Tex formulas into your page dinamically creating PNG images for you.
This note tries to remaind the required packages and the main steps to follow to have Tex working inside a MediaWiki and a Slackware OS. At the end I will present some troubleshooting.
This howto was tested on Slackware versions 12.0 and 13.37.
Ghostscript
- Info & download: http://pages.cs.wisc.edu/~ghost/doc/GPL/gpl900.htm
- Mediawiki requires the gs command
The gs program is available inside the package l/libgsf.
Ghostscript is already included in Slackware (ap/ghostscript and ap/ghostscript-fonts-std) but if you are running a minimal server you may have to install them yet.
libfontconfig
This library is included into x/fontconfig package. It's required by ImageMagick.
ImageMagick
- Info: http://www.imagemagick.org/script/index.php
- Download source: http://www.imagemagick.org/script/install-source.php
- This package is also distributed by slackware (xap/imagemagick)
- Mediawiki requires convert command support
wget http://www.imagemagick.org/download/ImageMagick-6.8.1.9.tar.bz2 tar xvfj ImageMagick-6.8.1.9.tar.bz2 cd ImageMagick-6.8.1.9 chown -R root:root . ./configure \ --without-x \ --with-png \ --with-freetype \ --with-dps \ --with-gslib make make install ldconfig
Testing
try to type, from the command line
/usr/local/bin/convert logo: logo.gif
If you get the PNG file it's ok.
Ocaml
- Download from Slackbuild (http://slackbuilds.org/result/?search=ocaml&sv=), create the package and install as usual.
- Download source from here
- Ocaml is required to compile texvc
wget http://caml.inria.fr/pub/distrib/ocaml-3.12/ocaml-3.12.0.tar.bz2 tar xjf ocaml-3.12.0.tar.bz2 cd ocaml-3.12.0 chown -R root:root . ./configure make make install
dvipng
Download: http://sourceforge.net/projects/dvipng/
Prerequisites:
- libgd (l/gd pkg)
- libXpm (x/libXpm pkg), libxcb (x/libxcb), libXau (x/libXau) and libXdmcp (x/libXdmcp) which are prerequisites of libgd.
- Kpathsea (included in the Latex pkg, install everything in the t/ group)
- FreeType (pkg in l/freetype)
- T1lib (l/t1lib)
- libpng (l/libpng)
- libz (l/zlib)
- texinfo (ap/texinfo)
PATH=$PATH:/usr/share/texmf/bin/ export PATH
Remember to save this in your profile as well.
To avoid problems in linking kpathsea configure as follows
./configure \ --enable-selfauto-set \ LDFLAGS='-L/usr/lib/ -L/usr/share/texmf/lib/' \ CPPFLAGS='-I/usr/share/texmf/include/' make make install
The option
--enable-selfauto-set \
is useful when the installation is outside the texmf tree (more info here https://lists.nongnu.org/archive/html/dvipng/2007-08/msg00004.html) in order to let kpathsea
find the .map files.
AMS-LaTeX
Without AMS* some equation will render correctly while others won't render. Slackware tetex package already contains AMS, anyway if you don't have it:
cd /usr/share/texmf wget ftp://ftp.ams.org/pub/tex/amslatex.zip wget ftp://ftp.ams.org/pub/tex/amsrefs/amsrefs.zip unzip amslatex.zip unzip amsrefs.zip
you should find /usr/share/texmf/tex/latex/amsmath/amsmath.sty
Enabling Tex inside Mediawiki
To use TeX formulas in MediaWiki 1.18 and higher, you have to install the Math extension and build the texvc program, which uses LaTeX to render the formulas. The Math extension is already bundled in version 1.16. Follow the directives on http://www.mediawiki.org/wiki/Extension:Math
Download the files into $IP/extensions/Math.
Then cd tothe texvc directory:
cd /path/to/htdocs/mediawiki/math
Before compiling, to avoid a parse error, use the absolute PATH everywhere inside math/render.ml in such a way:
let cmd_dvips tmpprefix = "/usr/share/texmf/bin/dvips -q -R -E " ^ tmpprefix ^ ".dvi -f >" ^ tmpprefix ^ ".ps" let cmd_latex tmpprefix = "/usr/share/texmf/bin/latex " ^ tmpprefix ^ ".tex >/dev/null" (* Putting -transparent white in converts arguments will sort-of give you transperancy *) let cmd_convert tmpprefix finalpath = "/usr/local/bin/convert -quality 100 -density 120 " ^ tmpprefix ^ ".ps " ^ finalpath ^ " >/dev/null 2>/tmp/wiki_convert_error" (* Putting -bg Transparent in dvipng's arguments will give full-alpha transparency *) (* Note that IE have problems with such PNGs and need an additional javascript snippet *) (* Putting -bg transparent in dvipng's arguments will give binary transparency *) let cmd_dvipng tmpprefix finalpath backcolor = "/usr/local/bin/dvipng -bg \'" ^ backcolor ^ "\' -gamma 1.5 -D 120 -T tight --strict " ^ tmpprefix ^ ".dvi -o " ^ finalpath ^ " >/dev/null 2>/tmp/wiki_dvipng_error"
Now compile texvc:
make
Add the following to your LocalSettings.php:
require_once("$IP/extensions/Math/Math.php");
you might also have to add
$wgTexvc = '/your/path/to/texvc';
Run update.php as you would if you were upgrading:
php /your/path/to/mediawiki/maintenance/update.php
Installation can now be verified through your wiki's Special:Version page.
Troubleshooting
- Reference: http://www.mediawiki.org/wiki/Manual:Troubleshooting_math_display_errors - http://www.mediawiki.org/wiki/Manual:Enable_TeX/problems
Put inside a wiki page something like
0
and try to see what happens. This is the most frequent error message:
Failed to parse (PNG conversion failed; check for correct installation of latex, dvips, gs, and convert)
Check if the executables are in the path:
# ls -lH `which gs` `which latex` `which dvips` `which convert` -rwxr-xr-x 1 root root 5977916 2008-12-05 23:36 /usr/bin/gs* -rwxr-xr-x 1 root root 23410 2010-11-21 15:22 /usr/local/bin/convert* -rwxr-xr-x 1 root root 209308 2007-06-28 04:51 /usr/share/texmf/bin/dvips* -rwxr-xr-x 1 root root 1010984 2007-06-28 04:51 /usr/share/texmf/bin/latex*
Enable the log putting a line like this in LocalSettings.php
$wgDebugLogFile = "/tmp/wiki.log";
Open it and search for a line such as;
TeX: ./math/texvc '/path/to/htdocs/mediawiki/images/tmp' '/path/to/htdocs/mediawiki/images/tmp' '0' 'UTF-8' 'transparent' TeX output: Ccfcd208495d565ef66e7dff9f98764da0 0 ---
Try to execute the texvc command from the command line as the apache user (you can try more complex formulas replacing the 0 below):
cd math sudo -u apache ./texvc '../images/tmp' '../images/tmp' '0' 'UTF-8' 'transparent'
and check the PNG into the images/tmp folder. If you still get a parse error, double check the absolute path into math/render.ml, and recompile. And read the references.