Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix: enhance math-mode symbol handling in latex_dict and omml for improved LaTeX output
myhlolif18d6ac7f9d7
diff --git a/mineru/model/docx/tools/math/latex_dict.py b/mineru/model/docx/tools/math/latex_dict.pyindex dbe8375e..0d7d83d3 100644--- a/mineru/model/docx/tools/math/latex_dict.py+++ b/mineru/model/docx/tools/math/latex_dict.py@@ -146,6 +146,21 @@ T = {# Binary relations"\u00b1": "\\pm ","\u2213": "\\mp ",+ # Multiplication/division operators (text-mode pylatexenc mappings overridden to math-mode)+ "\u00b7": "\\cdot ", # MIDDLE DOT (·) — common in Chinese scientific notation+ "\u22c5": "\\cdot ", # DOT OPERATOR (⋅)+ "\u2219": "\\bullet ", # BULLET OPERATOR (∙)+ "\u00d7": "\\times ", # MULTIPLICATION SIGN (×)+ "\u00f7": "\\div ", # DIVISION SIGN (÷)+ "\u2212": "-", # MINUS SIGN (−)+ # Degree / prime — avoid ^{} syntax since escape_latex will mangle bare ^ and braces+ "\u00b0": "\\circ ", # DEGREE SIGN (°) — caller's context (e.g. 90°) provides the ^+ "\u2032": "'", # PRIME (′)+ "\u2033": "''", # DOUBLE PRIME (″)+ # Superscript digits — avoid \texttwosuperior / \textthreesuperior from pylatexenc+ "\u00b2": "2",+ "\u00b3": "3",+ "\u00b9": "1",# Italic, Latin, uppercase"\U0001d434": "A","\U0001d435": "B",diff --git a/mineru/model/docx/tools/math/omml.py b/mineru/model/docx/tools/math/omml.pyindex 454b00b0..8ea7d7b2 100644--- a/mineru/model/docx/tools/math/omml.py+++ b/mineru/model/docx/tools/math/omml.py@@ -384,9 +384,14 @@ class oMath2Latex(Tag2Method):return bo + BLANK.join(res)def process_unicode(self, s):- # s = s if isinstance(s,unicode) else unicode(s,'utf-8')- # print(s, self._t_dict.get(s, s), unicode_to_latex(s))- # _str.append( self._t_dict.get(s, s) )+ # Check T dictionary first for known math-mode symbols.+ # The T dictionary holds explicit math-mode LaTeX mappings and takes precedence+ # over pylatexenc, which uses text-mode mappings by default and therefore produces+ # text-mode commands like \textperiodcentered (for U+00B7 ·) that are invalid+ # inside math environments.+ t_result = self._t_dict.get(s)+ if t_result is not None:+ return t_resultout_latex_str = self.u.unicode_to_latex(s)@@ -402,11 +407,15 @@ class oMath2Latex(Tag2Method):out_latex_str = out_latex_str.replace("\\ensuremath{", " ")out_latex_str = out_latex_str.replace("}", " ")- if out_latex_str.strip().startswith("\\text"):- out_latex_str = f" \\text{{{out_latex_str}}} "+ # Do NOT wrap remaining content in \text{}.+ # Previously this code matched any string starting with "\text" and wrapped it+ # again, producing invalid constructs like \text{ \textperiodcentered } for+ # textcomp symbols. Characters that truly need text mode should be mapped in+ # the T dictionary above; for all others we keep the pylatexenc output as-is.return out_latex_str+def do_r(self, elm):"""Get text from 'r' element,And try convert them to latex symbols