Compiling LaTeX to html with LaTeXML
LaTeXML (homepage) was developed for
the DLMF (the online Abramowitz and Stegun).
There is a tool latexml
which converts .tex
to an xml representation
and another tool latexmlpost
which converts the xml file to html5 and
uses MathML for the math content. MathML equations are tagged with
their latex source as alt text.
The github repo shows that it is under active development: in the last month there were 14 pull requests merged, 10 issues closed. The latest official release was 0.8.3 in July 2018.
Usage
latexml --dest=output.xml input.tex
latexmlpost --dest=output.html output.xml
Evaluation
Nearly everything works well:
- images
- equation numbering and references
- section numbering and table of contents
- double primes
- marginpars
- qedhere
- http links
- em-dash and en dashes
There’s just one big drawback: Firefox aside, modern browsers don’t render MathML. That’s easily fixed by adding
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/MathJax.js?config=TeX-MML-AM_CHTML"></script>
inside the <head>...</head>
part of the html output.
This is easily the best result so far.
Further links
A much better and more in-depth description of how to get good results
with latexml
is given in this blog post by Andy Tonks and Julia
Goedecke. Here are their example notes.
For personal reference, the commands I use are
latexml main.tex --dest=html/main.xml
cd html
latexmlpost main.xml --dest=main.html --split --splitat=section --navigationtoc=context --javascript="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=MML_HTMLorMML" --css=LaTeXML-navbar-left.css --css=normalize.css --urlstyle=file
with my modified css files in the html
directory.