First published 2026-09-15
tl;dr: no libraries that I tried convert images to text well, much less to Latex. I didn't try every library listed below.
Tesseract cannot natively produce LaTeX code from math equations or text.
citations:
How does Tesseract do with hand-written text?
sudo apt install tesseract-ocr sudo apt install python3-pip sudo apt install python3-pil sudo apt install python3.14-venv python3 -m venv .venv pip3 install pytesseract
The script
from PIL import Image
import pytesseract
text = pytesseract.image_to_string(Image.open('20260628_090059.jpg'))
print(text)
produces
$ python3 convert.py 20260628_090059.jpg coatravarient vector a= traa storm Com poasn +5 ke dx (by A' ;) covarient vec tof Componsr tS ror storm ) A stor like et (by B, se de; ar of de! describe the same physceal thing (di tlre ntal elerrnt of — leagth or oli tener thal element oF angle )
https://github.com/lukas-blecher/LaTeX-OCR aka https://lukas-blecher.github.io/LaTeX-OCR/ Developer is the lead author on the paper "Nougat: Neural Optical Understanding for Academic Documents" (https://arxiv.org/abs/2308.13418)
https://arxiv.org/abs/2308.13418
From Facebook Research:
https://github.com/facebookresearch/nougat aka
https://facebookresearch.github.io/nougat/
https://pix2tex.readthedocs.io/en/latest/
deprecated: https://github.com/blaisewang/img2latex-mathpix
Serve the LLM using
python3 -m llama_cpp.server --model ./models/gemma-4-E4B-it-qat-UD-Q4_K_XL.gguf --n_gpu_layers -1then send the image for conversion using
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"model": "gemma-4-E4B-it-qat-UD-Q4_K_XL.gguf",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": "Perform OCR on this image. Extract and output all text visible in it precisely."
},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,'$(base64 image.jpg)'"
}
}
]
}
]
}'
The output does feature Latex, but nothing related to what's in the image.
convert_heic_to_jpg.py contains
import argparse
from pathlib import Path
from PIL import Image
import pillow_heif
# Register HEIF decoder with Pillow
pillow_heif.register_heif_opener()
# Set up command-line argument parsing
parser = argparse.ArgumentParser(description="Convert a HEIC image to JPEG.")
parser.add_argument("input_image", type=str, help="Path to the input HEIC image")
args = parser.parse_args()
# Handle input and output paths using pathlib
input_path = Path(args.input_image)
output_path = input_path.with_suffix(".jpg")
# Open and convert the image
try:
image = Image.open(input_path)
image.save(output_path, "JPEG")
print(f"Successfully converted '{input_path}' to '{output_path}'")
except Exception as e:
print(f"Error converting image: {e}")