From 08f1d93f9e8dffa0631403482645756ab8f6e9cc Mon Sep 17 00:00:00 2001 From: mkorje Date: Fri, 25 Apr 2025 22:14:57 +1000 Subject: [PATCH] Allow a function as an argument to `size` in `stretch` and `lr` Previously there was always a short fall when scaling delimiters, even if the user requested a specific size. This is no longer the case; the short fall is only present in the default for `lr` (`x => x - 0.1em`) - the size of the delimiters is now actually what was specified in the size argument. This also makes the default for `lr` much clearer to the user. A slight hack was used by exploiting the `name` property in the `func` attribute macro so that the default value in the docs for `lr.size` would clearly show what the default function was (instead of just its name `default_lr_size` which is meaningless and inaccessible to the user). --- crates/typst-layout/src/math/attach.rs | 13 +-- crates/typst-layout/src/math/lr.rs | 50 +++++---- crates/typst-layout/src/math/stretch.rs | 32 +++--- crates/typst-library/src/math/attach.rs | 28 ----- crates/typst-library/src/math/lr.rs | 68 +++++++++--- crates/typst-library/src/math/mod.rs | 2 + crates/typst-library/src/math/stretch.rs | 125 +++++++++++++++++++++++ tests/ref/math-lr-size-function.png | Bin 0 -> 603 bytes tests/ref/math-stretch-function.png | Bin 0 -> 291 bytes tests/suite/math/attach.typ | 2 +- tests/suite/math/delimited.typ | 23 +++-- tests/suite/math/stretch.typ | 6 ++ 12 files changed, 252 insertions(+), 97 deletions(-) create mode 100644 crates/typst-library/src/math/stretch.rs create mode 100644 tests/ref/math-lr-size-function.png create mode 100644 tests/ref/math-stretch-function.png diff --git a/crates/typst-layout/src/math/attach.rs b/crates/typst-layout/src/math/attach.rs index 78b6f5515..7bb4cf319 100644 --- a/crates/typst-layout/src/math/attach.rs +++ b/crates/typst-layout/src/math/attach.rs @@ -1,8 +1,9 @@ use typst_library::diag::SourceResult; use typst_library::foundations::{Packed, StyleChain, SymbolElem}; -use typst_library::layout::{Abs, Axis, Corner, Frame, Point, Rel, Size}; +use typst_library::layout::{Abs, Axis, Corner, Frame, Point, Size}; use typst_library::math::{ AttachElem, EquationElem, LimitsElem, PrimesElem, ScriptsElem, StretchElem, + StretchSize, }; use typst_utils::OptionExt; @@ -66,12 +67,12 @@ pub fn layout_attach( let relative_to_width = measure!(t, width).max(measure!(b, width)); stretch_fragment( ctx, + styles, &mut base, Some(Axis::X), Some(relative_to_width), - stretch, - Abs::zero(), - ); + &stretch, + )?; } let fragments = [ @@ -154,7 +155,7 @@ pub fn layout_limits( } /// Get the size to stretch the base to. -fn stretch_size(styles: StyleChain, elem: &Packed) -> Option> { +fn stretch_size(styles: StyleChain, elem: &Packed) -> Option { // Extract from an EquationElem. let mut base = &elem.base; while let Some(equation) = base.to_packed::() { @@ -162,7 +163,7 @@ fn stretch_size(styles: StyleChain, elem: &Packed) -> Option() - .map(|stretch| stretch.size.resolve(styles)) + .map(|stretch| stretch.size.get_cloned(styles)) } /// Lay out the attachments. diff --git a/crates/typst-layout/src/math/lr.rs b/crates/typst-layout/src/math/lr.rs index 2348025e8..cdb44899f 100644 --- a/crates/typst-layout/src/math/lr.rs +++ b/crates/typst-layout/src/math/lr.rs @@ -1,11 +1,11 @@ use typst_library::diag::SourceResult; use typst_library::foundations::{Packed, StyleChain}; -use typst_library::layout::{Abs, Axis, Rel}; -use typst_library::math::{EquationElem, LrElem, MidElem}; +use typst_library::layout::{Abs, Axis}; +use typst_library::math::{EquationElem, LrElem, MidElem, StretchSize}; use typst_utils::SliceExt; use unicode_math_class::MathClass; -use super::{stretch_fragment, MathContext, MathFragment, DELIM_SHORT_FALL}; +use super::{stretch_fragment, MathContext, MathFragment}; /// Lays out an [`LrElem`]. #[typst_macros::time(name = "math.lr", span = elem.span())] @@ -22,7 +22,7 @@ pub fn layout_lr( // Extract implicit LrElem. if let Some(lr) = body.to_packed::() { - if lr.size.get(styles).is_one() { + if lr.size.get_ref(styles).is_lr_default() { body = &lr.body; } } @@ -41,14 +41,28 @@ pub fn layout_lr( .unwrap_or_default(); let relative_to = 2.0 * max_extent; - let height = elem.size.resolve(styles); + let height = elem.size.get_ref(styles); // Scale up fragments at both ends. match inner_fragments { - [one] => scale_if_delimiter(ctx, one, relative_to, height, None), + [one] => scale_if_delimiter(ctx, styles, one, relative_to, height, None)?, [first, .., last] => { - scale_if_delimiter(ctx, first, relative_to, height, Some(MathClass::Opening)); - scale_if_delimiter(ctx, last, relative_to, height, Some(MathClass::Closing)); + scale_if_delimiter( + ctx, + styles, + first, + relative_to, + height, + Some(MathClass::Opening), + )?; + scale_if_delimiter( + ctx, + styles, + last, + relative_to, + height, + Some(MathClass::Closing), + )?; } [] => {} } @@ -58,7 +72,7 @@ pub fn layout_lr( if let MathFragment::Glyph(ref mut glyph) = fragment { if glyph.mid_stretched == Some(false) { glyph.mid_stretched = Some(true); - scale(ctx, fragment, relative_to, height); + scale(ctx, styles, fragment, relative_to, height)?; } } } @@ -112,32 +126,32 @@ pub fn layout_mid( /// it is a delimiter, in a way that cannot be overridden by the user. fn scale_if_delimiter( ctx: &mut MathContext, + styles: StyleChain, fragment: &mut MathFragment, relative_to: Abs, - height: Rel, + height: &StretchSize, apply: Option, -) { +) -> SourceResult<()> { if matches!( fragment.class(), MathClass::Opening | MathClass::Closing | MathClass::Fence ) { - scale(ctx, fragment, relative_to, height); + scale(ctx, styles, fragment, relative_to, height)?; if let Some(class) = apply { fragment.set_class(class); } } + Ok(()) } /// Scales a math fragment to a height. fn scale( ctx: &mut MathContext, + styles: StyleChain, fragment: &mut MathFragment, relative_to: Abs, - height: Rel, -) { - // This unwrap doesn't really matter. If it is None, then the fragment - // won't be stretchable anyways. - let short_fall = DELIM_SHORT_FALL.at(fragment.font_size().unwrap_or_default()); - stretch_fragment(ctx, fragment, Some(Axis::Y), Some(relative_to), height, short_fall); + height: &StretchSize, +) -> SourceResult<()> { + stretch_fragment(ctx, styles, fragment, Some(Axis::Y), Some(relative_to), height) } diff --git a/crates/typst-layout/src/math/stretch.rs b/crates/typst-layout/src/math/stretch.rs index f1a22a814..2af491812 100644 --- a/crates/typst-layout/src/math/stretch.rs +++ b/crates/typst-layout/src/math/stretch.rs @@ -1,7 +1,7 @@ use typst_library::diag::{warning, SourceResult}; use typst_library::foundations::{Packed, StyleChain}; -use typst_library::layout::{Abs, Axis, Rel}; -use typst_library::math::StretchElem; +use typst_library::layout::{Abs, Axis}; +use typst_library::math::{StretchElem, StretchSize}; use typst_utils::Get; use super::{stretch_axes, MathContext, MathFragment}; @@ -14,14 +14,7 @@ pub fn layout_stretch( styles: StyleChain, ) -> SourceResult<()> { let mut fragment = ctx.layout_into_fragment(&elem.body, styles)?; - stretch_fragment( - ctx, - &mut fragment, - None, - None, - elem.size.resolve(styles), - Abs::zero(), - ); + stretch_fragment(ctx, styles, &mut fragment, None, None, elem.size.get_ref(styles))?; ctx.push(fragment); Ok(()) } @@ -29,29 +22,29 @@ pub fn layout_stretch( /// Attempts to stretch the given fragment by/to the amount given in stretch. pub fn stretch_fragment( ctx: &mut MathContext, + styles: StyleChain, fragment: &mut MathFragment, axis: Option, relative_to: Option, - stretch: Rel, - short_fall: Abs, -) { + stretch: &StretchSize, +) -> SourceResult<()> { let size = fragment.size(); - let MathFragment::Glyph(ref mut glyph) = fragment else { return }; + let MathFragment::Glyph(ref mut glyph) = fragment else { return Ok(()) }; // Return if we attempt to stretch along an axis which isn't stretchable, // so that the original fragment isn't modified. let axes = stretch_axes(&glyph.item.font, glyph.base_glyph.id); let stretch_axis = if let Some(axis) = axis { if !axes.get(axis) { - return; + return Ok(()); } axis } else { match (axes.x, axes.y) { (true, false) => Axis::X, (false, true) => Axis::Y, - (false, false) => return, + (false, false) => return Ok(()), (true, true) => { // As far as we know, there aren't any glyphs that have both // vertical and horizontal constructions. So for the time being, we @@ -62,16 +55,19 @@ pub fn stretch_fragment( hint: "this is probably a font bug"; hint: "please file an issue at https://github.com/typst/typst/issues" )); - return; + return Ok(()); } } }; let relative_to_size = relative_to.unwrap_or_else(|| size.get(stretch_axis)); + let target = stretch.resolve(ctx.engine, styles, relative_to_size)?; - glyph.stretch(ctx, stretch.relative_to(relative_to_size) - short_fall, stretch_axis); + glyph.stretch(ctx, target, stretch_axis); if stretch_axis == Axis::Y { glyph.center_on_axis(); } + + Ok(()) } diff --git a/crates/typst-library/src/math/attach.rs b/crates/typst-library/src/math/attach.rs index 0dda1d33d..95b8ecbcf 100644 --- a/crates/typst-library/src/math/attach.rs +++ b/crates/typst-library/src/math/attach.rs @@ -1,5 +1,4 @@ use crate::foundations::{elem, Content, Packed}; -use crate::layout::{Length, Rel}; use crate::math::{EquationElem, Mathy}; /// A base with optional attachments. @@ -128,30 +127,3 @@ pub struct LimitsElem { #[default(true)] pub inline: bool, } - -/// Stretches a glyph. -/// -/// This function can also be used to automatically stretch the base of an -/// attachment, so that it fits the top and bottom attachments. -/// -/// Note that only some glyphs can be stretched, and which ones can depend on -/// the math font being used. However, most math fonts are the same in this -/// regard. -/// -/// ```example -/// $ H stretch(=)^"define" U + p V $ -/// $ f : X stretch(->>, size: #150%)_"surjective" Y $ -/// $ x stretch(harpoons.ltrb, size: #3em) y -/// stretch(\[, size: #150%) z $ -/// ``` -#[elem(Mathy)] -pub struct StretchElem { - /// The glyph to stretch. - #[required] - pub body: Content, - - /// The size to stretch to, relative to the maximum size of the glyph and - /// its attachments. - #[default(Rel::one())] - pub size: Rel, -} diff --git a/crates/typst-library/src/math/lr.rs b/crates/typst-library/src/math/lr.rs index 5f5cb8616..ff234167e 100644 --- a/crates/typst-library/src/math/lr.rs +++ b/crates/typst-library/src/math/lr.rs @@ -1,6 +1,16 @@ -use crate::foundations::{elem, func, Content, NativeElement, SymbolElem}; -use crate::layout::{Length, Rel}; -use crate::math::Mathy; +use crate::foundations::{elem, func, Content, NativeElement, NativeFunc, SymbolElem}; +use crate::layout::{Em, Length, Ratio, Rel}; +use crate::math::{Mathy, StretchSize}; + +const DELIM_SHORT_FALL: Em = Em::new(-0.1); + +#[func(name = "x => x - 0.1em")] +pub const fn default_lr_size(base: Length) -> Rel { + Rel { + rel: Ratio::zero(), + abs: Length { abs: base.abs, em: DELIM_SHORT_FALL }, + } +} /// Scales delimiters. /// @@ -8,9 +18,13 @@ use crate::math::Mathy; /// unmatched delimiters and to control the delimiter scaling more precisely. #[elem(title = "Left/Right", Mathy)] pub struct LrElem { - /// The size of the brackets, relative to the height of the wrapped content. - #[default(Rel::one())] - pub size: Rel, + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. + #[default(::data().into())] + pub size: StretchSize, /// The delimited content, including the delimiters. #[required] @@ -42,9 +56,13 @@ pub struct MidElem { /// ``` #[func] pub fn floor( - /// The size of the brackets, relative to the height of the wrapped content. + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. #[named] - size: Option>, + size: Option, /// The expression to floor. body: Content, ) -> Content { @@ -58,9 +76,13 @@ pub fn floor( /// ``` #[func] pub fn ceil( - /// The size of the brackets, relative to the height of the wrapped content. + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. #[named] - size: Option>, + size: Option, /// The expression to ceil. body: Content, ) -> Content { @@ -74,9 +96,13 @@ pub fn ceil( /// ``` #[func] pub fn round( - /// The size of the brackets, relative to the height of the wrapped content. + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. #[named] - size: Option>, + size: Option, /// The expression to round. body: Content, ) -> Content { @@ -90,9 +116,13 @@ pub fn round( /// ``` #[func] pub fn abs( - /// The size of the brackets, relative to the height of the wrapped content. + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. #[named] - size: Option>, + size: Option, /// The expression to take the absolute value of. body: Content, ) -> Content { @@ -106,9 +136,13 @@ pub fn abs( /// ``` #[func] pub fn norm( - /// The size of the brackets, relative to the height of the wrapped content. + /// The size of the delimiters, relative to the height of the wrapped + /// content. + /// + /// See the [stretch documentation]($math.stretch.size) for more + /// information on sizes. #[named] - size: Option>, + size: Option, /// The expression to take the norm of. body: Content, ) -> Content { @@ -119,7 +153,7 @@ fn delimited( body: Content, left: char, right: char, - size: Option>, + size: Option, ) -> Content { let span = body.span(); let mut elem = LrElem::new(Content::sequence([ diff --git a/crates/typst-library/src/math/mod.rs b/crates/typst-library/src/math/mod.rs index 2e6d42b13..4f4bbb03b 100644 --- a/crates/typst-library/src/math/mod.rs +++ b/crates/typst-library/src/math/mod.rs @@ -9,6 +9,7 @@ mod lr; mod matrix; mod op; mod root; +mod stretch; mod style; mod underover; @@ -21,6 +22,7 @@ pub use self::lr::*; pub use self::matrix::*; pub use self::op::*; pub use self::root::*; +pub use self::stretch::*; pub use self::style::*; pub use self::underover::*; diff --git a/crates/typst-library/src/math/stretch.rs b/crates/typst-library/src/math/stretch.rs new file mode 100644 index 000000000..847127d4b --- /dev/null +++ b/crates/typst-library/src/math/stretch.rs @@ -0,0 +1,125 @@ +use comemo::Track; + +use crate::diag::{At, SourceResult}; +use crate::engine::Engine; +use crate::foundations::{ + cast, elem, Content, Context, Func, NativeFunc, NativeFuncData, Resolve, StyleChain, +}; +use crate::layout::{Abs, Rel}; +use crate::math::{default_lr_size, Mathy}; + +/// Stretches a glyph. +/// +/// This function can also be used to automatically stretch the base of an +/// attachment, so that it fits the top and bottom attachments. +/// +/// Note that only some glyphs can be stretched, and which ones can depend on +/// the math font being used. However, most math fonts are the same in this +/// regard. +/// +/// ```example +/// $ H stretch(=)^"define" U + p V $ +/// $ f : X stretch(->>, size: #150%)_"surjective" Y $ +/// $ x stretch(harpoons.ltrb, size: #3em) y +/// stretch(\[, size: #150%) z $ +/// ``` +#[elem(Mathy)] +pub struct StretchElem { + /// The glyph to stretch. + #[required] + pub body: Content, + + /// The size to stretch to, relative to the maximum size of the glyph and + /// its attachments. + /// + /// This value can be given as a [relative length]($relative), or a + /// [function]($function) that receives the size of the glyph as a + /// parameter (an absolute length) and should return a (relative) length. + /// For example, `{x => x * 80%}` would be equivalent to just specifying `{80%}`. + /// + /// Note that the sizes of glyphs in math fonts come about in two ways: + /// + /// - First, there are pre-made variants at specific sizes. This means you + /// will see discrete jumps in the stretched glyph's size as you increase + /// the size parameter. It is up to the font how many pre-made variants + /// there are and what their sizes are. + /// + /// - Then, if the pre-made variants are all too small, a glyph of the + /// desired size is assembled from parts. The stretched glyph's size will + /// now be the exact size requested. + /// + /// It could be the case that only one of the above exist for a glyph in + /// the font. + /// + /// The value given here is really a minimum (but if there is no assembly + /// for the glyph, this minimum may not be reached), so the actual size of + /// the stretched glyph may not match what you specified. + /// + /// ```example + /// #for i in range(0, 15) { + /// $stretch(\[, size: #(10pt + i * 2pt))$ + /// } + /// + /// #set math.stretch(size: x => x + 0.5em) + /// $x stretch(=)^"def" y$ + /// ``` + #[default(Rel::one().into())] + pub size: StretchSize, +} + +/// How to size a stretched glyph. +#[derive(Debug, Clone, PartialEq, Hash)] +pub enum StretchSize { + /// Sized by the specified length. + Rel(Rel), + /// Resolve the size for the given base size through the specified + /// function. + Func(Func), +} + +impl StretchSize { + /// Resolve the stretch size given the base size. + pub fn resolve( + &self, + engine: &mut Engine, + styles: StyleChain, + base: Abs, + ) -> SourceResult { + Ok(match self { + Self::Rel(rel) => *rel, + Self::Func(func) => func + .call(engine, Context::new(None, Some(styles)).track(), [base])? + .cast() + .at(func.span())?, + } + .resolve(styles) + .relative_to(base)) + } + + /// Whether the size is the default used by `LrElem`. + pub fn is_lr_default(&self) -> bool { + *self == ::data().into() + } +} + +impl From for StretchSize { + fn from(rel: Rel) -> Self { + Self::Rel(rel) + } +} + +impl From<&'static NativeFuncData> for StretchSize { + fn from(data: &'static NativeFuncData) -> Self { + Self::Func(Func::from(data)) + } +} + +cast! { + StretchSize, + self => match self { + Self::Rel(v) => v.into_value(), + Self::Func(v) => v.into_value(), + }, + v: Rel => Self::Rel(v), + v: Func => Self::Func(v), +} diff --git a/tests/ref/math-lr-size-function.png b/tests/ref/math-lr-size-function.png new file mode 100644 index 0000000000000000000000000000000000000000..437bed04650d8905e54ee3dc116c55131fa3ade2 GIT binary patch literal 603 zcmV-h0;K(kP)L7!9!gtvIwn&JYh`F6_cC z?7~uTuC)L__^vSAl$aS^!=i9c(4M<~3c^#HO8aG-Al&)T5p@|cI9KVc-jiZ*w9#3U z9x=GRU&+d}6ufFo$(CzEusJ)Ubk_lEeeSK-3BRAGc5q8+dv(H3J!+45h2WdDYL6`y zf`fHxzg{8)A6cyS{W$M0GGR4Cqk7;|E7X2G7of#% z%vL?{p#=aKzP{!Hz@1sZk7i0|n;!VaMgZC#Q3F7t0(f&8jPUds0h;u{J=FksimCm1 zfY?GHbpmp+>5~8&wchFmIszg4R{wTlTlK(as{r_L@7;9+;MshDg8<2a43Ir4`8b8% z!th{x%{RD}(gXKxQ2SK{0RAGrtLzxydp~;MW6RVYEC;~&0^m)P2Kkr7xe%ZW4%Mg~ zUvAH#C`ow`ZoQoDP*wZs}%gC!CC3GNWrX|a>S+ca&W-!h3IME002ovPDHLkV1nF?8sq=~ literal 0 HcmV?d00001 diff --git a/tests/ref/math-stretch-function.png b/tests/ref/math-stretch-function.png new file mode 100644 index 0000000000000000000000000000000000000000..8e1daa46ce75ce760822f770c986b6667088e28b GIT binary patch literal 291 zcmV+;0o?wHP)MSv+CXV)|NqVxTOZO*4z%4wS_e17q>O_M-!1@j=D5wzkZ+ob0y1 zwu1Dwj8-7`7+r$;%+!I3V?q`Wv+Q)?$-r2Af5j~X=kMA7+y7!%{F){fFYGydWY>l5 zn>YS`wdcyzt`8Ic-8}N(?DB1|Xb9WBy zEq>d7c=_42+YaabeQ|up)s~-i|I2?gKAZuPTuMWWcdq)sdGowIYc}qDaq#ZHweM!$ py1ehs002ovPDHLkV1kUKl9vDg literal 0 HcmV?d00001 diff --git a/tests/suite/math/attach.typ b/tests/suite/math/attach.typ index 979018478..a058ea425 100644 --- a/tests/suite/math/attach.typ +++ b/tests/suite/math/attach.typ @@ -187,5 +187,5 @@ $ a0 + a1 + a0_2 \ --- math-attach-scripts-extended-shapes --- // Test script attachments positioning if the base is an extended shape (or a // sequence of extended shapes). -$lr(size: #130%, [x])_0^1, [x]_0^1, \]_0^1, x_0^1, A_0^1$ \ +$lr(size: #115%, [x])_0^1, [x]_0^1, \]_0^1, x_0^1, A_0^1$ \ $n^2, (n + 1)^2, sum_0^1, integral_0^1$ diff --git a/tests/suite/math/delimited.typ b/tests/suite/math/delimited.typ index b8656151b..9cfbf7657 100644 --- a/tests/suite/math/delimited.typ +++ b/tests/suite/math/delimited.typ @@ -31,9 +31,14 @@ $ lr(a/b\]) = a = lr(\{a/b) $ --- math-lr-size --- // Test manual scaling. -$ lr(]sum_(x=1)^n x], size: #70%) +$ lr(]sum_(x=1)^n x], size: #60%) < lr((1, 2), size: #200%) $ +--- math-lr-size-function --- +// Test using a function as an argument to size. +#set math.lr(size: x => if x > 10pt { 1em } else { 4 * x }) +$ (a) (1/2) $ + --- math-lr-shorthands --- // Test predefined delimiter pairings. $floor(x/2), ceil(x/2), abs(x), norm(x)$ @@ -57,16 +62,16 @@ $ { x mid(|) sum_(i=1)^oo phi_i (x) < 1 } \ #set page(width: auto) $ lr({ A mid(|) integral }) quad - lr(size: #1em, { A mid(|) integral }) quad - lr(size: #(1em+20%), { A mid(|) integral }) \ + lr(size: #0%, { A mid(|) integral }) quad + lr(size: #(1em+10%), { A mid(|) integral }) \ lr(] A mid(|) integral ]) quad - lr(size: #1em, ] A mid(|) integral ]) quad - lr(size: #(1em+20%), ] A mid(|) integral ]) \ + lr(size: #0%, ] A mid(|) integral ]) quad + lr(size: #(1em+10%), ] A mid(|) integral ]) \ lr(( A mid(|) integral ]) quad - lr(size: #1em, ( A mid(|) integral ]) quad - lr(size: #(1em+20%), ( A mid(|) integral ]) $ + lr(size: #0%, ( A mid(|) integral ]) quad + lr(size: #(1em+10%), ( A mid(|) integral ]) $ --- math-lr-mid-size-nested-equation --- // Test mid size when lr size is set, when nested in an equation. @@ -74,8 +79,8 @@ $ lr({ A mid(|) integral }) quad #let body = ${ A mid(|) integral }$ $ lr(body) quad - lr(size: #1em, body) quad - lr(size: #(1em+20%), body) $ + lr(size: #0%, body) quad + lr(size: #(1em+10%), body) $ --- math-lr-mid-class --- // Test that `mid` creates a Relation, but that can be overridden. diff --git a/tests/suite/math/stretch.typ b/tests/suite/math/stretch.typ index d145f72a1..f5ee05af6 100644 --- a/tests/suite/math/stretch.typ +++ b/tests/suite/math/stretch.typ @@ -91,3 +91,9 @@ $ body^"text" $ } $body^"long text"$ } + +--- math-stretch-function --- +// Test using a function as an argument to size. +$stretch(<-, size: #(x => x - 0.5em))_"function"$ +#set math.stretch(size: x => x + 0.5em) +$stretch(|) |$