summaryrefslogtreecommitdiff
path: root/src/library/math/script.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/library/math/script.rs')
-rw-r--r--src/library/math/script.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/library/math/script.rs b/src/library/math/script.rs
new file mode 100644
index 00000000..09f52164
--- /dev/null
+++ b/src/library/math/script.rs
@@ -0,0 +1,31 @@
+use std::fmt::Write;
+
+use super::*;
+use crate::library::prelude::*;
+
+/// A sub- and/or superscript in a mathematical formula.
+#[derive(Debug, Hash)]
+pub struct ScriptNode {
+ /// The base.
+ pub base: MathNode,
+ /// The subscript.
+ pub sub: Option<MathNode>,
+ /// The superscript.
+ pub sup: Option<MathNode>,
+}
+
+impl Texify for ScriptNode {
+ fn texify(&self) -> EcoString {
+ let mut tex = self.base.texify();
+
+ if let Some(sub) = &self.sub {
+ write!(tex, "_{{{}}}", sub.texify()).unwrap();
+ }
+
+ if let Some(sup) = &self.sup {
+ write!(tex, "^{{{}}}", sup.texify()).unwrap();
+ }
+
+ tex
+ }
+}