Skip to content

Recognise $$ display math and \( \) inline math - #55

Merged
Mearman merged 1 commit into
mainfrom
math-delimiter-parsing
Aug 17, 2026
Merged

Recognise $$ display math and \( \) inline math#55
Mearman merged 1 commit into
mainfrom
math-delimiter-parsing

Conversation

@Mearman

@Mearman Mearman commented Aug 17, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds MarkdownMathBlockNode ($$...$$) and MarkdownMathInlineNode (\(...\)) to the AST, with block/inline parser support and lowering into ContentDocument as preserved literal LaTeX text — styleId: "MathBlock" for the block form, a dedicated ContentRun.fontFamily marker (Cambria Math) for the inline form, mirroring how a code span already uses Courier New. Full write-side inverse in src/emit.
  • Fixes the reported bug where \(...\) was silently read as an escaped literal ( and ), eating the delimiters.
  • As part of this, ( and ) are removed from escapeMarkdownText's own ESCAPE_CHARS: escaping them was always unnecessary (neither carries special meaning in ordinary running text under CommonMark's grammar), and once \( \) means something, keeping them escaped would manufacture the same shape out of any ordinary parenthetical remark and misread it as math on a later reparse. Verified via the full CommonMark/GFM conformance suite — only one genuinely irreducible divergence surfaced (a synthetic "escape every punctuation character" torture-test example), added to the shrink-only exclusion list with its own named reason.
  • Converting the preserved LaTeX to real MathML is out of scope here — that's a documents.js question (Math write path: pptx formula support, odp formula write, and deciding LaTeX-to-MathML conversion documents.js#563), left open deliberately per discussion on that issue.

Closes #53.

Test plan

  • pnpm typecheck
  • pnpm lint
  • pnpm test — 939 tests passing, including new coverage for math block/inline parsing, lowering, emit, and diagnostics reachability
  • pnpm test:workers
  • pnpm test:smoke

Generated by Claude Code

Adds MarkdownMathBlockNode/MarkdownMathInlineNode to the AST, block/inline
parser support, and lowering into ContentDocument as preserved literal
LaTeX text (styleId "MathBlock" for the block form, a dedicated
ContentRun.fontFamily marker for the inline form), with a full write-side
inverse in src/emit. Converting the preserved LaTeX to real MathML is out
of scope here -- that is a documents.js question (ExaDev/documents.js#563).

Fixes the reported bug where \( \) was silently read as an escaped
literal '(' and ')', eating the delimiters. As part of this, '(' and ')'
are removed from escapeMarkdownText's own ESCAPE_CHARS: escaping them was
always unnecessary (neither carries special meaning in ordinary running
text under CommonMark's grammar), and once \( \) means something, keeping
them escaped would manufacture the same shape out of any ordinary
parenthetical remark and misread it as math on a later reparse.

Closes #53.
@Mearman
Mearman merged commit f21ee9b into main Aug 17, 2026
11 checks passed
@Mearman
Mearman deleted the math-delimiter-parsing branch August 17, 2026 08:53
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse $$ display-math blocks and \( \) inline math

1 participant