From 95e70962f1d7cf1f339a88fde9c907111e194726 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 11 Jul 2025 09:52:14 +0200 Subject: [PATCH] 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 --------- Signed-off-by: Christoph Auer 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 --- docling/backend/docx/latex/omml.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docling/backend/docx/latex/omml.py b/docling/backend/docx/latex/omml.py index f927885b..0db4fdce 100644 --- a/docling/backend/docx/latex/omml.py +++ b/docling/backend/docx/latex/omml.py @@ -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"))