Theme authoring

The contents below link to each definition. Function entries show the signature, then a description, then the parameters with their types and defaults; variable entries show the declared type.

Turns a passive theme definition into a setup function.

setup(theme) -> function
Description

Two different things are called setup here, and the distinction is worth stating plainly. mosaic.setup is the document show rule you apply to a deck. mosaic.themes.setup sets up nothing on its own: it takes a theme definition and returns a show rule of that same kind, with the same signature as mosaic.setup plus any options the theme declares. So the usual shape is a facade that names the result once,

#let setup = mosaic.themes.setup(definition)

and decks then apply that setup exactly as they would a built-in theme’s. Applying the result inline works too, as the example below shows.

A theme is data, not code: you describe colors, defaults, and rules in a plain dictionary. The definition is validated here, where the setup is built, so a malformed theme fails at that line rather than somewhere inside a deck.

Every bundled theme facade also exports the definition its own setup was built from, so mosaic.themes.default.definition and friends are the starting points for a variation on a bundled look.

#let starlight = (
  name: "Starlight",
  colors: (
    canvas: rgb("#0b1020"), surface: rgb("#161d33"),
    text: white, muted: rgb("#9aa4c0"),
    line: rgb("#2a3350"), accent: rgb("#7cc4ff"),
    warning: rgb("#fbbf24"), error: rgb("#f87171"),
  ),
  defaults: (overflow: "error"),
  options: (density: "airy"),
  apply: (body, colors: (:), options: (:)) => {
    set text(
      font: "Inter",
      size: if options.density == "airy" { 30pt } else { 26pt },
    )
    show heading: set text(fill: colors.accent)
    body
  },
)

#show: mosaic.themes.setup(starlight).with(density: "dense")

Definition keys

Only colors is required.

Theme options

Names declared in options become named arguments of the returned setup function. They are consumed before ordinary setup validation and handed to layouts and apply as the options dictionary, so a theme can offer choices Mosaic itself knows nothing about. An option name that collides with a built-in setup option is an error. Every other named argument passes through as an ordinary setup option.

Arguments
themedictionary
The passive theme definition dictionary described above.