TypstDocumentation

arguments

Captured arguments to a function.

Like built-in functions, custom functions can also take a variable number of arguments. You can specify an argument sink which collects all excess arguments as ..sink. The resulting sink value is of the arguments type. It exposes methods to access the positional and named arguments and is iterable with a for loop. Inversely, you can spread arguments, arrays and dictionaries into a function call with the spread operator: func(..args).

Example

#let format(title, ..authors) = [
  *#title* \
  _Written by #(authors
    .pos()
    .join(", ", last: " and "));._
]

#format("ArtosFlow", "Jane", "Joe")
Preview

Methods
Question mark

pos method

Returns the captured positional arguments as an array.

value.pos(
) -> array

named method

Returns the captured named arguments as a dictionary.

value.named(
) -> dictionary