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

Layout

Backend-neutral layout values for Spectra.

These constructors describe intent. They deliberately contain no measured coordinates or Typst-specific layout state; a Pict is plain data a backend interprets later, which is why building one needs no effects and shows as the constructors it is made of:

fn main() = println(show(column(8, [text("hi")])))
Layout.Column(8, Layout.Left, [Layout.Text(Layout.TextStyle { size = 0, color = "", align = Layout.Left }, [Layout.Plain("hi")])])

Types

Align

type Align = Left | Center | Right deriving (Eq, Show)

Horizontal alignment of a picture’s children.

FitMode

type FitMode = Contain | Cover deriving (Eq, Show)

How a picture fills the box it is fitted into: letterboxed inside it, or filling it and cropping the overflow.

Inline

type Inline
  = Plain(String)
  | Emphasis(List(Inline))
  | Strong(List(Inline))
  | InlineCode(String)
  | Link(String, List(Inline))
  | Colored(String, List(Inline))
  deriving (Eq, Show)

A span of inline text: plain characters, an emphasis or strength wrapper, inline code, a link, or a color role.

TextStyle

type TextStyle = TextStyle {
  size: Int,
  color: String,
  align: Align
} deriving (Eq, Show)

The type settings of a text picture. A size of zero and an empty color both mean “whatever the theme says”.

Pict

type Pict
  = Empty
  | Text(TextStyle, List(Inline))
  | CodeBlock(String, String)
  | Image(String)
  | Rectangle(String, Int, Int)
  | Row(Int, List(Pict))
  | Column(Int, Align, List(Pict))
  | Overlay(List(Pict))
  | Inset(Int, Int, Int, Int, Pict)
  | Fit(FitMode, Pict)
  | Fragment(Int, Pict)
  | RawTypst(String)
  deriving (Eq, Show)

A picture: the layout intent of one region of a slide, as plain data a backend interprets later.

Functions and Values

text

text : (String) -> Pict

Normal body text in the theme foreground. A size of zero means “theme body size” to the renderer.

rich_text

rich_text : (List(Inline)) -> Pict

Rich inline text in the theme foreground.

para

para : (List(Inline)) -> Pict

A paragraph-sized inline sequence. This is an authoring synonym for rich_text, retained because it reads naturally inside a slide builder.

item_text

item_text : (List(Inline)) -> Pict

A bullet item rendered as an accent arrow and rich inline text.

item

item : (String) -> Pict

A plain bullet item.

row

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

Children laid out left to right, gap points apart.

column

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

Children laid out top to bottom, gap points apart, left aligned.

centered

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

Children laid out top to bottom, gap points apart, centered.

overlay

overlay : (List(Pict)) -> Pict

Children stacked on one another, first at the back.

inset

inset : (Int, Pict) -> Pict

A child padded by all points on every side.

raw_typst

raw_typst : (String) -> Pict

Typst source admitted verbatim, escaping nothing.