--- name: md-pdf-validator description: Compare a PDF with the Markdown file that Microsoft MarkItDown (or any PDF-to-Markdown converter) generated from it, find everything the Markdown lost or damaged, and append the missing content to the Markdown file. Use this skill whenever the user supplies a PDF together with its converted .md/.markdown file and asks to validate, verify, compare, audit, fix, complete, or "append the missing content" of the conversion, or says the conversion dropped figures, tables, equations, pages, or text, even if they do not name MarkItDown. compatibility: Python 3 with pdfplumber (and Pillow/pypdfium2, which pdfplumber pulls in). pdftotext from poppler is used when present, with an automatic pdfplumber fallback. --- # MD ↔ PDF validator PDF-to-Markdown converters silently lose or damage content. This skill compares the source PDF with the Markdown, reports what is wrong, and **appends** the missing content to the Markdown as a clearly delimited appendix. The original Markdown is never edited, so the user can always diff before and after. ## What gets detected | Item type | Meaning | Who fills it in | |---|---|---| | `text` | Lines in the PDF text layer that the MD lacks (deleted text, whole missing pages, scrambled numbers) | Automatic: verbatim PDF text is pre-filled | | `figure` / `graphic` | Charts, diagrams, images with no text-layer equivalent | You, by looking at the crop image | | `table` | Table whose rows/columns were flattened or whose cells are damaged | Draft GFM table is pre-filled; you verify it | | `equation` | Numbered display equation that is garbled by font encoding or missing | You, by looking at the crop image (write LaTeX) | | `glyph_corruption` | Raw glyph codes such as `/C15`, `(cid:12)` left in the MD text | You confirm the real characters on the crops | ## Workflow Scripts live in `scripts/` next to this file. Use the actual install path of the skill (for example `/mnt/skills/user/md-pdf-validator/scripts`). Work in a scratch directory such as `/home/claude/work`. ### 1. Locate the inputs Find the PDF and its MD in `/mnt/user-data/uploads/` (pair them by file stem). If several pairs exist, process each one separately. If a file is missing, say so and stop. ### 2. Analyse ```bash python scripts/analyze.py --pdf /mnt/user-data/uploads/X.pdf --md /mnt/user-data/uploads/X.md --out /home/claude/work ``` Read the printed summary and `work/validation_report.md`. Key options: `--page-regex` if the MD uses unusual page markers (group 1 = page number), `--tables never` to skip table drafting, `--no-graphics` to skip figure detection. If the MD has no page markers, page attribution is approximate; tell the user. ### 3. Review every `open` item Open the crop image of each item with the `view` tool (`work/assets/*.png`; paths are in `report.json`). Never write a transcription without looking at the crop: the text layer is exactly what was unreliable. - **Figures with printed data labels**: transcribe as a Markdown table (label → value). Copy numbers exactly. - **Charts without labels**: give a short description and approximate values, marked "(approx., read from chart)". Prefer exact values quoted in the paper's own text or tables if they exist. - **Diagrams / flowcharts**: a Mermaid block (```mermaid) plus one or two sentences describing the flow. - **Equations**: display LaTeX, e.g. `$$\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} \tag{1}$$`. Only transcribe the equation whose tag matches the item; the crop can include a neighbour. - **Tables**: compare the draft with the crop. Fix header rows, merged/spanning headers, wrapped labels, and any damaged cells. Empty body = accept the draft as is. - **Glyph codes**: give a two-column table `Code | Meaning` (see `evidence.tokens` in the report; `suggested` values are heuristics, confirm them on the example crops). - **Decorative graphics** (logos, masthead art, "check for updates" badges): skip with a reason. - **`text` items** are pre-filled and marked `done`; skim them and skip any that are page furniture. ### 4. Record your decisions Write `work/resolutions.md` (plain Markdown, no JSON escaping needed): ``` ### @FIG-p8-1 done | Method | Features reduced (%) | |---|---| | Info Gain | 29.82 | ### @EQ-p5-1 done $$\chi^2 = \sum \frac{(O_i - E_i)^2}{E_i} \tag{1}$$ ### @TB-p6-1 done ### @GFX-p1-1 skip: publisher logo ``` Then merge it: `python scripts/resolve.py --report work/report.json --resolutions work/resolutions.md`. It lists anything still open. ### 5. Append and verify ```bash python scripts/apply_recovery.py --md /mnt/user-data/uploads/X.md --report work/report.json --out /mnt/user-data/outputs/X.md python scripts/analyze.py --pdf /mnt/user-data/uploads/X.pdf --md /mnt/user-data/outputs/X.md --out /home/claude/work_verify --verify ``` Verification should report 0 open items and 0 missing/partial lines. If not, fix the listed items and re-run step 4 to 5; re-running replaces the previous appendix. Use `--no-images` if the user only wants text, and `--strict` to fail while items are open. ### 6. Deliver Call `present_files` on the output `.md`, plus `work/validation_report.md`. Figure crops referenced by the appendix are copied to `X_assets/` next to the output MD; present those too when figures were appended. In the reply, summarise counts by type, list anything skipped or approximate, and state clearly what was NOT verified. ## Rules that keep the result trustworthy - Append only. Do not rewrite, reorder, or "clean up" the original MD, including line endings. - Never invent content. If a figure value or symbol cannot be read from the crop, say so in the appendix rather than guessing. - Report limits honestly: unnumbered inline math, scanned PDFs without a text layer (every line will show as missing; use the page renders and read visually), and tables without horizontal rules are not auto-detected. - Details of the report format and detection heuristics are in `references/report_schema.md`; read it if you need to tune thresholds or debug a false positive/negative.