Skip to main content

LatexToMathML

Struct LatexToMathML 

Source
pub struct LatexToMathML { /* private fields */ }
Expand description

A converter that transforms LaTeX math equations into MathML Core.

Implementations§

Source§

impl LatexToMathML

Source

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.

Source

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].

Source

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);
Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for LatexToMathML

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LatexToMathML

Source§

fn default() -> LatexToMathML

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.