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