This post is about putting charts and formulas in your web pages, creating editable and scalable PNG files, and the need for a standard for embedded application data in image files.

Earlier today I looked at Google Charts, which allows you to ‘dynamically generate charts’. Send a Google a suitable GET request and you will get a pie chart, a bar chart or whatever, as specified in your query string. Their example is

http://chart.apis.google.com/chart?cht=p3&chd=s:hW&chs=250x100&chl=Hello|World

which will produce the chart
Hello world pie chart

This is rather similar to MathTran, where are URL such as

http://www.mathtran.org/cgi-bin/mathtran?D=3;tex=1%20%2B%201%2F2%20%2B%201%2F4%20%2B%20%5Cldots%20%2B%201%2F2%5En

produces the image
1 + 1/2 + 1/4 + \ldots + 1/2^n

Google Charts allows you to dynamically create graphs, and MathTran allows you to dynamically create rendered mathematical formulas. The Google API is rather better than MathTran’s, and it is certainly better documents. But MathTran has something that Google Charts doesn’t have … yet. The PNG’s returned by MathTran can be edited.

Here’s how. If you open a MathTran image, such as the one above, in a text editor you will see that it contains some metadata, included the TeX instructions 1 + 1/2 + 1/4 + \ldots + 1/2^n that created the image. So to edit the image, extract the TeX source, edit the TeX source, and send it off to MathTran for re-rendering into a PNG image. The ‘D=3‘ in the URL specifies the scale of the image. At this point, I will own up and admit to being the main developer of MathTran, and many thanks to JISC and my employer The Open University for funding this project.

I think it would be great if the images returned by Google Charts were also editable, for then they would be much more useful. For example, another application could take a Google chart and convert it into PostScript or SVG for print purpose. Or authors could collaborate by sending charts to and fro by email, editing each other’s work.

This is already possible, on some platforms, with MathTran images. The developers at Humanized Inc, a Chicago startup, have created a Enso TeX Anywhere application that allows you to insert MathTran rendered formulas in HTML email (Windows only, I’m afraid). Their application also allows you to unrender the image, to recover the underlying TeX. I was well impressed by their providing the unrender function, because this possibility is not at all well documented in the source code.

If you are interested in using Enso TeX Anywhere, then I suggest you look at this MathTran wiki page. You can also use MathTran to put TeX images on your web page.

Also on the MathTran wiki is a discussion of a standard for math PNG files. This standard needs more work, and I’d like it to be able to cover both MathTran images and the charts produced by Google. I hope to make a more technical post latter about creating such a standard, and another on the tricky problem of baseline alignment of dynamic images, \int _0^1 x^2\, dx for example.

Finally, a few words about the 2007 EuroPython Conference. While I was there I spoke with Guido van Rossum, who told me about the Google Charts application when I told him about MathTran. I hope to do better at following up leads in future. Also at EuroPython, I gave a talk on MathTran, and Jono DiCarlo of Humanized was at the conference, and hence picked up on MathTran. So I got a lot out of that conference, and look forward to the next one. I’m particularly keen to meet with Django people.

Postscript (1 Feb 2008): Chris Heilmann has published on his blog a method for transforming data in an accessible table into a Google chart. This is very nice, and an example of how dealing with accessibility first can lead to a sound design.

Advertisements