[][src]Crate latex2mathml

latex2mathml

Provides a functionility to convert LaTeX math equations to MathML representation. This crate is implemented in pure Rust, so it works for all platforms including WebAssembly.

Usage

Main functions of this crate are latex_to_mathml and replace.

use latex2mathml::{latex_to_mathml, DisplayStyle};
 
let latex = r#"\erf ( x ) = \frac{ 2 }{ \sqrt{ \pi } } \int_0^x e^{- t^2} \, dt"#;
let mathml = latex_to_mathml(latex, DisplayStyle::Block).unwrap();
println!("{}", mathml);

For converting a document including LaTeX equasions, the function replace may be useful.

let latex = r#"The error function $\erf ( x )$ is defined by
$$\erf ( x ) = \frac{ 2 }{ \sqrt{ \pi } } \int_0^x e^{- t^2} \, dt .$$"#;
 
let mathml = latex2mathml::replace(latex).unwrap();
println!("{}", mathml);

If you want to transform the equations in a directory recursively, the function convert_html is useful.

use latex2mathml::convert_html;
 
convert_html("./target/doc").unwrap();

For more examples and list of supported LaTeX commands, please check examples/equations.rs and examples/document.rs.

Modules

ast
attribute
token

Enums

DisplayStyle

display style

LatexError

Functions

convert_html

Convert all LaTeX expressions for all HTMLs in a given directory.

latex_to_mathml

Convert LaTeX text to MathML.

replace

Find LaTeX equations and replace them to MathML.