注意 / Info
本站经 Typst GmbH 许可,提供 Typst v0.10.0+后期随缘更新 官方文档的翻译,由中文社区维护。建议与官方文档一同阅读,因为可能存在错译、漏译或过时信息。如有意改进翻译内容或网站本身,可在GitHub上提出 Issue、发起 Pull Requests。此外,也欢迎加入「Typst 非官方中文交流群」(QQ 793548390)
This site provides a Chinese translation of the Typst v0.10.0+后期随缘更新 documentation maintained by the “Typst Chinese Community” with permission from Typst GmbH. We recommend using this alongside the official documentation. We welcome contributions through Issues and Pull Requests on our GitHub repository for both translation improvements and website enhancements. Feel free to join our QQ chat group “Typst 非官方中文交流群” (793548390).
Typst文档简体中文版
v0.10.0+后期随缘更新

Calculation

Module for calculations and processing of numeric values.

These definitions are part of the calc module and not imported by default. In addition to the functions listed below, the calc module also defines the constants pi, tau, e, inf, and nan.

Function

abs

Calculates the absolute value of a numeric value.

#calc.abs(-5) \
#calc.abs(5pt - 2cm) \
#calc.abs(2fr)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The value whose absolute value to calculate.

pow

Raises a value to some exponent.

#calc.pow(2, 3)
Preview

base
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The base of the power.

exponent
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The exponent of the power.

exp

Raises a value to some exponent of e.

calc.exp()->
#calc.exp(1)
Preview

exponent
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The exponent of the power.

sqrt

Calculates the square root of a number.

calc.sqrt()->
#calc.sqrt(16) \
#calc.sqrt(2.5)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose square root to calculate. Must be non-negative.

root

Calculates the real nth root of a number.

If the number is negative, then n must be odd.

calc.root()->
#calc.root(16.0, 4) \
#calc.root(27.0, 3)
Preview

radicand
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The expression to take the root of

index
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

Which root of the radicand to take

sin

Calculates the sine of an angle.

When called with an integer or a float, they will be interpreted as radians.

calc.sin()->
#assert(calc.sin(90deg) == calc.sin(-270deg))
#calc.sin(1.5) \
#calc.sin(90deg)
Preview

angle
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The angle whose sine to calculate.

cos

Calculates the cosine of an angle.

When called with an integer or a float, they will be interpreted as radians.

calc.cos()->
#calc.cos(90deg) \
#calc.cos(1.5) \
#calc.cos(90deg)
Preview

angle
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The angle whose cosine to calculate.

tan

Calculates the tangent of an angle.

When called with an integer or a float, they will be interpreted as radians.

calc.tan()->
#calc.tan(1.5) \
#calc.tan(90deg)
Preview

angle
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The angle whose tangent to calculate.

asin

Calculates the arcsine of a number.

calc.asin()->
#calc.asin(0) \
#calc.asin(1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose arcsine to calculate. Must be between -1 and 1.

acos

Calculates the arccosine of a number.

calc.acos()->
#calc.acos(0) \
#calc.acos(1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose arcsine to calculate. Must be between -1 and 1.

atan

Calculates the arctangent of a number.

calc.atan()->
#calc.atan(0) \
#calc.atan(1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose arctangent to calculate.

atan2

Calculates the four-quadrant arctangent of a coordinate.

The arguments are (x, y), not (y, x).

calc.atan2()->
#calc.atan2(1, 1) \
#calc.atan2(-2, -3)
Preview

x
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The X coordinate.

y
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The Y coordinate.

sinh

Calculates the hyperbolic sine of a hyperbolic angle.

calc.sinh()->
#calc.sinh(0) \
#calc.sinh(1.5)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The hyperbolic angle whose hyperbolic sine to calculate.

cosh

Calculates the hyperbolic cosine of a hyperbolic angle.

calc.cosh()->
#calc.cosh(0) \
#calc.cosh(1.5)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The hyperbolic angle whose hyperbolic cosine to calculate.

tanh

Calculates the hyperbolic tangent of an hyperbolic angle.

calc.tanh()->
#calc.tanh(0) \
#calc.tanh(1.5)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The hyperbolic angle whose hyperbolic tangent to calculate.

log

Calculates the logarithm of a number.

If the base is not specified, the logarithm is calculated in base 10.

#calc.log(100)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose logarithm to calculate. Must be strictly positive.

base

The base of the logarithm. May not be zero.

默认值:

10

ln

Calculates the natural logarithm of a number.

calc.ln()->
#calc.ln(calc.e)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose logarithm to calculate. Must be strictly positive.

fact

Calculates the factorial of a number.

calc.fact()->
#calc.fact(5)
Preview

number
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number whose factorial to calculate. Must be non-negative.

perm

Calculates a permutation.

Returns the k-permutation of n, or the number of ways to choose k items from a set of n with regard to order.

calc.perm()->
$ "perm"(n, k) &= n!/((n - k)!) \
  "perm"(5, 3) &= #calc.perm(5, 3) $
Preview

base
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The base number. Must be non-negative.

numbers
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number of permutations. Must be non-negative.

binom

Calculates a binomial coefficient.

Returns the k-combination of n, or the number of ways to choose k items from a set of n without regard to order.

calc.binom()->
#calc.binom(10, 5)
Preview

n
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The upper coefficient. Must be non-negative.

k
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The lower coefficient. Must be non-negative.

gcd

Calculates the greatest common divisor of two integers.

calc.gcd()->
#calc.gcd(7, 42)
Preview

a
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The first integer.

b
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The second integer.

lcm

Calculates the least common multiple of two integers.

calc.lcm()->
#calc.lcm(96, 13)
Preview

a
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The first integer.

b
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The second integer.

floor

Rounds a number down to the nearest integer.

If the number is already an integer, it is returned unchanged.

calc.floor()->
#assert(calc.floor(3.14) == 3)
#assert(calc.floor(3) == 3)
#calc.floor(500.1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to round down.

ceil

Rounds a number up to the nearest integer.

If the number is already an integer, it is returned unchanged.

calc.ceil()->
#assert(calc.ceil(3.14) == 4)
#assert(calc.ceil(3) == 3)
#calc.ceil(500.1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to round up.

trunc

Returns the integer part of a number.

If the number is already an integer, it is returned unchanged.

calc.trunc()->
#assert(calc.trunc(3) == 3)
#assert(calc.trunc(-3.7) == -3)
#calc.trunc(15.9)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to truncate.

fract

Returns the fractional part of a number.

If the number is an integer, returns 0.

calc.fract()->
#assert(calc.fract(3) == 0)
#calc.fract(-3.1)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to truncate.

round

Rounds a number to the nearest integer.

Optionally, a number of decimal places can be specified.

#assert(calc.round(3.14) == 3)
#assert(calc.round(3.5) == 4)
#calc.round(3.1415, digits: 2)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to round.

digits

The number of decimal places.

默认值:

0

clamp

Clamps a number between a minimum and maximum value.

#assert(calc.clamp(5, 0, 10) == 5)
#assert(calc.clamp(5, 6, 10) == 6)
#calc.clamp(5, 0, 4)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to clamp.

min
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The inclusive minimum value.

max
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The inclusive maximum value.

min

Determines the minimum of a sequence of values.

calc.min(
any
)->
any
#calc.min(1, -3, -5, 20, 3, 6) \
#calc.min("typst", "in", "beta")
Preview

values
any
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。
变长参数
变长参数
变长参数可以传入多次。

The sequence of values from which to extract the minimum. Must not be empty.

max

Determines the maximum of a sequence of values.

calc.max(
any
)->
any
#calc.max(1, -3, -5, 20, 3, 6) \
#calc.max("typst", "in", "beta")
Preview

values
any
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。
变长参数
变长参数
变长参数可以传入多次。

The sequence of values from which to extract the maximum. Must not be empty.

even

Determines whether an integer is even.

calc.even()->
#calc.even(4) \
#calc.even(5) \
#range(10).filter(calc.even)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to check for evenness.

odd

Determines whether an integer is odd.

calc.odd()->
#calc.odd(4) \
#calc.odd(5) \
#range(10).filter(calc.odd)
Preview

value
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The number to check for oddness.

rem

Calculates the remainder of two numbers.

The value calc.rem(x, y) always has the same sign as x, and is smaller in magnitude than y.

#calc.rem(7, 3) \
#calc.rem(7, -3) \
#calc.rem(-7, 3) \
#calc.rem(-7, -3) \
#calc.rem(1.75, 0.5)
Preview

dividend
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The dividend of the remainder.

divisor
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The divisor of the remainder.

div-euclid

Performs euclidean division of two numbers.

The result of this computation is that of a division rounded to the integer n such that the dividend is greater than or equal to n times the divisor.

calc.div-euclid()->
#calc.div-euclid(7, 3) \
#calc.div-euclid(7, -3) \
#calc.div-euclid(-7, 3) \
#calc.div-euclid(-7, -3) \
#calc.div-euclid(1.75, 0.5)
Preview

dividend
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The dividend of the division.

divisor
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The divisor of the division.

rem-euclid

This calculates the least nonnegative remainder of a division.

Warning: Due to a floating point round-off error, the remainder may equal the absolute value of the divisor if the dividend is much smaller in magnitude than the divisor and the dividend is negative. This only applies for floating point inputs.

calc.rem-euclid()->
#calc.rem-euclid(7, 3) \
#calc.rem-euclid(7, -3) \
#calc.rem-euclid(-7, 3) \
#calc.rem-euclid(-7, -3) \
#calc.rem(1.75, 0.5)
Preview

dividend
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The dividend of the remainder.

divisor
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The divisor of the remainder.

quo

Calculates the quotient (floored division) of two numbers.

calc.quo()->
$ "quo"(a, b) &= floor(a/b) \
  "quo"(14, 5) &= #calc.quo(14, 5) \
  "quo"(3.46, 0.5) &= #calc.quo(3.46, 0.5) $
Preview

dividend
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The dividend of the quotient.

divisor
必需参数
必需参数
必需参数在调用函数时必须传入。
位置参数
位置参数
位置参数按顺序传入,不带参数名。

The divisor of the quotient.

转到官方文档(英文)

搜索