Description
The OMML -> LaTeX converter crashes with TypeError: 'NoneType' object is not iterable when an <m:r> (math run) element has no <m:t> text child — e.g. a run that only carries formatting properties (<m:rPr/>), which some Word equation editors (and equations pasted/translated via third-party tools) produce.
Root cause
do_r() in omml.py:
def do_r(self, elm):
_str = []
for s in elm.findtext("./{0}t".format(OMML_NS)):
_str.append(self._t_dict.get(s, s))
return escape_latex(BLANK.join(_str))
elm.findtext(...) returns None when the run has no <m:t> child, and iterating over None raises TypeError.
Impact
This is more severe than a single broken equation: pre_process_docx() applies math pre-processing to the entire word/document.xml in one pass, wrapped in a blanket try/except that falls back to the original (unconverted) XML on any exception. So one malformed run anywhere in the document silently drops every native Word equation in the file — the docx still converts, but with zero equations rendered, and no error surfaced to the caller.
Reproduced with a real-world .docx containing 62 <m:oMath> elements: all 62 were dropped because a single subscript expression contained an <m:r> with no text.
Proposed fix
for s in elm.findtext("./{0}t".format(OMML_NS)) or "":
...
This is a distinct root cause from #1979 (which is about math_root.find("oMath") returning None in _convert_omath_to_latex) and #1982 (unsupported function names) — different function, different failure mode.
I have a fix + regression tests ready and will open a PR referencing this issue.
Description
The OMML -> LaTeX converter crashes with
TypeError: 'NoneType' object is not iterablewhen an<m:r>(math run) element has no<m:t>text child — e.g. a run that only carries formatting properties (<m:rPr/>), which some Word equation editors (and equations pasted/translated via third-party tools) produce.Root cause
do_r()inomml.py:elm.findtext(...)returnsNonewhen the run has no<m:t>child, and iterating overNoneraisesTypeError.Impact
This is more severe than a single broken equation:
pre_process_docx()applies math pre-processing to the entireword/document.xmlin one pass, wrapped in a blankettry/exceptthat falls back to the original (unconverted) XML on any exception. So one malformed run anywhere in the document silently drops every native Word equation in the file — the docx still converts, but with zero equations rendered, and no error surfaced to the caller.Reproduced with a real-world
.docxcontaining 62<m:oMath>elements: all 62 were dropped because a single subscript expression contained an<m:r>with no text.Proposed fix
This is a distinct root cause from #1979 (which is about
math_root.find("oMath")returningNonein_convert_omath_to_latex) and #1982 (unsupported function names) — different function, different failure mode.I have a fix + regression tests ready and will open a PR referencing this issue.