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, (Box<LatexError<'static>>, String)>
pub fn new( config: MathCoreConfig, ) -> Result<Self, (Box<LatexError<'static>>, String)>
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. The error contains both the parsing error and the macro definition that caused the error.
Sourcepub fn convert_with_global_counter<'config>(
&'config mut self,
latex: &str,
display: MathDisplay,
) -> Result<String, Box<LatexError<'config>>>
pub fn convert_with_global_counter<'config>( &'config mut self, latex: &str, display: MathDisplay, ) -> Result<String, Box<LatexError<'config>>>
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>(
&'config self,
latex: &str,
display: MathDisplay,
) -> Result<String, Box<LatexError<'config>>>
pub fn convert_with_local_counter<'config>( &'config self, latex: &str, display: MathDisplay, ) -> Result<String, Box<LatexError<'config>>>
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.