Literature Document Parsing
Parse a scientific PDF into a structured result the reader can verify:
sections, tables, formulas, figures, references — each with a page +
bounding-box evidence anchor — plus an explicit list of what could not
be parsed. Focus: multi-column reading-order correction with
table and formula structure recovery. Python stdlib + poppler
pdftotext only; no network, no API keys, no third-party packages.
When to use
- The case gives you a research-paper PDF (in
/input/case.jsonand/or as a file under/input/) and asks for its content as structured, checkable output. - The paper may be single- or two-column, may contain tables, numbered equations, figures, footnotes and references.
- Do NOT use this Skill to answer a question that is not about the PDF's own content, and never invent text the PDF does not contain.
Workflow (follow in order)
1. Discover the input — do not assume filenames
- Read
/input/case.json(and the casetask.mdif present). - Find the PDF(s): check
case.jsonfieldspdf_path,pdf,file,input_pdf,material,document,input_files,files,documents,materials(string, list, or dict-with-path), then scan/input/recursively for*.pdf. - If no PDF exists, still write a
result.jsonwithstatus: "failed"andunparsed[0].kind: "no_input_pdf"— a missing input is a reportable outcome, not a silent stop. - Work under
/app/work; final outputs go under/app/output.
2. Run the parser — never hand-transcribe the PDF
Run the driver (it finds the PDFs, calls the parser, writes the bundle):
# The skill is installed under /skills/weekly-skill; SKILL_DIR is the
# directory containing this SKILL.md. Adjust the path if installed
# elsewhere.
SKILL_DIR=/skills/weekly-skill
python3 "$SKILL_DIR/scripts/run_case.py" \
--input /input/case.json --work /app/work --output /app/output
Or parse one PDF directly:
python3 "$SKILL_DIR/scripts/parse_pdf.py" input.pdf \
--json /app/work/result.json --md /app/work/full_text.md
How the parser works (details in README.md § Method):
pdftotext -bboxgives positioned words; fallback-layout, then-raw. If a page has < 50 extractable characters it is listed inunparsedasno_text_layer(probable scan) — never guessed.- Words are grouped into lines; a vertical whitespace gutter splits two-column pages. Lines that only look full-width because two column fragments share a baseline are split at the gutter (a real table row, formula or caption is never split). Within each zone, single-column lines before/after the two-column block stay in y order; inside the block, left column top-to-bottom, then right.
- Repeated marginal lines and bare page numbers are removed from the
body and recorded in
headers_footers; a marginal line seen only once is kept as body (nothing is silently dropped). - Headings (numbered, keyword, or larger-type short lines), figure /
table captions, tables (word-gap columns, interval-clustered
separators, cross-page continuation merge), formulas (Greek / math /
super-subscript symbols + equation numbers), footnotes and
references are recognised, each with
evidence: {page, block, bbox, verbatim}. - Hyphenated line-breaks are rejoined only when the next line starts lowercase; all other text is kept verbatim.
3. Check the output before finishing
- Open
/app/output/result.jsonand confirm:case_idmatches the case,statusiscompleteorpartial,countsare plausible (pages > 0, sections/tables/formulas as found), and every table / formula / figure carries anevidence.page. - Read
/app/output/full_text.mdonce: the reading order must make sense (no interleaved columns, no header/footer lines inside the body). If a page's columns are interleaved, the gutter detection failed on that page — say so inuncertainty, do not retype the text by hand. - If
statusispartial/unparseable, theunparsedlist must name the pages and the reason; copy those reasons into your final answer.
4. Write the final answer from result.json only
- Report
title,abstract, section structure, tables (as Markdown), formulas and figures, each with its page anchor. - State what is missing: quote
unparsedanduncertaintyverbatim in meaning — e.g. "page 3 has no text layer (probable scan); OCR was not available in this image, so page 3 is unparsed". - Never present a guess as a fact. If the PDF does not contain the information, say "not reported in the material".
Output contract (/app/output/result.json)
| Field | Meaning |
|---|---|
case_id | from case.json (case_id/id/caseId), else "unknown-case" |
status | complete (all pages parsed) / partial (some pages unparsed) / failed / unparseable |
title, authors, abstract | best-effort front matter (empty string / [] if absent) |
sections[] | {level, title, page, block_id, text, evidence} |
tables[] | {id, caption, page, columns, header_row, rows, row_count, evidence, note?} + Markdown in full_text.md |
formulas[] | {id, number, text, page, evidence} |
figures[] | {id, label, caption, page, evidence} |
footnotes[], references[], headers_footers[] | with page + evidence where available |
unparsed[] | {page, kind, detail} — every gap, honestly labelled |
uncertainty[] | fallbacks used, OCR availability, anything low-confidence |
counts, method, sources | page/element counts; tool versions and method; input path(s) |
Also written: parsed.json (per-document results), full_text.md
(human-readable rendering with anchors), run.log, arm_manifest.json.
Dependencies and fallbacks
- Required: Python 3.8+ (stdlib only) and
pdftotext(poppler). Verified on this image: Python 3.12.3, poppler 24.02.0. - If
pdftotext -bboxfails:-layoutis used (no word coordinates: no column correction, no bboxes; recorded inuncertainty), then-raw. - If
pdftotextis missing:status: "failed",unparsed[0].kind: "tool_missing"— the Skill degrades to an honest failure, it does not hallucinate a parse. - Scanned / image-only pages: listed in
unparsed; OCR runs only iftesseractis installed, and this version does not run OCR automatically (seeREADME.md§ Limits). No tesseract was present on the build image. - Encrypted PDFs:
status: "failed", kindencrypted_pdf.
Limits (do not work around them by guessing)
- Tables are recognised from word-gap columns, not ruling lines:
borderless or image-embedded tables may be missed or reduced to a
caption stub — check
tables[].note. - Formula structure is preserved as text (Unicode Greek, super/subscripts, equation numbers); formulas are not parsed into MathML/LaTeX and their scientific meaning is not interpreted.
- Merged/rotated cells, multi-line cells and cross-page tables are handled best-effort (continuation merge by matching columns).
- Footnotes are reported only when they carry a digit marker in the
bottom strip, with
confidence: "low". - Deterministic where possible: fixed ordering, sorted JSON keys, no
timestamps inside
result.json(timestamps live inrun.logonly).
Self-check (before you claim success)
python3 -c "import json; r=json.load(open('/app/output/result.json')); \
print(r['status'], r['counts']); \
assert r['case_id']; assert all('page' in t.get('evidence', {}) for t in r['tables'])"
A minimal labelled example (input + example output) is in
examples/EXAMPLE_OUTPUT.md; the sample PDF it uses is generated by
examples/make_sample_pdf.py and is not an official case.