# Book

<StatusBadge status="available" /> `format: book` assembles **several files** into one book:
an entry, `book.md`, that lists the chapters, and one Markdown (or JSON) file per chapter beside it.
A chapter is a story of its own; `---` separates its **sections**, and a scene of the book is a
section of a chapter. Chapters, figures and notes are numbered by the book, cross-references and
the index are resolved once, and the same book gives a web edition, an EPUB 3 and, through the
print chain, a PDF.

The examples are `book-novella` (a novella in two languages, one chapter written in JSON) and
`book-handbook` (tables, code and formulas). The directives of a chapter (figures, cross-references,
the index, epigraphs) and the notes are on [Book directives](/formats/book/directives).

## A minimal book

```text
my-book/
├── book.md          the entry: title, author, chapters, front and back matter
├── book.fr.md       its French variant (optional)
├── 00-preface.md    format: book — a chapter
├── 01-lorem.md
├── 01-lorem.fr.md   a chapter's French variant; a missing one falls back to the default language
├── 02-ipsum.md
├── images/map.svg
└── recit.config.ts  book: { noteNumbering: "chapter" }, i18n
```

The entry has front matter only: any scene written in it is an error (`book-entry-scene`).

```md title="book.md"
---
title: Lorem Ipsum
subtitle: Dolor sit amet
description: A novella in three chapters
author: Lorem Ipsum
format: book
lang: en
cover: ./images/cover.svg
chapters:
  - file: 00-preface.md
    numbered: false
  - 01-lorem.md
  - 02-ipsum.md
front: [half-title, title, copyright, toc]
back: [notes, index]
publication:
  publisher: Lorem Press
  rights: © 2026 Lorem Ipsum, CC BY 4.0
  edition: First edition
  isbn: 978-0-306-40615-7
---
```

A chapter is a story of its own:

```md title="01-lorem.md"
---
format: book
---

# Lorem

:::epigraph{source="Dolor"}
Sed ut perspiciatis unde omnis iste natus error.
:::

Lorem ipsum dolor sit amet[^1], as the map shows (:ref[fig-map]).

::figure[The Lorem valley.]{src=./images/map.svg id=fig-map alt="Three rounded hills"}

--- id=lorem-night break=page

Ut enim ad minim veniam.

[^1]: Duis aute irure dolor in reprehenderit.
```

- Every chapter declares `format: book`. Its first `#` heading is its title.
- Its id is its file name without the leading number (`01-lorem.md` → `lorem`), or `id:` in its
  front matter. The first section takes the chapter's id; a section takes `id=` on its separator.
- `break=page` starts the section on a new page in print, `break=right` on a right-hand (odd) page
  (with `engine: chromium`, without Paged.js, `break=right` gives a plain page break); the web
  edition marks them with a larger space before the section. On the first section of a chapter,
  `break=right` also starts that chapter on a right-hand page when `pdf.chapterStart` is `any`.
- Ids are unique in the whole book: a duplicate names both places.

`recit init --format book` writes a starter entry and two chapters beside it.

## Settings

In the front matter of the entry:

| Setting         | Meaning                                                                                                                                      | Default        |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -------------- |
| `chapters`      | The chapter files (and optional `{ part, id?, chapters }` parts) in reading order; `{ file, numbered: false }` for a preface or an afterword | required       |
| `front`         | Pages before the chapters: `half-title`, `title`, `copyright`, `toc`                                                                         | `[title, toc]` |
| `back`          | Pages after them: `notes`, `index`, `glossary`                                                                                               | `[]`           |
| `noteNumbering` | `chapter` (1 again in each chapter) or `book`                                                                                                | `chapter`      |
| `cover`         | The cover image, relative to the entry                                                                                                       | —              |
| `publication`   | `publisher`, `rights` (a text or one per language), `edition`, `isbn` (ISBN-13, check digit verified), `identifier`                          | —              |
| `pdf`           | The PDF options, below                                                                                                                       | A5, Paged.js   |

`subtitle` (or `description` when `subtitle` is absent) is the subtitle of the title page, the web
edition and the EPUB (`title-type` `subtitle`). `chapters`, `cover` and `publication` belong to one
book, so they are written in the entry only. The `book:` section of `recit.config.ts` gives the
defaults of every book of a folder, and the entry wins:

| Key                  | What it does                                                      |
| -------------------- | ----------------------------------------------------------------- |
| `book.front`         | the pages before the chapters, as `front` above                   |
| `book.back`          | the pages after them, as `back` above                             |
| `book.noteNumbering` | `chapter` or `book`, as `noteNumbering` above                     |
| `book.pdf`           | the PDF options of the book, the same keys as `pdf:` in the entry |

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  i18n: { defaultLocale: "en", locales: ["en", "fr"] },
  book: {
    front: ["half-title", "title", "copyright", "toc"],
    back: ["notes", "index"],
    noteNumbering: "chapter",
    pdf: { page: { size: "A5", mirror: true } },
  },
});
```

### The glossary

`back: [glossary]` adds a page of the terms the chapters use. A `:term[label]{id=…}` of a chapter
(or a word the automatic link finds) is read from the glossaries of `terms.sources` in
`recit.config.ts`, as in any story ([Glossary](/formats/glossary/overview)). The book prints it as a
link to its entry, without the hover card of the web; the glossary page lists each term used, sorted
in the book's language, with its short definition and a link to each occurrence. In the PDF these
links become the page numbers of the occurrences, as in the index; the EPUB marks the page and its
entries (`glossary`, `glossterm`, `glossdef`). Without `glossary` in `back`, a term is its label
alone.

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  terms: { sources: ["./glossary.md"] },
  book: { back: ["notes", "glossary", "index"] },
});
```

### Parts

An entry of `chapters` may be a part `{ part, id?, chapters }` grouping consecutive chapters under
one title (`examples/book-handbook`). `id` defaults to the slug of `part` or, when the title has no
Latin letter, its number (`1`, `2`…); chapter numbers continue across parts, and chapters outside a
part (a preface, an appendix) stay at the top level. A book without parts is unchanged.

```yaml
chapters:
  - file: 00-preface.md
    numbered: false
  - part: Foundations
    id: foundations
    chapters:
      - 01-basics.md
      - 02-tables.md
  - part: Practice
    id: practice
    chapters:
      - 03-code.md
      - 04-formulas.md
  - file: 05-appendix.md
    numbered: false
```

- **PDF**: each part gets its own right-hand page (`Part I`, `Partie II`, Arabic numerals in Hebrew)
  before its first chapter, and the table of contents nests its chapters under the part with their
  page numbers.
- **EPUB 3**: each part is written to `part-<id>.xhtml` (`epub:type="part"`) in the spine, and both
  `toc.xhtml` and `nav.xhtml` nest its chapters under the part link.
- **Web edition**: no separate page is added; each part appears as a non-link group heading above
  its chapters in the reader's table of contents.

### The PDF

`recit export --to pdf book.md` prints the book through the same chain as every format that prints.
The options sit under `pdf:` in the entry's front matter, `settings.pdf` of its twin, or `book.pdf`
in `recit.config.ts`, and the command line goes last. They are the
[PDF options](/documentation/configuration/recit-config#pdf-options) of every paginated format
(`outline`, `tagged`, `colorMode`, `output`, `engine`, `page`, `toc`, `header`, `footer`), plus
three of the book's own:

| Key                     | Default                  | What it does                                                                                                                         |
| ----------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ |
| `chapterStart`          | `right`                  | each chapter on a right-hand page, a blank page when needed; `any` does not, but for a chapter whose first section has `break=right` |
| `frontMatter.numbering` | `roman`                  | the numbers of the pages before the first chapter, `roman` or `arabic`                                                               |
| `footnotes`             | the notes page of `back` | `page` (at the foot of their page), `chapter-end` or `book-end`                                                                      |

```yaml
pdf:
  page:
    size: { width: 5in, height: 8in }
    mirror: true
    margins: { top: 18mm, bottom: 20mm, inside: 22mm, outside: 16mm }
  chapterStart: right
  frontMatter:
    numbering: roman
  footnotes: page
```

By default a book is A5 with 20 mm margins, laid out by Paged.js (`engine: pagedjs`): chapters on a
right-hand page, the front matter numbered in roman numerals and the chapters from 1, the book's
title as the running head of the left pages and the chapter's of the right ones (inverted in a
right-to-left book), the contents and the index with the page numbers of their targets, each one a
link. The PDF is tagged, its bookmarks come from the headings, and the running heads are left out of
the tagged content. `engine: chromium` prints without Paged.js: no running chapter title, no page
numbers in the contents, chapters on the next page; `footnotes: page`, `toc.pageNumbers` and
`page.bleed` then are an error of the options. With `frontMatter.numbering: arabic`, or with
`engine: chromium`, the numbering goes on from the front matter to the first chapter.

## A described character (preview)

A book whose entry names a bible with `cast:` can draw a character the bible describes (its `model`,
see [The bible](/documentation/scenario/bible#a-described-character-preview)) in any chapter, as a
vector still figure, with `::character{…}` (`@recit/character`, an optional package):

```md
::character{character=lorem pose=idle caption="Dolor sit amet."}
```

`pose=` and `expression=` give the figure, `animation=` shows the first image of one of its cycles,
`render=` picks a `vector` render and `variant=` a variant; `alt=` replaces its accessible name
(default, « name, pose »), and `caption=` writes a `<figcaption>`. The same `<svg>` is drawn in the
web edition, the PDF and the EPUB. `poses=` (fragments of a slide) and anything the model does not
declare are refused with their file and line.

## The JSON twin

The entry and every chapter have a typed JSON twin (`{ "kind": "story", "format": "book" }`),
validated by `https://recit.dev/schema/v1/book.json` and round-trip tested. `break` stays in a
section's `attrs`; figures, epigraphs and references stay directives of the `body`.

```bash
npx recit convert book.md --to json --chapters
```

writes the twin of the entry and, next to each chapter, its own (`01-lorem.json`). A book assembled
from its JSON files is the same book: `examples/book-novella` writes its third chapter in JSON only.

Alongside the entry `settings` above (`settings.id` on a chapter file, `settings.chapters`,
`settings.front`, `settings.back`, `settings.noteNumbering`, `settings.cover`,
`settings.publication`, `settings.pdf`), `book.json` defines `settings.cast` and the shared `scenes`
keys (see [Scenes › In the JSON twin](/documentation/writing/scenes#in-the-json-twin)):

| Key             | Type / values                                 | Effect                                                                                                                                                                |
| --------------- | --------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `settings.cast` | `string` or `string[]` (non-empty)            | Bible path or non-empty list of bible paths relative to the entry (`cast:` in front matter, preview; [A described character](#a-described-character-preview)).        |
| `scenes`        | `object[]`                                    | Required in `kind: "story"`: `[]` in the book entry (a non-empty scene raises `book-entry-scene`), and the ordered sections of a chapter file.                        |
| `scenes.id`     | `string` (non-empty)                          | Required. Stable section identifier across languages (`--- id=…` in Markdown; [Scenes](/documentation/writing/scenes#in-the-json-twin)).                              |
| `scenes.body`   | `string` or `Record<string, string>`          | Optional Markdown or MDX prose and chapter directives of the section ([Scenes](/documentation/writing/scenes#in-the-json-twin)).                                      |
| `scenes.notes`  | `string` or `Record<string, string>`          | Optional author notes in Markdown (`:::notes`; [Scenes](/documentation/writing/scenes#in-the-json-twin)).                                                             |
| `scenes.attrs`  | `Record<string, string \| number \| boolean>` | Optional separator attributes (`--- key=value`) other than `id`, including `break` (`"page"` or `"right"`; [Scenes](/documentation/writing/scenes#in-the-json-twin)). |

## Commands

| Command                               | What it does                                                                                                  |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
| `recit dev book.md`                   | the web edition, reloaded when the entry, a chapter, a twin or an image changes                               |
| `recit build book.md -o dist`         | the web edition as static files: one HTML page per chapter, readable without JavaScript                       |
| `recit validate book.md`              | assembles the whole book without building it, and reports every error with its file and line                  |
| `recit convert book.md --to json`     | the twin of the entry; `--chapters` adds one per chapter                                                      |
| `recit convert book.md --to webstory` | a web story of the book: a title card, then a card per chapter with its epigraph or first sentence            |
| `recit export --to epub book.md`      | an EPUB 3 per language (`--locale fr`), listed in `exports.json`, identical bytes from one export to the next |
| `recit export --to pdf book.md`       | a PDF per language (`book.en.pdf`, `--locale fr`), laid out by Paged.js, listed in `exports.json`             |

In a multilingual project (`i18n` in `recit.config.ts`), build or export a language with the base
entry and `--locale` (`recit build book.md --locale fr`); passing `book.fr.md` builds that same
French book and warns (`book-variant-entry`). `-o, --output` names the file (a folder for `build`).
Every command and its flags are in [the CLI reference](/documentation/reference/cli).

### The errors

Every error of a book carries its file and its line, never a guess, in the one form every Récit
command prints, followed by its code:

```text
✖ 02-ipsum.md:14 — :ref: unknown id "fig-mapp" (did you mean "fig-map"?) (book-unknown-ref)
✖ book.md:9 — chapter "04-amet.md" is listed but missing (book-missing-chapter)
✖ 01-lorem.md:13 — ::figure "fig-map": image "./images/mapp.svg" not found (book-missing-image)
```

## Bridges

A book has one bridge, book → docs (see [Bridges](/formats/bridges)): its entry listed in a site,
each chapter becomes a page of the site and the table of contents its sidebar, as the next section
shows. The mapping is closed: one chapter is one page, with the `id` of the chapter as its last
segment, and the contents are the sidebar of those pages only. A book that does not assemble is
refused before the site is built, each error with its file and line (the site prints no code), never
published in part:

```text
The book book.md does not assemble:
✖ book.md:7 — chapter "02-ipsum.md" is listed but missing
```

No bridge leaves a book for a deck or a film: a chapter is prose, which no slide or shot holds
without a summary.

## In a site

In a site, `publish.entries` lists the **entry** of a book: each page of the book gets its route
(`/<prefix>/<slug>/<chapter>`), the table of contents becomes the sidebar of its pages, Pagefind
indexes each chapter, and `<StoryEmbed slug="novella" format="book" chapter="lorem" />` shows one
chapter in a page.

The MCP server describes the format (`describe_format`, `recit://guide/book`) and its `book_outline`
tool lists the ids a chapter can cite.

## Packages

```ts
import { assembleBook, renderBookHtml } from "@recit/book/node";

const book = await assembleBook("book.md");
const web = renderBookHtml(book, { target: "web" });
```

| Import                   | Contents                                                                          |
| ------------------------ | --------------------------------------------------------------------------------- |
| `@recit/book`            | `assembleBookFiles`, `renderBookHtml`, the book model, no React                   |
| `@recit/book/node`       | `assembleBook`, reading a book from disk, and `writeEpub`, the EPUB 3 (Node only) |
| `@recit/book/components` | the web edition (`BookReader`, `BookToc`, `BookIndex`…)                           |
| `@recit/book/runtime`    | `mountBook`, the page of `recit dev` and `recit build`                            |
| `@recit/book/print`      | the printable view (`bookPrintDocument`)                                          |
| `@recit/book/styles.css` | the stylesheet of the web edition                                                 |
