On this page:
8.5.1 Required Fields
8.5.2 Optional Fields
8.5.3 Parts
8.5.4 Example
8.5.5 Book Configuration
book
book-part
part
chapter
8.5.6 Typst Rendering
camp-typst-render%
new
camp-doc->typst
escape-typst-text
escape-typst-string
default-typst-tag
9.1

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?)
A hash-view representing a book configuration. A book is most commonly defined using #lang camp/book.

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?
A hash-view representing a book part configuration. Book parts are most commonly defined within a #lang camp/book configuration module.

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.

hash-view

(hash-view part (name chapters))

  name : string?
  chapters : (listof chapter?)
A hash-view containing a gathered part: the actual ordered list of chapters within a part collected at build time. Passed to render functions.

hash-view

(hash-view chapter (slug doc))

  slug : string?
  doc : document?
A hash-view representing a gathered chapter. The doc field contains the Punct document; call camp-doc->typst to convert it to Typst markup.

8.5.6 Typst Rendering🔗ℹ

Camp provides a Typst renderer for book publishing that extends Punct’s Typst renderer with cross-reference support.

class

camp-typst-render% : class?

  superclass: punct-typst-render%

Extends punct-typst-render% with Camp-specific features:
  • 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
Convenience function to render a Punct document to Typst markup. If slug is provided and the document starts with a level-1 heading, a reference label is attached.

(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?
Escapes special Typst characters in text content. Re-exported from punct/render/typst.

procedure

(escape-typst-string str)  string?

  str : string?
Escapes characters in quoted Typst string arguments (URLs, paths). Re-exported from punct/render/typst.

procedure

(default-typst-tag tag attrs elems)  string?

  tag : symbol?
  attrs : (listof (list/c symbol? string?))
  elems : list?
Converts a custom element to a Typst function call. Re-exported from punct/render/typst.

  • (term () "REST") becomes #term[REST]

  • (term-definition ((name "rest")) "REST") becomes #term_definition(name: "rest")[REST]

  • Hyphens in tag names are converted to underscores