# Book Publishing

> Use when publishing a book, preparing an arXiv submission, formatting a manuscript for KDP, or turning a markdown manuscript into a print-ready PDF. End-to-end pipeline orchestrating parallel agent swarms for LaTeX (memoir) conversion, BibTeX citation extraction, diagram/chart generation, image upcycling, and visual verification. NOT for single-document LaTeX compilation (use latex-documents), general prose editing, or ebook-only EPUB flows.

- Skill: `dreamlab-ai/book-publishing` (Agent Skill, multi-file: 3 files)
- Install (CLI): `npx skillmds@latest add dreamlab-ai/book-publishing`
- Raw SKILL.md: https://api.skillmd.com/api/skills/dreamlab-ai/book-publishing/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- Author: dreamlab-ai (https://skillmd.com/u/dreamlab-ai)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/dreamlab-ai/book-publishing

---


# Book Publishing Skill

End-to-end pipeline: markdown manuscript → arXiv-compliant / KDP-ready PDF, using parallel agent swarms for each stage.

## Pipeline Overview

```
Markdown Source
      │
      ├─── [Skeleton Builder]     → main.tex skeleton (FIRST, blocking)
      ├─── [BibTeX Extractor]     → references.bib   (parallel)
      │
      ├─── [Chapter Converters × N]  → chapters/ch*.tex  (after skeleton)
      ├─── [Front Matter]            → front/            (after skeleton)
      ├─── [Appendix Converter]      → appendices/       (after skeleton)
      ├─── [Citation Index]          → cite_index.tex    (after bibtex)
      ├─── [Design Consultant]       → typography/styles (after skeleton)
      │
      ├─── [Diagram Engineer]        → TikZ + Mermaid .mmd   (parallel)
      ├─── [Market Analyst]          → matplotlib charts/PDF  (parallel)
      ├─── [Wardley Mapper]          → Wardley .mmd files     (parallel)
      ├─── [Research Verifier]       → citation verification  (parallel)
      │
      ├─── [Image Upcycler]          → Gemini-enhanced PNGs   (after diagrams)
      │
      └─── [Build + Verify]          → latexmk + PDF preview  (final)
```

## Stage 1: Skeleton Builder (Blocking — runs first)

Creates the root `main.tex` with:
- Document class: `memoir` (12pt, a4paper, twoside)
- Package imports (fontspec, microtype, biblatex, hyperref)
- Chapter `\include{}` stubs
- Front/back matter structure

**All other converters wait for skeleton before starting.**

Full memoir/biblatex package list, UK typography rules (spaced endash, scene breaks,
drop caps), chapter-style code, and the arXiv folder layout are in
[references/latex-conventions.md](references/latex-conventions.md) — load it before
building the skeleton or hand-editing a chapter.

## Stage 2: Parallel Foundation

Run simultaneously after skeleton:

```bash
# BibTeX Extractor
# Scans all markdown footnotes, extracts URLs and references
# Outputs: references.bib + cite_mapping.json
# cite_mapping.json format: {chapter: {footnote_num: cite_key}}
# Full pattern, footnote-vs-cite-key decision rule, and worked example:
# references/latex-conventions.md#cite_mappingjson-pattern

# Chapter Converters — split into batches of 6
# Batch A: chapters 1–6
# Batch B: chapters 7–12  
# Batch C: chapters 13–18
# (etc.)

# Each converter: markdown → LaTeX, respecting cite_mapping.json
# URL-only footnotes → \footnote{\href{...}{...}}
# Multi-use citations → \cite{key}
```

## Stage 3: Parallel Content Generation

All run simultaneously:

| Agent | Output | Notes |
|-------|--------|-------|
| Diagram Engineer | TikZ `.tex` files | Compile standalone, include via \includegraphics |
| Market Analyst | matplotlib `.pdf` charts | Python script, PDF for vector quality |
| Wardley Mapper | `.mmd` + rendered `.png` | See Wardley Maps skill |
| Research Verifier | verification report | Web search, flag unverifiable claims |

## Stage 4: Image Upcycling

After diagrams exist, upscale them for print. **A Gemini image path exists when
`GOOGLE_API_KEY` is provisioned** — see [art/references/diagram-upcycling.md](../art/references/diagram-upcycling.md)
for the current nano-banana model ids and the route-through-the-skill's-own-tool
pattern; otherwise the offline ImageMagick pass is the default, deterministic and never
hallucinates text:

```bash
convert diagram.png -resize 200% -unsharp 0x1.0 diagram_hires.png
```

Prefer regenerating charts as vector PDF over raster upscaling where possible. Even
with a provisioned key, an AI-enhanced diagram must be visually diffed against the
source before shipping — its output can alter text/data. Full guardrails:
[references/image-upcycling.md](references/image-upcycling.md).

## Stage 5: Build and Verify

```bash
# Full build
latexmk -xelatex -biber -interaction=nonstopmode main.tex

# Visual verification via browser sidecar
# Navigate to output PDF, screenshot pages for review
browser_navigate({ url: "file:///path/to/main.pdf" })
browser_take_screenshot({ filename: "page_verify.png", fullPage: false })
```

## Swarm Topology (claude-flow)

```javascript
// Initialize swarm
mcp__claude-flow__swarm_init({
  topology: "hierarchical",
  maxAgents: 15,
  strategy: "book-conversion"
})

// Stage 1: skeleton (blocking)
await mcp__claude-flow__agent_spawn({
  agentType: "coder",
  name: "skeleton-builder",
  task: "Build main.tex skeleton with memoir class, all chapter stubs, preamble"
})

// Stage 2: parallel foundation (after skeleton signals complete)
await Promise.all([
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "bibtex-extractor", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "chapter-conv-A", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "chapter-conv-B", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "chapter-conv-C", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "front-matter", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "appendix-conv", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "design-consultant", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "diagram-engineer", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "analyst", name: "market-analyst", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "researcher", name: "research-verifier", ... }),
  mcp__claude-flow__agent_spawn({ agentType: "coder", name: "wardley-mapper", ... }),
])

// Stage 3: after diagrams
await mcp__claude-flow__agent_spawn({ agentType: "coder", name: "image-upcycler", ... })
```

## Publication Targets

### arXiv
- memoir class, XeLaTeX, biber-compiled `.bbl`
- All fonts embedded, no shell-escape
- Submit: source `.tex` + `.bbl` + figures (PDF/PNG/JPG)
- Full compliance checklist: [references/latex-conventions.md](references/latex-conventions.md#arxiv-compliance-checklist)

### KDP (Kindle Direct Publishing)
- PDF/X-1a or PDF/X-4 for print
- Bleed: 3mm all sides (`\setlrmarginsandblock` in memoir)
- Cover: separate high-res PDF (300 DPI minimum)
- Interior: 6×9 inch (memoir `[6in,9in]`)

### Print-on-Demand (general)
- Trim size specified in `\setstocksize{9in}{6in}`
- Spine calculation: pages × 0.002252 inches (60gsm paper)

## Quality Gates

Before shipping:
- [ ] `latexmk` exits 0 (no errors)
- [ ] Zero overfull hbox warnings > 10pt
- [ ] All `\cite{}` keys resolve (biber reports 0 unresolved)
- [ ] All `\includegraphics` paths exist
- [ ] PDF opens and pages render correctly (browser sidecar check)
- [ ] First 3 and last 3 chapters spot-checked visually

## Related Skills

- `wardley-maps` — Wardley map generation with LaTeX integration
- `art` — Gemini API image enhancement (diagram upcycling)
- `browser` — PDF preview, Mermaid rendering workaround
- `latex-documents` — general LaTeX compilation outside the book pipeline

LaTeX conventions, memoir class packages, UK typography, and citation patterns
(formerly the `latex-book` skill) now live in
[references/latex-conventions.md](references/latex-conventions.md); `latex-book` is a
deprecated redirect stub.

