diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-10-04 13:42:49 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-10-04 13:45:16 +0200 |
| commit | 5a8534a395b500a25cbc46ee15ec031c8231de59 (patch) | |
| tree | a525c447c3243fe315c7ed91923e158df131809b /src/library/math/script.rs | |
| parent | 7ef6cb31df0fe1ebec99b1077053a586a349f530 (diff) | |
Parse basic math syntax
Diffstat (limited to 'src/library/math/script.rs')
| -rw-r--r-- | src/library/math/script.rs | 31 |
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 + } +} |
