/textbook-to-note:textbook-to-mdfrom textbook-to-note
Converts PDF/EPUB textbooks to searchable markdown files for AI agent reference. Useful for building a knowledge base from personal library of reference books.
Ships in textbook-to-note. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This skill calls scripts in your clone of the textbook-to-note repo. At install time, replace
{REPO}below with the absolute path of the clone. Installed as a Claude Code plugin? Then{REPO}is${CLAUDE_PLUGIN_ROOT}— Claude Code fills in that path when the skill loads. If the previous line shows a$-placeholder instead of a path, the skill was copied by hand: use the clone's path.
Convert PDF or EPUB textbooks into searchable markdown that the agent can grep/read directly, eliminating the need for PDF-library extraction at every query.
Output lives outside the note vault, at the path configured by
OUTPUT_DIR in shared/config.py (default ./output/), and is
for the agent's consumption, not for the user's reading.
Figures are on-demand, not pre-extracted. This skill produces markdown text only. Figures are extracted one at a time when a note needs them, via the
figure-remapskill's entrypoint (QC-gated). Do not batch-extract a whole book's figures into afigures/folder — that approach does not scale and is unnecessary since the on-demand path already handles it. A legacyfigures/folder may exist for books converted before this design; new conversions are markdown-only.
# Single file
python {REPO}/converter/convert.py "path/to/chapter.pdf"
# Single file with custom output and label
python {REPO}/converter/convert.py "path/to/chapter.pdf" "output.md" --book-label "Author Title 2e — Ch32"
# Batch-dir: convert ALL PDFs in a directory tree (auto chapter split; source PDFs are never modified)
python {REPO}/converter/convert.py --batch-dir "path/to/your/textbook/folder"
# Force re-convert (ignore existing md)
python {REPO}/converter/convert.py --batch-dir "path/to/your/textbook/folder" --force
# Force OCR for ALL PDFs in batch-dir (bypass the text-extraction path entirely).
# Use when the text layer "looks" healthy but quality is actually bad (OCR-overlay
# scans, some digitized reprints) — auto-detection won't trigger because the text
# layer passes the shallow check.
python {REPO}/converter/convert.py --batch-dir DIR --force --force-surya
# EPUB → markdown (the 2nd arg is a FOLDER, not a .md file)
python {REPO}/converter/convert.py "path/to/book.epub" "<OUTPUT_DIR>/Author_Title_2e_2022"
Batch mode skips files whose markdown already exists and is newer than the
source PDF. Batch-dir mode saves progress to batch_progress.json — if
interrupted, re-running resumes where it stopped. --batch-dir also picks
up .epub files automatically.
pandoc (epub → gfm). EPUBs are reflowable, so there are no
<!-- page N --> markers; files carry a <!-- SOURCE: epub --> marker
instead.chNN_*.md + full_text.md (same shape as a PDF
book) — the single-file 2nd argument is the output directory, not a
.md path.pandoc on PATH. Figures are not extracted from EPUB (the
on-demand figure flow is PDF-only).<OUTPUT_DIR>/{PDF_stem}/
(OUTPUT_DIR from shared/config.py; default ./output)full_text.md (complete with <!-- page N --> markers) plus a
chapter splitdocs/ocr-ladder.md). Falls back to
skip-with-explanation if the OCR environment is missing. Output is
full_text.md with page markers, and a chapter split is attempted on the
OCR'd text too (numbered-heading patterns often survive OCR); it is
best-effort and simply yields no chapters when heading detection fails<OUTPUT_DIR>/ ← default ./output (shared/config.py)
├── Author_Title_Edition_Year/
│ ├── ch01_Chapter_Title.md ← conversion produces md only
│ ├── ch02_....md
│ ├── full_text.md
│ └── figures/ ← LEGACY ONLY — not produced by conversion
└── Another_Book/ ← single-file conversions use the same <book>/full_text.md layout
Figure-registry generation (figure_registry.json) is an optional external
hook, not a shipped script — set the FIGURE_REGISTRY_SCRIPT env var to a
generator script if you have one; if unset, post_convert.py skips that
step.
==Conversion writes .md files only.== A figures/ subdirectory is legacy —
present only on books converted before the on-demand switch. New conversions
never create one; figures are pulled on demand by figure-remap.
Each markdown file contains:
<!-- page X --> at every page boundary, to map content
back to the source PDFFig. 32.1, Table 31.2, etc.), an HTML comment
<!-- REF: Fig. 32.1 → see PDF page X --> is inserted so the agent knows
where to look in the original PDFTwo search methods:
grep -r "your search term" "$OUTPUT_DIR" # default ./output
If the user has handed the corpus to ask-your-library (Profile C: convert.py --resplit → ask-your-library's corpus.py add — see docs/setup-details.md
Step 5), a textbook_search tool becomes available for concept-level
queries that don't depend on exact wording.
After converting new books, run the post-pipeline:
# Full pipeline: verify quality + refresh index.md + refresh figure registry + ask-your-library hand-off
python {REPO}/converter/post_convert.py
# Or individual steps:
python {REPO}/converter/post_convert.py --verify # check quality only
python {REPO}/converter/post_convert.py --resplit-only # re-split new / re-converted books into CORPUS_DIR
python {REPO}/converter/post_convert.py --index # that, then ask-your-library corpus.py add CORPUS_DIR
The pipeline does not extract figures — it only verifies page markers,
refreshes index.md + figure_registry.json from whatever figures already
exist, and (optionally) hands a --resplit corpus root to ask-your-library's
corpus.py add, which indexes and audits it. This repo never indexes
anything itself; with VAULT_SEARCH_DIR unset the hand-off prints the
command and [skip]. Figure extraction is never a batch post-step.
Missing page markers do not block indexing by design — EPUBs (reflowable)
and some vector-glyph PDFs legitimately lack <!-- page N --> and index with
page metadata = 0.
No pre-extraction step. A whole-book batch figure dump is retired and should
not be run on new books. When a note needs a figure, figure-remap extracts
that single figure on demand with QC. See "Using figures in notes" below.
Chapter N / CHAPTER N — standardPart N / PART N — with roman numerals (Part III)Section N / SECTION N / Unit N1 Introduction, 23 Shoulder (digit + title-case
text)Many textbooks repeat Chapter N Title as a running header on every page.
Only count the first occurrence of each unique chapter number — track a
seen_chapters set and skip duplicates.
pages_0001-0030.md).pdf (use an
Author_Title_Edition_Year convention)ch01_Chapter_Title.md, ch00_Front_Matter.mdpages_0001-0030.mdAfter conversion, check:
Always cite with year when referencing converted content:
(Author 2e, 2021), not just (Author).
When writing or supplementing a note that needs a figure (anatomy,
classification, imaging, algorithm), extract that one figure on demand —
never batch-dump a book. The markdown's
<!-- REF: Fig. 5.1 → see PDF page 42 --> markers tell you which figure
exists and what PDF page it's on; hand that to the gate.
Call the figure-remap skill's public entrypoint (figure_remap.py extract — not the internal gate script). The entrypoint runs deterministic
geometric matching by default and returns a stable contract:
python {REPO}/figures/figure_remap.py extract \
--book "{Book}" \
--fig-id "5-1" \
--caption "<caption text from the REF marker / md>" \
--out "path/to/your/vault/attachments/Fig_5-1_{BookShort}.jpeg" \
--pdf "<source PDF path>" \
--page {1-indexed PDF page from the REF marker}
Contract: {status: pass|fail|escalate, match_quality: exact|uncertain|failed, hard_fail, file, fig_id, reason, qc_degraded, qc_skipped} — those eight keys
exactly (figures/figure_remap.py CONTRACT_KEYS; the validator raises on any
extra or missing key, so branching on the engine's internal match_method is
not just discouraged, it is impossible).
status:fail (exit 1) is a deterministic miss — a correct refusal, not a
wrong crop; fix --page, escalate to vision, or leave a <!-- TODO -->.
Read the real caption to confirm the figure depicts what you intend.
On pass (exit 0), embed the --out path (result.file) in the note:
![[Fig_5-1_{BookShort}.jpeg|400]]
*Fig 5.1 — description (Author 2e, p.42)*
When writing a fresh note via the note-writing workflow (see
workflows/note-writing.md), figure harvest is Phase 3.5 — don't call the
gate manually there, the workflow does it. The manual call above is for
ad-hoc figure needs outside that workflow. Full fallback ladder + per-book
calibration: see the figure-remap skill.
figure_registry.json (produced by the post-conversion pipeline) records
each book's figure status. A status of "not extracted" or "lazy-only" is
the expected normal state — it does not mean a batch extraction has to
run first; the on-demand gate handles extraction from the PDF regardless.
{FigID}_{BookShort}.{ext} — e.g. Fig_5-1_AuthorName.jpeg,
Fig_32-1_AuthorName.jpeg. Avoids filename collisions across books in your
attachments folder.
<!-- page X -->.docs/ocr-ladder.md.dump_all figures: books where caption detection failed get
page-based filenames (page_0042.jpeg) without captions. Still usable,
but you must identify content by reading the image.The script accepts any PDF, not just your priority set. For ad-hoc conversions:
python {REPO}/converter/convert.py "path/to/any.pdf" "path/to/output.md" --book-label "Book Name — Chapter"
If no output path is specified, output goes to OUTPUT_DIR/<pdf name>/full_text.md — the same layout --batch-dir uses, so a later batch run skips it as already converted.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
2 skills in this plugin
npx claudepluginhub drpwchen/textbook-to-note --plugin textbook-to-noteOther plugins' skills for the same job