pub enum EqNode {
Show 19 variants
Text(String),
Space(f32),
Seq(Vec<EqNode>),
Sup(Box<EqNode>, Box<EqNode>),
Sub(Box<EqNode>, Box<EqNode>),
SupSub(Box<EqNode>, Box<EqNode>, Box<EqNode>),
Frac(Box<EqNode>, Box<EqNode>),
Sqrt(Box<EqNode>),
BigOp {
symbol: String,
lower: Option<Box<EqNode>>,
upper: Option<Box<EqNode>>,
},
Accent(Box<EqNode>, AccentKind),
Limit {
name: String,
lower: Option<Box<EqNode>>,
},
TextBlock(String),
MathFont {
kind: MathFontKind,
content: Box<EqNode>,
},
Delimited {
left: String,
right: String,
content: Box<EqNode>,
},
Matrix {
kind: MatrixKind,
rows: Vec<Vec<EqNode>>,
},
Cases {
rows: Vec<(EqNode, Option<EqNode>)>,
},
Binom(Box<EqNode>, Box<EqNode>),
Brace {
content: Box<EqNode>,
label: Option<Box<EqNode>>,
over: bool,
},
StackRel {
base: Box<EqNode>,
annotation: Box<EqNode>,
over: bool,
},
}Expand description
A node in the equation layout tree.
Returned by crate::parse_equation. Every variant is recursive, so a
fraction’s numerator can contain another fraction, a matrix cell can hold
a summation, and so on — there’s no depth limit.
§Walking the tree
use rust_latex_parser::{parse_equation, EqNode};
fn count_fractions(node: &EqNode) -> usize {
match node {
EqNode::Frac(n, d) => 1 + count_fractions(n) + count_fractions(d),
EqNode::Seq(nodes) => nodes.iter().map(count_fractions).sum(),
EqNode::Sup(base, sup) => count_fractions(base) + count_fractions(sup),
EqNode::Sub(base, sub) => count_fractions(base) + count_fractions(sub),
EqNode::Sqrt(inner) => count_fractions(inner),
_ => 0,
}
}
let tree = parse_equation("\\frac{\\frac{a}{b}}{c}");
assert_eq!(count_fractions(&tree), 2);Variants§
Text(String)
Plain text — a variable name, number, operator character, or Unicode symbol.
Examples: "x", "42", "+", "α", "∑".
Space(f32)
Horizontal space, measured in points.
Inserted automatically around binary operators (+, =, \leq, etc.)
and by explicit spacing commands (\quad, \,, \;).
Can be negative (e.g. \! produces Space(-3.0)).
Seq(Vec<EqNode>)
A horizontal sequence of nodes. This is the most common container —
any expression with more than one piece gets wrapped in a Seq.
Sup(Box<EqNode>, Box<EqNode>)
Base with superscript. Produced by x^2 or x^{2n}.
Fields: (base, superscript).
Sub(Box<EqNode>, Box<EqNode>)
Base with subscript. Produced by x_1 or x_{i+1}.
Fields: (base, subscript).
SupSub(Box<EqNode>, Box<EqNode>, Box<EqNode>)
Base with both superscript and subscript, stacked vertically to the
right of the base. Produced by x^2_3 or x_3^2 (order doesn’t matter).
Fields: (base, superscript, subscript).
Frac(Box<EqNode>, Box<EqNode>)
Fraction with numerator over denominator.
Produced by \frac{a}{b} or the shorthand a/b.
Fields: (numerator, denominator).
Sqrt(Box<EqNode>)
Square root wrapping its contents.
Produced by \sqrt{x} or the bareword sqrt(x).
BigOp
Big operator — summation, integral, product, etc. — with optional upper and lower limits.
The symbol field is a Unicode character (e.g. "∑", "∫", "∏").
Produced by \sum_{i=0}^{n} or the bareword sum_{i=0}^{n}.
Accent(Box<EqNode>, AccentKind)
An accent mark above a node.
Produced by \hat{x}, \bar{x}, \dot{x}, \ddot{x}, \tilde{x},
or \vec{v}. See AccentKind for the variants.
Limit
A named limit-style operator (lim, sin, log, etc.) with an
optional subscript limit.
These render as upright text (not italic), with the limit below when
present. Produced by \lim_{x \to 0} or barewords like sin, cos.
TextBlock(String)
Upright text block within an equation.
Produced by \text{hello world}. The content is not parsed as math —
it’s passed through as-is.
MathFont
Math font override for a subexpression.
Produced by \mathbb{R}, \mathbf{v}, \mathcal{F}, etc.
See MathFontKind for the supported font families.
Delimited
Content wrapped in stretchy delimiters.
Produced by \left( ... \right). The left and right strings are
the delimiter characters (e.g. "(" and ")"). An invisible delimiter
(\left. or \right.) produces an empty string.
Matrix
Matrix or matrix-like environment.
Produced by \begin{pmatrix}, \begin{bmatrix}, etc.
Each inner Vec<EqNode> is one row, each EqNode in a row is one cell.
See MatrixKind for the delimiter styles.
Cases
Piecewise / cases environment.
Produced by \begin{cases} ... \end{cases}. Each row is a
(value, optional_condition) pair. The condition comes after &.
Binom(Box<EqNode>, Box<EqNode>)
Binomial coefficient. Rendered as a stacked pair in parentheses.
Produced by \binom{n}{k}. Fields: (top, bottom).
Brace
Overbrace or underbrace with an optional label.
Produced by \overbrace{a+b}^{n} (over=true) or
\underbrace{x+y}_{text} (over=false).
StackRel
One expression stacked above or below another.
Produced by \overset{def}{=} (over=true), \underset{lim}{=}
(over=false), or \stackrel{above}{base} (over=true).