Skip to main content
Back

BabelDOC Translates Dense Academic PDFs Without Breaking Math or Layout

BabelDOC translates scientific PDFs into bilingual documents while preserving layout, formulas, and terminology — now backed by an ACL 2026 paper

Pro

  • What it is: BabelDOC is an open-source Python library that translates PDFs into bilingual documents while preserving layout, math formulas, and terminology — 9K+ GitHub stars.
  • Key innovation: An Intermediate Representation (IR) that decouples layout metadata from text, enabling document-level NLP operations like cross-page context and automatic glossary extraction.
  • Benchmark results: Scored 4.59/5 for layout fidelity in human evaluation, beating PDFMathTranslate (3.29) and DeepL (3.44) on a 200-page benchmark of arXiv papers, technical docs, and patents.
  • Free tier: 1,000 free pages/month via Immersive Translate online service; self-host with any OpenAI-compatible model for near-zero cost.
  • Limitations: Primarily optimized for English-to-Chinese; cross-page paragraph splits still reduce accuracy; author/reference sections can merge incorrectly.
  • Research backing: ACL 2026 paper formalizes the IR paradigm and evaluation methodology against DeepL and PDFMathTranslate baselines.

BabelDOC is an open-source Python library that translates PDF documents, especially dense academic papers, into bilingual side-by-side outputs while preserving the original layout. Math formulas stay rendered, multi-column grids stay aligned, footnotes get translated, and a glossary system keeps technical terms consistent across pages. With over 9,000 GitHub stars and a paper accepted at ACL 2026, it has become the default backend for serious PDF translation in the open-source ecosystem.

The problem researchers keep hitting

PDFs dominate scientific research, commerce, law, and technical exchange, but English's dominance in global knowledge production shuts out non-English-speaking researchers in ways that compound over time. The obvious workaround, copying text into Google Translate, destroys all formatting. Commercial tools like DeepL handle documents but mangle multi-column layouts and drop math entirely. Existing pipelines force a choice between linguistic accuracy and structural fidelity: translation tools discard layout metadata, while document parsers can extract content but cannot re-render it faithfully after translation. BabelDOC was built to avoid that tradeoff entirely.

The IR architecture doing the heavy lifting

The core innovation is an Intermediate Representation (IR), a structured JSON snapshot of the entire document that keeps layout metadata and text completely separate. Rather than treating translation as a black-box end-to-end task, BabelDOC explicitly decouples visual layout from semantic content. That separation enables document-level operations that monolithic pipelines cannot support: terminology extraction, cross-page context handling, glossary-constrained generation, and formula placeholdering. Once translation is complete, the translated content is re-anchored to the original layout through an adaptive typesetting engine.

This differs fundamentally from its predecessor, PDFMathTranslate. The earlier system's monolithic architecture lacked an explicit IR, which blocked scalability for semantic processing and structural manipulation, including cross-column context awareness and complex nested structure rendering.

Five stages inside the pipeline

  1. Parsing into IR: The PDF is parsed into a structured schema storing characters, text lines, graphic blocks, and inline images, each with spatial coordinates, bounding boxes, and stylistic attributes.
  2. Formula processing: A script detection unit identifies superscripts and subscripts from font-size variance, then masks all math as placeholders before the LLM sees the text. Formulas are reconstructed afterward with vector fidelity.
  3. Semantic translation: The LLM (any OpenAI-compatible model) operates on clean text with domain glossaries injected into the prompt. The IR also lets the engine stitch together paragraphs split across columns or pages, fixing a common accuracy failure in naive translators.
  4. Adaptive typesetting: Translated text in languages like Chinese or German can run longer or shorter than the English source. BabelDOC runs an iterative search to find the minimum font scaling factor (e.g., γ=0.85) that fits translated text back into the original bounding box without overflow.
  5. Nested structure reconstruction: XObjects, clipping paths, and matrix transformations are managed with push/pop stacks so complex academic layouts survive re-rendering intact.

What the benchmarks show

Experiments on a curated 200-page benchmark covering arXiv physics and math papers, technical documentation, and international patents combined automated metrics with human evaluation and multimodal LLM-as-a-judge scoring.

On the automated layout metric (BIoU, bounding box overlap between source and translated elements), BabelDOC scored 50.0% versus PDFMathTranslate's 48.7% and DeepL's 19.8%. Human evaluators rated BabelDOC 4.59/5 for layout fidelity, compared to 3.29 for PDFMathTranslate and 3.44 for DeepL. DeepL does edge ahead on one metric: fewer untranslated text blocks per page (2.33 versus BabelDOC's 2.85), pointing to extraction-side gaps on certain document types.

Where it works well, and where it falls short

BabelDOC handles these cases reliably:

  • Multi-column academic PDFs with dense math (arXiv papers, IEEE proceedings)
  • Footnote translation, a feature none of the compared systems support
  • Font style preservation (bold, italic, serif/sans-serif)
  • In-figure and in-table text translation
  • Terminology consistency across long documents via automatic glossary extraction
  • Scanned PDFs via an OCR workaround mode (--auto-enable-ocr-workaround)

Known limitations before you commit:

  • Paragraphs that split across page boundaries are treated as separate text blocks, so the LLM receives them in two separate API calls, dropping translation accuracy at those seams
  • Author and reference sections often merge into a single paragraph after translation
  • Drop caps are unsupported
  • Very large pages get skipped
  • Development has focused on English-to-Chinese; other language pairs have not been fully tested

How to run it

The fastest path uses uv, the modern Python package manager. Install and run in three commands:

uv tool install --python 3.12 BabelDOC
babeldoc --openai \
  --openai-model "gpt-4o-mini" \
  --openai-base-url "https://api.openai.com/v1" \
  --openai-api-key "your-key" \
  --files paper.pdf

BabelDOC outputs two PDFs by default: a monolingual translation and a bilingual side-by-side version. Pass a custom glossary CSV to lock down domain-specific terms:

# glossary.csv
source,target,tgt_lng
"attention mechanism","注意力机制",zh-CN
"transformer","变换器",zh-CN
babeldoc --openai --openai-model "gpt-4o-mini" \
  --openai-api-key "your-key" \
  --glossary-files glossary.csv \
  --files paper.pdf

For self-hosted or local models (Ollama, LM Studio), point --openai-base-url at your local endpoint and pass any string as the API key. Models like deepseek-chat and glm-4-flash are recommended for strong OpenAI API compatibility.

Cost and access

The library is free and open-source under AGPLv3. The online service via Immersive Translate offers 1,000 free pages per month. Beyond that, you pay only for the LLM API you connect: gpt-4o-mini at roughly $0.15 per million input tokens puts even a 50-page paper well under a dollar. Teams that want a full WebUI without managing the CLI can use PDFMathTranslate 2.0, which runs BabelDOC as its backend and supports Google, DeepL, Ollama, and OpenAI out of the box.

Why the architecture matters beyond translation

BabelDOC's bidirectional IR is the first open-source system to cleanly solve both sides of the layout-versus-linguistics problem at once. The modular design lets researchers swap in new layout models, OCR engines, or LLMs without touching the rendering core. As Vision-Language Models improve at understanding document structure, BabelDOC's plugin architecture can absorb those gains directly. The ACL 2026 paper formalizes the methodology and benchmark, giving the project a research foundation that should attract contributions well beyond the current English-to-Chinese focus.