Render textbook LaTeX as static MathML - #17
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4735149b5f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| { open: '$$', close: '$$', displayMode: true } | ||
| ]; | ||
|
|
||
| const AMS_ENVIRONMENT = /^\\begin\{(equation\*?|align\*?|alignat\*?|gather\*?|CD)\}\s*$/; |
There was a problem hiding this comment.
Accept alignat's required column argument
When a chapter uses a valid standalone AMS environment such as \begin{alignat}{2}, this anchored expression rejects the opener because alignat requires a column-count argument after the environment name. Consequently mathBlock declines the block and Markdown publishes the raw TeX instead of MathML, despite the renderer explicitly advertising alignat support; recognize and preserve the mandatory {n} argument for both alignat and alignat*.
Useful? React with 👍 / 👎.
| const contentStart = state.pos + fence.open.length; | ||
| const contentEnd = state.src.indexOf(fence.close, contentStart); | ||
| if (contentEnd < 0) return false; |
There was a problem hiding this comment.
Fail on unclosed inline TeX fences
When inline source contains an unclosed recognized opener such as Let \(x, returning false hands it to Markdown's escape rule, which silently publishes Let (x instead of failing the build. This contradicts the adapter's fail-closed behavior and makes a delimiter typo corrupt the displayed notation; once an unambiguous \( or \[ opener is encountered, report the missing closing fence rather than treating it as ordinary Markdown.
Useful? React with 👍 / 👎.
| if (!silent) { | ||
| const token = state.push('math_inline', 'math', 0); | ||
| token.content = state.src.slice(contentStart, contentEnd); | ||
| token.meta = { displayMode: fence.displayMode }; |
There was a problem hiding this comment.
Preserve formulas in image alternative text
When a chapter uses math in an image label, such as , this custom token is parsed inside the label but MarkdownIt's image renderer omits unknown token types while constructing alt, producing only alt="Graph of ". The formula therefore disappears for screen-reader users even though it remains part of the source; provide a plain-text representation of math tokens when rendering image alternative text.
Useful? React with 👍 / 👎.
Purpose
Repairs the actual current textbook defect: source LaTeX is fetched and displayed, but the existing plain
markdown-itpath has no math renderer and can consume\(,\),\[, and\]as ordinary Markdown escapes. The result is visibly untypeset or malformed mathematics even though the owning chapter source is intact.What changed
\(...\)\[...\]$$...$$equation,align,alignat,gather, andCDenvironmentstemml@0.13.3<annotation encoding="application/x-tex">Source and authority boundary
No textbook source file is modified. Chapter One remains owned by
The-Interdependency/ucns:docs/chapter-1.md, and every displayed chapter remains bound to its exact source commit, blob, and SHA-256 identity.The renderer proves only that the source notation was converted into MathML. It does not evaluate an equation, confer proof status, repair source mathematics, or transfer authority between repositories.
No runtime renderer
The generated chapter contains the MathML directly. There is no KaTeX, MathJax, Temml, jsDelivr, unpkg, or other runtime script dependency. The existing site JavaScript remains limited to the compact navigation enhancement.
Gates added
Build dependency
temmlis pinned exactly at0.13.3package-lock.jsonwas regenerated by Node 24/npm and records the package tarball integrityhmmm
Native MathML gives the site static, semantic, no-JavaScript mathematics. Cross-browser font metrics can still differ because this repair deliberately uses locally available math fonts rather than shipping a font file; the release gate now catches absence and gross presentation failure, while pixel-identical typography remains outside the contract.