Bento, the office suite that fits in a file
TypeScript mit-licenseofficeoffice-365office-suiteoffice-toolsoffice365open-sourcepowerpointself-hostedsingle-page-appslidesslideshareslideshowslideshow-galleryslideshow-makerslideshows
slides: maths is Bento's own engine — Temml replaced, Typst input, 66 KB smaller (#492)
nyblnet63c595f726c7
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 6a9c5d21..2d8d9bb8 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -1366,6 +1366,14 @@ jobs:# step. Decisions in slides/src/steps.ts, DOM-free (#282, option 2).run: node scripts/test-slides-steps.ts+ - name: Maths engine rig+ # slides/src/maths replaced Temml (2026-09-15): never-throws contract;+ # the 91-formula reference set matches Temml's FROZEN trees on ≥95%+ # (scripts/fixtures/maths-reference.json; every mismatch must be a+ # listed residual); Typst ≡ LaTeX on the shared tree; every emitted+ # attribute is the engine's own; the symbol table has no duplicates.+ run: node scripts/test-maths-lite.ts+- name: Reveal authoring rig# Reading order (top-to-bottom, then left-to-right, rows by vertical# overlap) is deterministic; the verbs continue the slide's sequence;diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 26ef4af1..50ba14ff 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -39,6 +39,20 @@ pre-1.0.scripts, `--fail-on warning` for a strict exit code. A document JSON worksas input too, checked inside the built shell. The other half of the agentloop that `AGENTS.md` describes: write, check, fix, check again.+- **Maths is Bento's own now, and it reads Typst.** Formulas in text used to+ go through Temml, a 64 KB library that every saved deck carried. A small+ engine of our own (slides/src/maths, about 8 KB) renders them instead, so+ every file you save is about 78 KB smaller, and nothing in the file changes:+ a formula is still the `$…$` source you typed. Measured against Temml on 91+ formulas, from our own decks and from Temml's own list of supported+ functions: 97.8% render pixel-identical, and the rest are places where+ Temml drew nothing on Chrome — `\overline` and `\underline` now draw their+ rule. New: Typst maths, asked for by thimotedupuch (#358) — write+ `$typst: a/b$` (or `$$typst: …$$`) and the formula is read as Typst:+ `sqrt(x)`, `sum_(i=1)^n`, `mat(a, b; c, d)`, `cases(…)`, `"if" x`. A plain+ `$…$` is LaTeX as before. Not covered, for now: `\substack`, `\xrightarrow`,+ chemistry (`\ce`), `\tag` and `\hline`; a formula using them shows as+ typed, the way any TeX Temml refused always has.- **A deck can be written the short way.** An AI agent writing a deck usedto spend most of its output on fields nobody chose — rotation 0, opacity 1,the font stack, weight 400, centre, middle, line height 1.25, on everydiff --git a/docs/DECISIONS.md b/docs/DECISIONS.mdindex 5163d0da..8229e6dd 100644--- a/docs/DECISIONS.md+++ b/docs/DECISIONS.md@@ -6981,4 +6981,69 @@ current release; a deck written by an older shell and read against a newerschema only ever gains optional keys, by additivity, so the unpinned form iscorrect for validation and the pinned twins exist for anyone who wantsexactness.+## 2026-09-15 — Maths: an in-house engine replaces Temml, and reads Typst++Temml (64 KB compressed, ~10% of the shell) rendered `$…$` to MathML. It is+gone; `slides/src/maths/` does the job — parse → one shared tree → MathML+emitter, a LaTeX front end and a Typst front end over ONE symbol table+(LaTeX name / Typst name / code point). Nothing in the file format changes:+the document stores the source the author typed, as it always did.++**Measured first, then built.** Every `$…$` in the starter deck, the gallery+decks, the guestbook and every rig fixture: 6 distinct formulas — fractions,+roots, scripts, `\left\right`, `\pm`. The gallery and guestbook decks carry+no maths at all. So the engine's supported set is the obvious tier over that,+not a cut of anything measured: fractions and roots, scripts and limits,+`\left\right` and the `\big` family, matrices/cases/aligned, accents and+braces, `\mathbb`/`\mathcal`/`\mathfrak` as Unicode code points (Chrome+ignores `mathvariant`), `\text`, `\textcolor`, `\boxed`. Not covered:+`\substack`, `\xrightarrow`, `\ce`, `\tag`, `\hline` — a formula using them+renders as typed, exactly as any TeX Temml refused did.++**Compared, in Chrome, 91 formulas** (the 11 from our corpus + 80 from the+categories of Temml's supported-functions page): normalised MathML trees+identical on 96.6%, rendered ink identical (<0.5% pixels) on 97.8%. Three+rounds closed every divergence that was ours by adopting Temml's metric+(`\mid`, `\!`, function application, upright Greek capitals, primes, `\iff`,+`\boxed`, accent sizes, the 2 px on every matrix cell). What remains is+Temml's: `\overline`/`\underline` via `menclose`, which Chrome does not draw+— we draw the rule, a fix; and one extra `mrow` level with 0.0% pixel change.++**`cases` and `aligned` centre their columns.** TeX left-aligns them; Temml+does too — through a stylesheet Bento never loaded, so every deck to date+rendered them centred. Measured `mtd` offsets: ours `[0, 20.2]`, Temml's+`[10.1, 10.1]`. The maintainer looked at both on the demo deck and chose+centred: it matches every existing deck, and it looks better. Recorded so+nobody "fixes" it back to TeX.++**Typst input, syntax A.** `$typst: a/b$` and `$$typst: …$$` — the marker is+`typst:` immediately after the opening delimiter, case-sensitive, optional+whitespace after the colon. Chosen over a per-document setting because it+costs the format nothing (the marker is text), a mixed deck works formula by+formula, and an older shell shows `$typst: a/b$` literally — degraded,+legible, the same promise `$…$` already makes. A per-document default can be+added later without contradicting this; the marker would still override it.+Typst and LaTeX agree on the shared tree for 122/122 equivalence cases once+Typst's paren groups (which script the whole group — a real semantic+difference, not a bug) are folded.++**Trust is structural.** Temml ran with `trust:false` so `\href` was inert.+The emitter constructs every attribute itself; the one place author text+reaches a `style` attribute — `\textcolor` — accepts only a CSS colour shape+(hex, a name, `rgb()`/`hsl()` over numbers). The rig throws `\href`,+`onload=`, `<script>` and a `url(` colour at it and asserts every emitted+attribute is on the engine's own list.++**The rig holds the comparison without Temml.** Temml's trees for the 91+formulas were frozen the day it left (`scripts/maths-freeze-reference.ts` →+`scripts/fixtures/maths-reference.json`, Temml 0.13.3). `scripts/+test-maths-lite.ts` compares the engine's trees to them and requires ≥95%+identical AND every mismatch to be on the explicit residual list — a printer+change that moves a glyph fails CI, not a slide. Pixels stay out of CI: they+were measured in the spike and there is no Temml left to draw the other side.++**Numbers.** Engine 775 lines, 24 KB minified, 8.3 KB gzip. Shell on the day+it shipped (#485, against main 131015e): 756,103 → 690,067 B compressed+(−66,036 B, −8.7%). The spike that measured all of the above was PR #483+(closed, three rounds).diff --git a/scripts/fixtures/maths-reference.json b/scripts/fixtures/maths-reference.jsonnew file mode 100644index 00000000..eecec9f0--- /dev/null+++ b/scripts/fixtures/maths-reference.json@@ -0,0 +1,552 @@+{+ "temml": "0.13.3",+ "frozen": "2026-09-15",+ "formulas": [+ {+ "src": "ax^2 + bx + c = 0",+ "display": true,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}"+ },+ {+ "src": "\\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2}",+ "display": true,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}]}]}]}"+ },+ {+ "src": "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}",+ "display": true,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"±\"}]},{\"tag\":\"msqrt\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]}]}]}]}"+ },+ {+ "src": "ax^2 + bx + c = 0",+ "display": false,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}"+ },+ {+ "src": "\\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2}",+ "display": false,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}]}]}]}"+ },+ {+ "src": "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}",+ "display": false,+ "from": "corpus:starterdeck.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"±\"}]},{\"tag\":\"msqrt\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]}]}]}]}"+ },+ {+ "src": "\\frac{a}{b}",+ "display": true,+ "from": "corpus:scripts/test-sanitize.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}"+ },+ {+ "src": "E=mc^2",+ "display": false,+ "from": "corpus:scripts/test-sanitize.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"E\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"m\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}]}"+ },+ {+ "src": "\\frac{a}{b}",+ "display": false,+ "from": "corpus:scripts/test-sanitize.ts",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}"+ },+ {+ "src": "x = \\frac{…}",+ "display": true,+ "from": "corpus:slides/src/editor/canvas.ts",+ "tree": null+ },+ {+ "src": "x = \\frac{…}",+ "display": false,+ "from": "corpus:slides/src/editor/canvas.ts",+ "tree": null+ },+ {+ "src": "x^2 + y^2 = z^2",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"y\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}]}"+ },+ {+ "src": "a_1 + a_2 + \\cdots + a_n",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⋯\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]}]}]}"+ },+ {+ "src": "x_i^2",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"msubsup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}"+ },+ {+ "src": "e^{i\\pi} + 1 = 0",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"e\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"π\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}"+ },+ {+ "src": "\\frac{a}{b}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}"+ },+ {+ "src": "\\frac{1}{1+\\frac{1}{x}}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]}]}]}"+ },+ {+ "src": "\\dfrac{a}{b}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}"+ },+ {+ "src": "\\tfrac{a}{b}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}"+ },+ {+ "src": "\\binom{n}{k}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"k\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\sqrt{2}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"msqrt\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}"+ },+ {+ "src": "\\sqrt[3]{x^3+1}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mroot\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"3\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"3\"}]}]}]}"+ },+ {+ "src": "\\sqrt{\\frac{a}{b}}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"msqrt\",\"kids\":[{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]}]}"+ },+ {+ "src": "\\sum_{i=1}^{n} i",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"munderover\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∑\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]}]}]}"+ },+ {+ "src": "\\sum_{i=1}^{n} i",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msubsup\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∑\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]}]}]}"+ },+ {+ "src": "\\prod_{k=1}^n k",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"munderover\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∏\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"k\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"k\"}]}]}]}"+ },+ {+ "src": "\\int_a^b f(x)\\,dx",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msubsup\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∫\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]}"+ },+ {+ "src": "\\oint_C \\vec{F}\\cdot d\\vec{r}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∮\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"C\"}]}]},{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"F\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⋅\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"r\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]}]}]}]}"+ },+ {+ "src": "\\iint_D f\\,dA",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∬\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"D\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]}]}]}"+ },+ {+ "src": "\\lim_{x \\to \\infty} f(x)",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"munder\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"lim\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"∞\"}]}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\lim_{x \\to 0} \\frac{\\sin x}{x} = 1",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"munder\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"lim\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"sin\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]}]}"+ },+ {+ "src": "\\max_{a \\in A} f(a)",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"munder\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"max\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"∈\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\left( \\frac{a}{b} \\right)",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\left[ x \\right]",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"[\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"]\"}]}]}]}"+ },+ {+ "src": "\\left\\{ x \\right\\}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"{\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"}\"}]}]}]}"+ },+ {+ "src": "\\left| x \\right|",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]}]}]}"+ },+ {+ "src": "\\left\\| v \\right\\|",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"‖\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"v\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"‖\"}]}]}]}"+ },+ {+ "src": "\\left\\langle a, b \\right\\rangle",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"⟨\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\",\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⟩\"}]}]}]}"+ },+ {+ "src": "\\left\\lfloor x \\right\\rfloor",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"⌊\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⌋\"}]}]}]}"+ },+ {+ "src": "\\left. \\frac{df}{dx} \\right|_{x=0}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}]}"+ },+ {+ "src": "\\bigl( x \\bigr)",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\Bigl[ x \\Bigr]",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"[\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"]\"}]}]}]}"+ },+ {+ "src": "\\biggl\\{ x \\biggr\\}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"{\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"}\"}]}]}]}"+ },+ {+ "src": "\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"[\"}]},{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"]\"}]}]}]}"+ },+ {+ "src": "\\begin{vmatrix} a & b \\\\ c & d \\end{vmatrix}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]},{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]}]}]}"+ },+ {+ "src": "\\begin{matrix} 1 & 2 \\\\ 3 & 4 \\end{matrix}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"3\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mn\",\"kids\":[{\"t\":\"4\"}]}]}]}]}]}"+ },+ {+ "src": "f(x) = \\begin{cases} x & x \\ge 0 \\\\ -x & x < 0 \\end{cases}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"{\"}]},{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"≥\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"−\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"<\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}]}]},{\"tag\":\"mo\",\"kids\":[]}]}]}"+ },+ {+ "src": "\\begin{aligned} a &= b + c \\\\ &= d \\end{aligned}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mtable\",\"kids\":[{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]}]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]}]}]},{\"tag\":\"mtr\",\"kids\":[{\"tag\":\"mtd\",\"kids\":[]},{\"tag\":\"mtd\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]}]}]}]}]}]}"+ },+ {+ "src": "\\hat{x}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"^\"}]}]}]}"+ },+ {+ "src": "\\vec{v}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"v\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]}]}]}"+ },+ {+ "src": "\\bar{z}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"‾\"}]}]}]}"+ },+ {+ "src": "\\tilde{a}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"~\"}]}]}]}"+ },+ {+ "src": "\\dot{x} + \\ddot{x}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"˙\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"¨\"}]}]}]}]}"+ },+ {+ "src": "\\overline{AB}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"menclose\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]}]}]}]}"+ },+ {+ "src": "\\underline{x}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"menclose\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]}"+ },+ {+ "src": "\\widehat{abc}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"^\"}]}]}]}"+ },+ {+ "src": "\\overbrace{a+b+c}^{n}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⏞\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]}]}"+ },+ {+ "src": "\\underbrace{x+y}_{2}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"munder\",\"kids\":[{\"tag\":\"munder\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"y\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⏟\"}]}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}"+ },+ {+ "src": "\\overrightarrow{AB}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]}]}]}"+ },+ {+ "src": "\\mathbb{R}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ℝ\"}]}]}"+ },+ {+ "src": "\\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ℕ\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⊂\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"ℤ\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⊂\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"ℚ\"}]}]}]}"+ },+ {+ "src": "\\mathcal{L}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ℒ\"}]}]}"+ },+ {+ "src": "\\mathfrak{g}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝔤\"}]}]}"+ },+ {+ "src": "\\mathbf{x}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝐱\"}]}]}"+ },+ {+ "src": "\\mathrm{d}x",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]}"+ },+ {+ "src": "\\mathsf{A}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝖠\"}]}]}"+ },+ {+ "src": "\\mathtt{code}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝚌\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝚘\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝚍\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"𝚎\"}]}]}]}"+ },+ {+ "src": "\\text{if } x > 0",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mtext\",\"kids\":[{\"t\":\"if\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\">\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}"+ },+ {+ "src": "\\textcolor{red}{x}",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}"+ },+ {+ "src": "\\boxed{E = mc^2}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"E\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"m\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]}]}]}"+ },+ {+ "src": "\\operatorname{sinc}(x)",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"sinc\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "\\alpha + \\beta = \\gamma",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"α\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"β\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"γ\"}]}]}]}"+ },+ {+ "src": "\\Delta x \\to 0",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"Δ\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}"+ },+ {+ "src": "\\forall \\epsilon > 0\\, \\exists \\delta",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"∀\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"ϵ\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\">\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"∃\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"δ\"}]}]}]}"+ },+ {+ "src": "A \\cup B \\cap C",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"∪\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"∩\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"C\"}]}]}]}"+ },+ {+ "src": "x \\in \\emptyset",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"∈\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"∅\"}]}]}]}"+ },+ {+ "src": "a \\le b \\ne c \\ge d",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"≤\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"≠\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"≥\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]}]}]}"+ },+ {+ "src": "p \\Rightarrow q \\iff \\neg q \\Rightarrow \\neg p",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"p\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⇒\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"q\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⟺\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"¬\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"q\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⇒\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"¬\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"p\"}]}]}]}"+ },+ {+ "src": "\\sin^2 \\theta + \\cos^2 \\theta = 1",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"sin\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"θ\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"+\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"cos\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"θ\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]}]}"+ },+ {+ "src": "\\log_2 n",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"log\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"2\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"n\"}]}]}]}"+ },+ {+ "src": "\\ln x",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ln\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]}]}]}"+ },+ {+ "src": "f'(x)",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"′\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "f''(x)",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"f\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"′\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"′\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}"+ },+ {+ "src": "a \\quad b \\qquad c",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]}]}]}"+ },+ {+ "src": "a\\,b\\;c\\!d",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"a\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"b\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"c\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"d\"}]}]}]}"+ },+ {+ "src": "x \\pm y \\mp z",+ "display": false,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"x\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"±\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"y\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"∓\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]}]}]}"+ },+ {+ "src": "\\nabla \\cdot \\vec{E} = \\frac{\\rho}{\\varepsilon_0}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∇\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"⋅\"}]},{\"tag\":\"mover\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"E\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"→\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ρ\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"ε\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"0\"}]}]}]}]}]}"+ },+ {+ "src": "\\partial_\\mu F^{\\mu\\nu} = J^\\nu",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"∂\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"μ\"}]}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"F\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"μ\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"ν\"}]}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"J\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"ν\"}]}]}]}]}"+ },+ {+ "src": "P(A \\mid B) = \\frac{P(B \\mid A)\\,P(A)}{P(B)}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"P\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"P\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"|\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"P\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"A\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"P\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"B\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]}]}]}]}"+ },+ {+ "src": "\\sigma(z)_i = \\frac{e^{z_i}}{\\sum_{j=1}^K e^{z_j}}",+ "display": true,+ "from": "standard",+ "tree": "{\"tag\":\"math\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"σ\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"(\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\")\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mfrac\",\"kids\":[{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"e\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"i\"}]}]}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"msubsup\",\"kids\":[{\"tag\":\"mo\",\"kids\":[{\"t\":\"∑\"}]},{\"tag\":\"mrow\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"j\"}]},{\"tag\":\"mo\",\"kids\":[{\"t\":\"=\"}]},{\"tag\":\"mn\",\"kids\":[{\"t\":\"1\"}]}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"K\"}]}]},{\"tag\":\"msup\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"e\"}]},{\"tag\":\"msub\",\"kids\":[{\"tag\":\"mi\",\"kids\":[{\"t\":\"z\"}]},{\"tag\":\"mi\",\"kids\":[{\"t\":\"j\"}]}]}]}]}]}]}]}"+ }+ ]+}diff --git a/scripts/fixtures/maths-set.json b/scripts/fixtures/maths-set.jsonnew file mode 100644index 00000000..f53358f5--- /dev/null+++ b/scripts/fixtures/maths-set.json@@ -0,0 +1,457 @@+[+ {+ "src": "ax^2 + bx + c = 0",+ "display": true,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "\\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2}",+ "display": true,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}",+ "display": true,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "ax^2 + bx + c = 0",+ "display": false,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "\\left(x + \\frac{b}{2a}\\right)^2 = \\frac{b^2 - 4ac}{4a^2}",+ "display": false,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}",+ "display": false,+ "from": "corpus:starterdeck.ts"+ },+ {+ "src": "\\frac{a}{b}",+ "display": true,+ "from": "corpus:scripts/test-sanitize.ts"+ },+ {+ "src": "E=mc^2",+ "display": false,+ "from": "corpus:scripts/test-sanitize.ts"+ },+ {+ "src": "\\frac{a}{b}",+ "display": false,+ "from": "corpus:scripts/test-sanitize.ts"+ },+ {+ "src": "x = \\frac{…}",+ "display": true,+ "from": "corpus:slides/src/editor/canvas.ts"+ },+ {+ "src": "x = \\frac{…}",+ "display": false,+ "from": "corpus:slides/src/editor/canvas.ts"+ },+ {+ "src": "x^2 + y^2 = z^2",+ "display": false,+ "from": "standard"+ },+ {+ "src": "a_1 + a_2 + \\cdots + a_n",+ "display": false,+ "from": "standard"+ },+ {+ "src": "x_i^2",+ "display": false,+ "from": "standard"+ },+ {+ "src": "e^{i\\pi} + 1 = 0",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\frac{a}{b}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\frac{1}{1+\\frac{1}{x}}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\dfrac{a}{b}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\tfrac{a}{b}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\binom{n}{k}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\sqrt{2}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\sqrt[3]{x^3+1}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\sqrt{\\frac{a}{b}}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\sum_{i=1}^{n} i",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\sum_{i=1}^{n} i",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\prod_{k=1}^n k",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\int_a^b f(x)\\,dx",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\oint_C \\vec{F}\\cdot d\\vec{r}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\iint_D f\\,dA",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\lim_{x \\to \\infty} f(x)",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\lim_{x \\to 0} \\frac{\\sin x}{x} = 1",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\max_{a \\in A} f(a)",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\left( \\frac{a}{b} \\right)",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\left[ x \\right]",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left\\{ x \\right\\}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left| x \\right|",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left\\| v \\right\\|",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left\\langle a, b \\right\\rangle",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left\\lfloor x \\right\\rfloor",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\left. \\frac{df}{dx} \\right|_{x=0}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\bigl( x \\bigr)",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\Bigl[ x \\Bigr]",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\biggl\\{ x \\biggr\\}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\begin{vmatrix} a & b \\\\ c & d \\end{vmatrix}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\begin{matrix} 1 & 2 \\\\ 3 & 4 \\end{matrix}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "f(x) = \\begin{cases} x & x \\ge 0 \\\\ -x & x < 0 \\end{cases}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\begin{aligned} a &= b + c \\\\ &= d \\end{aligned}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\hat{x}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\vec{v}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\bar{z}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\tilde{a}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\dot{x} + \\ddot{x}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\overline{AB}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\underline{x}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\widehat{abc}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\overbrace{a+b+c}^{n}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\underbrace{x+y}_{2}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\overrightarrow{AB}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathbb{R}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathbb{N} \\subset \\mathbb{Z} \\subset \\mathbb{Q}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathcal{L}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathfrak{g}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathbf{x}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathrm{d}x",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathsf{A}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\mathtt{code}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\text{if } x > 0",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\textcolor{red}{x}",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\boxed{E = mc^2}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\operatorname{sinc}(x)",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\alpha + \\beta = \\gamma",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\Delta x \\to 0",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\forall \\epsilon > 0\\, \\exists \\delta",+ "display": false,+ "from": "standard"+ },+ {+ "src": "A \\cup B \\cap C",+ "display": false,+ "from": "standard"+ },+ {+ "src": "x \\in \\emptyset",+ "display": false,+ "from": "standard"+ },+ {+ "src": "a \\le b \\ne c \\ge d",+ "display": false,+ "from": "standard"+ },+ {+ "src": "p \\Rightarrow q \\iff \\neg q \\Rightarrow \\neg p",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\sin^2 \\theta + \\cos^2 \\theta = 1",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\log_2 n",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\ln x",+ "display": false,+ "from": "standard"+ },+ {+ "src": "f'(x)",+ "display": false,+ "from": "standard"+ },+ {+ "src": "f''(x)",+ "display": false,+ "from": "standard"+ },+ {+ "src": "a \\quad b \\qquad c",+ "display": false,+ "from": "standard"+ },+ {+ "src": "a\\,b\\;c\\!d",+ "display": false,+ "from": "standard"+ },+ {+ "src": "x \\pm y \\mp z",+ "display": false,+ "from": "standard"+ },+ {+ "src": "\\nabla \\cdot \\vec{E} = \\frac{\\rho}{\\varepsilon_0}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\partial_\\mu F^{\\mu\\nu} = J^\\nu",+ "display": true,+ "from": "standard"+ },+ {+ "src": "P(A \\mid B) = \\frac{P(B \\mid A)\\,P(A)}{P(B)}",+ "display": true,+ "from": "standard"+ },+ {+ "src": "\\sigma(z)_i = \\frac{e^{z_i}}{\\sum_{j=1}^K e^{z_j}}",+ "display": true,+ "from": "standard"+ }+]\ No newline at end of filediff --git a/scripts/lib/mathml-tree.ts b/scripts/lib/mathml-tree.tsnew file mode 100644index 00000000..171bbe4a--- /dev/null+++ b/scripts/lib/mathml-tree.ts@@ -0,0 +1,78 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * MathML as a TREE, DOM-free — what an engine MEANS, not how it spells it.+ *+ * Used by scripts/test-maths-lite.ts to hold maths-lite to the frozen Temml+ * reference (scripts/fixtures/maths-reference.json) and by the script that+ * froze it. The normalisation is the one the spike's Chrome harness used+ * (spike-maths-lite, 2026-09-15), ported off DOMParser so CI needs no+ * browser: spelling attributes dropped, mstyle/mpadded/semantics unwrapped,+ * single-child and nested mrows folded, invisible operators and mspace+ * removed, entities decoded.+ *+ * The tokenizer expects what the two engines emit: well-formed tags,+ * double-quoted attributes, self-closing allowed. It is not an HTML parser.+ */++export type MNode = { tag: string; kids: MNode[]; attrs?: Record<string, string> } | { t: string }++const DROP_ATTR = new Set(['class', 'data-sym', 'data-msx', 'xmlns', 'style', 'stretchy', 'form', 'lspace', 'rspace', 'accent', 'accentunder', 'largeop', 'movablelimits', 'symmetric', 'fence', 'separator', 'minsize', 'maxsize', 'mathvariant', 'displaystyle', 'scriptlevel', 'columnalign', 'rowspacing', 'columnspacing', 'linethickness', 'width', 'height', 'depth', 'voffset', 'encoding', 'display', 'mathcolor', 'mathbackground', 'href', 'id', 'aria-hidden', 'columnlines', 'rowlines', 'frame', 'notation'])++const ENT: Record<string, string> = { amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: ' ' }+const decode = (s: string) => s.replace(/&(#x[0-9a-f]+|#\d+|[a-z]+);/gi, (m, e: string) => {+ if (e[0] === '#') return String.fromCodePoint(e[1] === 'x' || e[1] === 'X' ? parseInt(e.slice(2), 16) : parseInt(e.slice(1), 10))+ return ENT[e.toLowerCase()] ?? m+})++type Raw = { tag: string; attrs: Record<string, string>; kids: (Raw | string)[] }++/** Parse a markup string into a raw element tree (the first element found). */+export function parseMarkup(html: string): Raw | null {+ const root: Raw = { tag: '#root', attrs: {}, kids: [] }+ const stack: Raw[] = [root]+ const re = /<\/([a-zA-Z][\w:-]*)\s*>|<([a-zA-Z][\w:-]*)((?:\s+[\w:-]+(?:="[^"]*")?)*)\s*(\/?)>|([^<]+)/g+ let m: RegExpExecArray | null+ while ((m = re.exec(html))) {+ const top = stack[stack.length - 1]+ if (m[1]) { if (stack.length > 1) stack.pop() }+ else if (m[2]) {+ const attrs: Record<string, string> = {}+ for (const a of m[3].matchAll(/([\w:-]+)(?:="([^"]*)")?/g)) attrs[a[1]] = decode(a[2] ?? '')+ const el: Raw = { tag: m[2].toLowerCase(), attrs, kids: [] }+ top.kids.push(el)+ if (!m[4]) stack.push(el)+ } else if (m[5]) top.kids.push(decode(m[5]))+ }+ return root.kids.find((k): k is Raw => typeof k !== 'string') ?? null+}++function norm(node: Raw | string): MNode | null {+ if (typeof node === 'string') { const t = node.replace(/\s+/g, ' ').trim(); return t ? { t } : null }+ const tag = node.tag+ let kids = node.kids.map(norm).filter((k): k is MNode => !!k)+ if (tag === 'mstyle' || tag === 'mpadded' || tag === 'semantics') return kids.length === 1 ? kids[0] : { tag: 'mrow', kids }+ if (tag === 'annotation' || tag === 'annotation-xml') return null+ if (tag === 'mrow') {+ kids = kids.flatMap((k) => ('tag' in k && k.tag === 'mrow' ? k.kids : [k]))+ if (kids.length === 1) return kids[0]+ if (kids.length === 0) return null+ }+ if (tag === 'mo' && kids.length === 1 && 't' in kids[0] && /^[]$/.test(kids[0].t)) return null+ if (tag === 'mspace') return null+ const attrs: Record<string, string> = {}+ for (const [k, v] of Object.entries(node.attrs)) if (!DROP_ATTR.has(k)) attrs[k] = v+ return { tag, kids, ...(Object.keys(attrs).length ? { attrs } : {}) }+}++/** The <math> element of a rendered string, normalised — or null if none. */+export function mathTree(html: string): MNode | null {+ const el = parseMarkup(html)+ if (!el) return null+ const find = (r: Raw): Raw | null => (r.tag === 'math' ? r : r.kids.map((k) => (typeof k === 'string' ? null : find(k))).find(Boolean) ?? null)+ const m = find(el)+ return m ? norm(m) : null+}++/** A stable string key for equality. */+export const treeKey = (html: string): string | null => { const t = mathTree(html); return t ? JSON.stringify(t) : null }diff --git a/scripts/maths-freeze-reference.ts b/scripts/maths-freeze-reference.tsnew file mode 100644index 00000000..6e5b51f9--- /dev/null+++ b/scripts/maths-freeze-reference.ts@@ -0,0 +1,37 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// Freeze Temml's rendering of the maths reference set into+// scripts/fixtures/maths-reference.json — run ONCE, with Temml installed.+//+// cd slides && npm i --no-save [email protected] && cd .. && node scripts/maths-freeze-reference.ts+//+// Temml left the shell on 2026-09-15 (maths-lite replaced it), so the rig+// cannot ask it live. This file holds what it said: the 91 formulas the spike+// measured against — 11 from our own decks and rigs, 80 from the categories+// of Temml's supported-functions page — as NORMALISED trees (scripts/lib/+// mathml-tree.ts). scripts/test-maths-lite.ts compares maths-lite's trees to+// these and requires ≥95% identical, with the known residuals allowlisted.+// Pixels were measured in the spike (97.8% identical, Chrome) and stay out of+// CI: there is no Temml to draw the other side.+//+// Re-run only to widen the set; the fixture records the Temml version.++import { writeFileSync, readFileSync } from 'node:fs'+import { fileURLToPath } from 'node:url'+import { dirname, join } from 'node:path'+import { createRequire } from 'node:module'+import { treeKey } from './lib/mathml-tree.ts'++const root = join(dirname(fileURLToPath(import.meta.url)), '..')+const require = createRequire(join(root, 'slides/package.json'))+const temml = require('temml') as { version: string; renderToString(s: string, o: object): string }++const set = JSON.parse(readFileSync(join(root, 'scripts/fixtures/maths-set.json'), 'utf8')) as Array<{ src: string; display: boolean; from: string }>+const out = set.map((f) => {+ let tree: string | null = null+ try { tree = treeKey(temml.renderToString(f.src, { displayMode: f.display, throwOnError: true, trust: false })) } catch { tree = null }+ return { ...f, tree }+})+writeFileSync(join(root, 'scripts/fixtures/maths-reference.json'), JSON.stringify({ temml: temml.version, frozen: new Date().toISOString().slice(0, 10), formulas: out }, null, 1) + '\n')+console.log(`froze ${out.length} formulas from Temml ${temml.version}; ${out.filter((o) => o.tree).length} rendered`)diff --git a/scripts/test-convert/load.ts b/scripts/test-convert/load.tsindex dcd7daae..2a059a87 100644--- a/scripts/test-convert/load.ts+++ b/scripts/test-convert/load.ts@@ -12,7 +12,7 @@// in the actual app — and if it does not, nothing else matters.//// Mechanics: slides' validate.ts pulls render.ts, whose imports are-// extensionless and include the temml package, so plain node type-stripping+// extensionless (and pull in DOM-touching modules), so plain node type-stripping// cannot run it. Same answer as scripts/test-validate.ts: bundle with esbuild// first. This rig does that itself — when run directly it bundles ITSELF and// re-executes the bundle, so the runner (and a bare `node`) need no wrapper.diff --git a/scripts/test-maths-lite.ts b/scripts/test-maths-lite.tsnew file mode 100644index 00000000..b3d41026--- /dev/null+++ b/scripts/test-maths-lite.ts@@ -0,0 +1,199 @@+#!/usr/bin/env node+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+// Bento's maths engine (slides/src/maths): its contract, DOM-free.+//+// node scripts/test-maths-lite.ts+//+// WHAT THIS PROVES. Every formula of the reference set (11 from our own decks+// and rigs, 80 from the categories of Temml's supported-functions page)+// parses; a refused formula returns null rather than throwing (the+// never-throws contract render.ts relies on); the engine's NORMALISED MathML+// tree matches the tree Temml produced for the same formula on >=95% of the+// set -- Temml's trees were frozen into scripts/fixtures/maths-reference.json+// on the day it left the shell (scripts/maths-freeze-reference.ts), and every+// mismatch must be on the explicit residual list, so a printer change that+// moves a glyph goes red here rather than on a slide; the Typst front end and+// the LaTeX front end agree on the shared tree for the equivalence table;+// the emitter constructs every attribute itself (no href, no handlers, no+// author style -- the trust:false Temml ran with is structural here); the+// symbol table has no duplicate LaTeX names; every styled letter is a real+// Mathematical Alphanumeric code point (Chrome ignores mathvariant).+//+// Pixels stay out of CI: the spike measured 97.8% visually identical against+// Temml in Chrome (docs/DECISIONS.md, 2026-09-15), and there is no Temml in+// the tree any more to draw the other side.++import { readFileSync } from 'node:fs'+import { fileURLToPath } from 'node:url'+import { dirname, join } from 'node:path'+import { renderMath, parseMath, isTypst, stripMarker } from '../slides/src/maths/index.ts'+import { SYMBOLS, styledChar } from '../slides/src/maths/symbols.ts'+import { treeKey } from './lib/mathml-tree.ts'++let failures = 0+let checks = 0+function ok(cond: boolean, msg: string) {+ checks+++ if (!cond) { failures++; console.log(` FAIL ${msg}`) }+ else console.log(` ok ${msg}`)+}+const root = join(dirname(fileURLToPath(import.meta.url)), '..')++console.log('the never-throws contract\n')+ok(renderMath('\\frac{a}{b}') !== null, '\\frac{a}{b} renders')+ok(renderMath('\\frac{a}') === null, 'a broken fraction → null, no throw')+ok(renderMath('\\nosuchcommand x') === null, 'an unknown command → null')+ok(renderMath('x = \\frac{…}') === null, 'the canvas placeholder hint (\\frac{…} with one arg) → null, as Temml refused it')+ok(renderMath('a/b', { syntax: 'typst' }) !== null && renderMath('mat(1, 2; 3', { syntax: 'typst' }) === null, 'typst: valid renders, unterminated → null')+ok(renderMath('') === null || renderMath('') === '<math xmlns="http://www.w3.org/1998/Math/MathML"><mrow></mrow></math>', 'empty input does not throw')++console.log('\nthe reference set, against the frozen Temml trees\n')+type Ref = { src: string; display: boolean; from: string; tree: string | null }+const reference = JSON.parse(readFileSync(join(root, 'scripts/fixtures/maths-reference.json'), 'utf8')) as { temml: string; frozen: string; formulas: Ref[] }+ok(reference.formulas.length === 91 && reference.temml === '0.13.3', `the reference is the spike's 91-formula set, frozen from Temml ${reference.temml} on ${reference.frozen}`)+const corpus = reference.formulas.filter((f) => f.from.startsWith('corpus:') && !f.src.includes('…'))+ok(corpus.length >= 9 && corpus.every((c) => renderMath(c.src, { display: c.display }) !== null), `every formula our decks and rigs carry renders (${corpus.length})`)+// Known residuals -- each one a place where Temml's tree is NOT what we want:+// menclose is blank on Chrome (we draw the rule), and one extra mrow level+// with 0.0% pixel difference. Anything else that differs is a regression.+const RESIDUAL = new Set(['\\overline{AB}', '\\underline{x}', '\\sigma(z)_i = \\frac{e^{z_i}}{\\sum_{j=1}^K e^{z_j}}'])+let both = 0, same = 0+const unexpected: string[] = []+for (const f of reference.formulas) {+ const lite = renderMath(f.src, { display: f.display })+ const key = lite ? treeKey(lite) : null+ if (!f.tree || !key) { if (!!f.tree !== !!key) unexpected.push(`${f.src} (temml ${!!f.tree}, ours ${!!key})`); continue }+ both+++ if (key === f.tree) same+++ else if (!RESIDUAL.has(f.src)) unexpected.push(f.src)+}+ok(both === 89, '89 formulas render in both (the two refused are the canvas placeholder hint, refused by both)')+ok(same / both >= 0.95, `>=95% identical normalised trees: ${same}/${both} = ${(100 * same / both).toFixed(1)}%`)+ok(unexpected.length === 0, `every mismatch is a listed residual -- unexpected: ${unexpected.join(' · ') || 'none'}`)+ok(both - same === RESIDUAL.size, `and every listed residual still differs (${both - same} of ${RESIDUAL.size}) -- remove one from the list when it is closed`)++console.log('\nMathML shape\n')+const q = renderMath('x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}', { display: true })!+ok(q.startsWith('<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">'), 'display mode sets display="block"')+ok(/<mfrac><mrow><mo>−<\/mo><mi>b<\/mi><mo>±<\/mo><msqrt>/.test(q), 'the quadratic formula: minus is U+2212, ± from the table, the root is msqrt')+ok(/<msup><mi>b<\/mi><mn>2<\/mn><\/msup>/.test(q), 'b^2 is msup with an mn')+ok(renderMath('\\sum_{i=1}^n', { display: true })!.includes('<munderover>'), 'display-mode sum takes under/over limits')+ok(renderMath('\\sum_{i=1}^n')!.includes('<msubsup>'), 'inline sum keeps side scripts')+ok(renderMath('\\int_0^1', { display: true })!.includes('<msubsup>'), 'an integral keeps side limits even in display mode (TeX default)')+ok(renderMath('\\mathbb{R}')!.includes('ℝ') && renderMath('\\mathbb{A}')!.includes('𝔸'), '\\mathbb becomes code points: ℝ from the Letterlike block, 𝔸 from the Mathematical Alphanumerics')+ok(renderMath('\\mathcal{L}')!.includes('ℒ') && renderMath('\\mathfrak{g}')!.includes('𝔤'), 'cal and frak likewise')+ok(renderMath('\\text{if } x')!.includes('<mtext>if\u00a0</mtext>'), '\\text keeps its trailing space as a no-break space')+ok(renderMath('\\textcolor{red}{x}')!.includes('style="color:red"'), '\\textcolor → colour style')+ok(renderMath('\\boxed{x}')!.includes('border:'), '\\boxed → border emulation')+ok(renderMath('\\left( x \\right)')!.includes('<mo fence="true" form="prefix" stretchy="true">(</mo>'), '\\left( is a stretchy fence')+ok(renderMath('f(x)')!.includes('form="prefix"'), 'a bare ( says it is a prefix fence (no infix spacing)')+ok(renderMath('\\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix}')!.match(/<mtr>/g)!.length === 2, 'pmatrix: two rows')+ok(renderMath('\\begin{cases} a & b \\\\ c & d \\end{cases}')!.includes('<mo fence="true" form="prefix" stretchy="true">{</mo>'), 'cases: a left brace only')+ok(renderMath('\\sin x')!.includes('\u2061'), 'function application after \\sin')++console.log('\nround 2: the divergences closed against Temml (each was a measured miss)\n')+ok(renderMath('A \\mid B')!.includes('<mo lspace="0.22em" rspace="0.22em" stretchy="false">|</mo>'), '\\mid is a bar with relation spacing')+ok(renderMath('a\\!b')!.includes('<mrow style="margin-left:-0.1667em;"></mrow>'), '\\! is a negative margin, not a negative mspace')+ok(!renderMath('\\operatorname{sinc}(x)')!.includes('<mspace'), 'no thin space between a function name and a paren group')+ok(renderMath('\\sin x')!.includes('\u2061</mo><mspace width="0.1667em"></mspace><mi>x</mi>'), '…but a thin space before a bare operand')+ok(renderMath('\\Delta x')!.includes('<mi mathvariant="normal">Δ</mi>'), 'Greek capitals are upright')+ok(renderMath('\\alpha')!.includes('<mi>α</mi>'), 'Greek lowercase stays italic')+ok(renderMath("f''")!.includes('<msup><mi>f</mi><mrow><mo lspace="0em" rspace="0em">′</mo><mo lspace="0em" rspace="0em">′</mo></mrow></msup>'), 'primes: one mo each, no spacing, grouped')+ok(renderMath('a \\iff b')!.includes('<mspace width="0.2778em"></mspace><mo>⟺</mo><mspace width="0.2778em"></mspace>'), '\\iff carries a thick space each side')+ok(renderMath('a <==> b', { syntax: 'typst' }) === renderMath('a \\iff b'), 'typst <==> is the same node')+ok(renderMath('\\boxed{E}')!.includes('style="padding:3pt;border:1px solid"'), "\\boxed uses Temml's metric")+ok(renderMath('\\forall x')!.includes('<mi>∀</mi>'), '\\forall / \\exists are identifiers')+ok(renderMath('\\nabla \\cdot v')!.includes('<mo>∇</mo><mo form="prefix" stretchy="false">⋅</mo>'), 'an operator after an operator is prefix (no left space)')+ok(renderMath('a + \\cdots + b')!.includes('<mo>+</mo><mo>⋯</mo><mo>+</mo>'), '…but not after dots: + ⋯ + keeps its spacing')+ok(renderMath('\\sigma(z)_i')!.includes('<msub><mrow><mo fence="true" form="prefix" stretchy="false">(</mo><mi>z</mi><mo fence="true" form="postfix" stretchy="false">)</mo></mrow><mi>i</mi></msub>'), 'a paren group is one node: the script attaches to the group, as Temml and Typst do')+ok(renderMath('\\left( x \\right)')!.includes('<mo fence="true" form="prefix" stretchy="true">(</mo>'), '\\left( says fence/form as well as stretchy')+ok(renderMath('\\begin{cases} a & b \\\\ c & d \\end{cases}')!.includes('<mtd style="padding-left:1em;padding-right:0em">'), "cases: 1em before the condition column, columns CENTRED (Temml-in-Bento look, the maintainer's choice)")+ok(renderMath('\\begin{aligned} a &= b \\end{aligned}')!.includes('<mtable displaystyle="true">') && renderMath('\\begin{aligned} a &= b \\end{aligned}')!.includes('<mtd style="padding-left:0em;padding-right:0em">'), 'aligned: display style, no column padding, columns centred')+ok(!/text-align|columnalign/.test(renderMath('\\begin{cases} a & b \\end{cases}')!), 'no cell says an alignment — centred is the default, as Temml renders in Bento today')+ok(renderMath('\\vec{v}')!.includes('<mo stretchy="false">→</mo>') && renderMath('\\hat{x}')!.includes('style="math-depth:0"'), "\\vec shrinks to script size, \\hat stays full — Temml's look")+ok(renderMath('\\overrightarrow{AB}')!.includes('stretchy="true" style="math-depth:0"'), 'a stretchy arrow accent stays full size')+ok(renderMath('\\overline{AB}')!.includes('<mover><mrow><mi>A</mi><mi>B</mi></mrow><mo stretchy="true" style="math-depth:0">‾</mo></mover>'), "\\overline draws a stretchy rule (Temml's menclose is blank on Chrome — kept ours)")+ok(renderMath('\\binom{n}{k}')!.includes('stretchy="true">(</mo><mfrac linethickness="0">'), 'binom parens stretch')+ok(renderMath('\\int_0^1', { display: true })!.includes('<msubsup>'), 'integrals keep side limits in display mode')+ok(renderMath('\\begin{pmatrix} a \\\\ b \\end{pmatrix}')!.includes('<mtd style="padding-left:0em;padding-right:0em">'), 'a centred cell says nothing about alignment (the 2 px that kept matrices off Temml)')++console.log('\nround 3: Typst function application is tight (byte-identical to LaTeX)\n')+for (const [ty, tex] of [['f(x) = cases(x & x >= 0, -x & x < 0)', 'f(x) = \\begin{cases} x & x \\ge 0 \\\\ -x & x < 0 \\end{cases}'], ['g(x, y)', 'g(x, y)'], ['sin(x)', '\\sin(x)'], ['f(x)_i', 'f(x)_i']] as const)+ ok(renderMath(ty, { syntax: 'typst', display: true }) === renderMath(tex, { display: true }), `typst \`${ty}\` is byte-identical to latex \`${tex}\` — no gap around the group`)+ok(renderMath('f(x)', { syntax: 'typst' })!.includes('<mo fence="true" form="prefix" stretchy="false">('), 'a plain Typst group is the tight, non-stretchy paren')+ok(renderMath('(a/b)', { syntax: 'typst' })!.includes('<mo fence="true" form="prefix" stretchy="true">('), 'a group around a fraction stretches (Typst sizes to content)')++console.log('\nthe syntax marker (decided: $typst: …$)\n')+ok(isTypst('typst: a/b') && isTypst('typst:a/b'), 'typst: at the start, with or without a space')+ok(!isTypst(' typst: a/b') && !isTypst('Typst: a/b') && !isTypst('TYPST: a/b'), 'not after whitespace, not another case')+ok(!isTypst('a typst: b') && !isTypst('\\frac{typst:}{b}'), 'not anywhere else in the formula')+ok(stripMarker('typst: a/b') === 'a/b' && stripMarker('\\frac{a}{b}') === '\\frac{a}{b}', 'stripMarker removes exactly the marker')+const render = readFileSync(join(root, 'slides/src/render.ts'), 'utf8')+ok(/const m = \/\^typst:\\s\*\/\.exec\(tex\)/.test(render), 'render.ts applies the exact marker (case-sensitive, at the start)')+ok(!/temml/i.test(render.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, '')), 'render.ts imports nothing from temml -- the engine is ours')+ok(!/"temml"/.test(readFileSync(join(root, 'slides/package.json'), 'utf8')), 'temml is not a dependency of slides any more')++console.log('\ntrust: every attribute is ours\n')+const attrsOf = (html: string) => [...html.matchAll(/\s([a-zA-Z-]+)="/g)].map((m) => m[1])+const ALLOWED = new Set(['xmlns', 'display', 'mathvariant', 'stretchy', 'fence', 'form', 'lspace', 'rspace', 'style', 'linethickness', 'displaystyle', 'accent', 'width', 'minsize', 'maxsize', 'separator', 'symmetric', 'largeop', 'movablelimits', 'columnalign', 'rowspacing', 'columnspacing', 'scriptlevel', 'height', 'depth', 'voffset', 'mathcolor', 'mathbackground', 'columnlines', 'rowlines', 'frame', 'notation', 'accentunder'])+for (const src of ['\\href{javascript:alert(1)}{x}', 'x" onload="alert(1)', '<img src=x onerror=alert(1)>', '\\text{<script>1</script>}', '\\textcolor{red;background:url(x)}{y}', '\\textcolor{url(javascript:1)}{y}', '\\mathrm{a} onclick=1']) {+ const out = renderMath(src) ?? renderMath(src, { syntax: 'typst' }) ?? ''+ ok(!/<script|onload|onerror|onclick|javascript:|url\(/i.test(out) && attrsOf(out).every((a) => ALLOWED.has(a)), `no author-controlled attribute or tag survives: ${JSON.stringify(src)} -> ${out ? out.slice(0, 60) + '…' : 'refused'}`)+}+ok(renderMath('\\textcolor{#ff0000}{x}')!.includes('style="color:#ff0000"') && renderMath('\\textcolor{rebeccapurple}{x}')!.includes('color:rebeccapurple'), '\\textcolor takes a hex or a named colour')+// The style VALUE, not just the attribute name: every style="…" the emitter+// can produce is one of its own constant forms, or `color:` + a value of the+// colour shape isCssColor admits — one declaration, no `;`, no `(` outside+// rgb/hsl. A loosened isCssColor that lets a `;` through goes red here.+const STYLE_FORMS = [+ /^margin-left:-?[\d.]+em;$/, /^math-depth:0$/,+ /^padding-left:(0|1)em;padding-right:0em$/, /^padding-left:(0em|5\.9776pt);padding-right:(0em|5\.9776pt)$/,+]+const COLOR_SHAPE = /^(#[0-9a-f]{3,8}|[a-z]{3,20}|(rgba?|hsla?)\([\d.%,\s/]+\))$/i+const styleOk = (v: string) => STYLE_FORMS.some((re) => re.test(v)) || v.split(';').every((d) => d === 'padding:3pt' || d === 'border:1px solid' || d.startsWith('background:linear-gradient(to top right,transparent 47%,currentColor 47%,currentColor 53%,transparent 53%)') || (d.startsWith('color:') && COLOR_SHAPE.test(d.slice(6))))+const styleValues = (html: string) => [...html.matchAll(/\sstyle="([^"]*)"/g)].map((m) => m[1])+const STYLE_PROBES = ['\\textcolor{red}{x}', '\\textcolor{#abc}{x}', '\\textcolor{rgb(1, 2, 3)}{x}', '\\boxed{\\textcolor{blue}{y}}', '\\cancel{x}', 'a\\!b', '\\hat{x}', '\\begin{cases} a & b \\\\ c & d \\end{cases}', '\\begin{pmatrix} 1 & 2 \\\\ 3 & 4 \\end{pmatrix}', '\\begin{aligned} a &= b \\end{aligned}',+ '\\textcolor{red;position:fixed}{x}', '\\textcolor{red;font-size:900px}{x}', '\\textcolor{red}{x};background:url(x)', '\\textcolor{expression(1)}{x}', '\\textcolor{var(--x)}{x}', '\\textcolor{rgb(1,2,3);color:red}{x}']+for (const src of STYLE_PROBES) {+ const out = renderMath(src) ?? ''+ const vals = styleValues(out)+ ok(vals.every(styleOk), `every style value is a known form or a bare colour: ${JSON.stringify(src)} → ${JSON.stringify(vals)}`)+}+ok(!(renderMath('\\textcolor{red;position:fixed}{x}') ?? '').includes('style='), 'a colour carrying a `;` declaration is dropped entirely — no style at all')+ok(!(renderMath('\\textcolor{red;font-size:9px}{x}') ?? '').includes('font-size'), 'a `;`-declaration without url( is refused too')+ok(renderMath('\\text{a"b}')!.includes('a"b') && !/<mtext>[^<]*"/.test(renderMath('\\text{a"b}')!), 'a `"` in text is escaped to " (no text may ever end an attribute)')+ok(renderMath('"a<b>c"', { syntax: 'typst' })!.includes('<b>'), 'typst quoted text escapes too')++console.log('\nTypst ≡ LaTeX on the shared tree\n')+const pairs: Array<[string, string]> = [['a/b', '\\frac{a}{b}'], ['(a+b)/c', '\\frac{a+b}{c}'], ['sqrt(2)', '\\sqrt{2}'], ['root(3, x)', '\\sqrt[3]{x}'], ['x^(n+1)', 'x^{n+1}'], ['sum_(i=1)^n i', '\\sum_{i=1}^{n} i'], ['mat(a, b; c, d)', '\\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix}'], ['cases(x & x >= 0, -x & x < 0)', '\\begin{cases} x & x \\ge 0 \\\\ -x & x < 0 \\end{cases}'], ['bb(R)', '\\mathbb{R}'], ['hat(x)', '\\hat{x}'], ['alpha + beta', '\\alpha + \\beta'], ['a <= b != c', 'a \\le b \\ne c'], ['"if" x', '\\text{if} x'], ['lim_(x -> oo) f', '\\lim_{x \\to \\infty} f']]+for (const [ty, tex] of pairs) ok(renderMath(ty, { syntax: 'typst', display: true }) === renderMath(tex, { display: true }), `typst \`${ty}\` ≡ latex \`${tex}\``)+// Round 2 closed the one difference there was: a LaTeX paren group is now+// ONE node too (as Temml prints it), so f(x)_i scripts the group in both.+const noExplicit = (k: string, v: unknown) => (k === 'explicit' ? undefined : v) // Typst sizes its groups (\\left-like); the STRUCTURE is what must agree+ok(JSON.stringify(parseMath('f(x)_i', { syntax: 'typst' }), noExplicit) === JSON.stringify(parseMath('f(x)_i'), noExplicit), 'f(x)_i: both front ends script the paren group')++console.log('\nthe formula cache is bounded\n')+ok(/const MATH_CACHE_MAX = 256/.test(render) && /if \(mathCache\.size > MATH_CACHE_MAX\) mathCache\.delete\(mathCache\.keys\(\)\.next\(\)\.value!\)/.test(render), 'a 256-entry LRU: the oldest key is evicted past the cap')+ok(/mathCache\.delete\(key\); mathCache\.set\(key, hit\)/.test(render), 'a hit is re-inserted so it becomes the newest (Map insertion order = LRU)')++console.log('\nmorph: the engine gives the morph nothing new to handle\n')+// present.ts pairs elements by data-flip-id and tweens the ELEMENT box; the+// <math> inside rides along, exactly as Temml's did. DOM-free, that reduces+// to: the same source renders to the same string on every call (the cache+// key is display+source), so the paired elements carry identical MathML and+// nothing about the engine can make a pair diverge. Measured live in Chrome+// (PR body, "Morph"): both engines gave the same rects at every sample.+ok(renderMath('\\frac{a}{b}') === renderMath('\\frac{a}{b}') && renderMath('\\frac{a}{b}', { display: true }) !== renderMath('\\frac{a}{b}'), 'same source → same string; display mode is part of the identity')+ok(renderMath('a^2')!.startsWith('<math ') && renderMath('a^2 + b^2')!.startsWith('<math '), 'a changed formula is still a <math> — the box morphs, the content snaps')+ok(!/\son[a-z]+=|\sid=|<script/i.test(renderMath('x = \\frac{-b \\pm \\sqrt{b^2 - 4ac}}{2a}')!), 'no ids or handlers that a flip pairing could collide on')++console.log('\nthe symbol table\n')+const texNames = SYMBOLS.map((s) => s.tex)+ok(new Set(texNames).size === texNames.length, `no duplicate LaTeX names (${texNames.length} rows)`)+ok(SYMBOLS.every((s) => [...s.cp].length >= 1 && s.typst.length > 0), 'every row has a glyph and a Typst name')+ok(styledChar('R', 'bb') === 'ℝ' && styledChar('a', 'bb') === '𝕒' && styledChar('7', 'bb') === '𝟟', 'styledChar: holes patched, lowercase and digits from the block')+ok(styledChar('x', 'rm') === 'x' && styledChar('!', 'bf') === '!', 'rm and non-letters pass through')++console.log(`\n${checks - failures}/${checks} checks passed`)+process.exit(failures ? 1 : 0)diff --git a/slides/package-lock.json b/slides/package-lock.jsonindex d5ac2778..79fbbcea 100644--- a/slides/package-lock.json+++ b/slides/package-lock.json@@ -1,18 +1,17 @@{"name": "bento-slides",- "version": "1.0.18",+ "version": "1.1.0","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "bento-slides",- "version": "1.0.18",+ "version": "1.1.0","license": "MIT","dependencies": {"moveable": "^0.53.0","reveal.js": "^5.2.1",- "selecto": "^1.26.3",- "temml": "^0.13.3"+ "selecto": "^1.26.3"},"devDependencies": {"@gfx/zopfli": "^1.0.15",@@ -1711,15 +1710,6 @@"node": ">=8"}},- "node_modules/temml": {- "version": "0.13.3",- "resolved": "https://registry.npmjs.org/temml/-/temml-0.13.3.tgz",- "integrity": "sha512-GLNEdf5qBWux3adbOxFus4jlds8nCdEIkkKq99m/4GGTfqnsjlVlK/i371Ux7yYSg/WNmOyAkNT/GJlZoJ0v+w==",- "license": "MIT",- "engines": {- "node": ">=18.13.0"- }- },"node_modules/tinyglobby": {"version": "0.2.17","resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz",diff --git a/slides/package.json b/slides/package.jsonindex cc15a843..3f8a5930 100644--- a/slides/package.json+++ b/slides/package.json@@ -13,8 +13,7 @@"dependencies": {"moveable": "^0.53.0","reveal.js": "^5.2.1",- "selecto": "^1.26.3",- "temml": "^0.13.3"+ "selecto": "^1.26.3"},"devDependencies": {"@gfx/zopfli": "^1.0.15",diff --git a/slides/src/maths/ast.ts b/slides/src/maths/ast.tsnew file mode 100644index 00000000..78ad7d79--- /dev/null+++ b/slides/src/maths/ast.ts@@ -0,0 +1,49 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — the shared tree. Both front ends (latex.ts, typst.ts) produce+ * this; mathml.ts prints it. A node is what a browser's MathML layout needs+ * to know and nothing more: there is no font metric, no glyph box, no layout+ * here — MathML Core does that part, which is the whole reason a maths engine+ * can be small.+ *+ * Parse → tree → print, no regex chains. What was measured to arrive here+ * is in docs/DECISIONS.md (2026-09-15, maths).+ */++export type MNode =+ | { k: 'row'; c: MNode[] }+ /** an identifier (mi), number (mn) or operator (mo) */+ | { k: 'sym'; cls: 'i' | 'n' | 'o'; t: string; /** upright multi-letter (sin, lim) */ fn?: boolean; /** stretchy fence/accent op */ stretchy?: boolean; /** \mathrm-style upright single letter */ up?: boolean; /** big operator (sum) */ big?: boolean; /** \big family: minsize in em */ size?: number; /** explicit lspace/rspace (\mid) */ pad?: string; /** render-time: operator after an operator */ prefix?: boolean }+ | { k: 'text'; t: string }+ | { k: 'space'; em: number }+ | { k: 'frac'; n: MNode; d: MNode; /** no bar (binom, atop) */ nobar?: boolean; /** \dfrac/\tfrac */ display?: boolean }+ | { k: 'sqrt'; b: MNode; i?: MNode }+ /** scripts; `limits` = under/over placement (sum in display mode, \limits) */+ | { k: 'scr'; b: MNode; sub?: MNode; sup?: MNode; limits?: boolean }+ /** \left … \right and \big fences — l/r may be '' for \left. */+ | { k: 'fence'; l: string; r: string; c: MNode; /** minsize multiplier for \big family */ size?: number; /** \left…\right: say stretchy out loud (plain parens stretch by the operator dictionary anyway) */ explicit?: boolean }+ | { k: 'table'; rows: MNode[][]; l?: string; r?: string; /** column aligns, e.g. 'rl' for align */ align?: string; /** row lines */ lines?: boolean }+ | { k: 'accent'; b: MNode; a: string; under?: boolean; stretchy?: boolean }+ /** font/colour/box wrapper */+ | { k: 'style'; c: MNode; font?: Font; color?: string; box?: boolean; /** \cancel */ cancel?: boolean }++export type Font = 'bb' | 'cal' | 'frak' | 'bf' | 'it' | 'sf' | 'tt' | 'rm' | 'scr'++export const row = (c: MNode[]): MNode => (c.length === 1 ? c[0] : { k: 'row', c })+export const mi = (t: string, extra?: Partial<Extract<MNode, { k: 'sym' }>>): MNode => ({ k: 'sym', cls: 'i', t, ...extra })+export const mn = (t: string): MNode => ({ k: 'sym', cls: 'n', t })+export const mo = (t: string, extra?: Partial<Extract<MNode, { k: 'sym' }>>): MNode => ({ k: 'sym', cls: 'o', t, ...extra })++export class MathError extends Error {}++/** A table symbol as a node — the spellings Temml uses, so a deck keeps its look:+ * Greek capitals upright, \mid a bar with relation spacing, \iff/\implies+ * padded by a thick space each side. Both front ends go through here. */+export function symNode(s: { tex: string; cp: string; cls: 'i' | 'o' | 'big' }): MNode {+ if (s.cls === 'i') return /^[Α-Ω]$/.test(s.cp) ? mi(s.cp, { up: true }) : mi(s.cp)+ if (s.cls === 'big') return mo(s.cp, { big: true })+ if (s.tex === 'mid') return mo('|', { pad: '0.22em' })+ if (s.tex === 'iff' || s.tex === 'implies' || s.tex === 'impliedby') return { k: 'row', c: [{ k: 'space', em: 0.2778 }, mo(s.cp), { k: 'space', em: 0.2778 }] }+ return mo(s.cp)+}diff --git a/slides/src/maths/index.ts b/slides/src/maths/index.tsnew file mode 100644index 00000000..f86b4667--- /dev/null+++ b/slides/src/maths/index.ts@@ -0,0 +1,42 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — the entry point render.ts calls instead of Temml. Never+ * throws: a formula the parser refuses comes back as null so the caller+ * leaves the author's text exactly as typed (Temml's throwOnError contract).+ *+ * SYNTAX SELECTION (decided by the maintainer, 2026-09-15): a formula is+ * LaTeX unless its source begins with the marker `typst:` — `$typst: a/b$`+ * inline, `$$typst: a/b$$` display. The marker sits immediately after the+ * opening delimiter, is case-sensitive, and may be followed by whitespace.+ * The document stores the source with the marker; nothing in the format+ * changes, and an older shell shows `$typst: a/b$` as typed (degraded,+ * legible — the promise `$…$` already makes). `isTypst(src)` is the one+ * test; render.ts applies it.+ */++import { parseLatex } from './latex.ts'+import { parseTypst } from './typst.ts'+import { toMathML } from './mathml.ts'+import type { MNode } from './ast.ts'++export type Syntax = 'latex' | 'typst'++/** The marker, exactly: `typst:` at the very start, then optional whitespace. */+export const TYPST_MARKER = /^typst:\s*/+export const isTypst = (src: string): boolean => TYPST_MARKER.test(src)+/** Source with the marker removed (unchanged when there is none). */+export const stripMarker = (src: string): string => src.replace(TYPST_MARKER, '')++export function parseMath(src: string, opts: { display?: boolean; syntax?: Syntax } = {}): MNode {+ return (opts.syntax === 'typst' ? parseTypst : parseLatex)(src, !!opts.display)+}++/** MathML for `src`, or null when it is not valid maths in that syntax. */+export function renderMath(src: string, opts: { display?: boolean; syntax?: Syntax } = {}): string | null {+ try {+ return toMathML(parseMath(src, opts), !!opts.display)+ } catch {+ return null+ }+}diff --git a/slides/src/maths/latex.ts b/slides/src/maths/latex.tsnew file mode 100644index 00000000..2cdc5157--- /dev/null+++ b/slides/src/maths/latex.ts@@ -0,0 +1,255 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — the LaTeX front end: tokenizer + recursive-descent parser →+ * the shared tree (ast.ts). Supported set = what our decks use (the corpus+ * table in the spike handoff) plus the obvious tier. Unknown commands throw+ * MathError, which index.ts turns into "leave the source as typed", the same+ * contract Temml's throwOnError path has today.+ */++import { type MNode, type Font, row, mi, mn, mo, MathError, symNode } from './ast.ts'+import { byTex, FUNCTIONS, LIMIT_FUNCTIONS } from './symbols.ts'++type Tok = { t: 'cmd' | 'ch' | '{' | '}' | '^' | '_' | '&' | '\\\\' | 'ws'; v: string }++function tokenize(src: string): Tok[] {+ const out: Tok[] = []+ let i = 0+ while (i < src.length) {+ const c = src[i]+ if (c === '\\') {+ const m = /^\\([a-zA-Z]+|.)/s.exec(src.slice(i))+ if (!m) throw new MathError('dangling backslash')+ i += m[0].length+ if (m[1] === '\\') out.push({ t: '\\\\', v: '\\\\' })+ else out.push({ t: 'cmd', v: m[1] })+ // a control word swallows the whitespace after it+ if (/^[a-zA-Z]+$/.test(m[1])) while (i < src.length && /\s/.test(src[i])) i+++ continue+ }+ if (/\s/.test(c)) { while (i < src.length && /\s/.test(src[i])) i++; out.push({ t: 'ws', v: ' ' }); continue }+ if (c === '%') { while (i < src.length && src[i] !== '\n') i++; continue }+ if ('{}^_&'.includes(c)) { out.push({ t: c as Tok['t'], v: c }); i++; continue }+ out.push({ t: 'ch', v: c }); i+++ }+ return out+}++const OPEN_FENCES: Record<string, string> = { '(': '(', '[': '[', '\\{': '{', '|': '|', '.': '', '\\langle': '⟨', '\\lfloor': '⌊', '\\lceil': '⌈', '\\|': '‖', '\\vert': '|', '\\Vert': '‖', '\\lbrace': '{', '\\lbrack': '[' }+const CLOSE_FENCES: Record<string, string> = { ')': ')', ']': ']', '\\}': '}', '|': '|', '.': '', '\\rangle': '⟩', '\\rfloor': '⌋', '\\rceil': '⌉', '\\|': '‖', '\\vert': '|', '\\Vert': '‖', '\\rbrace': '}', '\\rbrack': ']' }+const BIG: Record<string, number> = { big: 1.2, Big: 1.8, bigg: 2.4, Bigg: 3 }+const ACCENTS: Record<string, [string, boolean?]> = { hat: ['^'], widehat: ['^', true], tilde: ['~'], widetilde: ['~', true], bar: ['‾'], overline: ['‾', true], vec: ['→'], dot: ['˙'], ddot: ['¨'], acute: ['´'], grave: ['`'], breve: ['˘'], check: ['ˇ'], overrightarrow: ['→', true], overleftarrow: ['←', true] }+const UNDER: Record<string, string> = { underline: '_', underbrace: '⏟', underrightarrow: '→' }+const OVER: Record<string, string> = { overbrace: '⏞' }+const FONTS: Record<string, Font> = { mathbb: 'bb', mathcal: 'cal', mathscr: 'scr', mathfrak: 'frak', mathbf: 'bf', boldsymbol: 'bf', bm: 'bf', mathit: 'it', mathsf: 'sf', mathtt: 'tt', mathrm: 'rm', operatorname: 'rm', textbf: 'bf', textit: 'it' }+const SPACES: Record<string, number> = { ',': 0.1667, ':': 0.2222, ';': 0.2778, '!': -0.1667, quad: 1, qquad: 2, ' ': 0.25 }+const ENV_FENCES: Record<string, [string, string]> = { matrix: ['', ''], pmatrix: ['(', ')'], bmatrix: ['[', ']'], Bmatrix: ['{', '}'], vmatrix: ['|', '|'], Vmatrix: ['‖', '‖'], cases: ['{', ''], aligned: ['', ''], align: ['', ''], 'align*': ['', ''], gathered: ['', ''], gather: ['', ''], array: ['', ''], smallmatrix: ['', ''] }++class Parser {+ i = 0+ /** inside \text{…} whitespace is content; everywhere else it is nothing */+ raw = false+ private toks: Tok[]+ private display: boolean+ constructor(toks: Tok[], display: boolean) { this.toks = toks; this.display = display }+ private skipWs() { if (!this.raw) while (this.toks[this.i]?.t === 'ws') this.i++ }+ peek(): Tok | undefined { this.skipWs(); return this.toks[this.i] }+ next(): Tok { this.skipWs(); const t = this.toks[this.i++]; if (!t) throw new MathError('unexpected end'); return t }+ is(t: Tok['t'], v?: string): boolean { const p = this.peek(); return !!p && p.t === t && (v === undefined || p.v === v) }++ /** A sequence up to a terminator the caller owns. */+ parseRow(stop: (t: Tok) => boolean): MNode {+ const c: MNode[] = []+ while (this.peek() && !stop(this.peek()!)) c.push(this.parseScripted())+ return row(c)+ }+ parseGroup(): MNode {+ if (this.is('{')) {+ this.next()+ const r = this.parseRow((t) => t.t === '}')+ if (!this.is('}')) throw new MathError('missing }')+ this.next()+ return r+ }+ return this.parseAtom()+ }+ /** atom followed by any ^ _ scripts */+ parseScripted(): MNode {+ let base = this.parseAtom()+ let sub: MNode | undefined, sup: MNode | undefined+ // big operators take under/over limits in display mode — except the+ // integrals, which TeX (and Temml) keep at the side+ let limits = base.k === 'sym' && !!base.big && this.display && !/[∫∬∭∮]/.test(base.t)+ if (base.k === 'sym' && base.fn && LIMIT_FUNCTIONS.includes(base.t)) limits = this.display+ for (;;) {+ if (this.is('cmd', 'limits')) { this.next(); limits = true; continue }+ if (this.is('cmd', 'nolimits')) { this.next(); limits = false; continue }+ if (this.is('^')) { this.next(); if (sup) throw new MathError('double superscript'); sup = this.parseGroup(); continue }+ if (this.is('_')) { this.next(); if (sub) throw new MathError('double subscript'); sub = this.parseGroup(); continue }+ // primes are superscripts+ if (this.is('ch', "'")) { const ps: MNode[] = []; while (this.is('ch', "'")) { this.next(); ps.push(mo('′', { pad: '0em' })) } const p = ps.length === 1 ? ps[0] : { k: 'row', c: ps } as MNode; sup = sup ? row([p, sup]) : p; continue }+ break+ }+ if (sub || sup) base = { k: 'scr', b: base, sub, sup, limits: limits || undefined }+ return base+ }+ parseAtom(): MNode {+ const t = this.next()+ switch (t.t) {+ case '{': this.i--; return this.parseGroup()+ case '}': throw new MathError('unexpected }')+ case '^': case '_': throw new MathError('script without base')+ case '&': case '\\\\': throw new MathError('alignment outside a table')+ case 'ch': return this.charAtom(t.v)+ case 'cmd': return this.command(t.v)+ case 'ws': return this.parseAtom() // unreachable outside raw mode+ }+ }+ charAtom(v: string): MNode {+ if (/[0-9]/.test(v)) { let n = v; while (this.is('ch') && /[0-9.]/.test(this.peek()!.v)) n += this.next().v; return mn(n) }+ // `(…)` / `[…]` with the closer in the same group is ONE node, the way Temml+ // (and Typst) see it: a script after `)` then belongs to the group.+ if (v === '(' || v === '[') {+ const close = v === '(' ? ')' : ']'+ let depth = 0, j = this.i, found = false+ for (; j < this.toks.length; j++) {+ const t = this.toks[j]+ if (t.t === '}' || t.t === '&' || t.t === '\\\\' || (t.t === 'cmd' && (t.v === 'right' || t.v === 'end'))) break+ if (t.t === 'ch' && t.v === v) depth+++ else if (t.t === 'ch' && t.v === close) { if (depth === 0) { found = true; break } depth-- }+ }+ if (found) {+ const c = this.parseRow((t) => t.t === 'ch' && t.v === close && this.i === j)+ this.next()+ return { k: 'fence', l: v, r: close, c }+ }+ }+ if (/[a-zA-Z]/.test(v)) return mi(v)+ if ('+-*/=<>,;:!?|.()[]'.includes(v)) return mo(v === '-' ? '−' : v === '*' ? '∗' : v)+ return mi(v)+ }+ command(name: string): MNode {+ const sym = byTex.get(name)+ if (sym) return symNode(sym)+ if (FUNCTIONS.includes(name) || LIMIT_FUNCTIONS.includes(name)) return mi(name, { fn: true })+ if (name in SPACES) return { k: 'space', em: SPACES[name] }+ if (name in FONTS) return this.font(FONTS[name], name === 'operatorname')+ if (name in ACCENTS) { const [a, s] = ACCENTS[name]; return { k: 'accent', b: this.parseGroup(), a, stretchy: s } }+ if (name in UNDER) { const b = this.parseGroup(); const node: MNode = { k: 'accent', b, a: UNDER[name], under: true, stretchy: true }; return this.braceLabel(node, name === 'underbrace', true) }+ if (name in OVER) { const b = this.parseGroup(); const node: MNode = { k: 'accent', b, a: OVER[name], stretchy: true }; return this.braceLabel(node, true, false) }+ if (name in BIG || /^[bB]igg?[lrm]$/.test(name)) {+ const size = BIG[name.replace(/[lrm]$/, '')]+ const d = this.delim()+ return mo(d, { stretchy: true, size })+ }+ switch (name) {+ case 'frac': case 'dfrac': case 'tfrac': return { k: 'frac', n: this.parseGroup(), d: this.parseGroup(), display: name === 'dfrac' ? true : name === 'tfrac' ? false : undefined }+ case 'binom': case 'dbinom': case 'tbinom': return { k: 'fence', l: '(', r: ')', c: { k: 'frac', n: this.parseGroup(), d: this.parseGroup(), nobar: true }, explicit: true }+ case 'sqrt': {+ let idx: MNode | undefined+ if (this.is('ch', '[')) { this.next(); idx = this.parseRow((t) => t.t === 'ch' && t.v === ']'); this.next() }+ return { k: 'sqrt', b: this.parseGroup(), i: idx }+ }+ case 'left': {+ const l = this.delim()+ const c = this.parseRow((t) => t.t === 'cmd' && t.v === 'right')+ if (!this.is('cmd', 'right')) throw new MathError('missing \\right')+ this.next()+ const r = this.delim(true)+ return { k: 'fence', l, r, c, explicit: true }+ }+ case 'right': throw new MathError('\\right without \\left')+ case 'text': case 'textrm': case 'textnormal': case 'mbox': case 'textsf': case 'texttt': return { k: 'text', t: this.rawGroup() }+ case 'textcolor': { const color = this.rawGroup(); return { k: 'style', c: this.parseGroup(), color } }+ case 'color': { const color = this.rawGroup(); return { k: 'style', c: this.parseRow((t) => t.t === '}'), color } }+ case 'boxed': return { k: 'style', c: this.parseGroup(), box: true }+ case 'cancel': return { k: 'style', c: this.parseGroup(), cancel: true }+ case 'displaystyle': { this.display = true; return { k: 'row', c: [] } }+ case 'textstyle': case 'scriptstyle': { this.display = false; return { k: 'row', c: [] } }+ case 'begin': return this.environment()+ case 'end': throw new MathError('\\end without \\begin')+ case 'not': { const a = this.parseGroup(); return a.k === 'sym' ? mo(a.t + '̸') : a }+ case 'stackrel': case 'overset': { const top = this.parseGroup(); const b = this.parseGroup(); return { k: 'scr', b, sup: top, limits: true } }+ case 'underset': { const bot = this.parseGroup(); const b = this.parseGroup(); return { k: 'scr', b, sub: bot, limits: true } }+ case 'phantom': return { k: 'style', c: this.parseGroup(), color: 'transparent' }+ case 'lVert': case 'rVert': return mo('‖')+ case 'lvert': case 'rvert': return mo('|')+ case 'lbrack': return mo('[')+ case 'rbrack': return mo(']')+ case 'hline': return { k: 'row', c: [] }+ case '$': return mi('$')+ case '%': return mi('%')+ case '&': return mi('&')+ case '#': return mi('#')+ case '_': return mi('_')+ case ' ': return { k: 'space', em: 0.25 }+ }+ throw new MathError(`unknown command \\${name}`)+ }+ /** a \left/\right/\big delimiter token */+ delim(close = false): string {+ const t = this.next()+ const key = t.t === 'cmd' ? '\\' + t.v : t.v+ const table = close ? CLOSE_FENCES : OPEN_FENCES+ if (key in table) return table[key]+ if (key in OPEN_FENCES) return OPEN_FENCES[key]+ if (key in CLOSE_FENCES) return CLOSE_FENCES[key]+ if (t.t === 'cmd' && byTex.get(t.v)) return byTex.get(t.v)!.cp+ if (t.t === 'ch' && '<>/'.includes(t.v)) return t.v === '<' ? '⟨' : t.v === '>' ? '⟩' : '/'+ throw new MathError(`bad delimiter ${key}`)+ }+ font(f: Font, isOp = false): MNode {+ if (isOp) return mi(this.rawGroup(), { fn: true })+ return { k: 'style', c: this.parseGroup(), font: f }+ }+ /** \text{…}: the braces' content verbatim (tokens joined, spaces kept) */+ rawGroup(): string {+ if (!this.is('{')) return this.next().v+ this.next()+ this.raw = true+ let depth = 1, s = ''+ try {+ while (depth) {+ const t = this.next()+ if (t.t === '{') depth+++ else if (t.t === '}') { depth--; if (!depth) break }+ else s += t.t === 'cmd' ? (t.v === ' ' ? ' ' : (byTex.get(t.v)?.cp ?? '\\' + t.v)) : t.v+ }+ } finally { this.raw = false }+ return s+ }+ braceLabel(node: MNode, allowSup: boolean, under: boolean): MNode {+ // \underbrace{x}_{label} / \overbrace{x}^{label}+ if (under && this.is('_')) { this.next(); return { k: 'scr', b: node, sub: this.parseGroup(), limits: true } }+ if (!under && allowSup && this.is('^')) { this.next(); return { k: 'scr', b: node, sup: this.parseGroup(), limits: true } }+ return node+ }+ environment(): MNode {+ const name = this.rawGroup()+ const fences = ENV_FENCES[name]+ if (!fences) throw new MathError(`unknown environment ${name}`)+ if (name === 'array') this.rawGroup() // column spec, ignored beyond alignment+ const rows: MNode[][] = [[]]+ const cur = () => rows[rows.length - 1]+ const cell = (): MNode => this.parseRow((t) => t.t === '&' || t.t === '\\\\' || (t.t === 'cmd' && t.v === 'end'))+ cur().push(cell())+ for (;;) {+ if (this.is('&')) { this.next(); cur().push(cell()); continue }+ if (this.is('\\\\')) { this.next(); if (this.is('ch', '[')) { while (!this.is('ch', ']')) this.next(); this.next() } rows.push([]); cur().push(cell()); continue }+ if (this.is('cmd', 'end')) { this.next(); const e = this.rawGroup(); if (e !== name) throw new MathError('mismatched \\end'); break }+ throw new MathError('bad table')+ }+ // a trailing \\ leaves an empty last row+ if (rows.length > 1 && rows[rows.length - 1].length === 1 && rows[rows.length - 1][0].k === 'row' && (rows[rows.length - 1][0] as { c: MNode[] }).c.length === 0) rows.pop()+ const align = name.startsWith('align') || name === 'aligned' ? 'rl' : name === 'cases' ? 'll' : 'c'+ return { k: 'table', rows, l: fences[0], r: fences[1], align }+ }+}++export function parseLatex(src: string, display: boolean): MNode {+ const p = new Parser(tokenize(src), display)+ const r = p.parseRow(() => false)+ if (p.peek()) throw new MathError('trailing input')+ return r+}diff --git a/slides/src/maths/mathml.ts b/slides/src/maths/mathml.tsnew file mode 100644index 00000000..83b62e39--- /dev/null+++ b/slides/src/maths/mathml.ts@@ -0,0 +1,146 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — tree → MathML Core. The browser lays it out; we only say what+ * each box is. Font styles become Unicode code points (Chrome ignores+ * mathvariant on <mi>; Temml does the same). \boxed is a border, \textcolor+ * is mathcolor + style, \cancel is a background gradient line — the three+ * things MathML Core dropped that decks still ask for.+ */++import type { MNode, Font } from './ast.ts'+import { styledChar } from './symbols.ts'++const esc = (s: string) => s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')++// operators that TeX spaces as relations/binaries get lspace/rspace from the+// browser's operator dictionary — we emit plain <mo> and let it work. The one+// thing the dictionary cannot know is a fence we invented (\left.), so '' is+// an invisible mo with no width.++export function toMathML(n: MNode, display: boolean): string {+ return `<math xmlns="http://www.w3.org/1998/Math/MathML"${display ? ' display="block"' : ''}>${print(n, undefined)}</math>`+}++/** a function name, or a scripted function name (\sin^2, \lim_{…}) */+const isFn = (n: MNode): boolean => (n.k === 'sym' && n.cls === 'i' && !!n.fn) || (n.k === 'scr' && isFn(n.b))++function print(n: MNode, font: Font | undefined): string {+ switch (n.k) {+ case 'row': {+ if (n.c.length === 0) return '<mrow></mrow>'+ if (n.c.length === 1) return print(n.c[0], font)+ // TeX puts a thin space between a function name and its operand+ // (\sin x): function application + 3mu, the way Temml spells it too.+ const parts: string[] = []+ n.c.forEach((c, i) => {+ // an operator straight after another operator (\nabla \cdot, - -) is+ // prefix in TeX's eyes — no left spacing; Temml marks it, so do we+ const prev = n.c[i - 1]+ const afterOp = c.k === 'sym' && c.cls === 'o' && '+−±∓⋅×∗'.includes(c.t) && prev?.k === 'sym' && prev.cls === 'o' && '+−±∓⋅×∗=<>≤≥≠∇∈'.includes(prev.t)+ parts.push(afterOp && c.k === 'sym' ? print({ ...c, prefix: true }, font) : print(c, font))+ const nxt = n.c[i + 1]+ if (nxt && isFn(c) && !(nxt.k === 'sym' && nxt.cls === 'o')) parts.push(nxt.k === 'fence' && !nxt.size ? '<mo>\u2061</mo>' : '<mo>\u2061</mo><mspace width="0.1667em"></mspace>')+ })+ return `<mrow>${parts.join('')}</mrow>`+ }+ case 'sym': {+ if (n.cls === 'n') return `<mn>${esc(n.t)}</mn>`+ if (n.cls === 'i') {+ if (n.fn) return `<mi>${esc(n.t)}</mi>` // multi-letter mi is upright by MathML default+ const t = font && font !== 'rm' ? [...n.t].map((c) => styledChar(c, font)).join('') : n.t+ // a single-letter mi is italic by default; \mathrm asks for upright+ return font === 'rm' || n.up ? `<mi mathvariant="normal">${esc(t)}</mi>` : `<mi>${esc(t)}</mi>`+ }+ const attrs: string[] = []+ if (n.pad !== undefined) attrs.push(` lspace="${n.pad}" rspace="${n.pad}"`)+ if (n.prefix && !'([{)]}'.includes(n.t)) attrs.push(' form="prefix" stretchy="false"')+ if (n.t === '|' && n.pad !== undefined) attrs.push(' stretchy="false"')+ // a bare "(" in the middle of a row would be inferred INFIX by MathML+ // Core and spaced like a binary operator; TeX treats it as an opening+ // fence. Temml spells this out per paren; so do we.+ if (!n.stretchy && '([{'.includes(n.t)) attrs.push(' fence="true" form="prefix" stretchy="false"')+ else if (!n.stretchy && ')]}'.includes(n.t)) attrs.push(' fence="true" form="postfix" stretchy="false"')+ if (n.stretchy) attrs.push(' stretchy="true"')+ if (n.size) attrs.push(` minsize="${n.size}em" maxsize="${n.size}em"`)+ if (n.big) attrs.push(' largeop="true"')+ return `<mo${attrs.join('')}>${esc(n.t)}</mo>`+ }+ // MathML trims an mtext's edge whitespace; \text{if } keeps its space+ // only as a no-break space (Temml does the same)+ case 'text': return `<mtext>${esc(n.t).replace(/ /g, '\u00a0')}</mtext>`+ case 'space': return n.em < 0 ? `<mrow style="margin-left:${n.em}em;"></mrow>` : `<mspace width="${n.em}em"></mspace>`+ case 'frac': {+ const inner = `<mfrac${n.nobar ? ' linethickness="0"' : ''}>${print(n.n, font)}${print(n.d, font)}</mfrac>`+ return n.display === undefined ? inner : `<mstyle displaystyle="${n.display}">${inner}</mstyle>`+ }+ case 'sqrt': return n.i ? `<mroot>${print(n.b, font)}${print(n.i, font)}</mroot>` : `<msqrt>${print(n.b, font)}</msqrt>`+ case 'scr': {+ const b = print(n.b, font), s = n.sub && print(n.sub, font), p = n.sup && print(n.sup, font)+ if (n.limits) return s && p ? `<munderover>${b}${s}${p}</munderover>` : s ? `<munder>${b}${s}</munder>` : `<mover>${b}${p}</mover>`+ return s && p ? `<msubsup>${b}${s}${p}</msubsup>` : s ? `<msub>${b}${s}</msub>` : `<msup>${b}${p}</msup>`+ }+ case 'fence': {+ // \left…\right / \big: stretchy, said out loud. A plain paren group+ // (Typst's, or LaTeX's when it needs an mrow): the bare-paren spelling.+ const f = (d: string, close: boolean) => n.explicit || n.size+ ? `<mo fence="true" form="${close ? 'postfix' : 'prefix'}" stretchy="true"${n.size ? ` minsize="${n.size}em" maxsize="${n.size}em"` : ''}>${esc(d)}</mo>`+ : `<mo fence="true" form="${close ? 'postfix' : 'prefix'}" stretchy="false">${esc(d)}</mo>`+ return `<mrow>${f(n.l, false)}${print(n.c, font)}${f(n.r, true)}</mrow>`+ }+ case 'table': {+ const cols = n.align ?? 'c'+ // MathML Core has no columnspacing: the gap between columns is padding+ // on the cells (Temml does the same, 0.5em a side, none at the edges)+ const ncol = Math.max(...n.rows.map((r) => r.length))+ // Temml's exact figure (an absolute 5.9776pt a side, not an em), so a+ // matrix on a slide keeps the width it has today+ // cases: 1em before the condition column; aligned: none (the & carries+ // the relation's own spacing); matrices: Temml's absolute 5.9776pt+ const pad = (i: number) => cols === 'll' ? `padding-left:${i === 0 ? '0' : '1'}em;padding-right:0em`+ : cols === 'rl' ? 'padding-left:0em;padding-right:0em'+ : `padding-left:${i === 0 ? '0em' : '5.9776pt'};padding-right:${i === ncol - 1 ? '0em' : '5.9776pt'}`+ // centred cells say nothing (the default); left/right say so the way+ // Temml's tml-left/tml-right classes would with its stylesheet+ // Every column is CENTRED — cases and aligned included. TeX would+ // left/right-align them, and Temml asks for that through CSS classes;+ // but Bento never loads Temml's stylesheet, so every deck today renders+ // those columns centred, and the maintainer chose to keep that look+ // (2026-09-15): nothing moves on update. `al` still decides the padding.+ const body = n.rows.map((r) => `<mtr>${r.map((c, i) => `<mtd style="${pad(i)}">${print(c, font)}</mtd>`).join('')}</mtr>`).join('')+ // aligned/gather rows are display-style (Temml sets it on the table)+ const table = `<mtable${cols === 'rl' ? ' displaystyle="true"' : ''}>${body}</mtable>`+ return n.l || n.r ? `<mrow><mo fence="true" form="prefix" stretchy="true">${esc(n.l ?? '')}</mo>${table}<mo fence="true" form="postfix" stretchy="true">${esc(n.r ?? '')}</mo></mrow>` : table+ }+ case 'accent': {+ // math-depth:0 keeps the accent glyph at full size inside scripts — the+ // same spelling Temml uses, so a deck looks the way it does today+ // Temml keeps hats/bars/tildes at full size (math-depth:0) but lets the+ // arrow accents shrink to script size — matched, so \vec looks as today+ const full = n.stretchy || !/[→←]/.test(n.a)+ const acc = `<mo stretchy="${n.stretchy ? 'true' : 'false'}"${full ? ' style="math-depth:0"' : ''}>${esc(n.a)}</mo>`+ // no accent="true": Chrome then draws the glyph as a plain over-script+ // at math-depth 0, which is how Temml's output (and so every deck today)+ // looks; with the attribute the hat sits higher and larger+ return n.under ? `<munder>${print(n.b, font)}${acc}</munder>` : `<mover>${print(n.b, font)}${acc}</mover>`+ }+ case 'style': {+ const inner = print(n.c, n.font ?? font)+ const st: string[] = []+ // A colour reaches a style attribute, so it is the ONE place author text+ // could carry CSS. Only a colour shape passes: #hex, a colour word,+ // rgb()/hsl() of digits. Anything else (a `;`, `url(`, an expression) is+ // dropped and the text renders uncoloured rather than refused.+ if (n.color && isCssColor(n.color)) st.push(`color:${n.color}`)+ if (n.box) st.push('padding:3pt;border:1px solid')+ if (n.cancel) st.push('background:linear-gradient(to top right,transparent 47%,currentColor 47%,currentColor 53%,transparent 53%)')+ return st.length ? `<mrow style="${st.join(';')}">${inner}</mrow>` : inner+ }+ }+}++/** A CSS colour and nothing else: hex, a name, or rgb()/rgba()/hsl()/hsla()+ * over numbers, percentages, commas, slashes and spaces. */+export const isCssColor = (c: string): boolean =>+ /^#[0-9a-f]{3,8}$/i.test(c) || /^[a-z]{3,20}$/i.test(c) || /^(rgba?|hsla?)\(\s*[\d.%,\s/]+\)$/i.test(c)+diff --git a/slides/src/maths/symbols.ts b/slides/src/maths/symbols.tsnew file mode 100644index 00000000..ec179fac--- /dev/null+++ b/slides/src/maths/symbols.ts@@ -0,0 +1,107 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — the ONE symbol table. Each row: LaTeX name (without the+ * backslash), Typst name, code point, class (i = identifier, o = operator).+ * Both front ends look symbols up here; there is no second list anywhere.+ * Every row costs bytes in the shell, so the table is what our decks and the+ * obvious tier need, not what TeX has.+ */++export type SymClass = 'i' | 'o' | 'big'+export type Sym = { tex: string; typst: string; cp: string; cls: SymClass }++// tex, typst, glyph, class — one line each so the table is diffable.+const T = (tex: string, typst: string, cp: string, cls: SymClass = 'o'): Sym => ({ tex, typst, cp, cls })++export const SYMBOLS: Sym[] = [+ // greek (lowercase italic in maths, uppercase upright)+ T('alpha', 'alpha', 'α', 'i'), T('beta', 'beta', 'β', 'i'), T('gamma', 'gamma', 'γ', 'i'), T('delta', 'delta', 'δ', 'i'),+ T('epsilon', 'epsilon', 'ϵ', 'i'), T('varepsilon', 'epsilon.alt', 'ε', 'i'), T('zeta', 'zeta', 'ζ', 'i'), T('eta', 'eta', 'η', 'i'),+ T('theta', 'theta', 'θ', 'i'), T('vartheta', 'theta.alt', 'ϑ', 'i'), T('iota', 'iota', 'ι', 'i'), T('kappa', 'kappa', 'κ', 'i'),+ T('lambda', 'lambda', 'λ', 'i'), T('mu', 'mu', 'μ', 'i'), T('nu', 'nu', 'ν', 'i'), T('xi', 'xi', 'ξ', 'i'),+ T('pi', 'pi', 'π', 'i'), T('rho', 'rho', 'ρ', 'i'), T('sigma', 'sigma', 'σ', 'i'), T('tau', 'tau', 'τ', 'i'),+ T('upsilon', 'upsilon', 'υ', 'i'), T('phi', 'phi', 'ϕ', 'i'), T('varphi', 'phi.alt', 'φ', 'i'), T('chi', 'chi', 'χ', 'i'),+ T('psi', 'psi', 'ψ', 'i'), T('omega', 'omega', 'ω', 'i'),+ T('Gamma', 'Gamma', 'Γ', 'i'), T('Delta', 'Delta', 'Δ', 'i'), T('Theta', 'Theta', 'Θ', 'i'), T('Lambda', 'Lambda', 'Λ', 'i'),+ T('Xi', 'Xi', 'Ξ', 'i'), T('Pi', 'Pi', 'Π', 'i'), T('Sigma', 'Sigma', 'Σ', 'i'), T('Phi', 'Phi', 'Φ', 'i'),+ T('Psi', 'Psi', 'Ψ', 'i'), T('Omega', 'Omega', 'Ω', 'i'),+ // binary operators+ T('pm', 'plus.minus', '±'), T('mp', 'minus.plus', '∓'), T('times', 'times', '×'), T('div', 'div', '÷'),+ T('cdot', 'dot.op', '⋅'), T('ast', 'ast', '∗'), T('star', 'star', '⋆'), T('circ', 'compose', '∘'),+ T('bullet', 'bullet', '∙'), T('cap', 'sect', '∩'), T('cup', 'union', '∪'), T('setminus', 'without', '∖'),+ T('oplus', 'plus.circle', '⊕'), T('otimes', 'times.circle', '⊗'), T('wedge', 'and', '∧'), T('vee', 'or', '∨'),+ // relations+ T('le', 'lt.eq', '≤'), T('leq', 'lt.eq', '≤'), T('ge', 'gt.eq', '≥'), T('geq', 'gt.eq', '≥'), T('ne', 'eq.not', '≠'), T('neq', 'eq.not', '≠'),+ T('approx', 'approx', '≈'), T('equiv', 'equiv', '≡'), T('sim', 'tilde.op', '∼'), T('simeq', 'tilde.eq', '≃'), T('cong', 'tilde.equiv', '≅'),+ T('propto', 'prop', '∝'), T('ll', 'lt.double', '≪'), T('gg', 'gt.double', '≫'), T('prec', 'prec', '≺'), T('succ', 'succ', '≻'),+ T('subset', 'subset', '⊂'), T('supset', 'supset', '⊃'), T('subseteq', 'subset.eq', '⊆'), T('supseteq', 'supset.eq', '⊇'),+ T('in', 'in', '∈'), T('notin', 'in.not', '∉'), T('ni', 'in.rev', '∋'), T('parallel', 'parallel', '∥'), T('perp', 'perp', '⟂'),+ T('mid', 'divides', '|'), T('models', 'models', '⊧'), T('vdash', 'tack.r', '⊢'),+ // arrows+ T('to', 'arrow.r', '→'), T('rightarrow', 'arrow.r', '→'), T('leftarrow', 'arrow.l', '←'), T('leftrightarrow', 'arrow.l.r', '↔'),+ T('Rightarrow', 'arrow.r.double', '⇒'), T('Leftarrow', 'arrow.l.double', '⇐'), T('Leftrightarrow', 'arrow.l.r.double', '⇔'), T('iff', 'arrow.l.r.double.long', '⟺'),+ T('mapsto', 'arrow.r.bar', '↦'), T('longrightarrow', 'arrow.r.long', '⟶'), T('uparrow', 'arrow.t', '↑'), T('downarrow', 'arrow.b', '↓'),+ T('implies', 'arrow.r.double.long', '⟹'), T('hookrightarrow', 'arrow.r.hook', '↪'),+ // logic & sets+ T('forall', 'forall', '∀', 'i'), T('exists', 'exists', '∃', 'i'), T('nexists', 'exists.not', '∄', 'i'), T('neg', 'not', '¬'), T('lnot', 'not', '¬'),+ T('emptyset', 'emptyset', '∅', 'i'), T('varnothing', 'nothing', '∅', 'i'), T('infty', 'infinity', '∞', 'i'), T('partial', 'diff', '∂', 'i'), T('nabla', 'nabla', '∇'),+ T('angle', 'angle', '∠'), T('triangle', 'triangle', '△'), T('hbar', 'planck.reduce', 'ℏ', 'i'), T('ell', 'ell', 'ℓ', 'i'),+ T('Re', 'Re', 'ℜ', 'i'), T('Im', 'Im', 'ℑ', 'i'), T('aleph', 'aleph', 'ℵ', 'i'), T('wp', 'wp', '℘', 'i'),+ T('degree', 'degree', '°'), T('prime', 'prime', '′'), T('therefore', 'therefore', '∴'), T('because', 'because', '∵'),+ // dots+ T('ldots', 'dots.h', '…'), T('cdots', 'dots.h.c', '⋯'), T('vdots', 'dots.v', '⋮'), T('ddots', 'dots.down', '⋱'), T('dots', 'dots', '…'),+ // big operators (limits go under/over in display mode)+ T('sum', 'sum', '∑', 'big'), T('prod', 'product', '∏', 'big'), T('coprod', 'coproduct', '∐', 'big'),+ T('int', 'integral', '∫', 'big'), T('iint', 'integral.double', '∬', 'big'), T('iiint', 'integral.triple', '∭', 'big'), T('oint', 'integral.cont', '∮', 'big'),+ T('bigcup', 'union.big', '⋃', 'big'), T('bigcap', 'sect.big', '⋂', 'big'), T('bigoplus', 'plus.circle.big', '⨁', 'big'), T('bigotimes', 'times.circle.big', '⨂', 'big'),+ T('bigwedge', 'and.big', '⋀', 'big'), T('bigvee', 'or.big', '⋁', 'big'),+ // fences that are also symbols+ T('langle', 'angle.l', '⟨'), T('rangle', 'angle.r', '⟩'), T('lfloor', 'floor.l', '⌊'), T('rfloor', 'floor.r', '⌋'),+ T('lceil', 'ceil.l', '⌈'), T('rceil', 'ceil.r', '⌉'), T('|', 'bar.v.double', '‖'), T('vert', 'bar.v', '|'), T('Vert', 'bar.v.double', '‖'),+ T('lbrace', 'brace.l', '{'), T('rbrace', 'brace.r', '}'), T('{', 'brace.l', '{'), T('}', 'brace.r', '}'), T('backslash', 'backslash', '\\'),+]++/** The upright function names: \sin → <mi>sin</mi>. Typst spells them the same. */+export const FUNCTIONS = ['sin', 'cos', 'tan', 'cot', 'sec', 'csc', 'arcsin', 'arccos', 'arctan', 'sinh', 'cosh', 'tanh', 'log', 'ln', 'lg', 'exp', 'det', 'dim', 'ker', 'deg', 'gcd', 'hom', 'arg', 'Pr']+/** Function names whose scripts sit under/over in display mode. */+export const LIMIT_FUNCTIONS = ['lim', 'max', 'min', 'sup', 'inf', 'limsup', 'liminf']++export const byTex = new Map(SYMBOLS.map((s) => [s.tex, s]))+export const byTypst = new Map<string, Sym>()+for (const s of SYMBOLS) if (!byTypst.has(s.typst)) byTypst.set(s.typst, s)++// --- Mathematical Alphanumeric code points -----------------------------------+// Chrome ignores mathvariant on <mi>, so \mathbb{R} must BE the code point ℝ.+// Ranges from the Unicode block U+1D400…; the letters Unicode left out of the+// block (ℂℍℕℙℚℝℤ, ℬℰℱℋℐℒℳℛ, ℭℌℑℜℨ) live in Letterlike Symbols and are patched.+const RANGES: Record<string, [number, number, number] | null> = {+ // [upper A, lower a, digit 0] base code points; null digits = none+ bf: [0x1d400, 0x1d41a, 0x1d7ce],+ it: [0x1d434, 0x1d44e, 0],+ bb: [0x1d538, 0x1d552, 0x1d7d8],+ cal: [0x1d49c, 0x1d4b6, 0],+ scr: [0x1d49c, 0x1d4b6, 0],+ frak: [0x1d504, 0x1d51e, 0],+ sf: [0x1d5a0, 0x1d5ba, 0x1d7e2],+ tt: [0x1d670, 0x1d68a, 0x1d7f6],+ rm: null,+}+const HOLES: Record<string, Record<string, string>> = {+ bb: { C: 'ℂ', H: 'ℍ', N: 'ℕ', P: 'ℙ', Q: 'ℚ', R: 'ℝ', Z: 'ℤ' },+ cal: { B: 'ℬ', E: 'ℰ', F: 'ℱ', H: 'ℋ', I: 'ℐ', L: 'ℒ', M: 'ℳ', R: 'ℛ', e: 'ℯ', g: 'ℊ', o: 'ℴ' },+ scr: { B: 'ℬ', E: 'ℰ', F: 'ℱ', H: 'ℋ', I: 'ℐ', L: 'ℒ', M: 'ℳ', R: 'ℛ', e: 'ℯ', g: 'ℊ', o: 'ℴ' },+ frak: { C: 'ℭ', H: 'ℌ', I: 'ℑ', R: 'ℜ', Z: 'ℨ' },+ it: { h: 'ℎ' },+}+export function styledChar(ch: string, font: string): string {+ const r = RANGES[font]+ if (!r) return ch+ const hole = HOLES[font]?.[ch]+ if (hole) return hole+ const c = ch.charCodeAt(0)+ if (c >= 65 && c <= 90) return String.fromCodePoint(r[0] + c - 65)+ if (c >= 97 && c <= 122) return String.fromCodePoint(r[1] + c - 97)+ if (r[2] && c >= 48 && c <= 57) return String.fromCodePoint(r[2] + c - 48)+ return ch+}diff --git a/slides/src/maths/typst.ts b/slides/src/maths/typst.tsnew file mode 100644index 00000000..4fda19f3--- /dev/null+++ b/slides/src/maths/typst.ts@@ -0,0 +1,206 @@+// SPDX-License-Identifier: MIT+// Copyright (c) 2026 The Bento authors+/**+ * maths-lite — the Typst maths front end → the same tree. Typst's rules, the+ * ones that matter for a formula on a slide:+ * a/b fraction of the neighbouring "atoms": (a+b)/c has no parens+ * x^2 x_1 attach; a parenthesised script (x^(n+1)) loses its parens+ * sqrt(x) function call; root(3, x); frac(a, b); binom; abs; norm;+ * floor; ceil; hat; tilde; bar; vec; dot; overline; underline;+ * overbrace(x, "t"); underbrace; mat(1, 2; 3, 4); vec(1, 2);+ * cases(a, b); bb(R); cal(L); frak(g); bold(x); upright(x);+ * sans; mono; italic; text(...) ; lr(...); sum_(i=1)^n+ * "quoted" text+ * pi, alpha named symbols (one table with LaTeX, symbols.ts)+ * sin, lim function names, upright+ * x y juxtaposition; multi-letter runs are names, single letters+ * are variables+ */++import { type MNode, type Font, row, mi, mn, mo, MathError, symNode } from './ast.ts'+import { byTypst, byTex, FUNCTIONS, LIMIT_FUNCTIONS } from './symbols.ts'++type Tok = { t: 'name' | 'num' | 'str' | 'op' | '(' | ')' | ',' | ';' | '^' | '_' | '/' ; v: string }++function tokenize(src: string): Tok[] {+ const out: Tok[] = []+ let i = 0+ while (i < src.length) {+ const c = src[i]+ if (/\s/.test(c)) { i++; continue }+ if (c === '"') { const j = src.indexOf('"', i + 1); if (j < 0) throw new MathError('unterminated string'); out.push({ t: 'str', v: src.slice(i + 1, j) }); i = j + 1; continue }+ if (/[0-9]/.test(c)) { const m = /^[0-9]+(\.[0-9]+)?/.exec(src.slice(i))!; out.push({ t: 'num', v: m[0] }); i += m[0].length; continue }+ if (/[a-zA-Z]/.test(c)) { const m = /^[a-zA-Z][a-zA-Z0-9]*(\.[a-zA-Z]+)*/.exec(src.slice(i))!; out.push({ t: 'name', v: m[0] }); i += m[0].length; continue }+ if ('(),;^_/'.includes(c)) { out.push({ t: c as Tok['t'], v: c }); i++; continue }+ // multi-char operators, longest first+ const m = /^(<==>|==>|<==|->|=>|<-|<=|>=|!=|:=|\.\.\.|\*\*|\|\||[-+*=<>|!:.&\[\]{}\\'])/.exec(src.slice(i))+ if (!m) throw new MathError(`unexpected ${c}`)+ out.push({ t: 'op', v: m[0] }); i += m[0].length+ }+ return out+}++const OPS: Record<string, string> = { '->': '→', '=>': '⇒', '<-': '←', '<=': '≤', '>=': '≥', '!=': '≠', '==>': '⟹', '<==': '⟸', '<==>': '⟺', ':=': '≔', '...': '…', '**': '∗', '||': '‖', '-': '−', '*': '⋅', '+': '+', '=': '=', '<': '<', '>': '>', '|': '|', '!': '!', ':': ':', '.': '.', '&': '&', '\\': '\\', "'": '′', '[': '[', ']': ']', '{': '{', '}': '}' }+const FONTS: Record<string, Font> = { bb: 'bb', cal: 'cal', scr: 'scr', frak: 'frak', bold: 'bf', italic: 'it', sans: 'sf', mono: 'tt', upright: 'rm' }+const ACCENTS: Record<string, [string, boolean?, boolean?]> = { hat: ['^'], tilde: ['~'], bar: ['‾'], macron: ['‾'], overline: ['‾', true], underline: ['_', true, true], arrow: ['→'], dot: ['˙'], 'dot.double': ['¨'], acute: ['´'], grave: ['`'], breve: ['˘'], caron: ['ˇ'], circle: ['˚'] }+const FENCED: Record<string, [string, string]> = { abs: ['|', '|'], norm: ['‖', '‖'], floor: ['⌊', '⌋'], ceil: ['⌈', '⌉'], round: ['⌊', '⌉'] }++class Parser {+ i = 0+ private toks: Tok[]+ private display: boolean+ constructor(toks: Tok[], display: boolean) { this.toks = toks; this.display = display }+ peek(o = 0): Tok | undefined { return this.toks[this.i + o] }+ next(): Tok { const t = this.toks[this.i++]; if (!t) throw new MathError('unexpected end'); return t }+ is(t: Tok['t'], v?: string, o = 0): boolean { const p = this.peek(o); return !!p && p.t === t && (v === undefined || p.v === v) }++ /** items until a stop token; handles a/b by folding the two neighbours */+ parseSeq(stop: (t: Tok) => boolean): MNode {+ const c: MNode[] = []+ while (this.peek() && !stop(this.peek()!)) {+ if (this.is('/')) {+ this.next()+ const num = c.pop() ?? { k: 'row', c: [] }+ const den = this.parseAttached()+ c.push({ k: 'frac', n: strip(num), d: strip(den) })+ continue+ }+ c.push(this.parseAttached())+ }+ return row(c)+ }+ /** an atom with its ^ _ attachments */+ parseAttached(): MNode {+ let base = this.parseAtom()+ let sub: MNode | undefined, sup: MNode | undefined+ const limits = (base.k === 'sym' && !!base.big && this.display && !/[∫∬∭∮]/.test(base.t)) || (base.k === 'sym' && !!base.fn && LIMIT_FUNCTIONS.includes(base.t) && this.display)+ for (;;) {+ if (this.is('^')) { this.next(); sup = strip(this.parseAtom()); continue }+ if (this.is('_')) { this.next(); sub = strip(this.parseAtom()); continue }+ if (this.is('op', "'")) { const ps: MNode[] = []; while (this.is('op', "'")) { this.next(); ps.push(mo('′', { pad: '0em' })) } const p = ps.length === 1 ? ps[0] : { k: 'row', c: ps } as MNode; sup = sup ? row([p, sup]) : p; continue }+ break+ }+ if (sub || sup) base = { k: 'scr', b: base, sub, sup, limits: limits || undefined }+ return base+ }+ parseAtom(): MNode {+ const t = this.next()+ switch (t.t) {+ case 'num': return mn(t.v)+ case 'str': return { k: 'text', t: t.v }+ case '(': {+ // a parenthesised group: stays visible as fences unless consumed by ^ _ /+ const inner = this.parseSeq((x) => x.t === ')')+ if (!this.is(')')) throw new MathError('missing )')+ this.next()+ // Typst sizes a matching pair to its content (its `lr` is automatic)+ // — but a stretchy paren in Chrome is a different, wider-bearing+ // glyph, so `f(x)` would gain gaps Typst never shows. Stretch only+ // when the content is tall (a fraction, root, table, under/over+ // limits); a plain group is the tight `(` the LaTeX path emits.+ return { k: 'fence', l: '(', r: ')', c: inner, explicit: isTall(inner) || undefined }+ }+ case ')': throw new MathError('unexpected )')+ case ',': return mo(',')+ case ';': return mo(';')+ case '^': case '_': case '/': throw new MathError(`unexpected ${t.v}`)+ case 'op': return t.v === '<==>' ? symNode(byTex.get('iff')!) : t.v === '==>' ? symNode(byTex.get('implies')!) : mo(OPS[t.v] ?? t.v)+ case 'name': return this.name(t.v)+ }+ }+ name(v: string): MNode {+ // function call?+ if (this.is('(')) {+ if (v in FONTS) { return { k: 'style', c: this.args1(), font: FONTS[v] } }+ if (v in ACCENTS) { const [a, s, u] = ACCENTS[v]; return { k: 'accent', b: this.args1(), a, stretchy: s, under: u } }+ if (v in FENCED) { const [l, r] = FENCED[v]; const c = this.args1(); return { k: 'fence', l, r, c, explicit: isTall(c) || undefined } }+ switch (v) {+ case 'sqrt': return { k: 'sqrt', b: this.args1() }+ case 'root': { const [i, b] = this.args(2); return { k: 'sqrt', b, i } }+ case 'frac': { const [n, d] = this.args(2); return { k: 'frac', n, d } }+ case 'binom': { const [n, d] = this.args(2); return { k: 'fence', l: '(', r: ')', c: { k: 'frac', n, d, nobar: true }, explicit: true } }+ case 'overbrace': { const [b, l] = this.args(1, 2); const node: MNode = { k: 'accent', b, a: '⏞', stretchy: true }; return l ? { k: 'scr', b: node, sup: l, limits: true } : node }+ case 'underbrace': { const [b, l] = this.args(1, 2); const node: MNode = { k: 'accent', b, a: '⏟', stretchy: true, under: true }; return l ? { k: 'scr', b: node, sub: l, limits: true } : node }+ case 'text': return { k: 'text', t: this.rawArg() }+ case 'lr': { const inner = this.args1(); return inner.k === 'fence' ? inner : inner }+ case 'mat': { const rows = this.rows(';', ','); return { k: 'table', rows, l: '(', r: ')', align: 'c' } }+ case 'vec': { const rows = this.rows(';', ','); return { k: 'table', rows: rows.length === 1 ? rows[0].map((c) => [c]) : rows, l: '(', r: ')', align: 'c' } }+ case 'cases': { const rows = this.rows(',', '&'); return { k: 'table', rows, l: '{', r: '', align: 'll' } }+ case 'display': { const inner = this.args1(); return inner }+ case 'op': return mi(this.rawArg(), { fn: true })+ case 'limits': case 'scripts': { const inner = this.args1(); return inner }+ }+ }+ const sym = byTypst.get(v)+ if (sym) return symNode(sym)+ // Typst's spacing words+ const SP: Record<string, number> = { thin: 0.1667, med: 0.2222, thick: 0.2778, quad: 1, wide: 2 }+ if (v in SP) return { k: 'space', em: SP[v] }+ if (v === 'oo') return mi('∞')+ if (v === 'dif') return mi('d', { up: true })+ if (FUNCTIONS.includes(v) || LIMIT_FUNCTIONS.includes(v)) return mi(v, { fn: true })+ if (v.length === 1) return mi(v)+ // a multi-letter run Typst does not know is an upright word; TeX users+ // would write \mathrm — treat it as an identifier run+ return mi(v, { fn: true })+ }+ /** one call argument list `( … )` returning the single content */+ args1(): MNode { const a = this.args(1); return a[0] }+ args(min: number, max = min): MNode[] {+ this.next() // (+ const out: MNode[] = []+ while (!this.is(')')) {+ out.push(strip(this.parseSeq((x) => x.t === ',' || x.t === ')')))+ if (this.is(',')) this.next()+ }+ this.next()+ if (out.length < min || out.length > max) throw new MathError('wrong argument count')+ return out+ }+ /** rows for mat/vec (`a, b; c, d`) and cases (`a & "if", b & "else"`) */+ rows(rowSep: string, colSep: string): MNode[][] {+ this.next() // (+ const rows: MNode[][] = [[]]+ const isSep = (x: Tok, s: string) => (s === '&' ? x.t === 'op' && x.v === '&' : x.t === s)+ while (!this.is(')')) {+ rows[rows.length - 1].push(strip(this.parseSeq((x) => isSep(x, rowSep) || isSep(x, colSep) || x.t === ')')))+ if (isSep(this.peek()!, colSep)) this.next()+ else if (isSep(this.peek()!, rowSep)) { this.next(); rows.push([]) }+ }+ this.next()+ if (rows[rows.length - 1].length === 0) rows.pop()+ return rows+ }+ rawArg(): string {+ this.next() // (+ let s = ''+ while (!this.is(')')) { const t = this.next(); s += (t.t === 'str' ? t.v : t.v) + (this.is('name') || this.is('num') ? ' ' : '') }+ this.next()+ return s.trim()+ }+}++/** Does this content need a delimiter taller than the line? */+function isTall(n: MNode): boolean {+ switch (n.k) {+ case 'frac': case 'sqrt': case 'table': return true+ case 'scr': return !!n.limits || isTall(n.b)+ case 'fence': return !!n.explicit || isTall(n.c)+ case 'row': return n.c.some(isTall)+ case 'style': return isTall(n.c)+ case 'accent': return isTall(n.b)+ default: return false+ }+}++/** `(x)` used as a script/fraction part loses its parentheses, as in Typst. */+function strip(n: MNode): MNode {+ return n.k === 'fence' && n.l === '(' && n.r === ')' && !n.size ? n.c : n // (explicit or not: a consumed group loses its parens)+}++export function parseTypst(src: string, display: boolean): MNode {+ const p = new Parser(tokenize(src), display)+ const r = p.parseSeq(() => false)+ if (p.peek()) throw new MathError('trailing input')+ return r+}diff --git a/slides/src/render.ts b/slides/src/render.tsindex 182e368f..597b5c5e 100644--- a/slides/src/render.ts+++ b/slides/src/render.ts@@ -7,7 +7,7 @@ import { offlineEnabled, isRemoteUrl, remoteSrcBlocked } from '../../kernel/src/import type { BentoDoc, EmbedElement, ShapeElement, Slide, SlideElement, SvgElement, TableElement } from './model'import { morphKey, paginates, isWebUrl } from './model'import { chartSnapshotSvg } from './charts'-import temml from 'temml'+import { renderMath as mathsLite } from './maths/index.ts'import { renderCodeInto } from './code'import { tipSpec, tipInsetPx, shortenPathEnds } from './tips'import { formatDate } from './datefmt'@@ -479,16 +479,22 @@ export function shapeSvg(el: ShapeElement): SVGSVGElement {* format gains nothing to version: an older build opening a newer file shows* the literal `$E=mc^2$` — degraded, legible, and nothing is lost.*- * MathML, not HTML+CSS, is what makes this affordable. Temml emits MathML and- * the browser lays it out with its own math fonts; KaTeX would have to ship a- * layout engine AND ~20 webfont faces (measured: +421KB against Temml's +64KB).+ * MathML, not HTML+CSS, is what makes this affordable: the engine emits MathML+ * and the browser lays it out with its own math fonts; KaTeX would have to+ * ship a layout engine AND ~20 webfont faces (measured: +421KB). Temml did+ * this at +64KB until 2026-09-15; src/maths does it at ~8KB and adds Typst.** MUST run AFTER sanitizeHtml, never before: the sanitizer unwraps every tag* outside its allowlist and strips all attributes, so it would demolish the* MathML. Running after is also why the allowlist needs no widening — this* markup is GENERATED by us from LaTeX source, never accepted from the author.- * Temml runs with trust off, so \href and friends are inert.+ * The engine emits only attributes it constructs itself — no \href, no+ * handlers, no author-supplied style — so trust is not a setting here.*/+// A small LRU (Map keeps insertion order): a deck's formulas are few and+// re-rendered often; an unbounded cache would grow with every keystroke+// while a formula is being typed.+const MATH_CACHE_MAX = 256const mathCache = new Map<string, string>()/** Undo the entity escaping sanitizeHtml applied, so `x < y` reaches TeX as `x < y`. */@@ -539,19 +545,27 @@ function tagSymbols(mathml: string): string {return tpl.innerHTML}+// Bento's own maths engine (src/maths, 2026-09-15; it replaced Temml — see+// docs/DECISIONS.md). THE SYNTAX MARKER: `$typst: …$` (and `$$typst: …$$`)+// is Typst maths — `typst:` immediately after the opening delimiter,+// optional whitespace after the colon, case-sensitive; anything else is+// LaTeX exactly as before. Nothing in the file format changes: the marker is+// part of the text the author typed, and an older shell shows it as typed.function renderMath(src: string, display: boolean): string | null {const key = (display ? 'D' : 'I') + srcconst hit = mathCache.get(key)- if (hit !== undefined) return hit || null+ if (hit !== undefined) { mathCache.delete(key); mathCache.set(key, hit); return hit || null }let out: string | null = nulltry {- out = tagSymbols(- temml.renderToString(decodeEntities(src), { displayMode: display, throwOnError: true, trust: false }),- )+ const tex = decodeEntities(src)+ const m = /^typst:\s*/.exec(tex)+ const ml = mathsLite(m ? tex.slice(m[0].length) : tex, { display, syntax: m ? 'typst' : 'latex' })+ out = ml ? tagSymbols(ml) : null // not valid maths — leave the author's text exactly as typed} catch {- out = null // not valid TeX — leave the author's text exactly as typed+ out = null}mathCache.set(key, out ?? '')+ if (mathCache.size > MATH_CACHE_MAX) mathCache.delete(mathCache.keys().next().value!)return out}