Texo: A SOTA LaTeX OCR Model with Only 20M Parameters, Open Source

If you do research, you end up writing LaTeX. If you write LaTeX often, you run into formulas you don't know how to type, or you have a pile of elegant formulas and want to turn them into LaTeX code. A few years ago, this was a real hassle. You could spend hours tearing your hair out and still not get anywhere. One thing that bugged me for a long time was how $\sum\limits_{i=0}^{\infty} \frac{1}{2^i}$ puts the subscript underneath the sum sign (the trick is adding limits, i.e. \sum\limits). Once you solve a little problem like that, you know the answer forever, but the first time is always a round of trial and error.
Thanks to deep learning, tasks that used to be tedious are now easy for AI.
This post introduces Texo (pronounced /ˈtɛːkoʊ/), which offers a simple, easy-to-use solution to exactly this problem. As a lightweight model with only 20M parameters, it not only keeps SOTA (State Of The Art) performance but also runs directly in the browser.
Key Features
Texo is designed around "minimalism" and "practicality." Its highlights:
- Extremely lightweight: Only 20M parameters, with very fast inference.
- Fully open source: Released under AGPL-3.0, free and open.
- Low barrier to training: No need to buy a 4090. You can fine-tune or train it on a consumer GPU.
- On-device: Supports ONNX export and can run directly in the browser, which protects privacy and eliminates latency.
- Tutorial-grade code: The code is clearly organized. It is not just a tool but also an excellent tutorial for learning how OCR models are built.
Architecture and Performance
Texo is essentially a distilled version of PPFormulaNet-S, fine-tuned on the UniMERNet-1M dataset. This strategy lets Texo cut the parameter count dramatically while retaining as much recognition accuracy as possible.
Here are Texo's benchmark results on the UniMERNet-Test dataset compared with mainstream larger models:
| Model | Params | Metric | SPE | CPE | SCE | HWE |
|---|---|---|---|---|---|---|
| UniMERNet-T | 107M | BLEU | 0.909 | 0.902 | 0.566 | 0.883 |
| Edit Dist | 0.066 | 0.075 | 0.239 | 0.078 | ||
| PPFormulaNet-S | 57M | BLEU | 0.8694 | 0.8071 | - | - |
| Texo-distill | 20M | BLEU | 0.9014 | 0.8909 | 0.7034 | 0.8606 |
| Edit Dist | 0.0780 | 0.1042 | 0.1941 | 0.0995 |
As the numbers show, Texo-distill has one fifth the parameters of UniMERNet-T yet a BLEU score (0.9014) very close to it (0.909), and it beats the 57M-parameter PPFormulaNet-S. In other words, Texo-distill is faster without sacrificing quality: the lighter weight brings a speed advantage with only a minimal impact on accuracy.
Note: Texo-distill uses the same tokenizer as UniMERNet, so the sequence metrics are strictly comparable.
In practice it is very fast. After uploading an image, recognition finishes in under a second.

Quick Start
Texo offers a thoroughly modern Python experience. uv is recommended for package management.
1. Environment Setup
git clone https://github.com/alephpi/Texo
uv sync
2. Download the Model
The project provides a convenient script to pull the model from Hugging Face:
# Download the inference model only
python scripts/python/hf_hub.py pull
# Download the full version including training checkpoints (for developers who want to continue training)
python scripts/python/hf_hub.py pull --with_useful_ckpts
3. Inference Demo
Once the download finishes, you can run the demo.ipynb notebook in the project to see how images are converted to LaTeX code.
Training Guide
For researchers who want to build on Texo or fine-tune it, the author provides detailed training instructions. Thanks to the lightweight design, the hardware requirements are very approachable.
Hardware Requirements
- Minimum: 20G CPU RAM (with streaming data loading) + 16G VRAM (with gradient accumulation). This means a high-end gaming GPU (such as an RTX 4080 or 4090) is enough to try training.
- Recommended: 50G CPU RAM + 40G VRAM.
- Author's setup: 50G CPU RAM + NVIDIA A40/L40S (46G).
Dataset Preparation
Texo uses the UniMER-1M dataset. For convenience, the author provides a version that has already been cleaned and normalized:
Start Training
The project uses hydra for configuration management and supports flexible training launches:
# Start standard training
python src/train.py
# Resume from a checkpoint
python src/train.py training.resume_from_ckpt="<ckpt_path>"
# Debug mode (quickly verify the code)
python src/train.py --config-dir="./config" --config-name="train_debug.yaml"
Training logs and visualizations (loss curves, BLEU scores, and so on) are saved automatically in the outputs directory and can be viewed in TensorBoard.
Final Thoughts
For small LaTeX questions, you can just ask an AI assistant. But if you are interested in LaTeX OCR projects, or you want to build your own lightweight offline LaTeX OCR solution, Texo is absolutely worth a try.
Resources
- GitHub repository: https://github.com/alephpi/Texo
- Online demo: https://texocr.netlify.app