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: update CHARS definition and enhance do_eqarr method to handle equation tags in LaTeX
myhloli1ab41b8e622c
diff --git a/mineru/model/docx/tools/math/latex_dict.py b/mineru/model/docx/tools/math/latex_dict.pyindex caf03268..e7043f20 100644--- a/mineru/model/docx/tools/math/latex_dict.py+++ b/mineru/model/docx/tools/math/latex_dict.py@@ -3,7 +3,7 @@ Adapted from https://github.com/xiilei/dwml/blob/master/dwml/latex_dict.pyOn 23/01/2025"""-CHARS = ("{", "}", "_", "^", "#", "&", "$", "%", "~")+CHARS = ("{", "}", "_", "^", "#", "&", "$", "%")BLANK = ""BACKSLASH = "\\"@@ -80,6 +80,10 @@ CHR_BO = {}T = {+ # Whitespace characters+ " ": " ", # NON-BREAKING SPACE (U+00A0) — pylatexenc maps this to "~" (text-mode),+ # which escape_latex would mangle to "\~" (invalid in math mode);+ # use a plain space instead.# Greek letters"\U0001d6fc": "\\alpha ","\U0001d6fd": "\\beta ",diff --git a/mineru/model/docx/tools/math/omml.py b/mineru/model/docx/tools/math/omml.pyindex 8ea7d7b2..5ea2f574 100644--- a/mineru/model/docx/tools/math/omml.py+++ b/mineru/model/docx/tools/math/omml.py@@ -4,6 +4,8 @@ Office Math Markup Language (OMML)Adapted from https://github.com/xiilei/dwml/blob/master/dwml/omml.pyOn 23/01/2025"""+import re+import lxml.etree as ETfrom loguru import loggerfrom pylatexenc.latexencode import UnicodeToLatexEncoder@@ -317,13 +319,37 @@ class oMath2Latex(Tag2Method):def do_eqarr(self, elm):"""- the Array object- """- return ARR.format(- text=BRK.join(- [t for stag, t, e in self.process_children_list(elm, include=("e",))]- )- )+ the Array object.++ Handles two cases:+ 1. Single-row eqArr with a right-aligned equation tag encoded as+ ``\\#(n)`` at the end of the row (OMML column-alignment syntax).+ The ``#`` column separator and the equation number ``(n)`` are+ converted to LaTeX ``\\tag{n}`` so KaTeX can render the tag,+ and the unnecessary ``\\begin{array}{c}...\\end{array}`` wrapper+ is omitted.+ 2. Single-row eqArr without a tag: content is returned as-is (no+ array wrapper needed).+ 3. Multi-row eqArr: kept as ``\\begin{array}{c}...\\end{array}``.+ """+ rows = [t for stag, t, e in self.process_children_list(elm, include=("e",))]++ if len(rows) == 1:+ row = rows[0]+ # Detect the OMML equation-tag pattern: the text element "#(n)" is+ # stored verbatim inside the row; do_r converts "#" via pylatexenc+ # to "\# " (escaped hash with surrounding spaces due to brace-+ # protection stripping). Match that at the end of the row,+ # allowing optional whitespace between "\#" and the opening "(".+ tag_match = re.search(r'\\#\s*\(([^)]*)\)\s*$', row)+ if tag_match:+ formula = row[:tag_match.start()].rstrip()+ tag_content = tag_match.group(1)+ return f'{formula}\\tag{{{tag_content}}}'+ # Single row without tag — no array wrapper required.+ return row++ return ARR.format(text=BRK.join(rows))def do_limlow(self, elm):"""