LaTeX Formula Extraction from PDF
This skill extracts display-mode LaTeX formulas from PDF research papers, cleans them, validates bracket matching, and produces a markdown output file.
Workflow
- Extract: Use marker-pdf to convert PDF to markdown (preserves LaTeX formulas)
- Detect: Use surya layout detection to find equation bounding boxes
- Cross-reference: Use texify on cropped equation regions for verification
- Clean: Remove
\tag{}, trailing equation numbers, trailing commas/periods - Validate: Check bracket matching (
\left/\rightpairs) and command spelling - Fix: Generate corrected versions for formulas with syntax errors
- Output: Write original formulas followed by fixed versions
Key Functions
extract_formulas_with_marker(pdf_path, output_dir)- Extract formulas via marker-pdfdetect_equation_bboxes(pdf_path)- Find equation regions using surya layoutextract_formulas_with_texify(pdf_path, bboxes)- Extract formulas from cropped regionsclean_formula(formula)- Remove tags, numbers, punctuationvalidate_brackets(formula)- Check \left/\right delimiter matchingfix_bracket_mismatches(formula)- Fix mismatched delimiter pairscheck_misspelled_commands(formula)- Detect misspelled LaTeX commandsrun_extraction_pipeline(pdf_path, output_path)- End-to-end entry pointvalidate_output(output_path)- Validate output file format
Usage Example
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-latex-formula-extraction/scripts') from utils import run_extraction_pipeline, validate_output # Run the full pipeline pdf_path = '/root/latex_paper.pdf' output_path = '/root/latex_formula_extraction.md' original, fixed = run_extraction_pipeline(pdf_path, output_path) # Validate the output validate_output(output_path)
Important Notes
- Only display-mode formulas (on their own line) are extracted, not inline math
- Bracket validation covers:
(),[],\{\},\langle\rangle,|,\| - Fix only syntax/typographical errors, never mathematical content
- Original erroneous formulas are kept; fixed versions are appended after all originals
- Deduplication is applied to avoid repeated formulas


