### LaTeXMath, a Kwiki Plugin for Mathematics

Yesterday, I was thinking about math and whenever I start thinking about math I want to write it down. I hate writing on paper anymore and like writing on wikis, so I decided to see if anyone had written a LaTeX module for Kwiki, my wiki of choice. Alas, no one had.

Now, a fact of life is that I'd rather write code than math. In a former life, I did formal verification in HOL which allowed me to write code and math at the same time. As a consequence, I was easily diverted to a new task and I hacked together a LaTeXMath module for Kwiki last night. You can see it in action on this introductory page. Essentiall, it turns this:

.latexmath
\\int H(x,x')\\psi(x')dx' = -\\frac{\\hbar^2}{2m}\\frac{d^2}{dx^2}
\\psi(x)+V(x)\\psi(x)
.latexmath


into this:

I've put some other examples online as well.

The module is a wrapper for a hacked up version of John Walker's TeX to Gif translator. The module invokes five different programs via system calls for every equation (ouch!), but its hard to imagine it doing anything much different.

To cut down on the cost, the images are stored in a file with a name that is generated as an MD5 digest of the equation text. The plugin checks to see whether the image already exists and only generates a new one if necessary.

One minor problem is that the plugin doesn't know when an image is no longer needed, so they are never deleted. This is only a minor problem since they are fairly small. In addition, the directory could be periodically purged of old images using a cron job since they will be automatically regenerated when ever the page is viewed again.

I'm sure I messed this up horribly and I haven't tested it extensively yet, but I'll let you know if there are any major changes. I know that my plugin could be a little friendlier (it makes you create the directory to store the images, for example) and there are several parameters that ought to be in a config file rather than just stored in the module itself. Let me know what you think.