Edit book pdf
Live-edit a generated multi-part book PDF by editing its LaTeX source and recompiling — never by editing the PDF directly. Use whenever the user wants to fix text, typos, wording, math, layout, spacing, overflowing boxes, figures, or page order in a book PDF built from per-chapter LaTeX sources, or asks to rebuild / re-merge / regenerate the book.From its SKILL.md
npx -y skills add kwnstantina/book-pdf-toolkit --skill edit-book-pdfAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
9.1 KB, as published. Nobody here has run it
<applies_to> A book that is one merged PDF assembled from several independently compiled parts: optional front matter, a numbered run of chapter PDFs, optional back matter. Each chapter is its own standalone LaTeX document, so a fix in one chapter recompiles only that chapter and the rest is re-stitched as-is.
Nothing about any particular book is hardcoded. Layout comes from bookpdf.config.json at
the book root; project-specific quirks come from the notes file it points at.
</applies_to>
<essential_principles> 1. Never edit the PDF directly. The merged PDF is generated. Hand-editing it breaks fonts, math and reflow, and it is wiped on the next rebuild. Always edit the source and recompile. (Direct PDF surgery is only for whole-page operations — see references/architecture.md.)
2. Read the config before doing anything.
bookpdf.config.json at the book root defines the output name, the parts, the chapter
sources, the engine, and whether folios are renumbered. Never assume paths, filenames, page
counts, or chapter count — read them. If there is no config, run first-run setup below.
3. Read the project notes if they exist.
The config's notes_file (default BOOK-NOTES.md) holds this book's quirks: which chapters
are text vs images, where the real source of truth lives, the styling vocabulary, known
traps. Read it once per conversation before editing. It overrides your general assumptions.
4. One command rebuilds everything.
rebuild.py N recompiles chapter N and re-merges the whole book. It backs the PDF up first
and won't clobber a viewer-locked file.
5. Locate before you edit.
A user says "page 142 is wrong." Page numbers are book-global; sources are per-chapter and
shift as content changes. Run rebuild.py map 142 to resolve book page → chapter + local
page live. Never hardcode or remember page ranges — they go stale.
6. Confirm the fix landed. After rebuilding, the reported page count and the changed page should reflect the edit. For layout changes, render the affected page to an image and look at it before declaring done. </essential_principles>
<first_run_setup>
If bookpdf.config.json is missing, do NOT ask the user to write one. Detect it:
- Run
python <skill>/scripts/rebuild.py detectfrom the book root. It prints the detected layout as JSON plus anoteslist explaining each finding. - Show the user the
noteslines — they are written to be read aloud — and any warnings. - Ask them to confirm, flagging anything the probe was unsure about (an ambiguous output PDF, uncompiled chapters, a chapter run larger than the book).
- On confirmation run
rebuild.py initto write the config. If they want changes, write the corrected JSON yourself instead.
Detection works by page arithmetic: it finds the numbered .tex run, then looks for an
existing merged PDF whose page count equals some contiguous window of chapters plus the
front/back matter. When that matches, the layout is certain rather than guessed.
</first_run_setup>
- "page N is wrong / typo / overflow / figure" → fix workflow (locate → edit → rebuild → verify)
- "rebuild" / "re-merge" / "regenerate the book" → rebuild only
- "what chapter is page N" / "where is X" → map only
Only ask a clarifying question if the fix target is genuinely ambiguous — they describe a problem with no page, chapter, or quotable phrase to find it by. </intake>
<process> **The fix loop — follow in order:**Step 1: Locate
Given a book page number, run rebuild.py map <page> for the chapter and local page. Given a
quote or phrase, Grep the chapter sources for it. Establish exactly which source file holds
the content before touching anything.
Step 2: Identify the edit target
- Text / typo / wording / math → edit the chapter
.texdirectly. If the project notes say the.texis generated from data files, fix the data too so the change survives a regenerate. - Layout / spacing / overflow / page breaks → edit the
.tex: box environments, geometry margins, font sizing, explicit spacing or breaks. See references/architecture.md. - Figures / placeholders → check the project notes first; a book usually has an established convention for where figures come from. Follow it rather than inventing one.
Step 3: Edit the source
Make the change with Edit. Read the surrounding source first so the edit matches existing style — language, environments, macros.
Step 4: Rebuild
rebuild.py N for the chapter you touched. For front/back-matter-only changes, rebuild.py merge. Watch for compile errors — the script halts and prints the log tail; fix the LaTeX and
re-run.
Step 5: Verify
Confirm the reported page count is what you expected. For layout fixes, render the affected page and inspect it. Tell the user if downstream page numbers shifted. </process>
<commands> Run from the book root (the directory holding `bookpdf.config.json`). The script lives at `${CLAUDE_PLUGIN_ROOT}/skills/edit-book-pdf/scripts/rebuild.py`; users who prefer a short command can copy it to their book root and just run `python rebuild.py`.python rebuild.py detect # probe the project, print the layout it infers
python rebuild.py init # probe, then write bookpdf.config.json
python rebuild.py N # recompile chapter N, re-merge the book
python rebuild.py 3 7 # multiple chapters
python rebuild.py all # recompile every configured chapter, re-merge
python rebuild.py merge # re-stitch only (no compile)
python rebuild.py map # full book-page → part table
python rebuild.py map 142 # resolve one book page → part + local page
Render a page to check it (PyMuPDF):
import fitz
fitz.open("<output>.pdf")[141].get_pixmap(dpi=150).save("_check.png") # page 142, 0-based
</commands>
<live_preview>
For changes to appear as you work, the user should keep the PDF open in a viewer that reloads
on file change and does not lock the file — SumatraPDF on Windows, Skim on macOS.
Acrobat and some browsers lock or cache the file, so the merge cannot replace it; the script
then leaves the new build at <output>.tmp.pdf and says so. Recommend a reloading viewer if
they hit that.
</live_preview>
<reference_index>
- references/architecture.md — the build model, source-of-truth question, layout-fix vocabulary, folio renumbering, and when direct PDF surgery is acceptable.
- references/configuration.md — every config field, how detection works, and troubleshooting.
- The book's own
BOOK-NOTES.md(or whatevernotes_filepoints at) — project-specific quirks. Always prefer it over general assumptions. </reference_index>
<success_criteria> A fix is done when:
- The correct source file was edited (not the PDF)
- The rebuild ran clean (no compile errors) and reported the expected page count
- The change is visible on the rebuilt page (verified by render for layout changes)
- The user was told if downstream page numbers shifted </success_criteria>