Fontlex Math

The box below is a plain text box holding a little LaTeX. The font typesets it: fractions, roots, superscripts and subscripts, Greek letters and a few symbols, laid out by the text engine that lays out the letters, as you type. The characters stay exactly as typed. No script on this page lays anything out.

Each line is read on its own. A construct that isn't complete yet, or that breaks a rule below, stays as its characters until it is. Inside a fraction the caret stays at the fraction's start: the fraction's glyphs are drawn where they belong, but take no room of their own.

What it typesets

How it works

Every character gets four empty glyphs after its own, and 238 passes, compiled to OpenType substitutions, rewrite them: they match braces, check what is complete, give each character its role and size, add up widths (in two digits, so the rules stay few), and finally turn every glyph into something drawn or a mover. Positioning then does the layout. Outside fractions, text keeps its advance and is raised or lowered. Inside a fraction nothing advances: each glyph is a mark attached to the one before it, and movers between them carry the fraction's chain to the numerator, back over the bar and down to the denominator, with the bars and root signs' overbars drawn by pieces hung off the chain.

The compiled font has 47,653 glyphs and 1,097 substitution and 301 positioning lookups. OpenType's lookup list holds only a few thousand, so the compiler shares nested lookups between passes and splits any glyph that would need more than a few dozen outcomes in one pass into two steps.

Results

Each line is shaped with the font, what it draws is read back from the glyphs (characters by name and size, rules from their outlines), and compared with a separate Python model of the layout (layout.py), to the font unit. Core Text (Safari, macOS) gives the same results.

LinesCountHarfBuzz
Edge cases (incomplete and broken input)44100.0%
Random formulas, some mistyped2,000100.0%

This page checks a sample each time it is built. The full check, 20,000 random lines and the edge cases in HarfBuzz and Core Text, matches the model on every line: see math/README.md.

Checked by screenshot (text against the outlines placed as HarfBuzz places them) in Chrome and Safari's WebKit on macOS, and in Chromium and Firefox on Linux and Windows; and by typing into the box key by key, which ends as the same text set at once does. A keystroke that completes a construct changes glyphs before the caret, and with a simpler test font Chrome kept their old shaping, so this page still makes it lay the box out again on every input (by switching font-kerning). Native Windows apps (DirectWrite) aren't checked.

Base font: JetBrains Mono (SIL Open Font License).