#[non_exhaustive]pub enum MathNode {
Show 34 variants
Atom(char, AtomKind),
Fraction(FracStyle, Box<MathNode>, Box<MathNode>),
Radical(Option<Box<MathNode>>, Box<MathNode>),
Superscript(Box<MathNode>, Box<MathNode>),
Subscript(Box<MathNode>, Box<MathNode>),
SubSup(Box<MathNode>, Box<MathNode>, Box<MathNode>),
Delimited(Delimiter, Box<MathNode>, Delimiter),
SizedDelim(Delimiter, DelimSize, AtomKind),
Row(Vec<MathNode>),
Matrix(MatrixStyle, Vec<ColSpec>, Vec<EnvRow>),
Substack(Vec<MathNode>),
Ref(String),
Tag {
star: bool,
body: Box<MathNode>,
},
Label(String),
NoNumber,
Hline,
Intertext(Box<MathNode>),
Sum(Option<Box<MathNode>>, Option<Box<MathNode>>),
Integral(IntegralKind, Option<Box<MathNode>>, Option<Box<MathNode>>),
Product(Option<Box<MathNode>>, Option<Box<MathNode>>),
Limit(Option<Box<MathNode>>),
OverUnder(Box<MathNode>, Option<Box<MathNode>>, Option<Box<MathNode>>),
Accent(Box<MathNode>, AccentKind),
CancelTo(Box<MathNode>, Box<MathNode>),
Text(TextRun, TextStyle),
Space(SpaceKind),
Operator(String, bool),
Symbol(String),
Color(Color, Box<MathNode>),
TextColor(Color, Box<MathNode>),
ColorBox(Color, Box<MathNode>),
FColorBox(Color, Color, Box<MathNode>),
Strut(Dim, Dim),
Phantom(PhantomKind, Box<MathNode>),
}Expand description
Typed math-mode syntax tree.
Produced by crate::parse(). MathNode::gold is the gold-stable debug form.
The enum is non-exhaustive so a later release can add a variant. A
downstream match needs a wildcard.
§Examples
use latex_rust::parse;
let n = parse("x^2").unwrap();
assert!(n.gold().contains("sup"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Atom(char, AtomKind)
Single character with a TeX atom class.
Fraction(FracStyle, Box<MathNode>, Box<MathNode>)
\frac / \dfrac / \tfrac / \cfrac / {a \over b}.
The style is the command. \over is FracStyle::Frac.
Radical(Option<Box<MathNode>>, Box<MathNode>)
\sqrt / \sqrt[n]. Index None is a square root.
Superscript(Box<MathNode>, Box<MathNode>)
x^{}
Subscript(Box<MathNode>, Box<MathNode>)
x_{}
SubSup(Box<MathNode>, Box<MathNode>, Box<MathNode>)
x_{}^{}
Delimited(Delimiter, Box<MathNode>, Delimiter)
\left ... \right
SizedDelim(Delimiter, DelimSize, AtomKind)
\big / \Big / \bigg / \Bigg (and l/r/m forms).
Row(Vec<MathNode>)
Horizontal list of nodes.
Matrix(MatrixStyle, Vec<ColSpec>, Vec<EnvRow>)
Matrix or multiline environment. colspec is the {array} preamble (empty otherwise).
Substack(Vec<MathNode>)
\substack{...} — stacked script-style lines.
Ref(String)
\ref{key}
Tag
\tag{...} / \tag*{...} (peeled into EnvRow when inside an environment).
Label(String)
\label{key}
NoNumber
\nonumber / \notag
Hline
\hline (peeled into EnvRow::Hline in environments).
Intertext(Box<MathNode>)
\intertext{...}
Sum(Option<Box<MathNode>>, Option<Box<MathNode>>)
\sum with optional lower / upper limits.
Integral(IntegralKind, Option<Box<MathNode>>, Option<Box<MathNode>>)
\int family with optional limits.
Product(Option<Box<MathNode>>, Option<Box<MathNode>>)
\prod with optional limits.
Limit(Option<Box<MathNode>>)
\lim with optional subscript.
OverUnder(Box<MathNode>, Option<Box<MathNode>>, Option<Box<MathNode>>)
\overset / \underset / \stackrel (base, over, under).
Accent(Box<MathNode>, AccentKind)
Accent or decoration on a nucleus.
CancelTo(Box<MathNode>, Box<MathNode>)
\cancelto{value}{expr}
Text(TextRun, TextStyle)
Styled character run (\mathrm, \text, …).
Space(SpaceKind)
Explicit math skip.
Operator(String, bool)
Named operator (\sin). The flag is \limits vs \nolimits.
Symbol(String)
Named glyph (\alpha, \times). The string is the control-sequence name.
Color(Color, Box<MathNode>)
\color applied to a following math list.
TextColor(Color, Box<MathNode>)
\textcolor{...}{...}
ColorBox(Color, Box<MathNode>)
\colorbox{...}{...}
FColorBox(Color, Color, Box<MathNode>)
\fcolorbox{border}{fill}{body}
Strut(Dim, Dim)
Vertical strut (height, depth) in em.
Phantom(PhantomKind, Box<MathNode>)
\phantom family.
Implementations§
Source§impl MathNode
impl MathNode
Sourcepub fn gold(&self) -> String
pub fn gold(&self) -> String
Gold-stable S-expression. One space between items; no trailing space.
The walk is an explicit heap stack, so a tree parse accepted cannot
overflow the caller’s stack here.
Sourcepub fn to_latex(&self) -> String
pub fn to_latex(&self) -> String
LaTeX reprint of this tree.
The method is total: every node prints, and it does not return
Err or panic. Braces and spaces may differ from the
source that built the tree, so compare trees, then compare a reprint
to a reprint. It is not a byte-preserving formatter.
Braces follow one rule based on the parser’s grouping rules
(documents/TEXT_MODE_SPEC.md section 5), and a reprint never nests
deeper than any source of the same tree. Command arguments always
print braced (\frac {1}{2}). A script argument that is a single
nucleus prints bare (x_a), a row is one group, and an empty
argument is {}. Row items print bare unless one would change
meaning: a nested row, a superscript character, or a ) that the
parser’s paren lookahead would pair with an earlier (. Superscript
primes print as ' marks. An alphabetic control word is followed by
a space, so \sin x does not become \sinx, and two bare letters
are split by a space. \overline is that full command.
A MathNode::Fraction prints as the command in its FracStyle.
\over is stored as FracStyle::Frac, so it prints as \frac;
\choose and \binom print as \binom.
A MathNode::Color is its own group. A color nested in a row
therefore does not swallow the nodes that follow it.
Sourcepub fn to_latex_with(&self, options: &ParseOptions) -> String
pub fn to_latex_with(&self, options: &ParseOptions) -> String
to_latex for a tree that will be read back with
options. Only ParseOptions::prime_symbol changes the output:
with it on, ' reads back as \prime, so a ′ superscript prints
as ^{′} instead of a ' mark.
Trait Implementations§
impl Eq for MathNode
impl StructuralPartialEq for MathNode
Auto Trait Implementations§
impl Forget for MathNode
impl Freeze for MathNode
impl RefUnwindSafe for MathNode
impl Send for MathNode
impl Sync for MathNode
impl Unpin for MathNode
impl UnsafeUnpin for MathNode
impl UnwindSafe for MathNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more