Skip to content

How-ToGPU

How to Convert Equations to LaTeX on Your PC With pix2tex

pix2tex (LaTeX-OCR) is a free, open-source AI model that turns a screenshot or image of a maths equation into LaTeX code on your own PC. Following its official README, we cover installing it with pip, the latexocr screenshot GUI, the command line, Python use and tips for accurate results.

By , Systems & Technical Editor

3 min read

How to Convert Equations to LaTeX on Your PC With pix2tex

Retyping a long equation from a PDF, a lecture slide or a textbook photo into LaTeX is slow and error-prone. pix2tex, also known as LaTeX-OCR, is a free, open-source AI model that looks at an image of a maths formula and returns the LaTeX code for it, running on your own computer rather than a cloud service.

What pix2tex is

pix2tex is a Python package published under the MIT licence. Its README describes the goal as "a learning based system that takes an image of a math formula and returns corresponding LaTeX code". Under the hood it uses a Vision Transformer (ViT) encoder with a ResNet backbone and a Transformer decoder. The latest release on PyPI at the time of writing is version 0.1.4, uploaded on 18 January 2025, so treat it as a mature but quietly maintained tool rather than a fast-moving one.

The project reports a BLEU score of 0.88, a normalised edit distance of 0.10 and token accuracy of 0.60 on its own test data. Those are the developer's figures, not ours, and token accuracy of 0.60 is a good reminder that you'll need to check its output.

What you need

  • Python 3.7 or newer, which the README lists as the minimum.

  • PyTorch. If it isn't already installed, the README points you to PyTorch's official install instructions first.

  • A little disk space for the model checkpoints, which pix2tex downloads automatically the first time it runs.

If you'd rather keep AI tools in Linux on a Windows PC, our guide to setting up WSL2 with GPU support for local AI covers the groundwork.

Step 1: Install pix2tex with the GUI

Open a terminal (ideally inside a Python virtual environment) and run:

pip install "pix2tex[gui]"

The [gui] extra pulls in the dependencies for the screenshot tool described below.

Step 2: Snip an equation with the GUI

Run:

latexocr

This opens a small window. Take a screenshot of the equation you want, and the predicted LaTeX is rendered with MathJax so you can compare it with the original, then copied to your clipboard ready to paste into your LaTeX editor.

On Linux the GUI uses gnome-screenshot where available. The README says users of wlroots-based Wayland compositors can use grim and slurp, and KDE Plasma users spectacle; you may need to set the SCREENSHOT_TOOL environment variable to grim or spectacle if gnome-screenshot is also installed.

If the model is unsure, clicking Retry may give a different answer each time. The temperature setting controls this: a low temperature produces the same result every time.

Step 3: Use the command line for saved images

If you already have image files, run:

pix2tex

The README says the command-line tool can read existing images from disk as well as images in your clipboard.

Step 4: Call it from Python or an API

For scripts, the README's Python example is short:

from PIL import Image
from pix2tex.cli import LatexOCR

img = Image.open('path/to/image.png')
model = LatexOCR()
print(model(img))

There's also an API with a Streamlit demo. Install it with pip install -U "pix2tex[api]" and run python -m pix2tex.api.run; the demo connects to the API on port 8502. A Docker image (lukasblecher/pix2tex:api) is available too.

Tips for better results

  • Don't zoom in too far. The README says the model works best with smaller images. pix2tex runs a second neural network that predicts the best resolution and resizes your image to resemble its training data, but it may still struggle with very large images.

  • If it's wrong, try another size. The developer suggests redoing the prediction at a different resolution when the answer is wrong.

  • Always check the output. The README explicitly says to double-check results carefully. Paste the LaTeX into a previewer and compare it symbol by symbol, especially subscripts and brackets.

  • Equations, not whole pages. pix2tex is designed for images of individual formulas. For whole PDFs with text and maths, see our comparison of Docling vs Marker.

Can you train it on your own data?

Yes. The README covers installing pix2tex[train], building a dataset from images and their LaTeX labels, editing a config file and running python -m pix2tex.train. Generating training images needs extra tools including XeLaTeX, ImageMagick with Ghostscript, and Node.js for KaTeX. That's well beyond what most people need, but it's useful if you work with unusual notation.

The bottom line

pix2tex is a quick, free way to turn screenshots of equations into LaTeX on your own PC: install it with pip, run latexocr, snip the formula and paste the result. It's best for single formulas rather than whole documents, the latest release dates from January 2025, and the developer's own advice applies - always check the LaTeX it gives you before you rely on it.

Sources

  1. 01pix2tex - LaTeX OCR README (lukas-blecher/LaTeX-OCR, GitHub)
  2. 02pix2tex package page (PyPI)

About the author

Marcus Thorne

Systems & Technical Editor

Marcus writes Forge PC's step-by-step build, troubleshooting and system optimisation guides. His background spans Windows kernel and power-state diagnostics, UEFI/BIOS configuration, NVMe storage arrays, ATX 3.1 power delivery and running local AI and LLM workloads on consumer graphics cards.

More from Marcus Thorne

Read next

How to Add an Exclusion to Microsoft Defender in Windows 11 (Safely)

How-To

How to Add an Exclusion to Microsoft Defender in Windows 11 (Safely)

Microsoft Defender keeps flagging a file you trust? Rather than switching protection off, you can exclude a file, folder, file type or process in Windows Security. Following Microsoft's guidance, we show how to add and remove exclusions, use wildcards safely and what exclusions don't cover.

Marcus Thorne4 min

The Best NVIDIA App Features in 2026: What's Worth Using on a GeForce PC

Best Picks

The Best NVIDIA App Features in 2026: What's Worth Using on a GeForce PC

The NVIDIA App does far more than update drivers. Based on NVIDIA's official pages, we pick the features most worth using on a GeForce PC, from DLSS Override and Smooth Motion to Instant Replay, the performance overlay, RTX HDR and one-click GPU tuning, and explain who each suits.

Hannah Vance4 min