agentsclimarketplace

Edit book pdf

Skill kwnstantina/book-pdf-toolkit/skills/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

Install
npx -y skills add kwnstantina/book-pdf-toolkit --skill edit-book-pdf

Assembled 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

<objective> Keep a generated book PDF correct by editing its **source** and recompiling, then re-merging the book. The final PDF is a build artifact, not a document to edit by hand. This skill is the fast feedback loop: the user names a fix → you edit the source → rebuild → they see it update in their viewer. </objective>

<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:

  1. Run python <skill>/scripts/rebuild.py detect from the book root. It prints the detected layout as JSON plus a notes list explaining each finding.
  2. Show the user the notes lines — they are written to be read aloud — and any warnings.
  3. Ask them to confirm, flagging anything the probe was unsure about (an ambiguous output PDF, uncompiled chapters, a chapter run larger than the book).
  4. On confirmation run rebuild.py init to 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>

<intake> The user almost always arrives with a concrete fix in mind. Do NOT ask a menu question — infer intent from what they said and act:
  • "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 .tex directly. If the project notes say the .tex is 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>

<gotchas> - **Engine matters.** The config's `engine` is detected from the preamble. A book using `fontspec`/`polyglossia` must build with `xelatex` or `lualatex` — `pdflatex` will fail on the fonts. Don't override it. - **Page drift.** Editing a chapter can change its page count, shifting every later page in the merged book. Re-run `map` after a rebuild before locating the next fix by page number. - **Two passes.** The script compiles each chapter twice by default so breakable boxes and cross-references settle. Don't reduce `passes` to 1 to save time. - **Backups.** Every merge copies the prior PDF to `<output>.premerge-backup.pdf`. To undo a bad rebuild, restore from it. - **Locked file.** If the merge can't replace the output, a viewer holds it open — ask the user to close it, output is at `<output>.tmp.pdf`. - **Folio renumbering.** When `renumber_folios` is on, each standalone chapter's local page number is redacted and restamped with its book-global position at merge time. It is self-correcting and never drifts, but it needs the folio font available on the system; if the script warns that a font wasn't found, set `folio_font_files` in the config. - **Chapter sources outside the book.** A project may hold more chapter sources than the book includes. Only the chapters in the config's `chapters` range are compiled and merged. </gotchas>

<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 whatever notes_file points 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>

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.