Skip to main content

Flatten and clean LaTeX files for LLM consumption

Project description

LaTeX LLM Cleaner

A Python CLI tool that takes a LaTeX .tex file and produces a flattened, cleaned version optimized for LLM consumption. Combines functionality from tools like flachtex, arxiv_latex_cleaner, and pandoc into a single utility.

Installation

pip install latex-llm-cleaner

Or from source:

pip install .
# or for development:
pip install -e ".[dev]"

Usage

latex-llm-cleaner paper.tex                    # output to stdout
latex-llm-cleaner paper.tex -o cleaned.tex     # output to file
latex-llm-cleaner paper.tex --no-bibliography  # skip bib inlining

All features are on by default. Disable individual steps with --no-* flags:

latex-llm-cleaner INPUT_FILE [options]

Options:
  -o, --output FILE          Write to FILE (default: stdout)
  --no-flatten               Disable \input/\include flattening
  --no-comments              Disable comment removal
  --no-bibliography          Disable bibliography inlining
  --no-figures               Disable figure summary substitution
  --figure-summary-suffix S  Suffix for summary files (default: _summary.txt)
  --encoding ENC             File encoding (default: utf-8)
  -v, --verbose              Print processing info to stderr

Processing Pipeline

The four steps run in this order (each operates on the output of the previous step):

  1. Flatten includes — inline \input{}, \include{}, and \subfile{} recursively, with cycle detection
  2. Remove comments — strip % comments while respecting \% escapes and verbatim environments
  3. Inline bibliography — use a pre-compiled .bbl file if available (common in arXiv downloads), otherwise parse .bib files; replaces \bibliography{} with a \begin{thebibliography} block
  4. Figure summary substitution — replace \includegraphics with text descriptions when summary files are available

Figure Summaries

LLMs (as of early 2026) are still poor at extracting precise information from complex figures in papers — dense plots, multi-panel layouts, small labels, etc. To work around this, latex-llm-cleaner can replace figures with equivalent text descriptions.

For each image (e.g., figs/plot.png), place a summary file alongside it with the configured suffix:

figs/plot.png              ← the image
figs/plot_summary.txt      ← the text summary

What to put in a summary

A summary should be data-equivalent to the figure: it should convey the same information a reader would get from looking at the figure, and nothing more. Avoid editorial commentary, interpretation, or conclusions that aren't visually present in the figure itself.

Good example:

Bar chart with four groups (A, B, C, D). Method X scores 0.92, 0.87, 0.76, 0.81. Method Y scores 0.85, 0.91, 0.80, 0.74. Error bars show standard deviation across 5 runs.

Bad example:

This figure clearly demonstrates the superiority of Method X, which aligns with our hypothesis.

Accessibility benefits

LaTeX has limited built-in support for producing accessible output — generated PDFs typically lack alt-text for figures, making them difficult to navigate with screen readers. These same summary files can serve as alt-text source material when compiling to tagged PDF or HTML, improving accessibility beyond the LLM use case.

Development

pip install -e ".[dev]"
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latex_llm_cleaner-0.2.1.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latex_llm_cleaner-0.2.1-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file latex_llm_cleaner-0.2.1.tar.gz.

File metadata

  • Download URL: latex_llm_cleaner-0.2.1.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for latex_llm_cleaner-0.2.1.tar.gz
Algorithm Hash digest
SHA256 173ba90bb13e1afc366b092563b05f9bc289050ca9952e5972816b857ae40e33
MD5 f54e5ba21f0adc144852f2888b679b3b
BLAKE2b-256 e1588b4d7cdb9017e874a5be43b2142e3f1df40834d8f913f7fcff329800a2c8

See more details on using hashes here.

File details

Details for the file latex_llm_cleaner-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for latex_llm_cleaner-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eea6274a5e04ee205df027c49d94d51cb3cd99e04ca38ba5530511908f643522
MD5 51e52b5ae951fcfc4e4f0a50ca852bfe
BLAKE2b-256 3e11d9114cfd975a5674473f98192a67563359ad7f8292a7e837313724ec9057

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page