PDF Visual Audit
Purpose
Use this skill when text extraction is not enough. The core move is to render the PDF pages to images, inspect the page visually, then repair the clean Markdown against the rendered source of truth.
This complements text extraction skills. Use text extraction to find candidate locations, but trust rendered PDF pages for formulas, layout, tables, and two-column ordering.
Workflow
Locate the source PDF and converted artifacts.
Prefer explicit paths from the user. If a directory contains reference.pdf, reference.full.md, pages/page-XX.md, chunks.jsonl, or reference.raw.txt, treat the PDF as the visual source of truth and the Markdown as the editable artifact.
Render the relevant PDF pages.
Use the bundled renderer on macOS:
bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 4
The third argument is scale. Use 3 or 4 for formula reading. Add page bounds when only a range matters:
bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 4 4 8
Inspect rendered pages.
Use view_image on full pages first. If formulas are small, crop with sips into temporary files and inspect those. Keep crops in /tmp or /private/tmp.
Reconstruct clean Markdown.
Convert equations into block LaTeX:
$$
...
\tag{19}
$$
Prefer the PDF's notation exactly: hats, tildes, bars, superscripts, subscripts, calligraphic force symbols, case definitions, sums, and integration bounds. Do not infer notation from broken text when the rendered PDF shows otherwise.
Preserve audit material.
If page files contain both ## Clean Text and ## Raw PDFKit Text, edit only Clean Text unless the user explicitly asks to rewrite raw extraction. Raw blocks are useful evidence of extraction failure.
Synchronize derived artifacts.
If reference.full.md is assembled from pages/page-XX.md, regenerate it from clean page text after page edits. If chunks.jsonl exists, rebuild it so retrieval does not keep old broken formula fragments.
Validate.
Run targeted checks before finishing:
rg -n "ZaccT|Zta|JCLIP|Coc k|Col k|πθold|σ2|µθ|^[ˆ˜¯˚]$" reference.full.md chunks.jsonl
rg -n -F "\tag{" reference.full.md
Also check math delimiters are balanced:
python3 - <<'PY'
from pathlib import Path
for f in [Path("reference.full.md"), *Path("pages").glob("page-*.md")]:
text = f.read_text()
if f.name.startswith("page-"):
text = text.split("## Clean Text", 1)[1].split("## Raw PDFKit Text", 1)[0]
if text.count("$$") % 2:
print("unbalanced $$", f, text.count("$$"))
PY
Formula Repair Heuristics
- Treat standalone
ˆ, ˜, ¯, ˚, Z, and X lines as extraction artifacts until verified visually.
- For numbered equations, count tags and compare against the PDF sequence. Missing or duplicated tags usually reveal a bad page splice.
- For two-column papers, check whether text blocks crossed columns. Reorder paragraphs according to the rendered page, not the extracted line order.
- For formulas split across pages, remove dangling half-sentences on the previous page and complete the sentence on the next page when the PDF shows a page break.
- For paper conversions, use
\mathrm{...} for semantic superscripts like tr, au, ch, wt, ob, in, out, CLIP; use \mathcal{...} only when the PDF uses calligraphic symbols.
- Keep variables consistent across equations and explanatory text.
Renderer Notes
The bundled script compiles a temporary Objective-C helper using macOS CoreGraphics and writes PNG pages. It applies a vertical flip by default because CoreGraphics bitmap coordinates otherwise commonly produce inverted PDF pages in command-line rendering.
If a page looks inverted after rendering, rerun with --no-flip:
bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 4 1 1 --no-flip
If pdftoppm, mutool, or a reliable OCR/Mathpix tool is available, it can be used as an aid. Still verify against rendered pages before writing formulas into Markdown.
1---2name: pdf-visual-audit3description: Use when Codex needs to repair or verify extracted Markdown/text from a local PDF by visually auditing rendered PDF pages, especially when equations, LaTeX, tables, page order, two-column text, headers/footers, or figure captions are scrambled by PDF text extraction. Use for tasks like fixing formulas in converted MD, reconstructing numbered equations from a paper PDF, comparing clean text against the PDF, or producing agent-readable reference files while preserving raw extraction audit text.4---56# PDF Visual Audit78## Purpose910Use this skill when text extraction is not enough. The core move is to render the PDF pages to images, inspect the page visually, then repair the clean Markdown against the rendered source of truth.1112This complements text extraction skills. Use text extraction to find candidate locations, but trust rendered PDF pages for formulas, layout, tables, and two-column ordering.1314## Workflow15161. Locate the source PDF and converted artifacts.1718 Prefer explicit paths from the user. If a directory contains `reference.pdf`, `reference.full.md`, `pages/page-XX.md`, `chunks.jsonl`, or `reference.raw.txt`, treat the PDF as the visual source of truth and the Markdown as the editable artifact.19202. Render the relevant PDF pages.2122 Use the bundled renderer on macOS:2324 ```bash25 bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 426 ```2728 The third argument is scale. Use `3` or `4` for formula reading. Add page bounds when only a range matters:2930 ```bash31 bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 4 4 832 ```33343. Inspect rendered pages.3536 Use `view_image` on full pages first. If formulas are small, crop with `sips` into temporary files and inspect those. Keep crops in `/tmp` or `/private/tmp`.37384. Reconstruct clean Markdown.3940 Convert equations into block LaTeX:4142 ```markdown43 $$44 ...45 \tag{19}46 $$47 ```4849 Prefer the PDF's notation exactly: hats, tildes, bars, superscripts, subscripts, calligraphic force symbols, case definitions, sums, and integration bounds. Do not infer notation from broken text when the rendered PDF shows otherwise.50515. Preserve audit material.5253 If page files contain both `## Clean Text` and `## Raw PDFKit Text`, edit only `Clean Text` unless the user explicitly asks to rewrite raw extraction. Raw blocks are useful evidence of extraction failure.54556. Synchronize derived artifacts.5657 If `reference.full.md` is assembled from `pages/page-XX.md`, regenerate it from clean page text after page edits. If `chunks.jsonl` exists, rebuild it so retrieval does not keep old broken formula fragments.58597. Validate.6061 Run targeted checks before finishing:6263 ```bash64 rg -n "ZaccT|Zta|JCLIP|Coc k|Col k|πθold|σ2|µθ|^[ˆ˜¯˚]$" reference.full.md chunks.jsonl65 rg -n -F "\tag{" reference.full.md66 ```6768 Also check math delimiters are balanced:6970 ```bash71 python3 - <<'PY'72 from pathlib import Path73 for f in [Path("reference.full.md"), *Path("pages").glob("page-*.md")]:74 text = f.read_text()75 if f.name.startswith("page-"):76 text = text.split("## Clean Text", 1)[1].split("## Raw PDFKit Text", 1)[0]77 if text.count("$$") % 2:78 print("unbalanced $$", f, text.count("$$"))79 PY80 ```8182## Formula Repair Heuristics8384- Treat standalone `ˆ`, `˜`, `¯`, `˚`, `Z`, and `X` lines as extraction artifacts until verified visually.85- For numbered equations, count tags and compare against the PDF sequence. Missing or duplicated tags usually reveal a bad page splice.86- For two-column papers, check whether text blocks crossed columns. Reorder paragraphs according to the rendered page, not the extracted line order.87- For formulas split across pages, remove dangling half-sentences on the previous page and complete the sentence on the next page when the PDF shows a page break.88- For paper conversions, use `\mathrm{...}` for semantic superscripts like `tr`, `au`, `ch`, `wt`, `ob`, `in`, `out`, `CLIP`; use `\mathcal{...}` only when the PDF uses calligraphic symbols.89- Keep variables consistent across equations and explanatory text.9091## Renderer Notes9293The bundled script compiles a temporary Objective-C helper using macOS `CoreGraphics` and writes PNG pages. It applies a vertical flip by default because CoreGraphics bitmap coordinates otherwise commonly produce inverted PDF pages in command-line rendering.9495If a page looks inverted after rendering, rerun with `--no-flip`:9697```bash98bash scripts/render_pdf_pages.sh /abs/path/file.pdf /tmp/pdf-pages 4 1 1 --no-flip99```100101If `pdftoppm`, `mutool`, or a reliable OCR/Mathpix tool is available, it can be used as an aid. Still verify against rendered pages before writing formulas into Markdown.