AnyParseNode

Enum AnyParseNode 

Source
pub enum AnyParseNode {
Show 58 variants Array(ParseNodeArray), OrdGroup(ParseNodeOrdGroup), SupSub(ParseNodeSupSub), Genfrac(Box<ParseNodeGenfrac>), LeftRight(ParseNodeLeftRight), LeftRightRight(ParseNodeLeftRightRight), Sqrt(Box<ParseNodeSqrt>), Atom(ParseNodeAtom), MathOrd(ParseNodeMathOrd), Op(ParseNodeOp), Spacing(ParseNodeSpacing), Text(ParseNodeText), Styling(ParseNodeStyling), Font(ParseNodeFont), Color(ParseNodeColor), Accent(Box<ParseNodeAccent>), Overline(ParseNodeOverline), Underline(ParseNodeUnderline), Phantom(ParseNodePhantom), Hphantom(ParseNodeHphantom), Vphantom(ParseNodeVphantom), Rule(ParseNodeRule), CdLabel(ParseNodeCdLabel), CdLabelParent(ParseNodeCdLabelParent), ColorToken(ParseNodeColorToken), Raw(ParseNodeRaw), Size(ParseNodeSize), Tag(ParseNodeTag), Url(ParseNodeUrl), Verb(ParseNodeVerb), TextOrd(ParseNodeTextOrd), AccentToken(ParseNodeAccentToken), OpToken(ParseNodeOpToken), AccentUnder(Box<ParseNodeAccentUnder>), Cr(ParseNodeCr), Delimsizing(ParseNodeDelimsizing), Enclose(ParseNodeEnclose), Environment(Box<ParseNodeEnvironment>), Hbox(ParseNodeHbox), HorizBrace(ParseNodeHorizBrace), Href(ParseNodeHref), Html(ParseNodeHtml), HtmlMathMl(ParseNodeHtmlMathMl), Includegraphics(ParseNodeIncludegraphics), Infix(ParseNodeInfix), Internal(ParseNodeInternal), Kern(ParseNodeKern), Lap(ParseNodeLap), MathChoice(ParseNodeMathChoice), Middle(ParseNodeMiddle), Mclass(ParseNodeMclass), OperatorName(ParseNodeOperatorName), Pmb(ParseNodePmb), Raisebox(ParseNodeRaisebox), Sizing(ParseNodeSizing), Smash(ParseNodeSmash), Vcenter(ParseNodeVcenter), XArrow(ParseNodeXArrow),
}
Expand description

The core Abstract Syntax Tree (AST) node type for KaTeX mathematical expressions.

This enum represents all possible parse nodes that can appear in a parsed LaTeX/KaTeX mathematical expression. Each variant corresponds to a specific type of mathematical construct, from simple symbols to complex structures like arrays and fractions.

The AST is built during parsing and represents the hierarchical structure of mathematical expressions, which is then used for rendering and further processing.

§Architecture

The enum uses the strum crate for discriminant generation, allowing runtime type checking and serialization. The NodeType discriminant provides a way to identify node types without pattern matching.

§Usage

Parse nodes are typically created by the parser from LaTeX input and then processed by the rendering engine. They can be traversed, transformed, and analyzed using the provided utility functions.

§See Also

Variants§

§

Array(ParseNodeArray)

§Structural Nodes

Array/matrix environments with rows and columns

§

OrdGroup(ParseNodeOrdGroup)

Ordered groups of expressions (parentheses, etc.)

§

SupSub(ParseNodeSupSub)

Superscript/subscript combinations

§

Genfrac(Box<ParseNodeGenfrac>)

Generalized fractions (fractions, binomials)

§

LeftRight(ParseNodeLeftRight)

Left-right delimiter pairs

§

LeftRightRight(ParseNodeLeftRightRight)

Right delimiters in left-right delimiter pairs (\left…\right).

§

Sqrt(Box<ParseNodeSqrt>)

Square roots and nth roots

§

Atom(ParseNodeAtom)

§Symbol Nodes

Atomic symbols with specific mathematical meaning

§

MathOrd(ParseNodeMathOrd)

Ordinary mathematical symbols

§

Op(ParseNodeOp)

Mathematical operators

§

Spacing(ParseNodeSpacing)

Explicit spacing elements

§

Text(ParseNodeText)

§Text and Styling

Text content within math

§

Styling(ParseNodeStyling)

Style changes (bold, italic, etc.)

§

Font(ParseNodeFont)

Font family changes

§

Color(ParseNodeColor)

Color specifications

§

Accent(Box<ParseNodeAccent>)

§Functions and Commands

Accents over symbols (hats, bars, etc.)

§

Overline(ParseNodeOverline)

Horizontal lines on top of expressions

§

Underline(ParseNodeUnderline)

Horizontal lines below expressions

§

Phantom(ParseNodePhantom)

Invisible content for spacing or alignment

§

Hphantom(ParseNodeHphantom)

Horizontal phantom content for spacing (\hphantom{…}).

§

Vphantom(ParseNodeVphantom)

Vertical phantom content for spacing (\vphantom{…}).

§

Rule(ParseNodeRule)

Horizontal/vertical rules

§

CdLabel(ParseNodeCdLabel)

§Miscellaneous Nodes

Labels for arrows in commutative diagram environments (\begin{CD}…\end{CD}).

§

CdLabelParent(ParseNodeCdLabelParent)

Parent containers for CD labels in commutative diagrams.

§

ColorToken(ParseNodeColorToken)

Color tokens for setting current color context (\color{name}).

§

Raw(ParseNodeRaw)

Raw content passed through without mathematical processing.

§

Size(ParseNodeSize)

Size specifications for spacing and dimensions (\rule, spacing commands).

§

Tag(ParseNodeTag)

Tagged equations with labels (\tag{label} or automatic numbering).

§

Url(ParseNodeUrl)

Hyperlinks in mathematical expressions (\url{…}).

§

Verb(ParseNodeVerb)

Verbatim text preserving exact formatting (\verb|text| or \begin{verbatim}…\end{verbatim}).

§

TextOrd(ParseNodeTextOrd)

Ordinary text symbols in math mode (letters, punctuation).

§

AccentToken(ParseNodeAccentToken)

Accent symbols for diacritical marks (\hat, \bar, \tilde, etc.).

§

OpToken(ParseNodeOpToken)

Operator symbols with special positioning (\sum, \int, \lim, etc.).

§

AccentUnder(Box<ParseNodeAccentUnder>)

Accent marks placed below expressions (\underline, \underbar, etc.).

§

Cr(ParseNodeCr)

Carriage returns and line breaks (\, \newline).

§

Delimsizing(ParseNodeDelimsizing)

Delimiter sizing for proper enclosure (\big, \Big, \bigg, etc.).

§

Enclose(ParseNodeEnclose)

Enclosed expressions with styling (\boxed, \colorbox, etc.).

§

Environment(Box<ParseNodeEnvironment>)

Custom mathematical environments (\begin{env}…\end{env}).

§

Hbox(ParseNodeHbox)

Horizontal boxes for grouping content (\hbox{…}).

§

HorizBrace(ParseNodeHorizBrace)

Horizontal braces above/below expressions (\overbrace, \underbrace).

§

Href(ParseNodeHref)

Hyperlinks with custom text (\href{url}{text}).

§

Html(ParseNodeHtml)

Embedded HTML content within math expressions.

§

HtmlMathMl(ParseNodeHtmlMathMl)

Content renderable in both HTML and MathML formats.

§

Includegraphics(ParseNodeIncludegraphics)

Included graphics/images (\includegraphics{…}).

§

Infix(ParseNodeInfix)

Custom infix operators between operands.

§

Internal(ParseNodeInternal)

Internal parser nodes for implementation details.

§

Kern(ParseNodeKern)

Explicit kerning/spacing adjustments (\kern, \mkern).

§

Lap(ParseNodeLap)

Overlapping content for annotations (\rlap, \llap, \clap).

§

MathChoice(ParseNodeMathChoice)

Different renderings for display/text/script modes (\mathchoice{…}{…}{…}{…}).

§

Middle(ParseNodeMiddle)

Middle delimiters in expressions (\middle|).

§

Mclass(ParseNodeMclass)

Math class specifications for spacing and rendering (mord, mbin, mrel, etc.).

§

OperatorName(ParseNodeOperatorName)

Operator names with special formatting (\operatorname{…}).

§

Pmb(ParseNodePmb)

Poor man’s bold text formatting (\pmb{…}).

§

Raisebox(ParseNodeRaisebox)

Raised or lowered content (\raisebox{…}{…}).

§

Sizing(ParseNodeSizing)

Size changes for expressions (\scriptsize, \large, etc.).

§

Smash(ParseNodeSmash)

Smashed content ignoring height/depth (\smash{…}).

§

Vcenter(ParseNodeVcenter)

Vertically centered content (\vcenter{…}).

§

XArrow(ParseNodeXArrow)

Extensible arrows with labels (\xleftarrow{…}, \xrightarrow{…}).

Implementations§

Source§

impl AnyParseNode

Source

pub fn is_character_box(&self) -> Result<bool, ParseNodeError>

TeXbook algorithms often reference “character boxes”, which are simply groups with a single character in them. To decide if something is a character box, we find its innermost group, and see if it is a single character.

This is equivalent to utils.isCharacterBox in the JS codebase.

Source

pub fn to_base_elem(&self) -> Result<&Self, ParseNodeError>

Sometimes we want to pull out the innermost element of a group. In most cases, this will just be the group itself, but when ordgroups and colors have a single element, we want to pull that out.

This is equivalent to utils.getBaseElem in the JS codebase.

Source

pub fn mode(&self) -> Mode

Get the mode of current node

Source

pub fn text(&self) -> Option<&str>

Get the text field of the node

checkSymbolNodeType checks if the node is a symbol and returns its text later in Javascript.

Source

pub fn label(&self) -> Option<&str>

Get the label field of the node

Trait Implementations§

Source§

impl Clone for AnyParseNode

Source§

fn clone(&self) -> AnyParseNode

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 AnyParseNode

Source§

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

Formats the value using the given formatter. Read more
Source§

impl ErrorLocationProvider for AnyParseNode

Implementation of ErrorLocationProvider for AnyParseNode.

This implementation extracts the source location from various parse node types used in mathematical expression parsing. It handles all variants of AnyParseNode to provide accurate error positioning in LaTeX/KaTeX expressions.

The location information is crucial for generating user-friendly error messages that highlight the exact position in the input string where a parsing error occurred.

§Error Handling

Returns None if the parse node does not have location information available.

§See Also

Source§

fn loc(&self) -> Option<&SourceLocation>

Get the source location if available
Source§

impl<'_enum> From<&'_enum AnyParseNode> for NodeType

Source§

fn from(val: &'_enum AnyParseNode) -> NodeType

Converts to this type from the input type.
Source§

impl From<AnyParseNode> for NodeType

Source§

fn from(val: AnyParseNode) -> NodeType

Converts to this type from the input type.
Source§

impl From<ParseNodeColor> for AnyParseNode

Source§

fn from(node: ParseNodeColor) -> Self

Converts to this type from the input type.
Source§

impl From<ParseNodeEnvironment> for AnyParseNode

Source§

fn from(value: ParseNodeEnvironment) -> Self

Converts to this type from the input type.
Source§

impl IntoDiscriminant for AnyParseNode

Source§

type Discriminant = NodeType

Enum listing the same variants as this enum but without any data fields
Source§

fn discriminant(&self) -> Self::Discriminant

Source§

impl PartialEq for AnyParseNode

Source§

fn eq(&self, other: &AnyParseNode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AnyParseNode

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.