This post is mainly for system administrators and developers who want to add mathematics capabilities to a blog or wiki that they host or develop. We hope that in a year or so some of the ideas we describe here will be available to ordinary users who have a blog, say on WordPress.

After an Introduction, we discuss Light-, Medium- and Heavy- weight installation of MathTran. Then we discuss how to print mathematics using MathTran. Finally, we revisit the examples in the introduction, and state conclusions.


In fact, let’s start with Terry Tao’s blog, which is on WordPress. In case you didn’t know, Terry Tao is an eminent and talented young mathematician who is extremely web-savvy. He decided to move from a static web-site to a blog for his news and discussion articles about a year ago. Original he moved to blogspot, but then soon moved on to WordPress, because it gave better LaTeX support. Last month he told us that he has decided to publish a book version of his blog.

For me, Terry Tao’s blog provides a good example of where we are right now, and where we’d like to be. Of course, there are other examples. Most of us are not nearly as mathematical as Tao is. The many mathematics pages on Wikipedia provide another example. The Wikimedia foundation has recently announced a project to convert Wikipedia content to PDF. (The development of the software is being led by, whose web-site is one of the case studies in The Django Book, which neatly ties in with another interest of mine.)

So this may be enough to set the stage. We’re interested in getting mathematics on blog, wikis, forums and other ‘Web2.0′ sites. We want good LaTeX support, good display, and the ability to go to PDF.

Lightweight installation

MathTran is a public web service, and so a lightweight installation can be made simple by putting some Javascript in the HTML header, and coding up the IMG elements on the page appropriately. All this is described on the MathTran home page (at present, it might get moved later).

Another intriguing form of installation is via a MathTran bookmarklet, which has been devised by my colleague Tim Hunt at The Open University. This allows MathTran to do it’s magic on content that has been marked up using TeX’s traditional $$ x^2+y^2=1$$ notation. This is a transformation controlled by the web-browser and its user. It does not require the server of the web page to do anything at all. To try it, install this bookmarklet in the way Tim described above and click on it. You will see the previous formula be replaced by it’s rendered TeX form. (The MathTran client Enso TeX Anywhere does something similar in many Windows documents.)

MathTran can provide lightweight installation because

  • It is a high-performance web service (it runs TeX as a daemon, waiting and ready for the next request)
  • It is a public web service
  • It can provide its service via dynamic HTML

Any public high-performance dynamic HTML web service will support lightweight installation. One of the most widely deployed examples is the Google Ad Client, which adds advertising to many web pages (and provides revenue to the owner of the page).

Medium-weight installation

Now suppose you don’t want your users to get the mathematical images from the public MathTran server. Several good (and perhaps not so good) reasons for this are

  • You don’t want to rely on a third party service.
  • Your users are in a secure or mobile environment, and do not have direct contact with the Internet.
  • You want goodies, such as baseline alignment of images, that at present require the page and the image to come from the same server.
  • You want to write code that works as if you had your own MathTran server.
  • You want a backup in case your own MathTran server (see below) goes down.
  • You don’t want your users to know you’re using MathTran.

You can get most or all of this by setting up a transparent proxy server, complete with caching if you need it. None of this should be at all hard for a web-developer, and if you need and write one please do let us know so we can share it. Who knows, perhaps there’s one out there already.

[Some clever Javascript programming, together with serving JSON, allows baseline alignment even when the images come from somewhere else. But for now I encourage you to set up a transparent proxy if you can.]

Heavy-weight installation

This will be, as the name suggests, more work. For a start, you will need Linux or Unix because the MathTran server uses named pipes and sockets in a way that Windows does not support. I hope to discuss this further in another post.

Printing mathematics

Let’s suppose you want to produce a high-quality PDF file from a web page that contains MathTran mathematics (or at least mathematics that MathTran can handle).

Well, you’ll need something to handle the ordinary text, and if that something is TeX then you can probably just feed the TeX-encoded mathematics into it. But suppose your using some other tool, such as Apache’s FOP. MathTran generates bitmaps, so then can be included into the output by FOP. But we want high-quality output, and that means using outline fonts.

Each bitmap image served by MathTran contain invisible metadata, including the dvi output from TeX specific to that image. This dvi output, when combined with a suitable header, can be processed by dvips to produce EPS files, which FOP knows how to handle. An alternative route, which is more work but which probably produce better results, is to teach the PDF-writer used by FOP how to translate the dvi output into PDF directly.

Compared to writing a high-quality typesetting program such as TeX, writing software that translates TeX output to EPS or PDF or whatever is fairly simple (or so I believe, not having written either). Integrating MathTran into an open source PDF formatting program should not be so difficult, and would certainly be easier than writing an alternative to TeX.

Here is an example. After the EuroPython 2007 conference Dinu Gherman created a simple test script (lightweight application) that shows how to use MathTran with ReportLab (which has an open source version).


Both WordPress and Wikipedia use (La)TeX as their input syntax, and use TeX typesetting to generate mathematical images. TeX is the mathematics notation used by research mathematicians and physicists. MathTran makes TeX typesetting available as a public web service, which allows for lightweight installation in third party applications.

The present situation is not satisfactory – Terry Tao has to do manual conversion work to turn his blog into a book, and I expect that PediaPress will have to work hard to get mathematics working in their output. However, I hope that I have shown how MathTran both improves things where we are and is part of the path that takes us to where we want to be.

[Clearly, there's more to say than we've said here. Please leave comments and I'll write another post.]


A Java client – 27 Feb 2008

Alex Clk has written a simple MathTran client in Java. To answer a couple of questions he asks in that post,

  • To change the size of the image, use D=<n> in the query string, where <n> ranges from 1 to 10.
  • The MathTran service has funding to August 2008, and is I expect that funding for 2009 will also be found.

Of course, the more useful and used it is, the easier it is to find funds.

IE has a bookmarklet length limit – 4 Mar 2008

Internet Explorer has a length limit on bookmarklets,  and Tim Hunt’s MathTran bookmarklet exceeds it.  With rewriting it can be cut down to fit, but I’ve not done that yet.  For more details see Browser Bugs on this page.

About these ads