fix: remove extra closing brace from caron and ring-above accent templates - #2279
Open
Andrew Avery (AndrewAvery7) wants to merge 1 commit into
Open
fix: remove extra closing brace from caron and ring-above accent templates#2279Andrew Avery (AndrewAvery7) wants to merge 1 commit into
Andrew Avery (AndrewAvery7) wants to merge 1 commit into
Conversation
`CHR["\u030c"]` and `CHR["\u030a"]` each carried a fourth `}`, so the
templates read `\check{{{0}}}}` and `\ocirc{{{0}}}}`. Every other accent
in the table is `\name{{{0}}}`. `oMath2Latex.do_acc` applies these with
`latex_s.format(c_dict["e"])`, and an unbalanced template raises
`ValueError: Single '}' encountered in format string`.
The damage is not limited to the accented equation. `pre_process_docx`
runs `_pre_process_math` over the whole of `word/document.xml` inside a
blanket `except Exception` and, on error, writes the *original*
unprocessed XML back. Mammoth does not render OMML, so a single caron or
ring-above accent silently removes **every** equation in the document,
with no error and a zero exit code.
Both are standard entries in Word's Equation > Accent gallery
(U+030C COMBINING CARON, U+030A COMBINING RING ABOVE).
Measured on the repo's own `equations.docx` fixture: 2 equations
recovered normally, 0 after appending one caron-accented equation, 3
with this fix applied.
Adds `test_docx_math_accents.py`: a table-wide guard asserting every
`{0}` template survives `.format()`, plus direct coverage of the two
affected accents and an unaffected control.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A DOCX containing a caron- or ring-accented equation loses every equation in the document, silently, with a zero exit code.
Root cause
In
converter_utils/docx/math/latex_dict.py, two entries inCHRcarry a fourth closing brace:Every other accent in the table is
"\name{{{0}}}".oMath2Latex.do_accapplies these unguarded:so both raise
ValueError: Single '}' encountered in format string. Of the 46{0}templates acrossCHR,CHR_BO,CHR_DEFAULT,POSandPOS_DEFAULT, these two are the only ones affected.The damage is not local to the accented equation.
pre_process_docxruns_pre_process_mathover the whole ofword/document.xmlinside a blanketexcept Exceptionand, on error, writes the original unprocessed XML back:Mammoth does not render OMML, so every equation in that file disappears from the Markdown. Nothing is logged and the exit code is 0.
Both are standard entries in Word's Equation → Accent gallery, not obscure codepoints.
Reproduction
Using this repository's own
tests/test_files/equations.docx, repackaged, then repackaged again with a single caron<m:acc>paragraph appended:$$\check{x}$$)Fix
Remove the extra brace from both templates.
Tests
Adds
tests/test_docx_math_accents.py:test_accent_templates_are_formattable— asserts every{0}template in the accent tables survives.format(). This guards the whole table against the same class of typo rather than just these two entries.test_caron_and_ring_accents— covers U+030C and U+030A directly.test_unmodified_accent_still_converts— control on U+0302, which was never broken.The first two fail on
mainand pass with the fix; the control passes either way.Full suite locally: 322 passed before, 325 after, with the same 14 pre-existing failures in
test_cli_vectors.py/test_module_misc.py(Windows console encoding, unrelated to this change) in both runs.Notes
\ocircis not standard LaTeX —\mathringis — but neighbouring entries follow the same upstream dwml/STIX naming (\ovhook,\candra,\droang), so I have kept this PR to the brace fix to stay obviously correct rather than mixing in a naming change.Related: #2188 describes this same symptom (DOCX math converter silently dropping all equations) from a different root cause in
do_r; the PRs against it do not touchlatex_dict.CHR.