geom-typst

Text label layer whose label aesthetic is always evaluated as Typst markup.

Sibling of geom-text. Use this when every label string must be interpreted as Typst markup at the call site, without wrapping each column reference in typst.

Usage

geom-typst(
  mapping: none,
  data: none,
  size: 10pt,
  colour: auto,
  font: auto,
  alpha: auto,
  anchor: "center",
  angle: 0deg,
  label: none,
  segment: false,
  segment-colour: auto,
  segment-stroke: 0.4pt,
  min-segment-length: 0.05,
  arrow: false,
  arrow-length: 4pt,
  box-padding: 0.05,
  repel: false,
  point-padding: 0.05,
  max-iter: 100,
  force-pull: 0.1,
  force-push: 0.2,
  force-segment: 0.3,
  seed: 0,
  stat: "identity",
  position: "identity",
  inherit-aes: true,
)

Parameters

Parameter Default Description
mapping none Layer-specific aesthetic mapping built with aes. Must map x and y. Map label to a column when each row carries its own label, or pass label: directly to use a single constant value for every row.
data none Layer-specific dataset, or a function applied to the plot data returning the layer frame. Falls back to the plot data when none.
size 10pt Text size (a Typst length).
colour auto Fixed text colour. auto inherits the theme ink. Used when no colour mapping is active.
font auto Label font family. auto uses the theme text font, then the document font.
alpha auto Text opacity in [0, 1]. auto honours any mapped alpha aesthetic.
anchor "center" CeTZ anchor (e.g., "center", "west") controlling placement.
angle 0deg Rotation applied to each label (a Typst angle, e.g., 45deg). Positive angles rotate anticlockwise about the anchor.
label none Constant label drawn at every row’s (x, y). Accepts a Typst content block ([#math.alpha], [*bold*]) or a markup string ("$alpha$") eval’d as Typst at render time. When none, the label is read from the label aesthetic mapping.
segment false Draw a connector from each label back to its anchor point. When true, the connector is routed to avoid the AABBs of other labels of the same layer; dropped when no L-bend clears the obstacles.
segment-colour auto Connector paint. auto inherits the theme ink.
segment-stroke 0.4pt Connector thickness (a Typst length).
min-segment-length 0.05 Connectors shorter than this distance (canvas units, 1 = 1cm) are suppressed.
arrow false Draw a small V-mark at the anchor end of the connector.
arrow-length 4pt Arrow stroke length (a Typst length).
box-padding 0.05 Extra cm padding around each measured label when routing connectors.
repel false Repel labels off each other (and off their anchor points) via an iterative force-based layout, ggrepel-style. Pair with segment: true to keep the visual link to each anchor.
point-padding 0.05 Minimum clearance (cm) between a label and any anchor point when repel is on.
max-iter 100 Maximum number of repulsion iterations.
force-pull 0.1 Strength of the spring pull that keeps each label near its anchor.
force-push 0.2 Strength of the repulsion between overlapping labels.
force-segment 0.3 Strength of the penalty that pushes a label off another label’s connector path.
seed 0 Random seed for the small initial jitter applied to coincident anchors.
stat "identity" Statistical transform name. Usually "identity".
position "identity" Position adjustment name. Usually "identity".
inherit-aes true Whether to merge the plot-level mapping into this layer’s mapping.

Returns

Layer dictionary consumed by plot.

Examples

Each row’s label column carries Typst markup that is evaluated in place; no typst() wrapper is needed at the call site.

#let d = (
  (x: 1, y: 1, t: "$alpha$"),
  (x: 2, y: 2, t: "*bold*"),
  (x: 3, y: 3, t: "#emph[italic]"),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y", label: "t"),
  layers: (geom-typst(),),
  width: 10cm,
  height: 6cm,
)

Three text labels at (x, y) = (1, 1), (2, 2), (3, 3) showing alpha symbol, bold word, and italic word evaluated from Typst markup.

Three text labels at (x, y) = (1, 1), (2, 2), (3, 3) showing alpha symbol, bold word, and italic word evaluated from Typst markup.

Use a constant content block as the label at every row.

#let d = (
  (x: 1, y: 1),
  (x: 2, y: 2),
  (x: 3, y: 3),
)
#plot(
  data: d,
  mapping: aes(x: "x", y: "y"),
  layers: (geom-typst(label: [#math.alpha]),),
  width: 10cm,
  height: 6cm,
)

Three positions at (1, 1), (2, 2), (3, 3) each labelled with the same constant Greek alpha symbol drawn in place.

Three positions at (1, 1), (2, 2), (3, 3) each labelled with the same constant Greek alpha symbol drawn in place.

See also

geom-text, typst, annotate.

Back to top