Two YAML files and a handful of command-line flags control everything about a
book: what it is, how it looks, and how it is built. This part is the reference
— every key in book_metadata.yaml and book_style.yaml, then every
subcommand of the tool.
Chapter 8 The book_metadata.yaml File
book_metadata.yaml holds the book’s identity — the facts that stay true no
matter how the book is styled. Every key is optional except title. Anything you
leave out (or set to an empty string) is simply omitted: no blank author, no
empty copyright line.
title — The book’s title; defaults to “Untitled”. A \n in the value
stacks the title across lines on the print title page — "The\nRotary\nWaltz"
sets three lines — while everywhere else (PDF metadata, EPUB, HTML, running
heads) the breaks collapse to spaces.
subtitle — A subtitle, set beneath the title on the title page and
carried into the digital outputs. Turn on title-rule (in book_style.yaml) to
draw a rule between the two on the PDF title page.
author (or authors) — One name as a string, or several as a YAML
list. Either key works. The author appears on the title page, in the PDF and
EPUB metadata, and in the “Also by” heading.
author: "Thomas Hill"
# Or:
authors:
- "Ada Lovelace"
- "Charles Babbage"
year — The publication year. Used as the EPUB date (<dc:date>).
publisher — Publisher name, shown on the copyright page and in the EPUB
metadata.
rights — The copyright or rights statement printed on the copyright page
(and stored as the EPUB <dc:rights>). When you pass --build-id, a
“Printing: …” line is appended to it in the EPUB.
isbn — Printed on the copyright page and used as the EPUB identifier
(tagged as ISBN-13).
credits — An acknowledgements line on the copyright page — a cover
credit, for instance: "Cover photo courtesy of RJ Muna."
language — A language code such as en or fr. It sets the document
language for the PDF and the EPUB (<dc:language>) and drives hyphenation.
Defaults to en.
cover — A path (relative to the book directory) to a cover image. The
pdf command places it as the first page, epub embeds it as the EPUB cover,
and the whole-book html output embeds it near the top of the page. print
ignores it: KDP takes the print cover as a separate upload, so it never belongs
in the interior PDF. Builds that use the cover stop if the file is missing.
html-body-end — A path (relative to the book directory) to a file whose
contents are injected verbatim just before </body> in the whole-book html
output. This is the clean place for an end-of-body script — a web-analytics
snippet, for instance — without editing a chapter. It is HTML only by design:
epub, pdf, and print never read this key, so they stay script-free (and the
EPUB stays valid: EPUB restricts scripting, so keeping the snippet out of it is
what you want). The file is passed through as-is — raw HTML and JavaScript —
so put a complete <script>…</script> there. If the file is missing, the build
warns and produces the page normally, just without the snippet — a mistyped
name costs you the snippet, never the page’s formatting.
# book_metadata.yaml
html-body-end: analytics.html
The “Also by” page
Give an also-by: list and book4matter adds an “Also by Author” page in the
front matter of the PDF outputs; omit it and there is no such page. Each entry
needs a title and may add a cover image, a qr image, and a url. A bare
string is treated as a title-only entry.
also-by:
- title: "How to Teach Ballroom Dancing"
cover: "media/htbd-cover.jpg"
qr: "media/htbd-qr.png"
url: "howtoteachballroomdancing.com"
# Title only.
- "An Earlier Work"
Tracked items
tracked: registers the kinds of thing book4matter auto-numbers, cross-references,
and can list — exercises, figures, charts, tables, whatever you use. Each kind
maps to a label, the word printed before the number (Exercise 3) and heading
its list. A bare string is shorthand for the label.
tracked:
exercise: { label: "Exercise" }
figure: { label: "Figure" }
chart: "Chart"
Omit the key and nothing is tracked. How to write the {...} tokens themselves
— defining items, referring to them, and placing a list — is covered in the
Auto-Numbering, Cross-References, and Lists chapter.
Listing chapters explicitly
By default every file in chapters/ is built, in natural filename order. To fix
the order by hand instead, list the files under chapters:, relative to the book
directory; only those files, in that order, are built. A listed file that does
not exist stops the build.
chapters:
- chapters/010-introduction.md
- chapters/020-first-steps.md
Not a metadata key: --build-id is a command-line flag, not something
you put here, because it changes from build to build. See the Command-Line
chapter.
Chapter 9 The book_style.yaml File
book_style.yaml controls appearance only — page size, margins, fonts, and a
little page furniture. Point several books at one style file and they share a
look; restyle them all by editing that one file. Every key has a sensible
default, so the smallest possible style file is no file at all.
trim — The finished page size. Write it as 6x9 (inches), or as an
explicit mapping for an unusual size. Defaults to 6x9, the standard US trade
paperback.
trim: 6x9
# --- or ---
trim: {width: 5.5, height: 8.5}
margins — The four page margins in inches: inside, outside, top,
bottom. The inside margin is the binding (gutter) edge and is normally the
widest, because the binding swallows part of every page. Omit margins and
book4matter fills them in: outside 0.625, top and bottom 0.75, and an
inside gutter sized to the book’s length. With no --pages hint it uses a
generous 0.875” (safe to ~500 pages); with --pages N it picks KDP’s minimum for
that length plus 0.125” of breathing room:
| Interior pages |
KDP minimum gutter |
With --pages |
| ≤ 150 |
0.375” |
0.5” |
| 151–300 |
0.5” |
0.625” |
| 301–500 |
0.625” |
0.75” |
| 501–700 |
0.75” |
0.875” |
| 701+ |
0.875” |
0.875” |
Anything you set here overrides those defaults.
font — The body typeface. Defaults to Libertinus Serif, which is
bundled in the image, so the default needs no setup. To use another face, drop
its files into the book’s fonts/ folder and name the family here; see the
Customizing chapter.
heading-font — The face for parts, chapters, and headings. Defaults to
Liberation Sans (a Helvetica-metric face, also bundled).
font-size — Body text size, for example 11pt. A bare number is read as
points (11 means 11pt). Defaults to 11pt.
blockquote — The shared appearance of ordinary Markdown blockquotes
(>). width controls the quote measure relative to the normal text width;
rule-width controls each centered rule above and below it; spacing is the
vertical air around the quote; and text-align and font-style control the
quote text. The defaults are 80%, 50%, 1.25em, center, and italic.
The same map is used by the PDF, EPUB, and HTML outputs.
indent — PDF outputs only. How paragraphs are indented. all (the
default) indents every paragraph’s first line, openers included; standard
leaves the first paragraph after a heading flush and indents the rest (the
trade-book convention, and what EPUB and HTML already do); none drops indents
entirely and tells paragraphs apart by the space between them. Defaults to all.
toc — Whether to include the Contents page in the PDF outputs. Defaults
to true for a book that has any titles, and to false for a wholly un-titled
novel (nothing to list). Set it explicitly to force the issue either way. The
Contents lists parts and chapters; a front-matter chapter shows its roman folio.
EPUB and whole-book HTML always get a generated navigation structure from Pandoc.
no-parts — PDF outputs only. When true, treat top-level # headings
as chapters rather than parts, shifting every heading down one level (# →
chapter, ## → section, …). Use it for a book that has chapters but no parts
and writes # for the chapter. Defaults to false, though a book that uses no
## anywhere is read this way regardless (see the Novels and Flat Books chapter).
The --no-parts command-line flag does the same thing.
toc-depth — How many heading levels the Contents includes. 2 (the
default) lists parts and chapters; 3 also lists topics (level-3 ###
headings), set smaller and nested under their chapter. Applies to print, digital
PDF, EPUB, and HTML.
running-heads — PDF outputs only. When true, body pages carry a
small-caps running head: the book title on left-hand (verso) pages and the
current chapter on right-hand (recto) pages. It is suppressed in the front matter
and on any page where a part or chapter opens. Defaults to false. EPUB and
HTML ignore it — those readers paginate themselves.
title-rule — When true, draw a horizontal rule between the title and
subtitle on the title page. Defaults to false.
chapter-style — PDF outputs only. The chapter opener’s layout.
centered (the default) centers a bare chapter numeral over a short rule with
the title centered beneath — which carries a wrapped title gracefully. left
instead prints a “CHAPTER N” label with the title flush left. Defaults to
centered.
part-style — PDF outputs only. The part divider’s layout. classic
(the default) prints an all-caps label and arabic number (“PART 1”) above the
title in bold capitals, sitting a third of the way down the page. fancy
instead sets the divider in the body serif as a small letterspaced label, a large
Roman numeral, a short rule, and the title in title-case — the literary look of
a trade book’s section openers. Any text written beneath the part heading in its
chapter file prints as a centered italic blurb on the divider itself. Defaults to
classic.
part-label — The word for the top-level division, replacing “Part”
everywhere it is auto-generated: the PDF divider and table of contents (set in
capitals there, so SECTION TWO · ...), and the EPUB and HTML labels. Defaults
to Part. Set it to Section, Book, Volume, or anything else. It does not
touch wording you write yourself in a heading or in body text.
parts-recto — PDF outputs only. When true, every part divider begins
on a recto (the right-hand, odd-numbered page); a blank page is inserted before
it when the previous page would otherwise leave it on a verso. The blank is
counted and may carry a folio. Defaults to false. EPUB and HTML have no fixed
page sides, so they ignore it.
chapters-recto — PDF outputs only. The same for chapters: when true,
each chapter opens on a recto page. Defaults to false.
Not supported: a line-height: key appears in some older example files,
but the tool does not read it — body leading is fixed in the template. Leave
it out.
Chapter 10 Command-Line Reference
Every command runs through run.sh, which builds the Docker image if it is
missing and then runs the tool with your current directory mounted inside the
container. The general form is:
./run.sh [--rebuild] <command> [arguments]
--rebuild forces the image to be rebuilt first — do this after changing a
template or updating the tool. The commands are print, pdf, epub, html,
import, and impose. For the book-building commands, bookdir defaults to the
current directory.
print
./run.sh print [bookdir] [--pages N] [--keep] [--no-parts] [--build-id ID]
Builds the print interior PDF to bookdir/out/<title>-interior.pdf. Use this
for KDP upload or for a file you intend to print as a book. The print interior
does not include the cover, because KDP takes the print cover as a separate
upload. It also removes internal hyperlinks from the table of contents,
footnotes, and cross-references, because Amazon KDP enforces no hyperlinks in a
print interior. External web links are converted to visible text plus their
destination, as in CLICK HERE (https://www.example.com).
--pages N — the estimated final page count. It selects a KDP-appropriate
inside gutter (see the margins table in the previous chapter). Omit it and a
generous default gutter is used. Any margins in book_style.yaml win
regardless.
--keep — keep the intermediate Typst files (_body.typ, _meta.typ,
book.typ, main.typ) in out/ instead of deleting them. Handy when you want
to read the generated Typst.
--no-parts — treat # headings as chapters, not parts, shifting every
heading down one level. See the Novels and Flat Books chapter.
--build-id ID — a printing identifier, printed as “Printing: ID” on the
copyright page.
pdf
./run.sh pdf [bookdir] [--pages N] [--keep] [--no-parts] [--build-id ID]
Builds a digital PDF to bookdir/out/<title>.pdf. Use this when you will send
someone a PDF directly. It uses the same page layout as print, but keeps
hyperlinks live for the table of contents, footnotes, cross-references, and
external links. If book_metadata.yaml has a cover: image, the digital PDF
includes it as the first page.
--pages N — the estimated final page count, using the same gutter logic as
print.
--keep — keep the intermediate Typst files in out/.
--no-parts — treat # headings as chapters, not parts (as for print).
--build-id ID — a printing identifier, printed as “Printing: ID” on the
copyright page.
epub
./run.sh epub [bookdir] [--no-check] [--build-id ID]
Builds an EPUB 3 to bookdir/out/<title>.epub. The result is validated with
epubcheck — the same kind of check KDP runs on upload — and validation errors
fail the build.
--no-check — skip the epubcheck step.
--build-id ID — appended to the rights line in the EPUB metadata.
The EPUB cover, if any, comes from the cover: key in book_metadata.yaml.
html
# Whole book: one standalone page with a clickable table of contents.
./run.sh html [bookdir]
# Just the contents, as a link-free fragment.
./run.sh html toc [bookdir]
# One chapter, as an HTML fragment.
./run.sh html chapter NN [bookdir]
- The whole-book form is a single self-contained page (resources embedded) with a
clickable table of contents — the form used for the book4matter website. It
links an optional
book_style.css after the embedded styles, so dropping a
book_style.css next to the page (or copying your project’s CSS into out/
under that name) themes the site; omit it and the embedded styling stands. If
book_metadata.yaml has a cover: image, the whole-book page embeds it near
the top.
toc emits a <nav class="book-toc"> of plain, unlinked titles to drop into a
web page (the in-book anchors would point nowhere off-site).
chapter NN picks one chapter: NN matches the leading number in a filename
(010-foo.md is 10), or a 1-based position in the chapter list, or a
filename/stem.
--build-id is accepted for parity with the other commands but is not stamped
on web output.
impose
./run.sh impose <file.pdf> [--paper P] [--signature N] \
[--single] [--margin INCHES] [-o NAME]
Rearranges a PDF two-up into printable signatures for home binding. It is
separate from the print command: KDP and commercial print shops impose pages
for you, but impose is useful when you are printing on a home printer, folding
the sheets, and binding the book yourself. A signature is a small stack of
sheets folded together down the middle; several signatures are then stacked and
sewn or glued into a codex.
impose takes any PDF, not just a book4matter interior. The output is written
next to its input, so docs/out/book4matter-interior.pdf produces
docs/out/book4matter-signatures.pdf. Print the result double-sided, flipping on
the short edge, then fold each signature down the middle. The page streams are
Flate-compressed, so the imposed PDF stays about the size of the input.
--paper letter or --paper a4 — the sheet you print on. The default is
letter.
--signature N — sheets per signature. The default is 4, which makes
16-page signatures because each sheet folds to four pages.
--single — impose the whole PDF as one folded booklet, useful for thin
saddle-stitched work.
--margin INCHES — safe margin inside each half-page cell. The default is
0.25.
-o NAME or --output NAME — output filename, still written beside the
input.
import
./run.sh import <file.docx> [bookdir] [--no-split] [--force]
Converts a Word manuscript into chapters/*.md plus an extracted media/
folder, splitting the document into one file per Heading 1.
--no-split — write a single Markdown file instead of splitting on H1.
--force — overwrite a chapters/ directory that already has files.
The Importing from Word chapter covers this in full.
Stamping builds with –build-id
--build-id is how you make a given printing identifiable. Compute the value
once — usually the repository’s short git hash — and pass it to the outputs
that stamp it. This manual’s own build.sh does exactly that:
BUILD_ID="$(git rev-parse --short=10 HEAD)"
./run.sh print docs/ --build-id "$BUILD_ID"
./run.sh pdf docs/ --build-id "$BUILD_ID"
./run.sh epub docs/ --build-id "$BUILD_ID"