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, MacroParseError>
pub fn new(config: MathCoreConfig) -> Result<Self, MacroParseError>
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 the parsing error, the macro index and the macro definition that caused the error.
Sourcepub fn convert_with_global_state(
&mut self,
latex: &str,
display: MathDisplay,
) -> Result<ConvertResult, Box<LatexError>>
pub fn convert_with_global_state( &mut self, latex: &str, display: MathDisplay, ) -> Result<ConvertResult, Box<LatexError>>
Convert LaTeX to MathML with a global equation counter.
For basic usage, see the documentation of [convert_with_local_state].
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_state].
Sourcepub fn convert_with_local_state(
&self,
latex: &str,
display: MathDisplay,
) -> Result<ConvertResult, Box<LatexError>>
pub fn convert_with_local_state( &self, latex: &str, display: MathDisplay, ) -> Result<ConvertResult, Box<LatexError>>
Convert LaTeX 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 result = converter.convert_with_local_state(latex, MathDisplay::Inline).unwrap();
println!("{}", result.mathml);
let latex = r#"x = \frac{ - b \pm \sqrt{ b^2 - 4 a c } }{ 2 a }"#;
let result = converter.convert_with_local_state(latex, MathDisplay::Block).unwrap();
println!("{}", result.mathml);Sourcepub fn reset_global_state(&mut self)
pub fn reset_global_state(&mut self)
Reset the equation counter and the label map.
This should normally be done at the beginning of a new document or section.
Sourcepub fn convert_all(
&self,
snippets: &[(&str, MathDisplay)],
) -> Vec<Result<ConvertResult, Box<LatexError>>>
pub fn convert_all( &self, snippets: &[(&str, MathDisplay)], ) -> Vec<Result<ConvertResult, Box<LatexError>>>
Convert a collection of LaTeX snippets to MathML.
This method handles forward references correctly, meaning that if an earlier snippet contains a reference to an equation in a later snippet, the reference will be resolved correctly. However, in order to achieve this, all snippets need to be parsed first and can only then be emitted. This means you have to first extract all LaTeX snippets from your document and then call this method with the whole set.