glu
TeX math

Typeset TeX math

This recipe writes formulas in Markdown with TeX dollar syntax: inline math between single dollars, display math between double dollars. The TeX is converted to MathML and set by glu’s OpenType-MATH engine, so no Pandoc, no JavaScript, and no external converter are involved.

Rendered page with inline and display formulas

Full example: glu/markdown/tex-math

Step 1: switch math on

Math parsing is off by default, so a $ used as a currency sign is never reinterpreted. Enable it in the frontmatter:

---
title: TeX math in Markdown
lang: en
css: tex-math.css
math: true
---

The mass-energy equivalence $E=mc^2$ sits inline with the prose.

The quadratic formula, set as a display equation:

$$x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}$$

A summation in display style, where the engine enlarges the operator
and places the limits above and below:

$$\sum_{i=1}^{n} i = \frac{n(n+1)}{2}$$

Step 2: provide a math font

The engine needs a font carrying an OpenType MATH table (Latin Modern Math, STIX Two Math, XITS Math, Cambria Math, …). The dollars become a <math> element internally, and that element looks up font-family on itself, so point it at the font in the stylesheet:

@font-face {
  font-family: "Latin Modern Math";
  src: url("latinmodern-math.otf");
}

math {
  font-family: "Latin Modern Math";
  font-size: 12pt;
}

Without a MATH-table font the formulas cannot be set; this is the one required piece of configuration.

Step 3: run it

glu tex-math.md

Safe dollars

Opening and closing delimiters follow the same strict rule Pandoc uses: the opening $ must not be followed by whitespace, the closing $ must not be preceded by whitespace and must not be directly followed by a digit. So it costs $5 and $10 stays plain prose, while $x+1$ is a formula. Dollars inside code spans and fenced code blocks are always left alone.

What works

Fractions, roots, super- and subscripts, Greek letters, big operators with limits (\sum, \prod, \int), stretchy fences (\left( … \right)), primes, and named operators like \sin or \lim. An unknown command degrades to its name as an upright identifier instead of failing the render. Matrices, \begin{} environments, and accents such as \hat are not yet covered; the full table is in the Markdown mode reference.

Accessibility for free

The example sets format: PDF/UA-2 in its frontmatter. Because each formula becomes MathML, it rides the full accessibility path automatically: a Formula structure element with a text alternative, plus the MathML source embedded as an associated file for assistive technology.

Related