Skip to content

Render math as native MathML via Pandoc (offline support) #626

@srid

Description

@srid

Problem

Currently, math rendering requires client-side JavaScript loaded from CDNs:

  • MathJax: cdn.jsdelivr.net/npm/mathjax@3
  • KaTeX: cdn.jsdelivr.net/npm/katex@0.16.9 (CSS + JS + auto-render)

These are opt-in via <snippet var="js.mathjax" /> or <snippet var="js.katex" /> in page.headHtml. Generated sites cannot render math when viewed offline.

Proposed Solution

Use Pandoc's built-in --mathml support (writerHTMLMathMethod = MathML) to render TeX math as native MathML elements at build time.

Implementation

  1. Set writerHTMLMathMethod = MathML in the Pandoc writer configuration
  2. Pandoc will emit <math> MathML elements directly in the HTML output
  3. No client-side JavaScript needed — browsers render MathML natively
  4. Remove or deprecate js.mathjax and js.katex snippets (or keep as opt-in fallback)
  5. Optionally add a small CSS snippet for MathML styling

Browser Support

Native MathML is supported in:

  • Firefox (long-standing support)
  • Safari (long-standing support)
  • Chrome 109+ (January 2023)

This covers the vast majority of current browsers.

Benefits

  • Generated site works fully offline
  • No client-side JavaScript needed for math
  • Faster page loads
  • Math is part of the HTML document structure

Tradeoffs

  • Very old browsers (Chrome < 109) won't render math correctly
  • MathML rendering may look slightly different from MathJax/KaTeX

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions