Repository navigation
fix(docx): keep the other equations when one cannot be converted - #2714
Open
Mohammad Hijjawi (MohammadHijjawi97) wants to merge 1 commit into
Open
Mohammad Hijjawi (MohammadHijjawi97) wants to merge 1 commit into
Mohammad Hijjawi (MohammadHijjawi97) wants to merge 1 commit into
Conversation
_pre_process_math converts every equation of a part in one pass, and
pre_process_docx wraps that pass in a blanket except that writes the
original XML back on any error. Mammoth does not render OMML, so a single
equation the OMML converter cannot handle (for example an m:limLow over
sup or inf, as pandoc writes for \sup_{x}) silently removed every equation
in the document.
Catch the failure per equation instead, so only the equation that cannot
be converted is left as it was and the rest are still rendered as LaTeX.
|
Mohammad Hijjawi (@MohammadHijjawi97) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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
_pre_process_mathconverts every equation inword/document.xml(and footnotes/endnotes) in a single pass, andpre_process_docxruns it inside a blanketexcept Exceptionthat writes the original XML back on any error. Mammoth does not render OMML, so a single equation the OMML converter cannot handle silently removes every equation in the document, with no error and exit code 0.One construct that triggers this on
maintoday is anm:limLowwhose base is notlim/max/min, which pandoc writes for\sup_{x},\inf_{x}or\underset{x}{y}(do_limlowraisesNotImplementedError). The existing tests intest_docx.pyalready note this "not local to the equation" effect for several other constructs.Before (document with
E=mc, inlinea+b, onesupequation, and a block paragraph containingy=2plus asupequation):After:
Change
_get_omath_tag_replacementcatches a conversion failure for that one equation and returnsNone;_replace_equationsthen leaves only that equation unconverted, so the rest of the document's equations are still rendered as LaTeX. This complements fixes for individual constructs: whatever the converter does not support yet now costs only the equation that uses it.Tests
test_docx_unsupported_equation_keeps_the_other_equations(fails onmain, passes with the fix), covering block, inline, and a block paragraph mixing a convertible and an unconvertible equation.tests/test_docx.py: 101 passed, 1 skipped; fullpackages/markitdown/tests: all pass excepttest_speech_transcription(no ffmpeg locally, unrelated); markitdown-ocr docx tests pass; black 23.7.0 clean.