Skip to main content

Crate math_core

Crate math_core 

Source
Expand description

Convert LaTeX math to MathML Core.

For more background on what that means and on what to do with the resulting MathML code, see the repo’s README: https://github.com/tmke8/math-core

§Usage

The main struct of this library is LatexToMathML. In order to use the library, create an instance of this struct and then call one of the convert functions. The constructor of the struct expects a config object in the form of an instance of MathCoreConfig.

Basic use looks like this:

use math_core::{LatexToMathML, MathCoreConfig, MathDisplay};

let latex = r#"\erf ( x ) = \frac{ 2 }{ \sqrt{ \pi } } \int_0^x e^{- t^2} \, dt"#;
let config = MathCoreConfig::default();
let converter = LatexToMathML::new(config).unwrap();
let result = converter.convert_with_local_state(latex, MathDisplay::Block).unwrap();
println!("{}", result.mathml);

§Features

  • std (enabled by default): Uses the Rust standard library. Disabling this feature (with default-features = false) makes the crate no_std; the alloc crate is still required. Note that disabling std also disables some speedups in dependencies (e.g. memchr then can no longer use runtime CPU feature detection).
  • serde: With this feature, MathCoreConfig implements serde’s Serialize and Deserialize.
  • ariadne: Adds LatexError::to_report(), which converts an error into an ariadne report for pretty-printing the error together with a source code snippet. The ariadne crate itself requires std, so this feature is not usable on no_std targets.

Structs§

ConvertResult
The result of a LaTeX to MathML conversion.
CssClassNames
LatexError
Represents an error that occurred during LaTeX parsing.
LatexToMathML
A converter that transforms LaTeX math equations into MathML Core.
MathCoreConfig
Configuration object for the LaTeX to MathML conversion.
MaxExpansions
The maximum number of custom command expansions allowed in one snippet.
Warnings

Enums§

IndentKeyword
Indentation
MathDisplay
Display mode for the LaTeX math equations.
PrettyPrint
Configuration for pretty-printing the MathML output.
UnicodeSubstitution
Configuration for using Unicode symbols in the MathML output.

Type Aliases§

MacroParseError
The error type returned when parsing a custom macro definition fails. Contains the parsing error, the index of the macro definition in the macros vector and the macro definition itself.