18  Content and Fragments Reference

See Fragments and Equations for the narrative version.

18.1 place()

typ.place(x, y, body, align: center + horizon)

Places arbitrary content at diagram coordinates; its measured box folds into diagram bounds. align must use physical left/center/right and top/horizon/bottom components — logical start/end is rejected, since diagram coordinates are physical and direction-independent.

18.2 group()

typ.group(dx: 0, dy: 0, scale: 1, rotate: 0deg, pivot: (0, 0), ..items)
Argument Effect
dx, dy Translation, in diagram units.
scale Positive number; resizes node shapes, labels (about pivot), edge strokes, and highlights, in addition to repositioning everything.
rotate Angle, diagram-space math convention; turns positions, deferred relative vectors, Bézier controls, bend: amounts, gate-port attachment directions, and outward endpoint handle directions/strengths about pivot. Deliberately leaves node graphics, labels, and place() content upright.
pivot Numeric (x, y) coordinate the transform is centered on.
..items Positional only — diagram items (or nested group() results) to transform; a named argument here is an error.

group(rotate: angle)’s upright-labels behavior means a node whose shape should visually track the rotation needs its own style: (rotate: -angle) — the sign flips because group angles are diagram-space math convention while a node’s style.rotate is Typst screen convention (see Architecture).

18.3 Diagrams in equations

diagram()’s returned box aligns its y = anchor line (anchor: default 0) to the math axis. Prefix with # inside $ .. $ — required whenever the bound identifier contains a hyphen, since math parses a bare hyphen as subtraction; safe to use unconditionally. math-axis (normally 0.25em) and baseline (auto, or an explicit length) are the lower-level knobs this alignment is built from — see the Diagram Reference.