Sunday, November 08, 2009

Google can render your equations for you!

In my last post I mentioned that Knol and Google Docs now have equation editing. What I didn't mention is that this is an undocumented feature of the public Google Chart api, and it's easy to use. For instance, if I wanted to include the Schrödinger equation on this blog. I would construct an url like this:

http://chart.apis.google.com/chart?cht=tx&chf=bg,s,FFFFFF00&chco=AACCFF&chl=i\hbar\frac{\partial}{\partial t} \Psi(\mathbf{r},\,t) = \hat H \Psi(\mathbf{r},t)

Put your code in the chl parameter. The chf parameter lets you specify a background color in RGBA, chco lets you set the foreground color in RGB. When you drop it in inside of an image tag you get this:



If you anticipate making 250,000 calls to the chart server a day, contact Google first at chart-api-notifications@google.com. There's no limit to how much you can use it, but they reserve the right to turn you off.

3 comments:

Anonymous said...

Firefox can render my equations for me! (It is called MathML.)

Warren Young said...

A-w-e-s-o-m-e. Several years ago I hacked up a LaTeX-to-GIF equation formatter for my own site. It works reasonably well, but never did figure out how to get it to composite onto anything but paper white. Fortunately my site's background is close enough to white that you can't tell without zooming in, which normal visitors don't do. Even ignoring that, the Google output looks better than mine, probably more because it's using PNG transparency, rather than the GIF "single magic color" transparency that my scheme uses.

I'm now itching to replace my current lash-up.

Edward Kmett said...

@Anonymous

Only on some platforms and if the client has the right fonts installed when Mercury is in retrograde and even when it can, the spacing and alignment is nowhere near as good as it is in LaTeX. Did they ever fix it on MacOS X?

Speaking as someone who once mistakenly assumed that he could use Firefox MathML support gainfully in a firefox plugin, let alone a web page, eight months of wasted development later, I find myself much more jaded.

←me