A crate for parsing AsciiMath in rust.
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Julius Riegel 5d56a1d11e
Merge pull request #15 from Trivernis/develop
2 years ago
.github/workflows Add GITHUB ACTIONS 3 years ago
.idea Add operation symbols 3 years ago
src Change fields' visibilities to pub 2 years ago
.gitignore Add parsing function and test 3 years ago
Cargo.toml Increment version 2 years ago
LICENSE Create LICENSE 3 years ago
README.md Update README.md 3 years ago



This project aims to implement a fully functional AsciiMath parser for rust. It's part of the snekdown parser project.

See the spec.


  • charred used by the tokenizer to analyze the input string
  • maplit for an easy to use macro to define the token mappings
  • lazy_static to define static mappings for tokens
  • htmlescape for escaping html when converting to mathml


The simple way

use asciimath_rs::format::mathml::ToMathML;

fn main() {
    let expression = asciimath_rs::parse("sin(2x) + 3".to_string());
    let mathml_string = expression.to_mathml();

The less simple way

use asciimath_rs::parsing::tokenizer::Tokenizer;
use asciimath_rs::parsing::tree_parser::TreeParser;
use asciimath_rs::format::mathml::ToMathML;

fn main() {
    let mut tokenizer = Tokenizer::new("cos(2) - alpha".to_string());
    let tokens = tokenizer.parse();
    let mut tree_parser = TreeParser::new(tokens);
    let expression = tree_parser.parse();
    let mathml_string = expression.to_mathml();

How it works

As seen in the less simple example the parsing works in two steps. In the first step the raw input string is analyzed and converted into Tokens that represent the syntactic meaning of a sequence of characters. The second step takes the flat vector of tokens and converts it into a tree in a depth first way.

The resulting expression can then be converted into MathML with the default ToMathML trait implementation.


This project is Apache 2.0 licensed.