Development build 9f2b6e87
Typst文档简体中文版v0.15.1 + dev 9f2b6e87

arguments自始可用Go to source

Captured arguments to a function.

Arguments are either positional or named, and can be accessed through the pos, named, and at methods.

Additionally, named arguments can be accessed with field syntax similar to dictionaries.

Argument Sinks

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.

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

Spreading

Inversely to an argument sink, you can spread arguments, arrays and dictionaries into a function call with the ..spread operator:

#let array = (2, 3, 5) #calc.min(..array) #let dict = (fill: blue) #text(..dict)[Hello]

构造函数
Question mark
Go to source

Construct spreadable arguments in place.

This function behaves like let args(..sink) = sink.

Expand展开示例
#let args = arguments(stroke: red, inset: 1em, [Body]) #box(..args)
arguments(..any) → arguments

arguments
any
必需参数
Question mark
位置参数
Question mark
变长参数
Question mark

The arguments to construct.

函数
Question mark

len0.15.0起可用Go to source

The number of arguments, positional or named.

self.len() → int

at0.12.0起可用Go to source

Returns the positional argument at the specified index, or the named argument with the specified name.

If the key is an integer, this is equivalent to first calling pos and then array.at. If it is a string, this is equivalent to first calling named and then dictionary.at.

Named arguments can also be accessed with field syntax (e.g. arguments(key: 42).key) if no default is needed. Unlike dictionaries, fields on arguments cannot be modified.

self.at() → any

key
int or str
必需参数
Question mark
位置参数
Question mark

The index or name of the argument to get.

default
any

A default value to return if the key is invalid.

pos自始可用Go to source

Returns the captured positional arguments as an array.

self.pos() → array

named自始可用Go to source

Returns the captured named arguments as a dictionary.

self.named() → dictionary

filter0.15.0起可用Go to source

Produces a new arguments with only the arguments for which the value passes the test.

Expand展开示例
#{ arguments(-1, a: 0, b: 1, 2) .filter(v => v > 0) }
self.filter(function) → arguments

test
function
必需参数
Question mark
位置参数
Question mark

The function to apply to each value. Must return a boolean.

map0.15.0起可用Go to source

Produces a new arguments by transforming each argument value with the passed function.

Expand展开示例
#{ arguments(0, a: 1, 2) .map(v => v + 1) }
self.map(function) → arguments

mapper
function
必需参数
Question mark
位置参数
Question mark

The function to apply to each value.