diff --git a/docling/backend/docx/latex/omml.py b/docling/backend/docx/latex/omml.py index 22e926d8..0db4fdce 100644 --- a/docling/backend/docx/latex/omml.py +++ b/docling/backend/docx/latex/omml.py @@ -263,9 +263,12 @@ class oMath2Latex(Tag2Method): pr = c_dict.get("fPr") if pr is None: # Handle missing fPr element gracefully - _log.warning("Missing fPr element in fraction, using default formatting") + _log.debug("Missing fPr element in fraction, using default formatting") latex_s = F_DEFAULT - return latex_s.format(num=c_dict.get("num", "formula_skipped"), den=c_dict.get("den", "formula_skipped")) + 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")) diff --git a/tests/test_omml_fraction_fix.py b/tests/test_omml_fraction_fix.py deleted file mode 100644 index 54a32f41..00000000 --- a/tests/test_omml_fraction_fix.py +++ /dev/null @@ -1,148 +0,0 @@ -""" -Test for OMML fraction processing with missing fPr elements -""" - -import lxml.etree as ET -from docling.backend.docx.latex.omml import oMath2Latex, OMML_NS - - -def test_omml_fraction_missing_fpr(): - """Test that fractions with missing fPr elements are handled gracefully""" - - # Create an OMML fraction without fPr element (this would cause KeyError before fix) - omml_xml = f''' - - - - - a - - - - - b - - - - - ''' - - # Parse and process the OMML - this should not raise KeyError - root = ET.fromstring(omml_xml) - result = oMath2Latex(root) - latex_result = str(result) - - # Should produce default fraction formatting - assert "\\frac{a}{b}" in latex_result - - -def test_omml_fraction_with_fpr(): - """Test that fractions with fPr elements still work correctly""" - - # Create an OMML fraction with fPr element - omml_xml = f''' - - - - - - - - x - - - - - y - - - - - ''' - - # Parse and process the OMML - root = ET.fromstring(omml_xml) - result = oMath2Latex(root) - latex_result = str(result) - - # Should produce fraction formatting with fPr properties - assert "\\frac{x}{y}" in latex_result - - -def test_omml_fraction_missing_components(): - """Test that fractions with missing numerator or denominator use placeholders""" - - # Create an OMML fraction with missing numerator - omml_xml_missing_num = f''' - - - - - b - - - - - ''' - - # Parse and process the OMML - root = ET.fromstring(omml_xml_missing_num) - result = oMath2Latex(root) - latex_result = str(result) - - # Should use placeholder for missing numerator - assert "formula_skipped" in latex_result - assert "b" in latex_result - - -def test_omml_complex_equation_with_missing_fpr(): - """Test that complex equations with missing fPr continue processing""" - - # Create a complex equation with a fraction missing fPr - omml_xml = f''' - - - x = - - - - - a + b - - - - - c - - - - - + y - - - ''' - - # Parse and process the OMML - root = ET.fromstring(omml_xml) - result = oMath2Latex(root) - latex_result = str(result) - - # Should process the entire equation correctly - assert "x =" in latex_result - assert "\\frac{a + b}{c}" in latex_result - assert "+ y" in latex_result - - -if __name__ == "__main__": - import logging - - # Set up logging to capture warnings - logging.basicConfig(level=logging.WARNING) - - # Run all tests - test_omml_fraction_missing_fpr() - test_omml_fraction_with_fpr() - test_omml_fraction_missing_components() - test_omml_complex_equation_with_missing_fpr() - - print("All OMML fraction tests passed!") \ No newline at end of file