Offline Math: Converting LaTeX to SVG with MathJax

No-JS purists cheer, MathML stans clap back—SVG goes offline

TLDR: A new tool converts LaTeX equations into SVG images so pages display math offline without JavaScript. Comments split: MathML fans want cleaner, semantic math with perfect fonts, while others back SVG for universal, rock‑solid portability—key for anyone publishing math across browsers and e‑readers.

A dev just dropped a neat trick: turn LaTeX equations (the fancy math text) into SVG images so your pages work offline and don’t need JavaScript. Think: math that shows up even on picky e‑readers. After a messy past with PhantomJS (a ghost browser full of weird bugs), they now use jsdom (a lightweight “pretend browser”) to let MathJax do its thing and then spit out clean, standalone HTML. And the crowd had thoughts.

Enter the MathML squad, led by commenter sathomasga: “skip images, use MathML.” That’s a web format that tells browsers what the math means, and supporters say it looks better and keeps your fonts perfect. The SVG defenders clap back: images render literally everywhere, even on ancient e-readers, and don’t rely on a browser being smart about math. Cue the No‑JS gang waving flags, while the “just ship JS” crew rolls their eyes.

Hot takes fly: CDN anxiety (when a cloud server goes down, your math vanishes), font drama (MathML stans swear theirs looks cleaner), and jokes about EPUB readers being “allergic to JavaScript.” It’s a mini math war: semantics vs screenshots, elegance vs portability. The code lives on GitHub, the debate lives rent‑free in the comments.

Key Points

  • Pandoc’s --mathjax output relies on a jsDelivr CDN script, which fails offline and on devices without JavaScript support.
  • MathML via Pandoc’s --mathml works well in modern browsers, but SVG is presented as the most portable option across devices.
  • Conversion methods include using MathJax (CLI) or a pdflatex-based pipeline; a headless approach can inject MathJax and serialize the DOM.
  • A lightweight Node.js/jsdom implementation runs MathJax, blocks external URLs, cleans up scripts, and outputs standalone HTML with SVG math.
  • The mathjax-embed tool’s pipeline produces HTML that requires no JavaScript and fetches no external MathJax resources, working fully offline.

Hottest takes

"instead of converting to SVG, convert to MathML" — sathomasga
"Browser support is pretty robust" — sathomasga
"the output is much nicer (e.g. preserves fonts)" — sathomasga
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.