Development build 586e1bd4
Typst文档简体中文版v0.15.1 + dev 586e1bd4

arguments自始可用Go to source

捕获的函数参数。 [⚠️💀]

参数收集器[⚠️]

与内置函数一样,自定义函数也可以接受可变数量的参数。您可以指定一个参数收集器,将所有多余参数收集为..sink。生成的sink值的类型为arguments。它暴露了访问位置参数和「通过名称传入的」(named)参数的方法。 [⚠️]

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

展开[⚠️]

与参数收集器相反,您可以展开参数、数组和字典,使用..spread运算符: [⚠️]

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

构造函数
Question mark
0.10.0起可用Go to source

在原地构造「可展开」(spreadable)的「参数」(argument)。

此函数的行为类似于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

构造的参数。 [⚠️]

定义
Question mark

len0.15.0起可用Go to source

The number of arguments, positional or named.

self.len() → int

at0.12.0起可用Go to source

返回指定索引处的「位置参数」,或具有指定名称的「命名参数」。

如果键是整数,这相当于先调用pos,然后调用array.at。如果是字符串,这相当于先调用named,然后调用dictionary.at[⚠️]

self.at() → any

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

要获取的参数的索引或名称。 [⚠️]

default
any

A default value to return if the key is invalid.

pos自始可用Go to source

将捕获的「位置参数」作为数组返回。 [⚠️]

self.pos() → array

named自始可用Go to source

将捕获的「命名参数」作为「字典」返回。 [⚠️]

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.