diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-30 14:12:28 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-30 14:12:28 +0200 |
| commit | f9e115daf54c29358f890b137f50a33a781af680 (patch) | |
| tree | 496de52246629ea8039db6beea94eb779ed2851d /src/library/math | |
| parent | f7c67cde72e6a67f45180856b332bae9863243bd (diff) | |
New block spacing model
Diffstat (limited to 'src/library/math')
| -rw-r--r-- | src/library/math/mod.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index 345bb3f6..7b4998ca 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -1,5 +1,6 @@ //! Mathematical formulas. +use crate::library::layout::BlockSpacing; use crate::library::prelude::*; use crate::library::text::FontFamily; @@ -19,6 +20,13 @@ impl MathNode { pub const FAMILY: Smart<FontFamily> = Smart::Custom(FontFamily::new("Latin Modern Math")); + /// The spacing above display math. + #[property(resolve, shorthand(around))] + pub const ABOVE: Option<BlockSpacing> = Some(Ratio::one().into()); + /// The spacing below display math. + #[property(resolve, shorthand(around))] + pub const BELOW: Option<BlockSpacing> = Some(Ratio::one().into()); + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { Ok(Content::show(Self { formula: args.expect("formula")?, @@ -36,7 +44,11 @@ impl Show for MathNode { } fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> { - Ok(Content::Text(self.formula.trim().into())) + let mut realized = Content::Text(self.formula.trim().into()); + if self.display { + realized = Content::block(realized); + } + Ok(realized) } fn finalize( @@ -50,12 +62,10 @@ impl Show for MathNode { map.set_family(family.clone(), styles); } - realized = realized.styled_with_map(map); - if self.display { - realized = Content::block(realized); + realized = realized.spaced(styles.get(Self::ABOVE), styles.get(Self::BELOW)); } - Ok(realized) + Ok(realized.styled_with_map(map)) } } |
