« Lightweight Identity | Main | Aggregating Risk »
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.
Posted by windley on January 12, 2005 9:42 AM



Comment from Eric at January 12, 2005 1:42 PM
Very cool! Fun to see so many levels patched together like this. Kind of like how this comment is all patched together since tags do not seem to be allowed. Ahh... Convergence.
To add to your last paragraph about potential things that could go wrong - the threat of someone worming their way into your system calls and algorithm complexity attacks are probably my main concerns. The MD5 cache technique is a nice touch - but unless you've got something monitoring disk space this could facilitate attacks designed to consume all disk space on the server if the cache is never cleaned. Nothing that couldn't be mitigated, but maybe something for the TODO list if you take this to the next level.
I wonder if there are already servers out there that let you pass WAFL in the URL and embed within an image tag, similar to ye olde site counter gif generator. That would be so easy to use and would "plug in" to whatever Wiki/Blog/etc software you use. In the right circles, you could even get away with calling it a web service. Keep up the good work. :)
Comment from Jooon at January 13, 2005 9:16 AM
Nice job!
I am planning to write something like this myself, ie. kwiki markup that generates an image. There is also one other existing. Kwiki::SocialMap I think it is called. After some time, someone will probably figure out the best way to generate, store and cache "kwiki markup to image" images.