Compiles all chapter PDFs into a single metricsAI book PDF. Detects modified chapters, regenerates their PDFs, then merges all chapters with cover page, copyright page, Brief Contents, Detailed Contents, Key Concepts TOC, clickable TOC hyperlinks, page numbers, and section-level PDF bookmarks. Use after editing any chapter notebook.
Automates the end-to-end pipeline for compiling the metricsAI textbook: detects modified chapters, regenerates their PDFs, and merges all 18 chapters into a single book PDF with professional formatting.
This skill manages the complete book compilation workflow. It detects which chapter notebooks have been modified since their last PDF generation, regenerates only those PDFs, then compiles everything into a single book with cover page, copyright page, three tables of contents (Brief Contents, Detailed Contents, Key Concepts), page numbers, and hierarchical PDF bookmarks.
Use this skill when:
Key Features:
/compile-book
Detects modified chapters, regenerates their PDFs, compiles the full book.
/compile-book ch05 ch08
Force-regenerates PDFs for chapters 5 and 8, then compiles.
/compile-book --all
Regenerates all 18 chapter PDFs from scratch, then compiles.
/compile-book --compile-only
Assumes all chapter PDFs are current. Just runs the book compiler.
/compile-book --check
Reports which chapters have outdated PDFs (read-only, no changes).
When you invoke this skill, follow these steps:
Extract chapter numbers and flags from the invocation:
ch05 or 5 -> normalized to ch05--compile-only -> skip PDF regeneration--check -> report-only mode (no compilation)--all -> regenerate all chapter PDFsch05 ch08 ch12For each chapter (ch00-ch17), compare modification times:
notebooks_quarto/chXX_*.qmdnotebooks_colab/chXX_*.pdf# Check if notebook is newer than its PDF
# A chapter needs regeneration if:
# 1. No PDF exists, OR
# 2. Notebook mtime > PDF mtime
Classify each chapter as:
Display a status table:
## PDF Freshness Report
| Chapter | Status | Notebook Modified | PDF Modified |
|---------|--------|-------------------|--------------|
| ch00 | Current | 2026-02-07 22:30 | 2026-02-07 23:00 |
| ch05 | Outdated | 2026-02-08 10:15 | 2026-02-07 23:00 |
| ch08 | Outdated | 2026-02-08 09:30 | 2026-02-07 23:00 |
| ... | ... | ... | ... |
**2 chapters need PDF regeneration.**
If --check flag: stop here (read-only mode).
For each chapter that needs regeneration, run the 3-step pipeline:
# Step 1: Convert notebook to HTML
quarto render notebooks_quarto/chXX_*.qmd --to html --output-dir notebooks_colab
# Step 2: Inject print CSS
python3 scripts/inject_print_css.py notebooks_colab/chXX_*.html notebooks_colab/chXX_*_printable.html
# Step 3: Generate PDF via Playwright
python3 scripts/generate_pdf_playwright.py chXX
Report each chapter's PDF size after generation.
Important: Run chapters sequentially (each uses Playwright which launches a browser).
Run the book compilation script:
python3 scripts/compile_book.py
This produces notebooks_colab/metricsAI_complete_book.pdf with:
images/book1cover.jpg)Display compilation summary:
## Compilation Complete
| Metric | Value |
|--------|-------|
| Total pages | 900 |
| File size | 62.3 MB |
| Chapters | 18 (CH00-CH17) |
| Key concepts | 189 |
| Sections in bookmarks | 110 |
| Clickable TOC links | 753 |
| Chapters regenerated | 2 |
| Output | notebooks_colab/metricsAI_complete_book.pdf |
open notebooks_colab/metricsAI_complete_book.pdf
Hierarchical navigation sidebar in PDF readers:
All three TOC sections include clickable hyperlinks (753 total) that jump directly to the target page:
https://internal.metricsai/page/{N})extract_toc_links() reads the rects and pypdf.annotations.Link creates internal GoTo links pointing to the correct final pageEach chapter PDF is generated through a 3-step pipeline:
.qmd to HTML with all contentscripts/notebook_pdf_styles.css for professional formatting (justified text, brand colors, optimized font sizes)Required software:
pip install playwright && playwright install chromium)pip install pypdf)pip install jupyter for nbconvert)Verify installation:
python3 -c "from playwright.sync_api import sync_playwright; print('Playwright OK')"
python3 -c "from pypdf import PdfReader; print('pypdf OK')"
quarto --version
Symptom: /compile-book says chapter is current but content is outdated.
Cause: Notebook file wasn't saved after editing.
Fix: Save the notebook, then re-run. Or force with /compile-book chXX.
Symptom: Error: Browser not found or Playwright not installed.
Fix: pip install playwright && playwright install chromium
Symptom: FileNotFoundError: No PDF found for chXX.
Fix: Run /compile-book chXX to generate the missing PDF.
Symptom: Book PDF exceeds 65 MB. Cause: High-resolution images or many plot outputs. Note: ~62 MB is expected for 900 pages with charts and plots.
Symptom: Some chapter sections missing from PDF bookmarks. Cause: Section title in notebook doesn't match PDF extracted text. Note: ~96% of sections are matched. Minor mismatches are expected.
Symptom: Clicking a chapter or section title in the TOC does not jump to the page.
Cause: The placeholder URL annotations may not have been preserved during PDF generation.
Fix: Ensure Playwright is rendering the TOC HTML correctly. Recompile with /compile-book --compile-only. Check that extract_toc_links() finds annotations in the generated TOC PDFs.
1. /chapter-standard chXX # Verify structure (target: 90+)
2. /proofread chXX --fix # Fix text quality issues
3. /compile-book chXX # Regenerate PDF and recompile book
1. /chapter-standard --all # Check all chapters
2. /proofread --all # Check all chapters
3. /compile-book # Auto-detect and regenerate modified chapters
| File | Purpose |
|---|---|
scripts/compile_book.py | Book compilation script (merges PDFs, generates TOCs, adds bookmarks, copyright page) |
scripts/generate_pdf_playwright.py | Chapter PDF generator (Playwright-based) |
scripts/inject_print_css.py | CSS injection for printable HTML |
scripts/notebook_pdf_styles.css | Master stylesheet for PDF formatting |
images/book1cover.jpg | Cover image (1407x1916px) |
notebooks_colab/metricsAI_complete_book.pdf | Output: compiled book |
notebooks_colab/chXX_*.pdf | Individual chapter PDFs |
Version: 2.0 | Updated: 2026-02-08 | Author: metricsAI project