December 22, 2009 at 10:54 PM by Dr. Drang
I’ve been seeing a link to this article, “A jQuery plugin to directly embed LaTeX into your website or blog,” on delicious.com/popular today. I have a strong interest in this topic—most recently expressed here and here—so I followed the link to have a look. It was disappointing.
Basically, the plugin
- Looks for a
- Extracts the contents, which should be valid LaTeX.
- Sends it off to Code Cogs LaTeX Equation Editor for processing into one of three image formats.
- Grabs the resulting image.
- Puts the image on your page.
You can use other online LaTeX generators in place of Code Cogs, but they all generate images.
How is this disappointing? Let me count the ways:
- It won’t do inline equations. Reliance on
<div>s forces each equation into its own block.
- You have to write the LaTeX and call the plugin for each equation.
- It relies on the LaTeX generator site to be up and running when someone visits your page.
- Although the equation is just a static image, that image has to be generated every time the page is visited.1
- Images don’t scale with the font size of the page.
- Images look like shit when printed because they’re lo-res bitmaps.
Andreas Grech, the plugin’s author corrects me in a comment below.
Point 2 is wrong. You need only call the plugin once per page. I read the source code of his example page too quickly and came to the wrong conclusion. He calls the plugin several times on that page because he’s demonstrating various ways of using it.
Point 1 is at least half wrong. Because the plugin works off classes, you can put equations in
<span>s. I’m not sure there’s a way to get LaTeX’s inline style, which is different from its display style.
His comment is a good defense of his plugin. It doesn’t persuade me to use the plugin, but it’s worth reading.
The jsMath system, which has been around for quite a while, has none of these disadvantages. OK, the equations are “typeset” on the page dynamically, but the work is done locally on the browser’s computer, so it’s well distributed and not being performed by some innocent third-party server.
You could argue that images have more universal support than the CSS tricks jsMath uses. That’s true, but apart from Mobile Safari, is anyone really using a browser that isn’t on jsMath’s supported list?
Maybe I shouldn’t be so harsh; after all, I’ve written plenty of scripts that must seem foolish to others. But if you want to use images for your equations, it’s far more efficient to generate them statically. You could even write a script that does what this plugin does, but saves the generated images to your site and inserts the appropriate
<img> tags into the HTML. Such a script would be run just once—or, at most, a few times as you’re editing the page.
And if you want equations that actually look good on your page, use jsMath.
I can see where this would be an advantage as you’re writing and editing the page, but once it’s done you’re just using the generator site’s bandwidth for no good reason. ↩︎