8.5 Book Configuration Language
| #lang camp/book | package: camp-lib |
The #lang camp/book language provides a TOML-based configuration format for defining books that can be compiled to PDF via Typst. Book configurations reference site collections and can filter pages by date range or taxonomy. All book metadata (title, authors, etc.) is handled by your render function, not the configuration.
8.5.1 Required Fields
Field |
| Type |
| Description |
render-with |
| datum |
| Render function @tt{(module-path identifier)} |
output-folder |
| string |
| Output directory for .typ and .pdf files |
8.5.2 Optional Fields
Field |
| Type |
| Description |
includes |
| array |
| Files/directories to copy to output folder |
8.5.3 Parts
Each [[parts]] entry defines a section of the book:
Field |
| Type |
| Required |
| Description |
name |
| string |
| yes |
| Part name |
pages |
| array |
| no |
| Explicit page paths (relative to site root) |
collections |
| array |
| no |
| Collections to include |
date-from |
| date |
| no |
| Include pages on or after this date |
date-to |
| date |
| no |
| Include pages on or before this date |
taxonomies |
| table |
| no |
| Filter by taxonomy values |
The taxonomies field is a table where keys are taxonomy names and values are either a single string (exact match) or an array of strings (match any).
8.5.4 Example
#lang camp/book render-with = "(mysite/render render-book)" output-folder = "_output" includes = ["template.typ", "fonts"] [[parts]] name = "Essays" collections = ["posts"] date-from = 2024-01-01 date-to = 2024-12-31 taxonomies = { category = "featured" } [[parts]] name = "Appendix" pages = ["appendix-a.poly.pm"]
The render function receives a list of gathered parts and returns a complete Typst document as a string. See Tutorial: Creating a Book from Your Blog for a complete example.
8.5.5 Book Configuration
Book configurations define the structure for print/PDF output via Typst. All book metadata (title, authors, etc.) is handled by your templates or render function, not the configuration.
For convenience, we use chapter to refer to a single source file that is included in a book. A book part is a named collection of chapters, built from a collection (from the site configuration) and optionally filtered by date ranges or taxonomy terms.
hash-view
(hash-view book ( render-with output-folder parts path includes))
render-with : list?
output-folder : string?
parts : (listof book-part?)
path : (or/c path? #f)
includes : (listof string?)
Required fields are render-with, output-folder, and parts. The path field is set by load-book.
The render-with field is a list of (module-path identifier) specifying the render function to call. The render function receives a list of part? hashes and returns a complete Typst document as a string.
The includes field lists files or directories to copy to the output folder before Typst compilation.
hash-view
(hash-view book-part ( name pages collections date-from date-to taxonomies))
name : string?
pages : (listof string?)
collections : (listof string?)
date-from : (or/c date-provider? #f)
date-to : (or/c date-provider? #f)
taxonomies : hash?
Only name is required. Parts can include explicit pages (paths relative to site root), collections to pull from, and filters (date-from, date-to, taxonomies) to select specific pages.
8.5.6 Typst Rendering
Camp provides a Typst renderer for book publishing that extends Punct’s Typst renderer with cross-reference support.
|
superclass: punct-typst-render% |
Automatic label attachment to leading H1 headings when a slug is provided
Handling of page-ref elements as Typst references
Falls through to default-typst-tag for term and term-definition
constructor
(new camp-typst-render% [doc doc] [ [slug slug]]) → (is-a?/c camp-typst-render%) doc : document? slug : (or/c string? #f) = #f Creates a renderer for doc. If slug is provided and the document starts with a level-1 heading, the heading is rendered with a Typst label <slug> attached, enabling cross-references via @slug.
procedure
(camp-doc->typst doc [#:slug slug]) → string?
doc : document? slug : (or/c string? #f) = #f
(camp-doc->typst doc) ; no label (camp-doc->typst doc #:slug "intro") ; attaches <intro> to leading H1
procedure
(escape-typst-text str) → string?
str : string?
procedure
(escape-typst-string str) → string?
str : string?
procedure
(default-typst-tag tag attrs elems) → string?
tag : symbol? attrs : (listof (list/c symbol? string?)) elems : list?
(term () "REST") becomes #term[REST]
(term-definition ((name "rest")) "REST") becomes #term_definition(name: "rest")[REST]
Hyphens in tag names are converted to underscores