summaryrefslogtreecommitdiff
path: root/src/library/math.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/math.rs')
-rw-r--r--src/library/math.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/library/math.rs b/src/library/math.rs
new file mode 100644
index 00000000..c75cdea8
--- /dev/null
+++ b/src/library/math.rs
@@ -0,0 +1,32 @@
+//! Mathematical formulas.
+
+use super::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 EvalContext, 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, _: StyleChain) -> Template {
+ let mut template = Template::Text(self.formula.trim().into());
+ if self.display {
+ template = Template::Block(template.pack());
+ }
+ template.monospaced()
+ }
+}