diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-18 19:09:19 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-18 19:09:57 +0200 |
| commit | 3965e10281ea3c8754a1877c9f7e71c1930bf4c3 (patch) | |
| tree | e221b11692ac3af9f97c66625824e1c4e345c2eb /src/library/math/mod.rs | |
| parent | 486f7b1bca15af3805ae1a8f63d72827f227a3d2 (diff) | |
Hack in ReX for now
Diffstat (limited to 'src/library/math/mod.rs')
| -rw-r--r-- | src/library/math/mod.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs index 5656890d..ce41bd49 100644 --- a/src/library/math/mod.rs +++ b/src/library/math/mod.rs @@ -1,14 +1,17 @@ //! Mathematical formulas. +mod rex; + use crate::library::layout::BlockSpacing; use crate::library::prelude::*; use crate::library::text::FontFamily; +use crate::syntax::Spanned; /// A mathematical formula. #[derive(Debug, Hash)] pub struct MathNode { /// The formula. - pub formula: EcoString, + pub formula: Spanned<EcoString>, /// Whether the formula is display-level. pub display: bool, } @@ -40,17 +43,23 @@ impl Show for MathNode { fn encode(&self, _: StyleChain) -> Dict { dict! { - "formula" => Value::Str(self.formula.clone()), + "formula" => Value::Str(self.formula.v.clone()), "display" => Value::Bool(self.display) } } - fn realize(&self, _: &mut Context, _: StyleChain) -> TypResult<Content> { - let mut realized = Content::Text(self.formula.trim().into()); - if self.display { - realized = Content::block(realized); - } - Ok(realized) + fn realize(&self, _: &mut Context, styles: StyleChain) -> TypResult<Content> { + let node = self::rex::RexNode { + tex: self.formula.clone(), + display: self.display, + family: styles.get(Self::FAMILY).clone(), + }; + + Ok(if self.display { + Content::block(node) + } else { + Content::inline(node) + }) } fn finalize( |
