Skip to content

OMML writer: don't fill hidden empty n-ary sub/sup with ZWSP - #309

Merged
jgm merged 2 commits into
jgm:masterfrom
Catloer:fix/nary-empty-subsup
Nov 25, 2026
Merged

jgm merged 2 commits into
jgm:masterfrom
Catloer:fix/nary-empty-subsup

Conversation

@Catloer

@Catloer Catloer commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

makeNary already sets subHide/supHide="on" for empty limits (EGrouped []), but it still routes the empty group through showExp, which — since 76d5a04 (#118) — fills empty groups with U+200B to avoid Word's dashed placeholder box. That ZWSP makes sense for visible empty groups (sSub/sSup have no hide property), but for n-ary limits it is pure noise: the limit is hidden anyway, yet the invisible character stays in word/document.xml. Downstream consumers trip over it: docx→markdown/LaTeX round-trips yield \sum_{​}^{​}, and pasting such formulas into LaTeX fails to compile on the invisible character.

Note that Word itself writes self-closing elements for hidden n-ary limits — see the existing Word-generated input test/reader/omml/substack.test, which the OMML reader already accepts.

Change: emit an empty <m:sub/>/<m:sup/> when (and only when) the corresponding hide flag is "on", reusing the same EGrouped [] condition (now named isEmptySub/isEmptySup). The three ZWSP sites from #118 (empty group, empty identifier, ESpace otherwise-branch) are untouched, so ordinary visible empty groups keep avoiding the dashed box.

Reproduce:

echo '\sum_{}^{} x' | texmath -f tex -t omml --inline

Currently this emits <m:sub><m:r><m:t>&#8203;</m:t></m:r></m:sub>; with this patch it emits <m:sub />.

All 3258 tests pass. Five writer/omml goldens with hidden n-ary limits change accordingly (regenerated with --accept; the diffs are only the ZWSP runs collapsing to self-closing tags).

On the pandoc side (I rebuilt pandoc 3.14 against this patch): on a formula corpus, document.xml U+200B drops from 15 to 5 — the 5 survivors are exactly the non-nary x_{}-type groups that must keep the ZWSP — and the nary hide-flag sequences are identical to the official build, so Word's rendering behavior is unchanged.

makeNary already sets subHide/supHide="on" for empty sub/sup
(EGrouped []), so Word never renders them.  But showExp still filled
<m:sub>/<m:sup> with the ZWSP run it injects for empty groups
(jgm#118), leaving U+200B in document.xml.  That leaks into
docx->markdown/latex roundtrips (\sum_{​}^{​}) and breaks
LaTeX compilation.  Emit an empty <m:sub/>/<m:sup/> instead, matching
what Word itself writes for hidden nary limits.
@jgm
jgm merged commit 452bd6c into jgm:master Nov 25, 2026
6 checks passed
@jgm

jgm commented Nov 25, 2026

Copy link
Copy Markdown
Owner

thanks!

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.

2 participants