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

Typst.Value

Typst’s value vocabulary as Prism types.

A length is not a string with a suffix: it is a constructor whose unit is part of the type, an invalid one is unrepresentable, and the rendering owns the spelling in exactly one place. The same holds for colors, alignment, and direction. Every show_* function here produces the literal Typst spelling and nothing else; the Typst root turns these into code expressions.

Types

Length

type Length
  = Pt(Int)
  | Em(Int)
  | Cm(Int)
  | Fr(Int)
  | Percent(Int)
  deriving (Eq, Show)

A length with its unit: points, ems, centimeters, fractions, or percent.

Color

type Color = Rgb(Int, Int, Int) | Luma(Int) deriving (Eq, Show)

A color: an RGB triple or a grayscale luma, each channel 0..255. The renderer clamps out-of-range channels rather than emitting invalid syntax.

Alignment

type Alignment
  = AStart
  | AEnd
  | ALeft
  | ACenter
  | ARight
  | ATop
  | AHorizon
  | ABottom
  deriving (Eq, Show)

A one-axis alignment. Typst’s two-axis alignments compose with + at the call site; this type owns the nine primitive spellings.

Dir

type Dir
  = Ltr
  | Rtl
  | Ttb
  | Btt
  deriving (Eq, Show)

A layout direction.

Functions and Values

show_length

show_length : (Length) -> String

The literal Typst spelling of a length.

show_length(Pt(12))
12pt

show_color

show_color : (Color) -> String

The literal Typst spelling of a color.

show_color(Rgb(109, 40, 217))
rgb(109, 40, 217)

show_alignment

show_alignment : (Alignment) -> String

The literal Typst spelling of an alignment.

show_dir

show_dir : (Dir) -> String

The literal Typst spelling of a direction.