MinerU Equation Extraction#
MinerU extracts two equation types — block-level (interline/display) and inline — producing LaTeX strings stored in middle.json. The mechanism differs significantly across backends:
| Backend | Equation Detection | LaTeX Generation |
|---|---|---|
| Pipeline | PP-DocLayoutV2 (MFD stage) | MFR model (pp_formulanet_plus_m / unimernet) |
| Hybrid | PP-DocLayoutV2 (MFD stage) | MFR model (same as pipeline) |
| VLM | End-to-end via vision-language model | Generated directly by the VLM |
VLM mode is actively being deprecated in favor of hybrid mode — see VLM Mode Deprecation .
Block Type Architecture#
All equation-related type constants are in mineru/utils/enum_class.py.
BlockType (block-level structure):
INTERLINE_EQUATION = 'interline_equation'— display-mode (block) formula used by pipeline/hybridEQUATION = 'equation'— standalone formula type emitted by the VLM backend; mapped toINTERLINE_EQUATIONduring processing
ContentType (span-level, inside lines):
INLINE_EQUATION = 'inline_equation'— inline formula spanINTERLINE_EQUATION = 'interline_equation'— display formula spanEQUATION = 'equation'— legacy span type
ContentTypeV2 (used in content_list_v2.json output):
EQUATION_INTERLINE = 'equation_interline'SPAN_EQUATION_INLINE = 'equation_inline'
In middle.json, display equations are indexed at the page level in interline_equations, while inline equations appear as spans (type inline_equation) embedded within text block lines .
Pipeline and Hybrid Backends: MFD → MFR Two-Stage Pipeline#
Both pipeline and hybrid backends use a two-stage process:
Stage 1 — MFD (Mathematical Formula Detection): PP-DocLayoutV2 detects display_formula and inline_formula regions on each page image. These are the only two formula-class labels in its 25-class schema . Detected bounding boxes are collected with an empty "latex" field placeholder.
Stage 2 — MFR (Mathematical Formula Recognition): The MFR model converts formula crops to LaTeX strings. The default model is pp_formulanet_plus_m; the alternative is unimernet. Selectable via MINERU_MFR_MODEL . The LaTeX output is written back into each detection's "latex" field, then propagated to span "content" in middle.json.
Formula number handling: Standalone formula_number blocks (e.g., (1), (2)) detected by PP-DocLayoutV2 are matched to adjacent display equations and appended as \tag{} to the equation's LaTeX content .
Inline equations in text: Inline formula bboxes from MFD are stored separately as page_inline_formula. During OCR, these regions are masked so character recognition is skipped; the MFR-generated LaTeX is used instead. The resulting spans appear as ContentType.INLINE_EQUATION within text block lines.
Entry points: batch_analyze.py (pipeline), hybrid_analyze.py (hybrid).
VLM Backend: Equation Handling#
The VLM backend processes layout and formula extraction in a single end-to-end model inference pass (Qwen2-VL / MinerU2.5-Pro). There is no separate MFD or MFR stage.
Block-level (interline) equations: The VLM emits blocks with "type": "equation". In vlm_magic_model.py, this is remapped to BlockType.INTERLINE_EQUATION and the span type is set to ContentType.INTERLINE_EQUATION. The "content" field is cleaned via isolated_formula_clean().
Inline equations: The VLM does not emit a distinct inline_equation block type. Instead, inline formulas are embedded in text block content using \( ... \) delimiters. vlm_magic_model.py parses these with a regex, splitting the content string into alternating ContentType.TEXT and ContentType.INLINE_EQUATION spans within the same line. This splitting is only triggered when \( and \) counts are balanced .
VLM-recognized block types include equation for display formulas; there is no explicit inline_formula block — inline math is always embedded in text content .
VLM Mode Deprecation and Hybrid Mode#
VLM mode (-b vlm-engine) is actively being deprecated in favor of hybrid mode (-b hybrid-engine / hybrid-auto-engine) .
Key reasons affecting equation extraction:
- The
merge_prevmarker in VLM model v2605 was corrupted during training, breaking cross-column and cross-page paragraph (and equation) merging in VLM mode . - Hybrid mode uses PP-DocLayoutV2 for layout detection (including formula region detection) and applies line-detection information to support cross-column/cross-page merging — critical for multi-line display equations.
- The online SaaS service at
opendatalab.comalready uses hybrid mode internally .
Migration: Replace -b vlm-engine with -b hybrid-engine. Hardware requirements are identical .
For hallucination-free equation extraction, use pipeline mode — the MFR model is purely recognition-based and cannot hallucinate content the way a generative VLM can .
Key Source Files#
| File | Relevance |
|---|---|
mineru/utils/enum_class.py | BlockType, ContentType, ContentTypeV2 — all equation type constants |
mineru/backend/vlm/vlm_magic_model.py | VLM equation-to-interline mapping; inline equation regex splitting |
mineru/backend/pipeline/batch_analyze.py | MFD/MFR call site; MFR_BASE_BATCH_SIZE |
mineru/model/mfr/pp_formulanet_plus_m/predict_formula.py | Default MFR model (PP-FormulaNet) |
mineru/model/mfr/unimernet/Unimernet.py | Alternative MFR model (UniMERNet) |
mineru/model/layout/pp_doclayoutv2.py | PP-DocLayoutV2: detects display_formula and inline_formula regions |