Info
This site is generated using the static site generator developed by the Typst Community. Please adjust the text content of this banner according to your usage requirements. At Typst GmbH's request, when publishing documentation, you must clearly indicate that it is non-official and display the version of Typst being documented. For details, refer to Issue #874 on typst/typst.
TypstDocumentEnglish
v0.dev.2025-09-12

measure
Context
Context
Context functions can only be used when the context is known.

Measures the layouted size of content.

The measure function lets you determine the layouted size of content. By default an infinite space is assumed, so the measured dimensions may not necessarily match the final dimensions of the content. If you want to measure in the current layout dimensions, you can combine measure and layout.

Example

The same content can have a different size depending on the context that it is placed into. In the example below, the #content is of course bigger when we increase the font size.

#let content = [Hello!]
#content
#set text(14pt)
#content
Preview

For this reason, you can only measure when context is available.

#let thing(body) = context {
  let size = measure(body)
  [Width of "#body" is #size.width]
}

#thing[Hey] \
#thing[Welcome]
Preview

The measure function returns a dictionary with the entries width and height, both of type length.

Parameter
Parameter
Parameters are input values for functions. Specify them in parentheses after the function name.

width

The width available to layout the content.

Setting this to auto indicates infinite available width.

Note that using the width and height parameters of this function is different from measuring a sized block containing the content. In the following example, the former will get the dimensions of the inner content instead of the dimensions of the block.

Default value:

auto

Show example
#context measure(lorem(100), width: 400pt)

#context measure(block(lorem(100), width: 400pt))
Preview

height

The height available to layout the content.

Setting this to auto indicates infinite available height.

Default value:

auto

content
Required
Required
Required parameters must be specified when calling the function.
Positional
Positional
Positional parameters can be set by specifying them in order, omitting the parameter name.

The content whose size to measure.

Open official docs

Search