diff --git a/README.md b/README.md index 132a92cd0..0c1e95fd7 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ A [gentle introduction][tutorial] to Typst is available in our documentation. However, if you want to see the power of Typst encapsulated in one image, here it is:

- Example + Example

@@ -78,13 +78,13 @@ Let's dissect what's going on: = Fibonacci sequence The Fibonacci sequence is defined through the - _recurrence relation_ $F_n = F_(n-1) + F_(n-2)$. - It can also be expressed in closed form: + recurrence relation $F_n = F_(n-1) + F_(n-2)$. + It can also be expressed in _closed form:_ - $ F_n = floor(1 / sqrt(5) phi.alt^n), quad + $ F_n = round(1 / sqrt(5) phi.alt^n), quad phi.alt = (1 + sqrt(5)) / 2 $ - #let count = 10 + #let count = 8 #let nums = range(1, count + 1) #let fib(n) = ( if n <= 2 { 1 } diff --git a/docs/src/general/changelog.md b/docs/src/general/changelog.md index ecb23efea..be1cdc370 100644 --- a/docs/src/general/changelog.md +++ b/docs/src/general/changelog.md @@ -18,11 +18,12 @@ description: | - Fixed [matrices]($func/mat) with explicit delimiter - Fixed build of CLI if `git` is not installed - Links in bibliographies are now affected by link styling - `[#counter(..).update(0)]` - Added support for disabling [matrix]($func/mat) and [vector]($func/vec) delimiters. Generally with `[#set math.mat(delim: none)]` or one-off with `[$mat(delim: #none, 1, 2; 3, 4)$]`. +- Added [`round`]($func/round) function for equations - Numberings now allow zeros. To reset a counter, you can write + `[#counter(..).update(0)]` - Added `--font-path` argument for CLI - Added Nix flake - Numerous documentation fixes diff --git a/library/src/math/delimited.rs b/library/src/math/delimited.rs index 3be17eae3..fe7d2d1ef 100644 --- a/library/src/math/delimited.rs +++ b/library/src/math/delimited.rs @@ -141,6 +141,24 @@ pub fn ceil( delimited(body, '⌈', '⌉') } +/// Round an expression. +/// +/// ## Example +/// ```example +/// $ round(x/2) $ +/// ``` +/// +/// Display: Round +/// Category: math +/// Returns: content +#[func] +pub fn round( + /// The expression to round. + body: Content, +) -> Value { + delimited(body, '⌊', '⌉') +} + /// Take the absolute value of an expression. /// /// ## Example diff --git a/library/src/math/mod.rs b/library/src/math/mod.rs index 4e91dd51c..b4a5b1567 100644 --- a/library/src/math/mod.rs +++ b/library/src/math/mod.rs @@ -57,6 +57,7 @@ pub fn module() -> Module { math.define("norm", norm); math.define("floor", floor); math.define("ceil", ceil); + math.define("round", round); // Attachments and accents. math.define("attach", AttachElem::func()); diff --git a/tests/ref/math/numbering.png b/tests/ref/math/numbering.png index a06e2b0c8..72abfed6b 100644 Binary files a/tests/ref/math/numbering.png and b/tests/ref/math/numbering.png differ diff --git a/tests/typ/math/numbering.typ b/tests/typ/math/numbering.typ index 71049a09d..fd303ff29 100644 --- a/tests/typ/math/numbering.typ +++ b/tests/typ/math/numbering.typ @@ -8,4 +8,4 @@ We define $x$ in preparation of @fib: $ phi.alt := (1 + sqrt(5)) / 2 $ With @ratio, we get -$ F_n = floor(1 / sqrt(5) phi.alt^n) $ +$ F_n = round(1 / sqrt(5) phi.alt^n) $