---
title: Playing with MathML
---

A while ago I wrote [a blog post about the coherence of measurement
systems](2020-05-22-metric_red_herring.html), 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](2020-05-22-improving_our_units.html), and that
soon grew into [an entire directory in my "projects" section](../projects/units)
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](https://en.wikipedia.org/wiki/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:

 - **Content MathML** provides markup to describe mathematical expressions. This
   mostly consists of "applying" operations/relations to other expressions, much
   like a verbose XML version of [s-expressions](2017-08-29-s_expressions.html).
 - **Presentation MathML** provides markup to describe graphical elements, like
   sub/superscripts, rows/tables, numerals, etc. This feels like using TeX,
   since it's focused on placement and rendering rather than meaning.
 - **MathML Core** is a subset of MathML that's suited for embedding in HTML,
   and purposefully avoiding some of the complications and redundancy of the
   full MathML standard (e.g. styling, spacing, etc. which are better suited to
   CSS when embedding in HTML). AFAIK MathML Core is a restricted version of
   Presentation MathML; I don't think any Content MathML is supported.

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](https://github.com/davidcarlisle/web-xslt/blob/main/ctop/ctop.xsl)
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.
