Lately I have been fooling around with wikis and CMSes. As minister of technology for my friend Danny (basically I give him space on this server), I was commissioned by his fiancee Bethany to set up a wiki. I did a little more searching around on wikis, and decided on mediawiki. I also looked at DokuWiki, but I liked the interface of mediawiki a bit better, and supposedly it supported LaTeX, of which I am a big fan.

Supposedly.

Installing mediawiki was very easy. It really only took about five minutes. I downloaded the tarball, untarred it, then followed the instructions. It even had a nice convenient web interface, which led me through the steps of creating a database and populating it. It did take a little while to figure out how to create new accounts and such, but once that was done, Bethany was creating content within minutes.

Installing LaTeX support was not so easy. First I had to turn it on in some setting files. After testing, I got a few errors, went and checked some permissions and such, and it was working. Then I got this very uninformative error:

Failed to parse (PNG conversion failed; check for correct installation of latex, dvips, gs, and convert):

I fiddled around a bit more, then decided to call it quits for the day. At some point the next day, I had done some real schoolwork, and decided to fiddle around with computers. I had thought of some other ways to debug the LaTeX support for mediawiki. I read a somewhat helpful blog entry by Aaarre Laakso who suggested that it might not be permissions, but rather paths that was the problem. He was ultimately correct, though it was not the path that he was talking about. He suggest editing render.ml, which texvc uses, and hard-coding in the paths to latex, dvips, etc. I did that, and then recompiled texvc (which involved install an ocaml compiler — fortunately there was a yum package available for my Fedora Core 5 box). Still no luck.

So then I started digging around in the php code of mediawiki to try to find out what it was doing. In the process, I wrote a little bash script which will grep for certain words in certain types of files, and return the names of the files and the grep output for files which match. Here is that script, which I have dubbed grepme:

#!/bin/bash
# this script will grep from all files matching the shell glob in $1
# and return files which contain the regexp in $2
if [ $# -ne 2 ]; then echo 'usage: ./grepme files pattern'>&2; exit 1; fi
for file in $1
do
return=`grep -c "$2" < "$file"` #echo $return if [ $return -gt 0 ] then echo '**' "$file" grep "$2" < "$file" echo fi done

Anyways, I found that there were only a couple files that I need to look at, the main one being includes/Math.php. I decided to copy that file and try to hack it on its own, and see what latex commands were being given. That didn't work so well, but eventually, I just started trying my own latex commands, and finally I was getting some meaningful debugging info. It turns out that running as the apache user, LaTeX couldn't find some files, most notably latex.fmt. So I tried copying that file to the images/tmp directory where the tmp .tex files are stored, and it finally worked!!!!. How nice. Only several hours of banging my head. Once that was done, it was late, and I went to bed, feeling that I had accomplished something. (Note that my solution is still a huge kludge, and if anyone can tell me how to properly set the path so latex can find the files while running as apache, I would be happy to hear them).