From 5a8534a395b500a25cbc46ee15ec031c8231de59 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Tue, 4 Oct 2022 13:42:49 +0200 Subject: Parse basic math syntax --- src/library/math/script.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/library/math/script.rs (limited to 'src/library/math/script.rs') 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, + /// The superscript. + pub sup: Option, +} + +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 + } +} -- cgit v1.2.3