fix: handle math run with no text child in OMML->LaTeX conversion#2189
Open
S1MS4 wants to merge 1 commit into
Open
fix: handle math run with no text child in OMML->LaTeX conversion#2189S1MS4 wants to merge 1 commit into
S1MS4 wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
do_r() called elm.findtext("./m:t") and iterated over the result
directly. When a math run (<m:r>) has no <m:t> text child (e.g. a
run that only carries formatting properties, produced by some Word
equation editors), findtext() returns None and iterating over it
raises TypeError: 'NoneType' object is not iterable.
Because equation pre-processing is applied at the whole-document.xml
level with a blanket try/except, this single malformed run aborts
LaTeX conversion for every equation in the document, silently
dropping all native Word equations from the output.
77f40af to
c8f2308
Compare
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.
Summary
Fixes #2188.
do_r()inomml.pycalledelm.findtext("./m:t")and iterated over the result directly. When a math run (<m:r>) has no<m:t>text child (e.g. a run that only carries formatting properties),findtext()returnsNone, and iterating overNoneraisesTypeError: 'NoneType' object is not iterable.pre_process_docx()pre-processes math for the wholeword/document.xmlin one pass wrapped in a blankettry/except, this single malformed run silently drops every equation in the document on fallback, with no error surfaced to the caller.elm.findtext(...) or ""so a missing text child is treated as an empty run instead of crashing.Verified against a real-world
.docxwith 62 native equations: before the fix, all 62 were silently dropped from the markdown output; after the fix, all render correctly as LaTeX (e.g.$l\_{1}$,$λ\_{1}\geq λ\_{2}\geq …\geq λ\_{k}$).This is a different root cause from #1979 (
math_root.find("oMath")returningNonein_convert_omath_to_latex) and #1982 (unsupported function names) — different function (do_r), different failure mode (missing<m:t>on an otherwise valid run).Test plan
packages/markitdown/tests/test_docx_omml.pywith regression tests:<m:t>child no longer crashes and yields an empty stringTypeError) and pass with the fixpytest packages/markitdown/tests/test_docx_omml.py -v— all passing