pub struct LatexToMathML { /* private fields */ }
Expand description
A converter that transforms LaTeX math equations into MathML Core.
Implementations§
Source§impl LatexToMathML
impl LatexToMathML
Sourcepub fn new(config: &MathCoreConfig) -> Result<Self, LatexError<'_>>
pub fn new(config: &MathCoreConfig) -> Result<Self, LatexError<'_>>
Create a new LatexToMathML
converter with the given configuration.
This function returns an error if the custom macros in the given configuration could not be parsed.
Sourcepub const fn const_default() -> Self
pub const fn const_default() -> Self
Create a new LatexToMathML
converter with default settings.
Sourcepub fn convert_with_global_counter<'config, 'source>(
&'config mut self,
latex: &'source str,
display: MathDisplay,
) -> Result<String, LatexError<'source>>where
'config: 'source,
pub fn convert_with_global_counter<'config, 'source>(
&'config mut self,
latex: &'source str,
display: MathDisplay,
) -> Result<String, LatexError<'source>>where
'config: 'source,
Convert LaTeX text to MathML with a global equation counter.
For basic usage, see the documentation of [convert_with_local_counter
].
This conversion function maintains state, in order to count equations correctly across different calls to this function.
The counter can be reset with [reset_global_counter
].
Sourcepub fn convert_with_local_counter<'config, 'source>(
&'config self,
latex: &'source str,
display: MathDisplay,
) -> Result<String, LatexError<'source>>where
'config: 'source,
pub fn convert_with_local_counter<'config, 'source>(
&'config self,
latex: &'source str,
display: MathDisplay,
) -> Result<String, LatexError<'source>>where
'config: 'source,
Convert LaTeX text to MathML.
The second argument specifies whether it is inline-equation or block-equation.
use math_core::{LatexToMathML, MathCoreConfig, MathDisplay};
let latex = r#"(n + 1)! = \Gamma ( n + 1 )"#;
let config = MathCoreConfig::default();
let converter = LatexToMathML::new(&config).unwrap();
let mathml = converter.convert_with_local_counter(latex, MathDisplay::Inline).unwrap();
println!("{}", mathml);
let latex = r#"x = \frac{ - b \pm \sqrt{ b^2 - 4 a c } }{ 2 a }"#;
let mathml = converter.convert_with_local_counter(latex, MathDisplay::Block).unwrap();
println!("{}", mathml);
Sourcepub fn reset_global_counter(&mut self)
pub fn reset_global_counter(&mut self)
Reset the equation counter to zero.
This should normally be done at the beginning of a new document or section.