How Math OCR Works: From a Formula Photo to LaTeX
Math OCR turns a picture of a formula into LaTeX in four steps: it cleans up the image, finds the individual symbols, works out how they relate in space — what is a superscript, what sits above a fraction bar — and writes that structure out as LaTeX. Here is what happens at each step, and why handwriting is harder than print.
Step 1: Image Preprocessing
Before any recognition happens, the image is cleaned up. This step matters more than most people realize.
TexPixel normalizes contrast, removes noise, deskews tilted images, and isolates the formula region from surrounding whitespace, printed text, or ruled lines. A formula photographed under harsh side-lighting — or scanned at a slight angle — is corrected before the model ever sees it.
This is why image quality affects accuracy so much: preprocessing can compensate for minor flaws, but severe blur or extremely low resolution (below ~72 DPI) leaves too little information to work with.
Step 2: Symbol Detection
The preprocessed image is fed into a visual encoder — a neural network that has learned, from millions of math images, what mathematical symbols look like.
The key challenge here isn't recognizing individual symbols in isolation. It's recognizing them in context. The symbol x looks different when it's a variable, when it's a multiplication sign, and when it's written in different handwriting styles. The model learns to distinguish these from surrounding context: is there a dot nearby? What's the vertical position relative to a fraction bar?
This contextual understanding is what separates a good math OCR system from a general-purpose character recognizer.
Step 3: Structure Parsing
Recognizing symbols is only half the problem. Math is two-dimensional in a way that ordinary text is not. A fraction has a numerator above a denominator. An integral has limits at the top and bottom. A matrix arranges expressions in rows and columns.
TexPixel's parser builds a structural tree from the detected symbols — understanding that this expression is a subscript of that symbol, and that expression lives inside a square root. This tree is then serialized into LaTeX, where the structural relationships are encoded as commands like \frac{}{}, \sqrt{}, \sum_{}^{}.
Step 4: LaTeX Generation
The final step is walking the structural tree and emitting valid LaTeX. This includes choosing the right command for ambiguous cases — for example, whether a large Σ should be rendered as \sum (display math) or \Sigma (inline), based on context.
The output is then validated to ensure it compiles without errors before being returned.
Why Handwriting Is Harder Than Print
Printed math (from textbooks or PDFs) has consistent, high-contrast strokes. Handwriting varies enormously — in size, slant, stroke weight, and letter formation. Two people's handwritten 7 and 1 can look nearly identical, and two people's β can look completely different.
Recognition models are trained on many handwriting styles to cope with this variation, but handwriting is still read less reliably than print — most mistakes involve look-alike symbols and cramped spacing. The tips in our handwriting guide remove most of those causes.
The Whole Pipeline in One Second
Preprocessing → symbol detection → structure parsing → LaTeX generation: all of this runs in under a second. It's a well-engineered pipeline, not magic — but the speed still surprises most people the first time they try it.
Upload an image, review the recognized formula, and copy LaTeX or export a Word document.
Try TexPixel