
pix2tex
Converts a picture of a math formula into LaTeX code using a learned image-to-text model.lukas-blecher/LaTeX-OCR
- Stars
- 16.6k
- Forks
- 1.3k
- Licence
- MIT
- Language
- Python
- Last update
- 1.8 years ago
- Type
- AI model / agent
No commits in over a year — check for forks or alternatives before adopting.
What it is
pix2tex takes an image of a math formula, such as a photo or screenshot, and returns the matching LaTeX code so you can paste it into a document. It is built on a neural network that combines a Vision Transformer encoder with a Transformer decoder. You can use it from a command line tool, a small desktop GUI, a Streamlit demo, or Python.
- Convert a screenshot of an equation into LaTeX with the pix2tex command line tool
- Paste a formula from your clipboard and get LaTeX output
- Use the latexocr GUI to take a screenshot of a formula and copy the resulting LaTeX
- Call the model from a Python script to process a folder of formula images
- Fine-tune the model on your own image and LaTeX data using the training instructions
Great for
- Students who want to turn a handwritten or printed formula photo into editable LaTeX
- Writers who need to copy a formula from a screenshot or PDF into LaTeX
- Developers who want to call a formula-to-LaTeX model from Python
- People who want a quick local tool and are comfortable installing Python packages
Not ideal for
- Users who need guaranteed-correct output: the README says to always double check results, and accuracy is moderate (token accuracy 0.60)
- Users with very large or heavily zoomed images, since the README says the model handles huge images poorly
- Users who cannot install Python or PyTorch, since the package requires them
- Users who need to convert whole documents rather than single formulas, since the project targets math formula images
How to get it
- 1
Install with a package manager
You'll need: Python 3.7+ · PyTorch (install separately by following the PyTorch instructions)
Install the package with GUI support
pip install "pix2tex[gui]" - 2
Run it
- Install PyTorch by following the instructions linked in the README if you do not have it
- Run pip install "pix2tex[gui]"
- Run the command line tool with pix2tex, or start the GUI with latexocr
- Check the returned LaTeX against the original image
- 3
Get the most out of it
- Set the temperature parameter in the GUI; low temperature gives the same result on each retry
- On Linux, set the SCREENSHOT_TOOL environment variable to grim or spectacle if gnome-screenshot is not compatible with your Wayland setup
- Avoid zooming in fully before taking a picture, since the model resizes images itself
- Use the Docker image for the API if you do not want to install Python dependencies locally
- Use the Google Colab notebooks linked in the README to try the model or training without local setup
Downloads
Strengths
- Free and open source under the MIT license
- Offers several ways to use it: command line, GUI, API, and Python
- Model checkpoints download automatically after installation
Trade-offs
- Output must be checked carefully; the README reports a BLEU score of 0.88 and token accuracy of 0.60
- Works best with smaller-resolution images and is sensitive to how the picture is taken
- Documentation is incomplete; the README says the author is still compiling it
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| LaTeX-OCR (this) | 16.6k | AI model / agent | intermediate | 1.8 years ago | Students who want to turn a handwritten or printed formula photo into editable LaTeX |
| nougat | 10.1k | AI model / agent | intermediate | 1.7 years ago | Researchers who want editable text from arXiv-style papers with equations and tables |
| annotated_deep_learning_paper_implementations | 67.6k | Learning resource | intermediate | 4 days ago | Students learning how transformers, GANs, or optimizers work internally |
| Made-With-ML | 49.9k | Learning resource | intermediate | 8 months ago | Software engineers who want to learn how ML models get deployed and maintained |
| pytorch-deep-learning | 19.3k | Learning resource | beginner | 1 months ago | Beginners in machine learning who want to learn PyTorch in a hands-on, code-first way |
| onnxruntime | 22.2k | Library | intermediate | 4 days ago | Developers who want to deploy a trained model inside an application or service |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.