Mechanics blog update

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 <div class="math">...</div> tags to produce display equations. The stuff between the tags is processed by a JavaScript equivalent of the TeX formatting engine to produce the equations. And before yesterday, I had the blog set up to process my posts through a customized version of MultiMarkdown, Fletcher Penney’s fork of John Gruber’s Markdown.

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 \[...\] 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.

Tags:


3 Responses to “Mechanics blog update”

  1. Fabien says:

    Hello, I am looking for a way to display math equations in Typepad blogging page.

    Do you have any tip on how to do this?

    Yours, FC

  2. Dr. Drang says:

    I’m not familiar with Typepad, other than I know it’s a Six Apart product, just like Movable Type, which is what I use.

    The trick of getting jsMath working on your blog is to

    1. download jsMath from Davide Cervone’s site (see the link in the post above);

    2. upload jsMath to your blog’s server, taking note of where it is in the directory structure; and

    3. change the blog template using Cervone’s instructions to call jsMath.

    Step 1 is easy. Steps 2 and 3 may or may not be easy, depending on how TypePad is set up and how configurable it is. Good luck!

  3. jason says:

    This is a great site. I have just completed cahpter 1 and these solutions will be a big help as I read on!