Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Spectra

Spectra: typed Prism presentations lowered to deterministic Typst.

A deck is an ordinary immutable value: metadata, a theme, and a list of slides whose bodies are Pict layout values. Everything else is a projection of that value, so building one is just building data:

fn main() =
  let d = make_deck(
      metadata("Prism in Six Slides", "sdiehl"),
      prism_theme,
      [titled_slide("Hello", item("A deck is a value."))],
    )
  match d.slides of
    Cons(s, Nil) =>
      match s.title of
        Some(t) => println(t)
        None => ()
    _ => ()
Hello

The effectful deck/slide/pict builders elaborate to this same pure representation; render_typst lowers a deck to a Typst document, and the standalone spectra executable (see SpectraCli) drives the pipeline through to a PDF. Slides can quote their own source through reflect fn, which is what makes a deck that explains its own code an ordinary program.

Types

Metadata

type Metadata = Metadata {
  title: String,
  author: String,
  subject: String
} deriving (Eq, Show)

Slide

type Slide = Slide {
  title: Option(String),
  body: Pict,
  notes: List(String)
} deriving (Eq, Show)

Deck

type Deck = Deck {
  metadata: Metadata,
  theme: Theme,
  slides: List(Slide)
} deriving (Eq, Show)

Effects

SlideBuilder

effect SlideBuilder
  place(Pict) : Unit
  reveal(Unit) : Unit

DeckBuilder

effect DeckBuilder
  add_slide(Slide) : Unit

Functions and Values

text

text : (String) -> Layout.Pict

rich_text

rich_text : (List(Layout.Inline)) -> Layout.Pict

para

para : (List(Layout.Inline)) -> Layout.Pict

plain

plain : (String) -> Layout.Inline

emphasis

emphasis : (List(Layout.Inline)) -> Layout.Inline

strong

strong : (List(Layout.Inline)) -> Layout.Inline
link : (String, List(Layout.Inline)) -> Layout.Inline

colored

colored : (String, List(Layout.Inline)) -> Layout.Inline

item_text

item_text : (List(Layout.Inline)) -> Layout.Pict

item

item : (String) -> Layout.Pict

row

row : (Int, List(Layout.Pict)) -> Layout.Pict

column

column : (Int, List(Layout.Pict)) -> Layout.Pict

centered

centered : (Int, List(Layout.Pict)) -> Layout.Pict

overlay

overlay : (List(Layout.Pict)) -> Layout.Pict

inset

inset : (Int, Layout.Pict) -> Layout.Pict

raw_typst

raw_typst : (String) -> Layout.Pict

code_block

code_block : (String, String) -> Layout.Pict

prism_code

prism_code : (String) -> Layout.Pict

inline_code

inline_code : (String) -> Layout.Inline

doctest

doctest : (String) -> Layout.Pict

Every example a reflected declaration’s docstring fences, each over the output the doctest runner proves it prints.

definition

definition : (String) -> Layout.Pict

A reflected declaration with its comment block removed.

read_doc

read_doc : (String) -> Example.Doc

examples_of

examples_of : (String) -> List(Example.Example)

example_pict

example_pict : (Example.Example) -> Layout.Pict

prism_theme

prism_theme : Theme.Theme

paper_theme

paper_theme : Theme.Theme

prism_dark_theme

prism_dark_theme : Theme.Theme

max_stage

max_stage : (Layout.Pict) -> Int

pict_assets

pict_assets : (Layout.Pict) -> List(String)

render_pict

render_pict : (Layout.Pict, Int, Theme.Theme) -> String

render_slide_page

render_slide_page : (Option(String), Layout.Pict, Int, Theme.Theme) -> String

typst_prelude

typst_prelude : (Theme.Theme) -> String

metadata

metadata : (String, String) -> Metadata

make_deck

make_deck : (Metadata, Theme.Theme, List(Slide)) -> Deck

title_slide

title_slide : (String, String) -> Slide

titled_slide

titled_slide : (String, Layout.Pict) -> Slide

pict

pict : (Layout.Pict) -> Unit ! {SlideBuilder}

reveal_next

reveal_next : () -> Unit ! {SlideBuilder}

slide

slide : (String, () -> Unit ! {SlideBuilder}) -> Unit ! {DeckBuilder}

Emit a built slide into the surrounding deck builder.

cover

cover : (String, String) -> Unit ! {DeckBuilder}

Emit a cover slide into the surrounding deck builder.

deck

deck : (Metadata, Theme.Theme, () -> Unit ! {DeckBuilder}) -> Deck

Run the effectful authoring surface into the same pure Deck used by the data-first API.

render_typst

render_typst : (Deck) -> Backend.TypstDocument

Pure, deterministic Typst lowering. Logical slides with reveals expand to one physical PDF page per stage.

envelope

envelope : (Deck) -> String

The exact one-line envelope consumed by the spectra host frontend.

emit_deck

emit_deck : (Deck) -> Unit ! {IO}

Emit exactly one framed envelope. The host rejects any extra output, so a stray debug print can never be interpreted as Typst source.