Wiki › Project

Mistral OCR to LaTeX

Article
From Chaipat's knowledge graph

Mistral OCR to LaTeX is a web app that takes a PDF or photo of an academic document, such as an exam or problem set, and returns a compilable .tex file with the questions and solutions visually separated. It runs entirely on the free tier of a single Mistral API key.

Pipeline

The backend is a FastAPI service in Python. Each upload is first resized to at most 2048 pixels, then takes one of two paths:

  • Images, often handwritten, are read by Pixtral 12B, Mistral's vision model. A second Pixtral pass cross-checks the transcription against the original pixels and corrects it.
  • PDFs go through Mistral OCR, which keeps the layout and extracts embedded figures. Pixtral then classifies each figure in parallel: redraw it as TikZ, keep it as an image, or skip it.

Both paths end with Mistral Large, which writes the LaTeX document and formats each question and solution in its own box. The result is checked for balanced \begin/\end pairs and braces. If the check fails, the model is sent the list of errors and asked to repair the file, up to two times.

Interface

A single page shows the original on the left and the result on the right. The right side has a rendered preview (Markdown with KaTeX for the maths) and the LaTeX source with syntax highlighting.

See also