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
NodeType
- The discriminant type for runtime type checkingassert_node_type
- Type assertion utilityParseNode
- Type alias for this enum
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
impl AnyParseNode
Sourcepub fn is_character_box(&self) -> Result<bool, ParseNodeError>
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.
Sourcepub fn to_base_elem(&self) -> Result<&Self, ParseNodeError>
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.
Trait Implementations§
Source§impl Clone for AnyParseNode
impl Clone for AnyParseNode
Source§fn clone(&self) -> AnyParseNode
fn clone(&self) -> AnyParseNode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AnyParseNode
impl Debug for AnyParseNode
Source§impl ErrorLocationProvider for AnyParseNode
Implementation of ErrorLocationProvider
for AnyParseNode
.
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
ParseError::with_token
for creating errors with location contextSourceLocation
for detailed location trackingAnyParseNode
for all supported parse node types