Now on ScienceBlogs: Dr. Rolando Arafiles: Antivaccine rhetoric, colloidal silver for the flu, and Morgellons disease

Enter to Win

Science After Sunclipse

A blag for math, physics and the New Enlightenment

Search

Profile

Blake Stacey is a physics boffin and science-fiction writer who wandered the Earth and eventually settled in the nation-state of Denial.

Recent Posts

Reader Favourites

Comments are temporarily disabled while I work on other things and slowly recharge my enthusiasm for blogging. In the meantime, why not read one of these?

front-cover-sidebar.jpg Support independent publishing: buy this book on Lulu.

Spiffy Icons

Recent Comments

Archives

Categories

Blagnet

« Skeptics' Circle #105 | Main | Exponent FAIL: Or, the Difference a Few Zeros Can Make »

How We (Don't) Write Mathematics on the Web

Category: Elitist BastardryMathematicsPopularizationSoftware
Posted on: February 16, 2009 10:50 AM, by Blake Stacey

I often joke that the technology for typesetting equations on the Web is of all-consuming interest to about twelve people. This is, of course, the kind of joke I make out of bitterness: it's a joyous day indeed when I meet one of the other eleven! Still, things can't be as bad as all that, since Brian Hayes managed to convince American Scientist — one of the few science magazines which hasn't yet seriously pissed off working scientists — to print an article on the problem. This bit of the introduction lays out the situation fairly well:

The truth is, the basic protocols of the Web offer almost no support for rendering mathematics or other specialized notations such as chemical formulas. Presenting such material on a Web page often requires software add-ons or plug-ins to be installed by the author or the reader or both. Fine-tuning the display of mathematics can be a fussy and finicky process, not much easier than formatting equations with a typewriter. The results sometimes render differently—or not at all—in various Web browsers. This is a sad situation: As the Web has evolved into a thriving marketplace and playground, the scholarly and scientific community that created the technology has not been well served.

The confused state of online mathematical typography is worrisome as well as sad. In years to come the Web will surely be the most important conduit for scientific information. Already it is a major channel for distributing publications and preprints in many disciplines, and it is becoming a venue for less-formal jottings and conversations—everything from homework assignments to blogs. Ideally, the Web would serve as an extension of the blackboard where people gather to talk about science and math during coffee breaks. We need chalk for that blackboard.

The problem is not one of simple neglect. Over the years there have been many earnest efforts to build a reliable facility for writing and reading mathematics online. The trouble is, no one solution has yet gained the kind of widespread adoption that would make it a standard, supported in mainstream Web servers and browsers.

You took the words right out of my hacked-together LaTeX-rendering plugin!

Hayes goes on to describe the various technologies cooked up to deliver mathematics over the Web: PDF, MathML, assorted ways of rendering TeX into images. Each has advantages and drawbacks. Pre-rendering equations written in TeX (or some flavour thereof) as GIF or PNG images is how I write things like this:

\displaystyle \frac{x^2}{a^2} + \frac{y^2}{b^2} = 1.

Or this:

I_x I_y - I_y I_x = \left(\begin{array}{ccc}0 & -1 & 0 \\ 1 & 0 & 0 \\ 0 & 0 & 0\end{array}\right) = I_z.

Most content-distribution platforms require an extra plugin to insert equation images. For blogging software like WordPress and Movable Type, there is LaTeXRender, which takes a string of text like \frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 and spits out an image. WordPress.org is still fixing bugs on the implementation which they use for the blogs they host, but glitches aside, it seems to function pretty well. The Movable Type analogue requires MT 4.0 or higher, and has not yet been installed on ScienceBlogs.

(How do I make the equations I use? Magic. Laborious, laborious magic.)

If you display your equations as pictures, they'll work in just about any browser, as the typesetting is done server-side ahead of time (rendering plugins typically provide the TeX source as alt text for accessibility purposes). This is convenient for people who are just Googling around for homework help and don't have the time or the inclination to install special browser plugins. Wikipedia does mathematics in this way, for example. One downside is that because the images are computed beforehand, there's no way to make them look right to the end user: browsers can be configured and reconfigured in all sorts of ways, and so the colours and sizes of the equations can end up completely wrong for their surroundings. The problem only gets worse when people start reading your content through RSS feeds. . . .

At the opposite technical pole is MathML, which is what its name says, a Markup Language for Mathematics. Of this, Hayes says,

On the Web, however, MathML has not exactly swept away the competition. One reason is lack of support in browsers. In the early years, the only way to read MathML Web documents was with plug-in software. More recently a few browsers—notably those of the Mozilla family, such as Firefox—have gained native support for MathML. But there is still confusion over how MathML content should be embedded in an HTML document. Moreover, MathML has not solved the fonts problem; readers are still responsible for installing appropriate fonts.

Another factor inhibiting the spread of MathML is simply that TeX is deeply entrenched, particularly in physics, mathematics and computer science. If you live in a TeX-centric universe—I have a friend who even writes love letters in TeX—it's hard to see any benefit of a new and very different language.

Who's been peeking into my LaTeX sonnet files?!

If you're willing to make your readers go through a couple software-installation steps, you can use a platform which turns TeX into MathML which is then rendered by the reader's Web browser. This is the approach taken by The n-Category Café, for example, a blog which serves a sufficiently specialized community that resolving a few TeXnical issues is seen as a reasonable price to pay for mathematics which meshes well with its surroundings.

An intermediate solution is the JavaScript-based tool jsMath, which is basically a TeX interpreter stuffed inside a JavaScript program. This allows equations to be rendered on the fly, but it can get bogged down when lots of content has to be processed. The same caution goes for Josh John Forkosh's MathTeX, which is pretty easily integrable with everything.

Share this: Stumbleupon Reddit Email + More

TrackBacks

TrackBack URL for this entry: http://scienceblogs.com/mt/pings/100020

Comments

1

I am a bit of a typography buff, and find this topic fucking fascinating! Nice post, holmes!

Posted by: Comrade PhysioProf | February 16, 2009 1:22 PM

2

Thank you.

Posted by: Blake Stacey | February 16, 2009 4:28 PM

3

I find that the LaTeX plugin at Wordpress suffices for the posts I usually write when I have the urge to write about math, though I was frustrated when I couldn't get matrices to render once. Oh well, what do you want for nothin'?

Posted by: Tyler DiPietro | February 16, 2009 8:19 PM

4

Working with matrices involves a strange mix between HTML parsing and LaTeX parsing. The syntax for the array environment requires an ampersand sign (&) to separate matrix cells in a row. The problem is that WordPress interprets the & for its own purposes and screws everything up, so you have to use the HTML entity & every time you would say "&" otherwise.

The sheer amount of time I spend dealing with such nonsense. . .

Posted by: Blake Stacey Author Profile Page | February 16, 2009 10:58 PM

5

You would think there'd be an easy solution to this. But I think rendering as a png seems to be the easiest of all possible solutions.

On a related note, I've often wondered how one might parse Plankalkül code. It suffers from many of the same problems.

Posted by: Brian X | February 17, 2009 2:11 AM

6

You've managed to collect several of the links I had squirreled away and mention at least a couple I hadn't seen. Great post. I'm keeping a copy of this one handy.

Posted by: efrique | February 17, 2009 7:25 PM

7

w00t, thanks for the shout-out to mathTeX and the JS hack.

I made a mistake (twice!) on that page, now corrected: it's John Forkosh, not Josh.

Posted by: Randall | February 17, 2009 7:39 PM

8

In practice, you could use PNGs with transparent backgrounds to partially solve the problem of clashing colors. It would still be a problem if the user's background color matched that of the equation, though. Size would also be a problem, being the same regardless of the user's preferences.

I'm particularly interested in this part of the AS article:


Ideally, the Web would serve as an extension of the blackboard where people gather to talk about science and math during coffee breaks.

How about integrating LaTeX-rendering into popular IMs? Most IM protocols already support directly sending/receiving images, so it should be possible. It would sure beat the painful "type latex code, compile, email compiled file" routine.

Posted by: FO | February 19, 2009 1:12 AM

9

It's not too hard to configure LaTeXrender to output PNGs with transparent backgrounds. My solution was to employ the ImageMagick convert utility. LaTeXrender uses LaTeX to turn text into DVI, then uses dvips to make that DVI into PostScript, and then runs ImageMagick to transform the PostScript file into a PNG. By throwing in a -transparent switch, the background of the PNG can be made see-through. Pages like this one were made by putting a line like the following into class.latexrender.php:

$command = $this->_convert_path." -density ".$this->_formula_density." -trim -transparent \"#FFFFFF\" -negate".$this->_tmp_filename.".ps".$this->_tmp_filename.".".$this->_image_format;

This gives light text on a transparent background, suitable for placement on a dark page. Of course, this goes awry when said page is viewed in an RSS reader with a different colour scheme.

Integrating LaTeX with IM is an interesting idea.

Posted by: Blake Stacey Author Profile Page | February 19, 2009 1:54 AM

10

How about integrating LaTeX-rendering into popular IMs?

Adium used to support it in the core program. Now there's a plugin.

Of course, it has to be installed on the receiver's end, and the sender needs to know the format (wrap in double-dollar signs), but there you go.

Posted by: John Armstrong | February 19, 2009 8:33 AM

11

I authored the plugin that wraps LaTeXRender for MT. Apparently the port of LaTeXRender from PHP to Perl was shoddy and AFAIK, someone was rewriting it. I haven't heard anything recently about it though :(

It seems like there are two issues for you: a) it needs to be easy to generate math via a keyboard and b) it needs to be easy for you to integrate it in your posts (and a sub-issue, c) it needs to be viewable by other people visiting without installing extras).

Does that seem like a correct assessment or is there something else I'm missing?

Posted by: Nick | February 19, 2009 1:28 PM

12

That's a fair assessment of the situation. It'd also be nice if equations could be used in the comments to posts, but that's more of a sub-issue.

Posted by: Blake Stacey Author Profile Page | February 19, 2009 1:40 PM

13

Re: IM, could imagine a LaTeX analogue of http://dpaste.com/ -- type in LaTeX, get back a short URL for a page with the code and image, send that on to your correspondent.

Only useful in a certain sort of situation -- when the LaTeX code isn't easily readable, and the IM-to-browser context switch is an acceptable cost. But that probably happens sometimes.

Anyway, idle talk unless I get building. :)

Posted by: Randall | February 19, 2009 5:55 PM

14

I've had "learn TeX basics" on my to-do list for 12 years now. Your post reminded me it's high time I addressed that.

Posted by: Brian | February 21, 2009 4:34 PM

15
Apparently the port of LaTeXRender from PHP to Perl was shoddy

appropriate, for a port from one shoddy language to another.

(full disclosure: i make my living writing Perl, and have dabbled in PHP.)

Posted by: Nomen Nescio | February 21, 2009 5:23 PM

16

One wonders if more math would get done if people could bloody well type their equations.

Believe it or not, even this math-challenged entity has bewailed the difficulty. I get really tired of having to search for a jpeg whenever I want to show an equation. Grr. Argh.

Posted by: Dana Hunter | March 7, 2009 5:41 AM

17

I try to avoid writing equations on my blog, and this is one of the reasons. Thankfully, simple arithmetic can be symbolized by symbols on a keyboard.

Posted by: Cujo359 | March 11, 2009 6:06 PM

18

Something else to think about: screen-readers and other devices like that for the disabled would have an even more difficult time with equations, particularly in image form.

Posted by: Meredith | March 21, 2009 9:27 PM

19

This is why LaTeXrender and such programs insert the TeX source code used to render each equation as ALT text in the image tag. It's not a great solution, but I'm not sure a better one has been cooked up.

Posted by: Blake Stacey Author Profile Page | March 22, 2009 11:17 AM

ScienceBlogs

Search ScienceBlogs:

Go to:

Advertisement
Collective Imagination
Enter to win the daily giveaway
Advertisement
Collective Imagination

© 2006-2009 ScienceBlogs LLC. ScienceBlogs is a registered trademark of ScienceBlogs LLC. All rights reserved.