Skip to main content

content

content() 

Positions Typst content in the canvas. Note that the content itself is not transformed only its position is.

To put text on a line you can let the function calculate the angle between its position and a second coordinate by passing it to angle:

Styling

Root: content

Anchors

Supports border anchors, the default anchor is set to center.

mid
Content center, from baseline to top bounds
mid-east
Content center extended to the east
mid-west
Content center extended to the west
base
Horizontally centered baseline of the content
base-east
Baseline height extended to the east
base-west
Baseline height extended to the west
text
Position at the content start on the baseline of the content
content((0,0), [Hello World!])
line((0, 0), (3, 1), name: "line")
content(
("line.start", 50%, "line.end"),
angle: "line.end",
padding: .1,
anchor: "south",
[Text on a line]
)
// Place content in a rect between two coordinates
content(
(0, 0),
(2, 2),
box(
par(justify: false)[This is a long text.],
stroke: 1pt,
width: 100%,
height: 100%,
inset: 1em
)
)

..args-style:

When one coordinate is given as a positional argument, the content will be placed at that position. When two coordinates are given as positional arguments, the content will be placed inside a rectangle between the two positions. All named arguments are styling and any additional positional arguments will panic.

Rotates the content by the given angle. A coordinate can be given to rotate the content by the angle between it and the first coordinate given in args. This effectively points the right hand side of the content towards the coordinate. This currently exists because Typst’s rotate function does not change the width and height of content.

anchor:

none or str

name:

none or str

padding:

Default: 0

Sets the spacing around content. Can be a single number to set padding on all sides or a dictionary to specify each side specifically. The dictionary follows Typst’s pad function: https://typst.app/docs/reference/layout/pad/

frame:

str or none
Default: none

Sets the frame style. Can be none, "rect" or "circle" and inherits the stroke and fill style.

auto-scale:

If true, apply current canvas scaling to the content. Defaults to false.

wrap:

Default: none

A function to apply the content body to. Must return content. Example: text.with(red) to wrap every content element in a text(red, <body>) element.