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
impl KatexContext
Sourcepub fn make_glue<T>(
&self,
measurement: &Measurement<T>,
options: &Options,
) -> Result<DomSpan, ParseError>
pub fn make_glue<T>( &self, measurement: &Measurement<T>, options: &Options, ) -> Result<DomSpan, ParseError>
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
impl KatexContext
Sourcepub fn define_function(&mut self, spec: FunctionDefSpec<'_>)
pub fn define_function(&mut self, spec: FunctionDefSpec<'_>)
Set default values of functions
Sourcepub fn define_function_builders(
&mut self,
node_type: NodeType,
html_builder: Option<HtmlBuilder>,
mathml_builder: Option<MathMLBuilder>,
)
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
Sourcepub fn define_environment(&mut self, spec: EnvDefSpec)
pub fn define_environment(&mut self, spec: EnvDefSpec)
Set default values of environments
Sourcepub fn get_global_metrics(&self, size: f64) -> &FontMetrics
pub fn get_global_metrics(&self, size: f64) -> &FontMetrics
Get the font metrics for a given size.
Sourcepub fn set_font_metrics(&mut self, font_name: &str, metrics: MetricMap)
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
impl KatexContext
Sourcepub fn calculate_size<T>(
&self,
size: &Measurement<T>,
options: &Options,
) -> Result<f64, ParseError>
pub fn calculate_size<T>( &self, size: &Measurement<T>, options: &Options, ) -> Result<f64, ParseError>
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.