Notes on diffusion

How these pages fake having math

The HTML you are reading contains the LaTeX, not the pictures. A script swaps one for the other.

Each page is a plain text file. Where a formula belongs, the source file has the LaTeX between $…$ or $$…$$ — the same delimiters the MathJax-style setups use. At load, math.js walks the text nodes of the body, finds those delimiters (and \(…\) and \[…\]), and replaces each with the SVG that the worker renders for it. Nothing is pre-built, nothing is on disk but the script, the stylesheet and the HTML.

The endpoint

formel is a Rust math-typesetting engine compiled to WebAssembly. The Cloudflare Worker keeps one renderer per isolate, parses a bundled New Computer Modern Math font once, and answers with a standalone SVG:

Display style has to be asked for in the LaTeX itself, with \displaystyle; the worker always typesets as inline math, so the script prepends it for a display block. The inline=1 flag asks for the box-sized SVG: no margin, currentColor for the fill, and its own vertical-align, which is what lets the result drop into a line of text at the right height and follow the page's light or dark ink without a second render.

What the script does, and what it costs

The cost of doing it this way rather than at build time is that the first reader of a page waits for a handful of round trips and the formulas arrive as pictures of text — selectable only through the SVG's own title. The benefit is that the site is three static files with no pipeline, and a changed formula is a text edit.