literature-document-parsing

Parse a research-paper PDF into structured, evidence-anchored results — two-column reading-order correction, section hierarchy, gap-based table extraction, formula/symbol preservation, header/footer filtering — with every element traceable to page + block and unreadable parts labelled honestly instead of guessed.

Qu'est-ce que literature-document-parsing ?

literature-document-parsing is a Claude Code agent skill that parse a research-paper PDF into structured, evidence-anchored results — two-column reading-order correction, section hierarchy, gap-based table extraction, formula/symbol preservation, header/footer filtering — with every element traceable to page + block and unreadable parts labelled honestly instead of guessed.

Compatible avec✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mekiann/literature-document-parsing/tree/HEAD

Installed? Explore more Recherche et analyse de données skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

Demander à votre IA préférée

Ouvre une nouvelle conversation avec cette compétence d'agent déjà préchargée.

Documentation

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.json and/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 case task.md if present).
  • Find the PDF(s): check case.json fields pdf_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.json with status: "failed" and unparsed[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):

  1. pdftotext -bbox gives positioned words; fallback -layout, then -raw. If a page has < 50 extractable characters it is listed in unparsed as no_text_layer (probable scan) — never guessed.
  2. 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.
  3. 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).
  4. 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}.
  5. 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.json and confirm: case_id matches the case, status is complete or partial, counts are plausible (pages > 0, sections/tables/formulas as found), and every table / formula / figure carries an evidence.page.
  • Read /app/output/full_text.md once: 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 in uncertainty, do not retype the text by hand.
  • If status is partial/unparseable, the unparsed list 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 unparsed and uncertainty verbatim 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)

FieldMeaning
case_idfrom case.json (case_id/id/caseId), else "unknown-case"
statuscomplete (all pages parsed) / partial (some pages unparsed) / failed / unparseable
title, authors, abstractbest-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, sourcespage/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 -bbox fails: -layout is used (no word coordinates: no column correction, no bboxes; recorded in uncertainty), then -raw.
  • If pdftotext is 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 if tesseract is installed, and this version does not run OCR automatically (see README.md § Limits). No tesseract was present on the build image.
  • Encrypted PDFs: status: "failed", kind encrypted_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 in run.log only).

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.

Skills associés