Skip to content

Add structural OMML handlers for remaining LaTeX macros#1

Closed
chitwitgit wants to merge 1 commit into
feat/expand-latex-symbol-coveragefrom
feat/structural-latex-omml
Closed

Add structural OMML handlers for remaining LaTeX macros#1
chitwitgit wants to merge 1 commit into
feat/expand-latex-symbol-coveragefrom
feat/structural-latex-omml

Conversation

@chitwitgit

Copy link
Copy Markdown
Owner

Summary

Follow-up to md2docx#7.

PR md2docx#7 replaces the hand-maintained symbol map with KaTeX-generated tables (~567 symbols). That covers most macros where the fix is simply resolving a command to the right Unicode glyph (e.g. \wedge).

The port still had gaps: some common macros need more than symbol lookup. N-ary operators must emit m:nary, not a ∫/∏ character in a text run. Layout commands like \binom and \stackrel need delimiter and limit structures. Font wrappers should render their argument, not the macro name. A few KaTeX macro-only symbols (\quad, \ne, \cdots) were also missing from the generated overrides.

This PR adds explicit handlers for those cases (~115 lines on top of md2docx#7).

What changed

lib/src/index.ts (+~110 lines)

Category Macros OMML
N-ary operators \prod, \int, \oint, \bigcup, \bigcap, \bigoplus, \bigotimes m:nary
Layout \binom{a}{b} m:d (round brackets + fraction)
Layout \stackrel{a}{b} m:limLoc + MathLimitUpper
Accents \overline, \widetilde createMathAccentCharacter
Font/text \mathrm, \mathit, \textbf, \textit, \underline, \overbrace, \underbrace argument content only (no literal macro name)
Skip \boxed, \boldsymbol no literal fallback
Other \newline space (non-empty OMML)

\sum unchanged — already handled via MathSum.

lib/scripts/generate-katex-data.ts (+4 lines)

Codegen fixes for macro-only symbols missed by simple alias parsing:

  • \quad, \qquad — fixed \\\\hskip regex for vendored KaTeX file
  • \ne (alias of \neq)
  • \cdots (via \@cdots)

Regenerated katexMeta.ts: 21 → 25 KATEX_SYMBOL_OVERRIDES.

Test plan

  • pnpm build passes in lib/
  • pnpm test passes in lib/
  • Spot-check in Word: \binom{n}{k}, \int_0^1, \stackrel{def}{=}, \mathrm{ABC}, \prod_{i=1}^n

Map n-ary operators, binom, stackrel, accents, and font wrappers to proper
Word OMML instead of Unicode fallbacks; fix quad/ne/cdots codegen overrides.

Co-authored-by: Cursor <cursoragent@cursor.com>
@chitwitgit chitwitgit closed this Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant