Forked from https://github.com/osanshouo/latex2mathml .
latex2mmlc
provides a functionality to convert LaTeX math equations to MathML Core.
This crate is implemented in pure Rust, so it works in any environments if Rust works (including WebAssembly).
0
, 3.14
, ...x
, \alpha
, \pi
, \aleph
, ...\infty
, \dagger
, \angle
, \Box
, \partial
, ...=
, >
, <
, \ll
, :=
, ...+
. -
, *
, /
, \times
, \otimes
, ...\sqrt
, \frac
, \sin
, \binom
, ...\left\{ .. \middle| .. \right]
, ...\int_0^\infty
, \iint
, \oint
, ...\sum
, \prod
, \bigcup_{i = 0}^\infty
, ...\lim
, \overset{}{}
, \overbrace{}{}
, ...\mathrm
, \mathbf
, \bm
, \mathit
, \mathsf
, \mathscr
, \mathbb
, \mathfrak
, \texttt
, \mathcal
(same as \mathscr
because Unicode doesn’t distinguish the two)\!
, \,
, \:
, \;
, \
, \quad
, \qquad
.\begin{matrix}
, \begin{pmatrix}
, \begin{bmatrix}
, \begin{vmatrix}
.\begin{align}
, \begin{align*}
, \begin{aligned}
.\slashed{\partial}
.See examples/equations.rs
for examples. Note that all supported commands are defined in src/token.rs
.
\\
, except for ones in a matrix or align environment.&
, except for ones in a matrix or align environment.<mmultiscripts>
).Dollar sign \$
is allowed for the latex_to_mathml
function, but the replace
function does not allow it.
This is because the replace
function assumes all dollar signs appear as boundaries of LaTeX equations.
If a feature you need is lacked, feel free to open an issue.
For a single LaTeX equation:
use latex2mathml::{latex_to_mathml, Display};
let latex = r#"\erf ( x ) = \frac{ 2 }{ \sqrt{ \pi } } \int_0^x e^{- t^2} \, dt"#;
let mathml = latex_to_mathml(latex, Display::Block).unwrap();
println!("{}", mathml);
For a document that includes LaTeX equations:
let text = r#"
Let us consider a rigid sphere (i.e., one having a spherical
figure when tested in the stationary system) of radius $R$
which is at rest relative to the system ($K$), and whose centre
coincides with the origin of $K$ then the equation of the
surface of this sphere, which is moving with a velocity $v$
relative to $K$, is
$$\xi^2 + \eta^2 + \zeta^2 = R^2$$
"#;
let mathml = latex2mathml::replace(text).unwrap();
println!("{}", mathml);
To convert HTML files in a directory recursively, use latex2mathml::convert_html
.
This function is for converting HTMLs generated by cargo doc
.
See also examples/equations.rs
and examples/document.rs
.