Guide ebook authoring from Markdown sources through Pandoc to PDF, EPUB, and HTML output. Use when the user wants to write a book, create an ebook, build a PDF from Markdown, set up a Pandoc pipeline, add diagrams to a book with Mermaid or D2, configure LaTeX templates, manage chapters, or mentions Pandoc, ebook, manuscript, or book project structure.
End-to-end workflow for writing, structuring, and producing ebooks from Markdown source files using Pandoc. Covers project scaffolding, chapter management, diagram embedding, cross-references, styling, and multi-format output (PDF via LaTeX, EPUB, HTML).
Verify these are installed before proceeding. Suggest installation commands if missing.
| Tool | Purpose | Check command |
|---|---|---|
pandoc | Document conversion | pandoc --version |
pdflatex or xelatex | PDF generation |
xelatex --version |
d2 | D2 diagrams (optional) | d2 --version |
mmdc (mermaid-cli) | Mermaid diagrams (optional) | mmdc --version |
pandoc-crossref | Cross-references (optional) | pandoc-crossref --version |
Scaffold this structure for any new book project:
book-title/
├── metadata.yaml # Book metadata and Pandoc config
├── Makefile # Build commands
├── chapters/
│ ├── 00-preface.md
│ ├── 01-introduction.md
│ ├── 02-chapter-name.md
│ └── ...
├── diagrams/
│ ├── src/ # D2 or Mermaid source files
│ │ ├── architecture.d2
│ │ └── flow.mmd
│ └── out/ # Rendered PNGs/SVGs (gitignored, generated)
├── assets/
│ ├── cover.png # Cover image
│ ├── images/ # Static images
│ └── fonts/ # Custom fonts (optional)
├── templates/
│ ├── template.tex # LaTeX template for PDF
│ └── style.css # CSS for EPUB/HTML
├── output/ # Generated files (gitignored)
│ ├── book.pdf
│ ├── book.epub
│ └── book.html
└── .gitignore
When the user asks to start a new book, create this structure:
mkdir -p book-title/{chapters,diagrams/{src,out},assets/{images,fonts},templates,output}
Then generate the starter files described in the following sections.
This file drives Pandoc. Generate it with the user's book details:
---