Math equation js

Write math equations for the browser in html in a simple format, the script converts it into math ml

I got inspiration from the math typesetting from typst https://typst.app/docs/reference/math/. But as of now there isn't a simple way to write math equations in the browser html.

Mathml features

MathML is divided into two parts:

Attribute Description Example
msup Superscript: like a^2 a 2
msub Subscript: like a_2 a 2
mfrac Fraction: like a/b a b
msqrt Square root: like sqrt(2) 2
msubsup Integral: like int_a^b(x^2) a b x 2
mo Operator: like a -> b a b
mi Identifier: like x x
mn Number: like 2 2
mfenced Group: like (a + b) a + b
mspace Space: like a b a b
mstyle Style: like bold(a) a
Matrix like [1 2; 3 4] [ 1 2 3 4 ]
mtable, mtr, mtd Table: like (1 2 3; 4 5 6) ( 1 2 3 4 5 6 )
Quadratic formula like (-b +- sqrt(b^2 - 4ac)) / 2a x = - b ± b2 - 4ac 2a
Summation like sum_(i=1)^infinity 1/i^2 i=1 1 i2
Limits like lim_(x->0) sin(x)/x lim x0 sin x x
Logarithm like log_2(8) log 2 8
Derivative like d(f(x))/dx d f ( x ) dx

Grammar

The grammar is simple, it is similar to asciimath but goal is to cover all the functionality of typst.

expression := unary_expression ~ (binary_op ~ unary_expression)* unary_expression := primary_expression | prefix_expression | postfix_expression primary_expression := number | identifier | array | function_call | "(" ~ expression ~ ")" array := "[" ~ expression ~ ("," ~ expression)* ~ "]" function_call := identifier ~ ("(" ~ (expression ~ ("," ~ c_expression)*)? ~ ")")+ prefix_expression := unary_op ~ primary_expression postfix_expression := primary_expression ~ unary_op binary_op := "+" | "-" | "*" | "/" | "^" | "==" | "!=" | "<" | ">" | "<=" | ">=" | "&&" | "||" unary_op := "-" | "!" | "++" | "--" identifier := [a-zA-Z_][a-zA-Z0-9_]*