Skip to main content

MathExpr

Enum MathExpr 

Source
#[non_exhaustive]
pub enum MathExpr {
Show 17 variants Row(Vec<MathExpr>), Identifier(String), Number(String), Operator(String), OperatorWithMetadata { text: String, lspace: Option<f32>, rspace: Option<f32>, large_operator: Option<bool>, movable_limits: Option<bool>, }, Text(String), Space(f32), Fraction { numerator: Arc<MathExpr>, denominator: Arc<MathExpr>, }, Sqrt(Arc<MathExpr>), Root { base: Arc<MathExpr>, index: Arc<MathExpr>, }, Scripts { base: Arc<MathExpr>, sub: Option<Arc<MathExpr>>, sup: Option<Arc<MathExpr>>, }, UnderOver { base: Arc<MathExpr>, under: Option<Arc<MathExpr>>, over: Option<Arc<MathExpr>>, }, Accent { base: Arc<MathExpr>, accent: Arc<MathExpr>, stretch: bool, }, Fenced { open: Option<String>, close: Option<String>, body: Arc<MathExpr>, }, Table { rows: Vec<Vec<MathExpr>>, column_alignments: Vec<MathColumnAlignment>, column_gap: Option<f32>, row_gap: Option<f32>, }, Source { source: Range<usize>, body: Arc<MathExpr>, }, Error(String),
}
Expand description

Presentation-oriented math expression tree, shaped like MathML Core.

Each variant corresponds to a MathML Core element (noted per variant), so MathML interchange is a near 1:1 mapping. Trees are produced by parse_tex/parse_mathml (or built directly) and turned into renderable boxes by layout_math.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Row(Vec<MathExpr>)

Horizontal sequence of sub-expressions (<mrow>).

§

Identifier(String)

Identifier such as a variable or function name (<mi>); rendered italic.

§

Number(String)

Numeric literal (<mn>); rendered upright.

§

Operator(String)

Operator, relation, or punctuation (<mo>). Spacing and big-operator behavior come from a built-in table keyed on the operator text.

§

OperatorWithMetadata

Operator (<mo>) with explicit attribute overrides; unset fields fall back to the built-in operator table used by MathExpr::Operator.

Fields

§text: String

The operator text.

§lspace: Option<f32>

Space before the operator in em (MathML lspace).

§rspace: Option<f32>

Space after the operator in em (MathML rspace).

§large_operator: Option<bool>

Whether to draw an enlarged glyph in block display (MathML largeop).

§movable_limits: Option<bool>

Whether attached scripts become under/over limits in block display (MathML movablelimits).

§

Text(String)

Literal text rendered upright (<mtext>).

§

Space(f32)

Horizontal space of the given width in em (<mspace>).

§

Fraction

Fraction with a horizontal rule (<mfrac>).

Fields

§numerator: Arc<MathExpr>

Expression above the fraction rule.

§denominator: Arc<MathExpr>

Expression below the fraction rule.

§

Sqrt(Arc<MathExpr>)

Square root (<msqrt>).

§

Root

Root with an explicit degree, e.g. a cube root (<mroot>).

Fields

§base: Arc<MathExpr>

Expression under the radical.

§index: Arc<MathExpr>

Degree of the root, drawn small above the radical’s hook.

§

Scripts

Base with attached subscript and/or superscript (<msub>/<msup>/<msubsup>).

Fields

§base: Arc<MathExpr>

Expression the scripts attach to.

§sub: Option<Arc<MathExpr>>

Subscript, if any.

§sup: Option<Arc<MathExpr>>

Superscript, if any.

§

UnderOver

Base with material placed directly below and/or above it (<munder>/<mover>/<munderover>), e.g. limits of a sum.

Fields

§base: Arc<MathExpr>

Expression the under/over material attaches to.

§under: Option<Arc<MathExpr>>

Expression centered below the base, if any.

§over: Option<Arc<MathExpr>>

Expression centered above the base, if any.

§

Accent

Accented base such as a hat or overline (<mover accent="true">).

Fields

§base: Arc<MathExpr>

Expression under the accent.

§accent: Arc<MathExpr>

The accent expression, drawn close above the base.

§stretch: bool

Whether the accent stretches to the base’s width (MathML stretchy); currently honored for overline-style accents.

§

Fenced

Body wrapped in (possibly stretchy) fence delimiters (<mfenced>, or an <mrow> with stretchy <mo> fences).

Fields

§open: Option<String>

Opening delimiter text, or None for no opening fence.

§close: Option<String>

Closing delimiter text, or None for no closing fence.

§body: Arc<MathExpr>

Expression between the fences.

§

Table

Rows and columns of aligned cells (<mtable>), also used for matrix and aligned/cases TeX environments.

Fields

§rows: Vec<Vec<MathExpr>>

Cell expressions, outer Vec per row, inner Vec per column.

§column_alignments: Vec<MathColumnAlignment>

Per-column alignment (MathML columnalign); columns beyond the list fall back to the last entry or the default (center).

§column_gap: Option<f32>

Gap between columns in em (MathML columnspacing), or None for the built-in default.

§row_gap: Option<f32>

Gap between rows in em (MathML rowspacing), or None for the built-in default.

§

Source

Transparent wrapper recording which byte range of the original source produced body; emitted by parse_tex_with_source_ranges and ignored by layout. No MathML equivalent.

Fields

§source: Range<usize>

Byte range into the original source string.

§body: Arc<MathExpr>

The wrapped expression.

§

Error(String)

Parse error or unsupported construct; the message is rendered as plain text in place of the expression.

Implementations§

Source§

impl MathExpr

Source

pub fn row(children: impl IntoIterator<Item = MathExpr>) -> Self

Builds a MathExpr::Row from children, collapsing the trivial cases: zero children yield an empty row and a single child is returned as-is without a wrapping row.

Source

pub fn source_range(&self) -> Option<&Range<usize>>

Returns the source byte range if this node is a MathExpr::Source wrapper, without descending into children.

Source

pub fn without_source(&self) -> &MathExpr

Unwraps any (nested) MathExpr::Source wrappers and returns the underlying expression; returns self for all other variants.

Trait Implementations§

Source§

impl Clone for MathExpr

Source§

fn clone(&self) -> MathExpr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for MathExpr

Source§

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

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

impl PartialEq for MathExpr

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 MathExpr

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.