# LaTeX-OCR

> pix2tex: Using a ViT to convert images of equations into LaTeX code

- Type: agent or tool
- Field: Image & Design
- Repository: https://github.com/lukas-blecher/LaTeX-OCR
- GitHub stars: 16592
- Licence: MIT
- Language: Python
- Last push: 2025-01-18
- Page: https://imutechz.in/agents/latex-ocr

## What it is
pix2tex (LaTeX-OCR) is a learning-based system that takes an image of a math formula and returns the corresponding LaTeX code. It uses a ViT-based model and is aimed at anyone who needs to convert equation images into LaTeX, from researchers to students. It can be used via a command line tool, a GUI with screenshot capture, an API with a Streamlit demo, or directly from Python.

## Features
- Converts images of math formulas into LaTeX code
- Command line tool that parses images from disk or clipboard
- GUI (latexocr) for screenshots with MathJax rendering and clipboard copy
- API mode with Streamlit demo and Docker image
- Python usage via LatexOCR class
- Automatic preprocessing that resizes input images to optimal resolution

## Best for
- Digitizing equations from papers or screenshots
- Quick LaTeX capture from screen via GUI
- Batch conversion of equation images from disk
- Integrating equation OCR into Python workflows

## Pros
- Model checkpoints are downloaded automatically
- Offers CLI, GUI, API, and Python interfaces
- Preprocessing step resizes images to improve performance on real-world images
- Training code and dataset generation are included

## Cons
- Requires Python 3.7+ and PyTorch installed separately
- Works best with smaller-resolution images and may not handle huge images optimally
- Results should be double-checked as predictions can be wrong

## Install
```
pip install "pix2tex[gui]"
```

## Usage
```
latexocr
```

Tags: latex, ocr, math, image-to-text, vit, pix2tex, equation-recognition, python
