element-typst

Typst-markup text element: same fields as element-text plus automatic Typst-markup evaluation for plain strings reaching this surface.

Drop-in replacement for element-text on any text key. Strings supplied via labs, scale names, or scale labels: callbacks are evaluated as Typst markup before rendering, so users do not need to wrap each value with typst. Per-call typst() and content ([…]) values still pass through unchanged.

Usage

element-typst(
  size: none,
  weight: none,
  colour: none,
  angle: none,
  family: none,
  margin: none,
)

Parameters

Parameter Default Description
size none Text size (a Typst length), or none to inherit.
weight none Font weight (e.g., "regular", "bold"), or none.
colour none Text colour, or none to inherit.
angle none Rotation angle (a Typst angle), or none to inherit.
family none Font family, or none to inherit.
margin none Per-side spacing built with margin. Each side accepts a Typst length (absolute or relative); em is preferred so spacing scales with the surface font size. Sides left at auto fall through to the renderer default. none keeps every side at the default.

Returns

Element dictionary consumed by theme.

Examples

Enable Typst markup for every plot title in a session by setting plot-title: element-typst() on the theme.

#let d = ((x: 1, y: 1), (x: 2, y: 4), (x: 3, y: 9))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  labs: labs(title: "Mean $bar(x)$ over Time"),
  theme: theme(plot-title: element-typst(size: 14pt, weight: "bold")),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x titled \"Mean x-bar over Time\" with the title rendered as 14pt bold Typst markup including a math glyph.

Scatter plot of y against x titled \"Mean x-bar over Time\" with the title rendered as 14pt bold Typst markup including a math glyph.

Mix typst and non-typst surfaces in the same theme:

#let d = ((x: 1, y: 1), (x: 2, y: 4), (x: 3, y: 9))
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-point(size: 2pt),),
  labs: labs(title: "Mean $bar(x)$", x: "Time (s)"),
  theme: theme(
    plot-title: element-typst(),
    axis-title: element-text(),
  ),
  width: 10cm,
  height: 6cm,
)

Scatter plot of y against x with a Typst-evaluated plot title rendering math glyphs while the axis titles stay as plain text.

Scatter plot of y against x with a Typst-evaluated plot title rendering math glyphs while the axis titles stay as plain text.

See also

theme, element-text, typst, margin.

Back to top