summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHydroH <ixlesis@gmail.com>2023-10-06 23:13:38 +0800
committerGitHub <noreply@github.com>2023-10-06 17:13:38 +0200
commitb584617c8d594cf2ba0ee5d3dd4a042eb65fc4a3 (patch)
tree70edec668f2950cd2a626d0261c00632ef2d1bdb
parente7443abfe681a27ee47993d192f8a82953d43b73 (diff)
Add `size:` argument for `abs`, `norm`, `floor`, `ceil` and `round` (#2292) (#2322)
-rw-r--r--crates/typst-library/src/math/lr.rs42
1 files changed, 33 insertions, 9 deletions
diff --git a/crates/typst-library/src/math/lr.rs b/crates/typst-library/src/math/lr.rs
index 0d3c855e..16696f2e 100644
--- a/crates/typst-library/src/math/lr.rs
+++ b/crates/typst-library/src/math/lr.rs
@@ -103,10 +103,13 @@ fn scale(
/// ```
#[func]
pub fn floor(
+ /// The size of the brackets, relative to the height of the wrapped content.
+ #[named]
+ size: Option<Smart<Rel<Length>>>,
/// The expression to floor.
body: Content,
) -> Content {
- delimited(body, '⌊', '⌋')
+ delimited(body, '⌊', '⌋', size)
}
/// Ceils an expression.
@@ -116,10 +119,13 @@ pub fn floor(
/// ```
#[func]
pub fn ceil(
+ /// The size of the brackets, relative to the height of the wrapped content.
+ #[named]
+ size: Option<Smart<Rel<Length>>>,
/// The expression to ceil.
body: Content,
) -> Content {
- delimited(body, '⌈', '⌉')
+ delimited(body, '⌈', '⌉', size)
}
/// Rounds an expression.
@@ -129,10 +135,13 @@ pub fn ceil(
/// ```
#[func]
pub fn round(
+ /// The size of the brackets, relative to the height of the wrapped content.
+ #[named]
+ size: Option<Smart<Rel<Length>>>,
/// The expression to round.
body: Content,
) -> Content {
- delimited(body, '⌊', '⌉')
+ delimited(body, '⌊', '⌉', size)
}
/// Takes the absolute value of an expression.
@@ -142,10 +151,13 @@ pub fn round(
/// ```
#[func]
pub fn abs(
+ /// The size of the brackets, relative to the height of the wrapped content.
+ #[named]
+ size: Option<Smart<Rel<Length>>>,
/// The expression to take the absolute value of.
body: Content,
) -> Content {
- delimited(body, '|', '|')
+ delimited(body, '|', '|', size)
}
/// Takes the norm of an expression.
@@ -155,17 +167,29 @@ pub fn abs(
/// ```
#[func]
pub fn norm(
+ /// The size of the brackets, relative to the height of the wrapped content.
+ #[named]
+ size: Option<Smart<Rel<Length>>>,
/// The expression to take the norm of.
body: Content,
) -> Content {
- delimited(body, '‖', '‖')
+ delimited(body, '‖', '‖', size)
}
-fn delimited(body: Content, left: char, right: char) -> Content {
- LrElem::new(Content::sequence([
+fn delimited(
+ body: Content,
+ left: char,
+ right: char,
+ size: Option<Smart<Rel<Length>>>,
+) -> Content {
+ let mut elem = LrElem::new(Content::sequence([
TextElem::packed(left),
body,
TextElem::packed(right),
- ]))
- .pack()
+ ]));
+ // Push size only if size is provided
+ if let Some(size) = size {
+ elem.push_size(size);
+ }
+ elem.pack()
}