Skip to main content

EqNode

Enum EqNode 

Source
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}.

Fields

§symbol: String
§

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.

Fields

§name: String
§

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.

Fields

§content: Box<EqNode>
§

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.

Fields

§left: String
§right: String
§content: Box<EqNode>
§

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.

Fields

§rows: Vec<Vec<EqNode>>
§

Cases

Piecewise / cases environment.

Produced by \begin{cases} ... \end{cases}. Each row is a (value, optional_condition) pair. The condition comes after &.

Fields

§

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).

Fields

§content: Box<EqNode>
§over: bool
§

StackRel

One expression stacked above or below another.

Produced by \overset{def}{=} (over=true), \underset{lim}{=} (over=false), or \stackrel{above}{base} (over=true).

Fields

§base: Box<EqNode>
§annotation: Box<EqNode>
§over: bool

Trait Implementations§

Source§

impl Clone for EqNode

Source§

fn clone(&self) -> EqNode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EqNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.