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: add support for additional LaTeX mappings in latex_dict and enhance font style handling in omml
myhlolia45827030d0a
diff --git a/mineru/model/docx/tools/math/latex_dict.py b/mineru/model/docx/tools/math/latex_dict.pyindex 4c010c1b..d04234fb 100644--- a/mineru/model/docx/tools/math/latex_dict.py+++ b/mineru/model/docx/tools/math/latex_dict.py@@ -151,6 +151,12 @@ T = {# Binary relations"\u00b1": "\\pm ","\u2213": "\\mp ",+ # Characters whose pylatexenc text-mode mappings are invalid in math environments+ "\u00f0": "\\eth ", # ð LATIN SMALL LETTER ETH — pylatexenc: \dh (tipa, not in KaTeX/MathJax)+ "\u0131": "\\imath ", # ı LATIN SMALL LETTER DOTLESS I — pylatexenc: \i (text-mode only)+ "\u2127": "\\mho ", # ℧ INVERTED OHM SIGN — pylatexenc: \textmho (textcomp, not in KaTeX/MathJax)+ "\u212e": "e", # ℮ ESTIMATED SIGN — pylatexenc: \textestimated (no math equivalent; use 'e')+ "\u00c5": "\\mathring{A} ", # Å LATIN CAPITAL LETTER A WITH RING — pylatexenc: \r{A} (text-mode only)# Multiplication/division operators (text-mode pylatexenc mappings overridden to math-mode)"\u00b7": "\\cdot ", # MIDDLE DOT (·) — common in Chinese scientific notation"\u22c5": "\\cdot ", # DOT OPERATOR (⋅)@@ -166,6 +172,23 @@ T = {"\u00b2": "2","\u00b3": "3","\u00b9": "1",+ # Big operators as plain text characters — pylatexenc maps some to non-KaTeX commands+ # (e.g. ∯→\surfintegral, ∰→\volintegral, ∱→\clwintegral) which don't render in KaTeX/MathJax.+ # Override with standard KaTeX-compatible commands; if no KaTeX equivalent exists, keep Unicode.+ "\u222f": "\\oiint ", # ∯ SURFACE INTEGRAL — pylatexenc: \surfintegral (not in KaTeX)+ "\u2230": "\\oiiint ", # ∰ VOLUME INTEGRAL — pylatexenc: \volintegral (not in KaTeX)+ "\u2231": "\u2231", # ∱ CLOCKWISE INTEGRAL — pylatexenc: \clwintegral (not in KaTeX); keep Unicode+ "\u2232": "\u2232", # ∲ CLOCKWISE CONTOUR INTEGRAL — no KaTeX equivalent; keep Unicode+ "\u2233": "\u2233", # ∳ ANTICLOCKWISE CONTOUR INTEGRAL — no KaTeX equivalent; keep Unicode+ # N-ary operators: ⨀⨁⨂ have KaTeX commands; ⨃⨄ do not — keep Unicode for those+ "\u2a00": "\\bigodot ", # ⨀ N-ARY CIRCLED DOT OPERATOR+ "\u2a01": "\\bigoplus ", # ⨁ N-ARY CIRCLED PLUS OPERATOR+ "\u2a02": "\\bigotimes ", # ⨂ N-ARY CIRCLED TIMES OPERATOR+ "\u2a03": "\u2a03", # ⨃ N-ARY UNION WITH DOT — no exact KaTeX equivalent; keep Unicode+ "\u2a04": "\u2a04", # ⨄ N-ARY UNION WITH PLUS — no exact KaTeX equivalent; keep Unicode+ # Wave arrows — pylatexenc: \arrowwaveleft / \arrowwaveright (not in KaTeX); keep Unicode+ "\u219c": "\u219c", # ↜ LEFTWARDS WAVE ARROW+ "\u219d": "\u219d", # ↝ RIGHTWARDS WAVE ARROW# 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 5ea2f574..5cf55e62 100644--- a/mineru/model/docx/tools/math/omml.py+++ b/mineru/model/docx/tools/math/omml.py@@ -41,6 +41,16 @@ from .latex_dict import (OMML_NS = "{http://schemas.openxmlformats.org/officeDocument/2006/math}"+# Mapping from OMML <m:scr> values to LaTeX math font commands.+# Used in do_r to convert math script/font style to appropriate LaTeX commands.+SCR_TO_LATEX = {+ "script": "\\mathscr{{{0}}}", # 手写体/花体 — \mathscr covers both upper and lowercase+ "fraktur": "\\mathfrak{{{0}}}", # 德国哥特体 — \mathfrak for upper and lowercase+ "double-struck": "\\mathbb{{{0}}}", # 双线体/黑板粗体 — \mathbb+ "sans-serif": "\\mathsf{{{0}}}", # 无衬线体+ "monospace": "\\mathtt{{{0}}}", # 等宽字体+}+def load(stream):tree = ET.parse(stream)@@ -466,6 +476,18 @@ class oMath2Latex(Tag2Method):if "}" not in base_proc_str and "\\}" in proc_str:proc_str = proc_str.replace("\\}", "}")+ # Handle <m:scr> math font style (script, fraktur, double-struck, etc.)+ # OMML encodes math alphabets via <m:rPr><m:scr m:val="..."/> rather than+ # Unicode math-alphabet codepoints, so we must apply the LaTeX wrapper here.+ rPr = elm.find(f"{OMML_NS}rPr")+ if rPr is not None:+ scr_elem = rPr.find(f"{OMML_NS}scr")+ if scr_elem is not None:+ scr_val = scr_elem.get(f"{OMML_NS}val")+ latex_template = SCR_TO_LATEX.get(scr_val)+ if latex_template and proc_str.strip():+ proc_str = latex_template.format(proc_str.strip())+return proc_strtag2meth = {