When looking at the ipython notebook interface, I came across a neat tool: mathjax. It's designed to allow embedding math in web documents. Now, MathML was supposed to do this, but support for MathML is still very spotty, and it's also really nasty trying to write MathML manually. So mathjax allows you to simply enter TeX format math and have it look okay in supposedly all browsers: both inline as \(e^{i\pi}=-1\) and displayed as $$\int_{-\infty}^{\infty}f(t)e^{2\pi i f t}dt. $$

The way that it does this is kind of amazing to me: it's essentially a TeX renderer written in javascript and running in your browser. I'm used to thinking of TeX as a batch-mode compiler that takes an appreciable time to run, but TeX has become the de facto standard way to write mathematics, and there are now several reimplementations of its renderer. Matplotlib has one, for example, though it can also call out to real TeX if you ask it to. But javascript!

Anyway, as you can see above, I've added it to the template for this blog, so I'll be a little freer with math from now on. Though I'm willing to bet it doesn't work in the RSS feed. Let me know if you have any problems with it.

Comment of the year

10 hours ago

## 3 comments:

I hadn't thought of that, but given that in-browser PDF renderers exist, LaTeX isn't much of a stretch, I suppose: http://andreasgal.com/2011/06/15/pdf-js/

Good god. Well, I suppose it's possible; I've been arguing for ages that it often makes sense to write substantial programs in scripting languages.

I will point out, though, that PDF and PostScript were designed to be rendered on printers with potentially very limited CPUs, while TeX is a full-featured programming language, and even the subset needed to render decent math is fairly sophisticated.

Hey, if Facebook can run on a (poorly-designed) interpreted scripting language, than anything can. I think it comes down to a decision of where to allocate your money, ie. more programming time vs. more hardware, and hardware's always getting cheaper.

You make a good point about printers with limited processing power, but PS is still Turing complete. pdf.js might choke on complex PS that generates fractals or some such but I think the approach is sound since browser technology in general (HTML5, JS) are mostly designed for rendering text and images, just like PS and \LaTeX.

On a related note, if you use Chromium, this makes its lack of MathML support somewhat less annoying:

https://chrome.google.com/webstore/detail/elbbpgnifnallkilnkofjcgjeallfcfa

Post a Comment