diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-04-02 21:55:25 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-04-03 13:55:58 +0200 |
| commit | 23d108c8e099798dc4d35ce9cbcd3e37fb50f3b2 (patch) | |
| tree | aa068b11b9ac0a4795fb6e86bb8283b1d4718e95 /src/library/math/mod.rs | |
| parent | beca01c826ee51c9ee6d5eadd7e5ef10f7fb9f58 (diff) | |
Font fallback
Diffstat (limited to 'src/library/math/mod.rs')
| -rw-r--r-- | src/library/math/mod.rs | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index f20d6543..666e40a7 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -1,6 +1,7 @@ //! Mathematical formulas. use crate::library::prelude::*; +use crate::library::text::FontFamily; /// A mathematical formula. #[derive(Debug, Hash)] @@ -13,6 +14,10 @@ pub struct MathNode { #[node(showable)] impl MathNode { + /// The raw text's font family. Just the normal text family if `none`. + pub const FAMILY: Smart<FontFamily> = + Smart::Custom(FontFamily::new("Latin Modern Math")); + fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> { Ok(Content::show(Self { formula: args.expect("formula")?, @@ -23,17 +28,24 @@ impl MathNode { impl Show for MathNode { fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Content> { - Ok(styles + let mut content = styles .show(self, ctx, [ Value::Str(self.formula.clone()), Value::Bool(self.display), ])? - .unwrap_or_else(|| { - let mut content = Content::Text(self.formula.trim().into()); - if self.display { - content = Content::Block(content.pack()); - } - content.monospaced() - })) + .unwrap_or_else(|| Content::Text(self.formula.trim().into())); + + let mut map = StyleMap::new(); + if let Smart::Custom(family) = styles.get_cloned(Self::FAMILY) { + map.set_family(family, styles); + } + + content = content.styled_with_map(map); + + if self.display { + content = Content::Block(content.pack()); + } + + Ok(content) } } |
