PDF equation extraction: a validation workflow
October 16, 2026 · Oyren AI Team (AI-written)
Recommendation: An equation extracted from a PDF needs four checks against the original page before it enters a derivation, a notebook or a note: source, extraction path, reading order and symbols. The result is editable TeX plus a short record of what was compared, kept separate from any claim that the mathematics is correct.
The four checks run in order because each one catches an error the next cannot fix. A symbol-by-symbol correction does nothing for an equation whose lines came out in the wrong order, and a clean reading order does nothing for a page that was never read. The gray cards in the map name the error each step catches.
The source reference
Every extracted equation points back to one place in one document:
| Field | Example | Why it is there |
|---|---|---|
| Paper and version | arXiv identifier with v2, or DOI | Equations change between versions |
| Page | PDF page 7 | Page numbers alone can be ambiguous with separately numbered front matter |
| Label or section | Equation (12), Section 3.1 | Locates the equation when page numbering differs |
| Crop | A private image of the region | A reading aid for comparison, not a redistributable copy |
The first check is scope. The extraction must include the whole equation, any continuation line, and the sentence that states its assumptions. An expression can match one line exactly and still lose a condition printed just above it.
Text layer or OCR
A PDF can hold selectable text, page images or both. The content decides the extraction path. A quick count of characters per page shows which pages have a text layer, using PyMuPDF:
python -c "import pymupdf, sys; print([len(p.get_text().strip()) for p in pymupdf.open(sys.argv[1])])" paper.pdf
p.get_text()returns the text layer of one page..strip()removes whitespace, so a page with only blank lines counts as0.- The printed list has one number per page. A
0marks a page with no text layer, which needs OCR.
For scanned pages, OCRmyPDF adds a text layer and can write the recognised text to a separate file:
ocrmypdf --skip-text --sidecar paper.txt paper.pdf paper-ocr.pdf
--skip-textpasses pages that already have text through without OCR.--sidecar paper.txtwrites the OCR text topaper.txt.paper.pdf paper-ocr.pdfare the input and output files.
The two flags interact. The sidecar holds only OCR output, so pages skipped because they already had text are missing from paper.txt. An empty or short sidecar is expected in that case, not a failure. The validation record names the tool, the flags and the pages processed, so a missing equation can be traced to the source or to a page that never went through recognition.
Reading order before symbols
On a two-column page or a page with a side figure, plain text extraction can place a line from the right column between two lines from the left. Every character can be correct and the sequence still wrong. PyMuPDF returns text blocks with their positions:
import pymupdf
page = pymupdf.open("paper.pdf")[6]
for x0, y0, x1, y1, text, *_ in page.get_text("blocks", sort=True):
print(round(x0), round(y0), text[:60].replace("\n", " "))
[6]selects PDF page 7, since pages are numbered from zero."blocks"groups text into paragraphs or equation lines, each with a bounding box.sort=Trueorders blocks top to bottom, then left to right.x0andy0are the top-left corner of each block. On a two-column page,x0falls into two clear groups, one per column.
Sorting by position is not the same as reading order. On a two-column page, the sorted list alternates between columns, and the x0 value shows which column each block came from. The review checks the order of the surrounding paragraphs and equation lines first, then looks for a label or footnote that landed inside the expression. Only then does symbol correction make sense.
A symbol checklist
| Element | Comparison with the original |
|---|---|
| Indices | Subscript, superscript and the object being indexed |
| Operators | Sign, relation and placement |
| Grouping | Parentheses, brackets and fraction boundaries |
| Bounds | Limits on sums, products and integrals |
| Conditions | Domain, exceptions and attached qualifiers |
| Definitions | The meaning assigned to each symbol |
This is an inspection order, not measured error-frequency data. Each change goes into a correction log with enough detail to repeat the comparison:
| Equation | Element | Extracted | Corrected | Source |
|---|---|---|---|---|
| (12) | Bounds | \sum_{i=1}^{n-1} | \sum_{i=1}^{n} | Page 7, upper limit |
| (12) | Conditions | missing | x \neq 0 | Page 7, line above |
The log keeps the extracted text and the corrected text side by side. That separates a transcription fix from a local notation choice.
Rendering the TeX
Tools such as Marker output Markdown with LaTeX equations, which makes the result editable. It does not mean each equation was checked against the page. Rendering is a separate step, and a renderer supports its own set of commands. KaTeX's supported functions list what will render on the web:
node -e 'const k = require("katex"), fs = require("fs"); k.renderToString(fs.readFileSync("eq-12.tex", "utf8"), { displayMode: true, throwOnError: true }); console.log("parsed")'
eq-12.texholds the corrected TeX for one equation.displayMode: truerenders it as a centred block equation, the way most numbered equations appear in papers.throwOnError: truestops with a parse error on an unsupported command instead of drawing it in red. The script printsparsedonly when every command is supported.
An unsupported command, such as a custom macro from the paper's preamble, may need a rewrite even when the extraction read it correctly. The rewrite goes into the correction log as a notation change, not as a transcription fix.
What a status record can claim
A transcription that matches the page is one result. A correct equation is another. The status record keeps them apart in four fields instead of one word such as "verified":
- Source compared means the TeX matches the page image. It does not show that the paper is right.
- Notation rendered means KaTeX parses the TeX. It does not show that the symbols match the source.
- Assumptions reviewed means the variables are defined and the domain and conditions are written down. A missing nonzero condition matters even when every copied character is correct.
- Formal argument stays open unless a proof exists. A small numerical example can test the intended behaviour of a formula, but it does not prove a general statement.
These fields are a note design. No extraction service assigns them automatically.
Source and note side by side
The scanned PDF to editable note guide shows the Oyren workflow for turning pages into editable blocks while the original PDF stays open as the reference. The comparison of OCR tools for scientific PDFs covers which extractor to run first. PDF OCR to Markdown notes keeps each equation next to its source page and the record of what was checked.