This package consists of a Movable Type plug-in that makes it possible to write equations in LaTeX format in weblog entries. Equations are converted to PNG files which are stored as part of the generated HTML, using the data: URL. (Internet Explorer users will therefore be unable to view the equations; both Safari and Mozilla-derived browsers can display the equations.)
Acknowledgements
This code is derived from Kjell Magne Fauske's code, available from <http://fauskes.net/nb/htmleqII/>. I reworked it to integrate with Movable Type's environment. Changes:
- eqhtml.py now uses stdin/stdout instead of taking filenames on the command line.
- Instead of storing the PNGs in the filesystem, they're converted into inline URLs of the form data:image/png;base64,....
- Uses HTML tidy to parse the entry's HTML, instead of requiring proper XHTML input.
- In case of error, the original input is returned.
- The code in eqhtml.py has been rearranged in various minor ways.
Requirements
- Movable Type: I've only tried this plug-in with version 2.661.
- A LaTeX installation, to convert equations into a .dvi file.
- dvipng, to convert .dvi files into PNG files.
- Python: I've used this code with Python 2.3; it should work with 2.4, too.
- The ElementTree XML parsing library for Python, available from <http://effbot.org/downloads/#elementtree>.
- HTML tidy <http://tidy.sf.net> is used to parse the HTML-format input without requiring you to write them in valid XHTML.
Installation
- Once Python and ElementTree have been installed, put eqhtml.py somewhere. You could put it into /usr/local/bin or into your MT installation's plug-in directory; I use /www/scripts/.
- Edit mt-math.pl to use the correct path for eqhtml.py.
- Copy mt-math.pl into your MT installation's plug-in directory.
Usage
The plug-in adds a new text formatting type when you're editing a weblog entry. In addition to the usual 'None' and 'Convert Line Breaks' choices, you will now have a 'Math to HTML' choice that applies the equation-formatting filter. This means that you can't both convert link breaks and use math. In entries that use equations, you'll have to put <p> at the start of every paragraph.
Equations are indicated by <div> or <span> elements of class 'eq'. For example:
<div class="eq"> y = \int_0^\infty \gamma^2 \cos(x) dx </div> <p> An inline equation <span class="eq">y^2=x^2+\alpha^2</span> here.</p>
Unfortunately, Movable Type doesn't support very good error handling. If you make an error in the LaTeX equation, the plug-in has no way to report the LaTeX errors. Instead it will leave the HTML alone, meaning that you'll see the LaTeX source in the published version of the entry.
See <http://www.amk.ca/diary/archives/004046.html> for a sample entry in my weblog that demonstrates some equations.
Fauske suggests using CSS to align the equations a bit better:
/* Center block equations */
div.eq {text-align:center;}
/* Align inline equations with parent's content area */
span.eq img {vertical-align:text-bottom;}