summaryrefslogtreecommitdiff
path: root/src/library/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/math')
-rw-r--r--src/library/math/mod.rs28
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)
}
}