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, (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.

Source

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

Source

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

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.

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.