Add size: argument for abs, norm, floor, ceil and round (#2292) (#2322)

This commit is contained in:
HydroH 2023-10-06 23:13:38 +08:00 committed by GitHub
parent e7443abfe6
commit b584617c8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,10 +103,13 @@ fn scale(
/// ``` /// ```
#[func] #[func]
pub fn floor( 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. /// The expression to floor.
body: Content, body: Content,
) -> Content { ) -> Content {
delimited(body, '⌊', '⌋') delimited(body, '⌊', '⌋', size)
} }
/// Ceils an expression. /// Ceils an expression.
@ -116,10 +119,13 @@ pub fn floor(
/// ``` /// ```
#[func] #[func]
pub fn ceil( 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. /// The expression to ceil.
body: Content, body: Content,
) -> Content { ) -> Content {
delimited(body, '⌈', '⌉') delimited(body, '⌈', '⌉', size)
} }
/// Rounds an expression. /// Rounds an expression.
@ -129,10 +135,13 @@ pub fn ceil(
/// ``` /// ```
#[func] #[func]
pub fn round( 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. /// The expression to round.
body: Content, body: Content,
) -> Content { ) -> Content {
delimited(body, '⌊', '⌉') delimited(body, '⌊', '⌉', size)
} }
/// Takes the absolute value of an expression. /// Takes the absolute value of an expression.
@ -142,10 +151,13 @@ pub fn round(
/// ``` /// ```
#[func] #[func]
pub fn abs( 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. /// The expression to take the absolute value of.
body: Content, body: Content,
) -> Content { ) -> Content {
delimited(body, '|', '|') delimited(body, '|', '|', size)
} }
/// Takes the norm of an expression. /// Takes the norm of an expression.
@ -155,17 +167,29 @@ pub fn abs(
/// ``` /// ```
#[func] #[func]
pub fn norm( 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. /// The expression to take the norm of.
body: Content, body: Content,
) -> Content { ) -> Content {
delimited(body, '‖', '‖') delimited(body, '‖', '‖', size)
} }
fn delimited(body: Content, left: char, right: char) -> Content { fn delimited(
LrElem::new(Content::sequence([ body: Content,
left: char,
right: char,
size: Option<Smart<Rel<Length>>>,
) -> Content {
let mut elem = LrElem::new(Content::sequence([
TextElem::packed(left), TextElem::packed(left),
body, body,
TextElem::packed(right), TextElem::packed(right),
])) ]));
.pack() // Push size only if size is provided
if let Some(size) = size {
elem.push_size(size);
}
elem.pack()
} }