Playing with MathML

Posted on by Chris Warburton

A while ago I wrote a blog post about the coherence of measurement systems, why that is the most important feature of the metric system, and why I find arguments about “multiples of ten” to be a meaningless distraction from this beautiful fact.

That post (like many of the pages on this blog!) was written as a long-form rant which I can link to, rather than re-hashing the same points over and over in comment sections every few years. It lead me to write a companion post about further improvements we can make, and that soon grew into an entire directory in my “projects” section which I’ve been adding to ever since.

There are still many rough edges and “TODO” comments, but I’ve recently given that section a major update by switching its formulas and equations to MathML (previously it was using LaTeX, rendered via an ad-hoc mixture of Pandoc, MathJax, etc.). MathML is the W3C’s recommended language for marking up mathematical content on the Web, although it has a few peculiarities to get used to!

Support by user agents

Firefox seems to have decent support for Presentation MathML (see below for the subsets!), which is good enough for me. Chrome’s support seems to be pretty crap at the moment; it was non-existent until about a year ago (since Google devs had previously dropped WebKit’s poorly-maintained implementation when they forked off Blink). It’s also unsupported in EWW, for what it’s worth ;)

Hopefully support will improve over time. In any case I’d write things “once and for all”, rather than having to keep translating it to whatever approach happens to be popular at that moment. The nice thing about choosing MathML for this is that it can describe the intended semantics, as well as merely laying out symbols.

The many subsets of MathML

MathML is currently at version 3, so I recommend ignoring any previous versions. MathML 3 defines quite a lot, but there are three interesting subsets:

Given this list, it’s clear that I should be targetting MathML Core, since all of my writing is embedded in HTML. However, I’ve found it better to write in Content MathML, and convert to MathML Core during rendering (I’ve found this XSL stylesheet useful, and added a few of my own rules too). This way, I can focus my writing on the subject matter, and leave all of the parentheses, infix operations, etc. up to the transformer.