May 31, 2006 at 9:03 PM by Dr. Drang
Until yesterday, I’d been having a pretty productive run on my mechanics blog: 10 posts in 7 days, with at least one post each day. That stopped yesterday because I decided it was time to rejigger the site before it got too unwieldy to make changes.
The blog uses Davide Cervone’s jsMath, to format its equations. In its most basic form, jsMath looks for
<span class="math">...</span> tags to produce inline equations and
My customization was the result of laziness and hubris (two of Larry Wall’s three great virtues): there was not way I wanted to keep typing
<span class="math"> over and over, and I figured I could just jump into Fletcher’s code and add the ability to create the tags jsMath needs. And it worked. I decided to use
$$ to delimit inline equations and
$$$ to delimit display equations--one more dollar sign than TeX uses because I wanted to be able to use single dollar signs as themselves. The system worked fine for months, and would still be working except…
Fletcher Penney is far more energetic than I am, and he keeps improving MultiMarkdown. If I want to keep up, I have to keep applying my additions to each new version that comes out, test to make sure it still works, and make alterations to my code if it doesn’t. Too much effort (see laziness above).
Fortunately, Davide Cervone has, as part of the jsMath package, a preprocessor of sorts, tex2math, which will take the LaTex delimiters
\[...\] and turn them into the span and div tags for later processing. Of course, in a Markdown environment backslashes are the escape character, so to get them to appear in the output they have to be doubled. Thus,
\\(...\\) for inline and
\\[...\\] for display, not much more typing than with the dollar signs.
(You maybe asking why I didn’t just use the tex2math preprocessor to begin with. Wouldn’t that have been even lazier than hacking around in MultiMarkdown? Well, yes. Either I missed tex2math when I first started using jsMath, or it wasn’t part of the package back when I first started using it. Let’s pretend it was the latter and I’ll feel better about myself.)
So the upshot of all this is that I wanted to start using tex2math and the standard version of MultiMarkdown. In some ways, this was easy. Replace my hacked up MultiMarkdown with the real thing and add a couple of tex2math lines to the Movable Type templates for the blog. But I also had a backlog of 20-some posts with my now-obsolete
$$$ notation that would have to be changed. I certainly didn’t want to edit them one by one, so I went through MT’s export procedure to get one big text file on my computer with all the entries and did some simple search-and-replaces. Because my opening and closing delimiters were the same, the replacements weren’t always correct, but there were probably only a couple dozen that needed fixing. I then deleted all the entries from the blog and imported the edited text file. Voila! A blog that looks the same but is different--and easier to update--under the hood.