fix: KeyError: 'fPr' when processing latex fractions in DOCX files (#1926)

* Initial plan

* Initial analysis and fix for KeyError: 'fPr' in OMML fraction processing

Co-authored-by: cau-git <60343111+cau-git@users.noreply.github.com>

* Add comprehensive test for OMML fraction fPr fix

Co-authored-by: cau-git <60343111+cau-git@users.noreply.github.com>

* Use debug logging, remove unnecesary test

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>

---------

Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: cau-git <60343111+cau-git@users.noreply.github.com>
Co-authored-by: Christoph Auer <cau@zurich.ibm.com>
This commit is contained in:
Copilot 2025-07-11 09:52:14 +02:00 committed by GitHub
parent c5fb353f10
commit 95e70962f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -260,7 +260,15 @@ class oMath2Latex(Tag2Method):
the fraction object
"""
c_dict = self.process_children_dict(elm)
pr = c_dict["fPr"]
pr = c_dict.get("fPr")
if pr is None:
# Handle missing fPr element gracefully
_log.debug("Missing fPr element in fraction, using default formatting")
latex_s = F_DEFAULT
return latex_s.format(
num=c_dict.get("num"),
den=c_dict.get("den"),
)
latex_s = get_val(pr.type, default=F_DEFAULT, store=F)
return pr.text + latex_s.format(num=c_dict.get("num"), den=c_dict.get("den"))