summaryrefslogtreecommitdiff
path: root/src/library/math
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-03-11 11:58:56 +0100
committerLaurenz <laurmaedje@gmail.com>2022-03-11 11:58:56 +0100
commite6b532391deb1e30dc356c4d20dd48199f748f29 (patch)
tree7b631414931164b9a47c9d154172195fc0e1316c /src/library/math
parentb71113d37a29bab5c7dc4b501c33ee9afbdb8213 (diff)
More restructuring
Diffstat (limited to 'src/library/math')
-rw-r--r--src/library/math/mod.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/library/math/mod.rs b/src/library/math/mod.rs
new file mode 100644
index 00000000..761b4480
--- /dev/null
+++ b/src/library/math/mod.rs
@@ -0,0 +1,37 @@
+use crate::library::prelude::*;
+
+/// A mathematical formula.
+#[derive(Debug, Hash)]
+pub struct MathNode {
+ /// The formula.
+ pub formula: EcoString,
+ /// Whether the formula is display-level.
+ pub display: bool,
+}
+
+#[class]
+impl MathNode {
+ fn construct(_: &mut Context, args: &mut Args) -> TypResult<Template> {
+ Ok(Template::show(Self {
+ formula: args.expect("formula")?,
+ display: args.named("display")?.unwrap_or(false),
+ }))
+ }
+}
+
+impl Show for MathNode {
+ fn show(&self, ctx: &mut Context, styles: StyleChain) -> TypResult<Template> {
+ Ok(styles
+ .show(self, ctx, [
+ Value::Str(self.formula.clone()),
+ Value::Bool(self.display),
+ ])?
+ .unwrap_or_else(|| {
+ let mut template = Template::Text(self.formula.trim().into());
+ if self.display {
+ template = Template::Block(template.pack());
+ }
+ template.monospaced()
+ }))
+ }
+}