KatexContext

Struct KatexContext 

Source
pub struct KatexContext {
    pub functions: KeyMap<String, Arc<FunctionSpec>>,
    pub html_group_builders: KeyMap<NodeType, HtmlBuilder>,
    pub mathml_group_builders: KeyMap<NodeType, MathMLBuilder>,
    pub symbols: Symbols,
    pub environments: KeyMap<String, Arc<EnvSpec>>,
    pub font_metrics: FontMetricsData,
}
Expand description

Global context struct for KaTeX

The KatexContext serves as the central registry for all KaTeX functionality, containing mappings for functions, HTML/MathML builders, symbols, and environments. This design enables runtime extensibility of LaTeX commands without recompilation.

Fields§

§functions: KeyMap<String, Arc<FunctionSpec>>

Corresponds to _functions in defineFunction.js All registered functions Parser requires this dictionary

§html_group_builders: KeyMap<NodeType, HtmlBuilder>

Corresponds to _htmlGroupBuilders in defineFunction.js All HTML builders. Should be only used in the define* and the build*ML functions.

§mathml_group_builders: KeyMap<NodeType, MathMLBuilder>

Corresponds to _mathmlGroupBuilders in defineFunction.js All MathML builders. Should be only used in the define* and the build*ML functions.

§symbols: Symbols

Corresponds to symbols in symbols.js Main symbol table mapping modes to character information

§environments: KeyMap<String, Arc<EnvSpec>>

Corresponds to _environments in defineEnvironment.js All registered environments.

§font_metrics: FontMetricsData

Font metrics data for character measurements

Implementations§

Source§

impl KatexContext

Source

pub fn make_glue<T>( &self, measurement: &Measurement<T>, options: &Options, ) -> Result<DomSpan, ParseError>
where T: AsRef<str>,

Create a glue (spacing) node with proper unit conversion

This method creates a spacing element that matches KaTeX’s behavior, properly converting measurements to CSS ems using the context’s calculate_size method.

Source§

impl KatexContext

Source

pub fn define_function(&mut self, spec: FunctionDefSpec<'_>)

Set default values of functions

Source

pub fn define_function_builders( &mut self, node_type: NodeType, html_builder: Option<HtmlBuilder>, mathml_builder: Option<MathMLBuilder>, )

Register only the HTML and MathML builders for a function

Source

pub fn define_environment(&mut self, spec: EnvDefSpec)

Set default values of environments

Source

pub fn get_global_metrics(&self, size: f64) -> &FontMetrics

Get the font metrics for a given size.

Source

pub fn set_font_metrics(&mut self, font_name: &str, metrics: MetricMap)

Set or override font metrics for a specific font family

Source§

impl KatexContext

Source

pub fn calculate_size<T>( &self, size: &Measurement<T>, options: &Options, ) -> Result<f64, ParseError>
where T: AsRef<str>,

Convert a Measurement (e.g., { number: 1.2, unit: "cm" }) into CSS ems for the given Options. Mirrors the logic in KaTeX calculateSize.

Returns an error if the unit is invalid.

Trait Implementations§

Source§

impl Default for KatexContext

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.