HOME

MathML in Org-mode HTML export

Publishing math on the Web

I have always wanted to write something about the Riemann zeta function. But I couldn’t, not without the ability to publish in a Free and Libre Open Standard for publishing equations on the Web.

Fortunately I’ve solved it, and it was so easy. Just hook up Emacs, org-mode, spend hours reading obsolete documentation, use Docker, Gitlab CI, an obscure latex→MathML Perl library, and wrangle some Perl. Easy.

For full implementation details, see the source code of this website.

org-mode

Org-mode is like Markdown, but better. It’s older, less popular and harder to compile to HTML.

When you write in Org mode, you can include LATEX anywhere in your document. By default, the export to HTML is handled using MathJax, a perfectly capable and widely used JavaScript library which handles all of the headaches of displaying math on the web for you, and does so transparently.

MathML

We can’t have that. An important sign of intelligence is not liking JavaScript. Think of all the blind math graduates.

MathML is an open and efficient standard by the W3C. It is in good company, along with XSLT, SVG and XHTML 2.0.

You can include MathML directly inline in the HTML, which is rendered natively by modern browsers like Chrome and also by Firefox.

(Update: couldn’t have been more wrong. Firefox displays MathML since forever, and Chrome doesn’t want to. But don’t let the truth get in the way of a bad joke.)

Latexml

Because MathML is modern (it was only introduced in 1998), org-mode doesn’t support it natively yet. Luckily, there is a very popular package that you can’t install on Mac OS, called latexml, written by a person who I definitely know, and who is definitely not susceptible to a supply chain attack.

Install latexml on Debian because that’s what you’re running in 2021:

apt-get install -y --no-install-recommends latexml

If you like Homebrew, and you want to keep liking it, don’t use it to install latexml.

org-publish

To tie it into org-mode, all you need to do is spend 3 hours reading the Emacs source code because the documentation is out of date and makes no sense. Easy:

(setq org-latex-to-html-convert-command "latexmlmath '%i' | sed -e 1d | perl -p -e 'chomp if eof'")

Don’t worry about the shell injection vulnerability, be happy.

Set the tex option to 'html in your setup.org file:

#+OPTIONS: tex:html

Now publish your project:

(org-publish-project "my-project")

And find something interesting to say about the Riemann zeta function.

The Riemann zeta function

The Riemann zeta function is a mathematical equation that proves infinity:

ζ ( s ) = n = 1 1 n s

It was independently discovered by Riemann and Zeta.

The n s part is widely believed to be included by Riemann to annoy his reviewers.

The Riemann-Zeta-Choice function is a British extension:

R Z C ( s ) = 1 - s + 2 - s + 3 - s +

It’s exactly the same but it’s easier to type.

Date: 2021-06-30

Copyright © 2021 Hraban Luyat