Problem
The @m2d/math plugin maps LaTeX commands to Unicode for Word OMML text runs via a hand-maintained LATEX_SYMBOLS table in lib/src/index.ts (~120 entries). This limits how many commands are handled well:
- Incomplete coverage — many common commands are not mapped and fall through as raw command names in DOCX output.
- Incorrect mappings — some entries appear wrong (e.g.
bigwedge was mapped to ⊓ instead of ⋀).
- Hard to maintain — adding or correcting symbols requires manual edits with no structured source to build from.
Accent handling is also limited: only \hat / \widehat produce OMML accent characters; other accent commands are treated as plain symbols.
Goal
Support as many LaTeX commands as possible when converting math to DOCX. The plugin should not be tied to any single renderer — the aim is broad LaTeX command coverage, not parity with a particular engine.
Proposed approach
Use KaTeX v0.16.22 as a practical starting point, not a target spec. Its symbol and macro tables are a convenient, well-structured source that is easy to vendor and codegen from, giving us a large baseline quickly. Other sources (manual overrides, additional macro tables, etc.) can be layered on later.
- Vendor KaTeX source snippets (
symbols.js, macros.js, functions/op.js) under lib/scripts/data/ as seed input.
- Add a codegen script (
pnpm generate:katex) that extracts:
- symbol → Unicode mappings
- macro aliases
- accent commands for
createMathAccentCharacter
- named functions (
\sin, \log, etc.) rendered as literal text
- macro-only symbol overrides (e.g.
\neq, \copyright)
- Replace the inline map in
index.ts with the generated tables and a resolveLatexSymbol() helper.
- Narrow
tsup entry to ./src/index.ts so generated data files are bundled, not published as separate entry points.
Acceptance criteria
Problem
The
@m2d/mathplugin maps LaTeX commands to Unicode for Word OMML text runs via a hand-maintainedLATEX_SYMBOLStable inlib/src/index.ts(~120 entries). This limits how many commands are handled well:bigwedgewas mapped to⊓instead of⋀).Accent handling is also limited: only
\hat/\widehatproduce OMML accent characters; other accent commands are treated as plain symbols.Goal
Support as many LaTeX commands as possible when converting math to DOCX. The plugin should not be tied to any single renderer — the aim is broad LaTeX command coverage, not parity with a particular engine.
Proposed approach
Use KaTeX v0.16.22 as a practical starting point, not a target spec. Its symbol and macro tables are a convenient, well-structured source that is easy to vendor and codegen from, giving us a large baseline quickly. Other sources (manual overrides, additional macro tables, etc.) can be layered on later.
symbols.js,macros.js,functions/op.js) underlib/scripts/data/as seed input.pnpm generate:katex) that extracts:createMathAccentCharacter\sin,\log, etc.) rendered as literal text\neq,\copyright)index.tswith the generated tables and aresolveLatexSymbol()helper.tsupentry to./src/index.tsso generated data files are bundled, not published as separate entry points.Acceptance criteria
pnpm typecheck,pnpm build, andpnpm testpass inlib/pnpm generate:katex