PDF2TeX
High-performance RAG-based PDF to LaTeX conversion module for large documents (2000+ pages).
Features
- Intelligent PDF Extraction: Multi-path content processing with PyMuPDF, Nougat, and PaddleOCR
- Math-First Approach: 95%+ accuracy on mathematical content using neural equation recognition
- RAG-Powered Generation: Context-aware LaTeX synthesis with Hugging Face LLMs
- Distributed Processing: Ray-based parallel processing for high throughput
- Chapter-Based Output: One
.texfile per chapter with master document
Architecture
PDF Input → Extract + OCR → Chunk + Index → RAG + LLM → LaTeX Output
↓ ↓ ↓
Ray Distributed Workers Pool
↓
Qdrant | Redis | MinIO | Postgres
Quick Start
Prerequisites
- Python 3.11+
- Docker & Docker Compose
- NVIDIA GPU (recommended)
- Hugging Face API token
Installation
# Clone repository
git clone https://github.com/pdf2tex/pdf2tex.git
cd pdf2tex
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -e ".[dev]"
# Start infrastructure
docker-compose up -d
# Run conversion
pdf2tex convert input.pdf --output ./output
Configuration
Create a .env file:
# Hugging Face
HUGGINGFACE_TOKEN=hf_xxxxxxxxxxxxx
# Database
POSTGRES_URL=postgresql+asyncpg://pdf2tex:password@localhost:5432/pdf2tex
# Vector Store
QDRANT_URL=http://localhost:6333
# Redis
REDIS_URL=redis://localhost:6379
# MinIO
MINIO_ENDPOINT=localhost:9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
# Ray
RAY_ADDRESS=auto
Usage
CLI
# Convert a PDF
pdf2tex convert document.pdf --output ./output
# Resume failed conversion
pdf2tex resume doc_abc123
# Check status
pdf2tex status doc_abc123
API
# Start API server
uvicorn pdf2tex.api.app:app --host 0.0.0.0 --port 8000
# Submit document
curl -X POST http://localhost:8000/documents \
-F "file=@textbook.pdf"
# Check status
curl http://localhost:8000/documents/doc_abc123
Python SDK
from pdf2tex import PDF2TeX
converter = PDF2TeX()
result = await converter.convert("textbook.pdf", output_dir="./output")
print(f"Converted {result.total_pages} pages in {result.duration}")
Project Structure
pdf2tex/
├── src/pdf2tex/
│ ├── extraction/ # PDF parsing, OCR, math extraction
│ ├── chunking/ # Text splitting, chapter detection
│ ├── rag/ # Embeddings, vector store, retrieval
│ ├── generation/ # LLM integration, LaTeX synthesis
│ ├── pipeline/ # Orchestration, distributed workers
│ └── api/ # FastAPI endpoints
├── tests/
├── docker-compose.yml
└── pyproject.toml
Performance
| Document Size | Processing Time | Workers |
|---|---|---|
| 500 pages | ~20 min | 10 |
| 1000 pages | ~40 min | 20 |
| 2000 pages | ~72 min | 20 |
License
MIT License - see LICENSE for details.
Metadata
Release files for pdf2tex 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pdf2tex-0.2.0.tar.gz | 88.2 kB | Without provenance | Details for pdf2tex-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pdf2tex-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pdf2tex-0.2.0-py3-none-any.whl |
Total release size: 160.5 kB
Release files / pdf2tex-0.2.0.tar.gz
| Download URL | pdf2tex-0.2.0.tar.gz |
|---|---|
| Size | 88.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc638f7a6994181b0050fb8dd81246a35bc34720741693f1233f44ee9faf13c3
|
|
BLAKE2b-256 checksum How to use checksums |
d9799447212b27a46fd67f1a3c5f7b9d0b647b79e2409fea33bfa9025a2b031a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / pdf2tex-0.2.0-py3-none-any.whl
| Download URL | pdf2tex-0.2.0-py3-none-any.whl |
|---|---|
| Size | 72.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0491a662fb607a1f6c57b50837baa0b4454b5ddb2830d6d847e7b11360c3c7e9
|
|
BLAKE2b-256 checksum How to use checksums |
7e6c4609143a4b947aa4c91eb10ff283dc36e8298f875cf78d076feda967fe5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for pdf2tex 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.