Skip to content

Instantly share code, notes, and snippets.

@aslakr
Last active February 8, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslakr/8630e041aeaff23fa03ea4f4a5d55404 to your computer and use it in GitHub Desktop.
Save aslakr/8630e041aeaff23fa03ea4f4a5d55404 to your computer and use it in GitHub Desktop.
AsciiMath syntax and test suite using double backticks
title date tags
AsciiMath syntax and test suite
2016-04-11
math
mathml
asciimath
markown

AsciiMath syntax

From http://asciimath.org but instead use double backticks (``).

Operation symbols

Type See
+ +
- -
* *
** **
*** ***
// //
\\ \\
xx xx
-: -:
` ><`
`>< `
` ><
@ @
o+ o+
ox ox
o. o.
sum sum
prod prod
^^ ^^
^^^ ^^^
vv vv
vvv vvv
nn nn
nnn nnn
uu uu
uuu uuu

Miscellaneous symbols

The use of | might confuse some table parser for |...|, |cdots|, |\ |, |quad|, |__, __|, |~ and ~|

Type See
2/3 2/3
2^3 2^3
sqrt x sqrt x
root(3)(x) root(3)(x)
int int
oint oint
del del
grad grad
+- +-
O/ O/
oo oo
aleph aleph
/_ /_
:. :.
` ...
` cdots
vdots vdots
ddots ddots
` \
` quad
/_ /_
frown frown
` quad
diamond diamond
square square
` __`
`__ `
` ~`
`~ `
CC CC
NN NN
QQ QQ
RR RR
ZZ ZZ
"hi" "hi"

Relation symbols

Type See
= =
!= !=
< <
> >
<= >=
>= >=
-< -<
-<= -<=
>- >-
>-= >-=
in in
!in !in
sub sub
sup sup
sube sube
supe supe
-= -=
~= ~=
~~ ~~
prop prop

Greek Letters

Type See
alpha alpha
beta beta
gamma gamma
Gamma Gamma
delta delta
Delta Delta
epsilon epsilon
varepsilon varepsilon
zeta zeta
eta eta
theta theta
Theta Theta
vartheta vartheta
iota iota
kappa kappa
lambda lambda
Lambda Lambda
mu mu
nu nu
xi xi
Xi Xi
pi pi
Pi Pi
rho rho
sigma sigma
Sigma Sigma
tau tau
upsilon upsilon
phi phi
Phi Phi
varphi varphi
chi chi
psi psi
Psi Psi
omega omega
Omega Omega

Logical symbols

The use of | might confuse some table parser _|_, |--, |==

Type See
and and
or or
not not
=> =>
if if
<=> <=>
AA AA
EE EE
`_ _`
TT TT
` --`
` ==`

Grouping brackets

Type See
( (
) )
[ [
] ]
{ {
{ }
(: (:
:) :)
<< <<
>> >>
{: x ) {: x )
( x :} ( x :}
abs(x) abs(x)
floor(x) floor(x)
ceil(x) ceil(x)
norm(vec x) norm(vec x)

Arrows

The use of | might confuse some table parser: |->

Type See
uarr uarr
darr darr
rarr rarr
-> ->
>-> >->
->> ->>
>->> >->>
` ->`
larr larr
harr harr
rArr rArr
lArr lArr
hArr hArr

Accents

Type See
hat x hat x
bar x bar x
ul x ul x
vec x vec x
dot x dot x
ddot x ddot x
overset(x)(=) overset(x)(=)
underset(x)(=) underset(x)(=)
ubrace(1+2) ubrace(1+2)
obrace(1+2) obrace(1+2)
color(red)(x) color(red)(x)
cancel(x) cancel(x)

Font commands

Type See
bb "AaBbCc" bb "AaBbCc"
bbb "AaBbCc" bbb "AaBbCc"
cc "AaBbCc" cc "AaBbCc"
tt "AaBbCc" tt "AaBbCc"
fr "AaBbCc" fr "AaBbCc"
sf "AaBbCc" sf "AaBbCc"

Standard Functions

sin, cos, tan, csc, sec, cot, sinh, cosh, tanh, log, ln, det, dim, lim, mod, gcd, lcm, min, max

Special Cases

Matrices: [[a,b],[c,d]] yields to [[a,b],[c,d]]

Column vectors: ((a,b),(c,d)) yields to ((a,b),(c,d))

Matrices can be used for layout: {(2x,+,17y,=,23),(x,-,y,=,5):} yields {(2x,+,17y,=,23),(x,-,y,=,5):}

Complex subscripts: lim_(N->oo) sum_(i=0)^N yields to lim_(N->oo) sum_(i=0)^N

Subscripts must come before superscripts: int_0^1 f(x)dx yields to int_0^1 f(x)dx

Derivatives: f'(x) = dy/dx yields f'(x) = dy/dx

For variables other than x,y,z, or t you will need grouping symbols: (dq)/(dp) for (dq)/(dp)

Overbraces and underbraces: ubrace(1+2+3+4)_("4 terms") yields ubrace(1+2+3+4)_("4 terms")

obrace(1+2+3+4)^("4 terms") yields obrace(1+2+3+4)^("4 terms")

Attention: Always try to surround the > and < characters with spaces so that the html parser does not confuse it with an opening or closing tag!

AsciiMath test cases

From https://github.com/camoy/amath/tree/master/test/input

List

  • hat(ab) bar(xy) ulA vec v dotx ddot y
  • ubrace(1+2+3+4)_("4 terms") - obrace(2+3)^(n)
  • (cancel((x+1))(x - 2))/(cancel((x+1))(x+3))
  • color(red)(x^2)+3x+color(green)(4)
  • abc-123.45^(-1.1)
  • d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h
  • bb{AB3}.bbb(AB].cc(AB).fr{AB}.tt[AB].sf(AB)
  • a//b
  • sin^(-1)(x)
  • int_0^1f(x)dx
  • [[a,b],[c,d]] ((n),(k))
  • (a,b]={x in RR | a < x <= b}
  • ((a*b))/c
  • (a/b)/(c/d)
  • sqrt sqrt root3x
  • x/x={(1,if x!=0),("undefined",if x=0):}
  • x^2 + y_1 + z_12^34
  • a/b/c/d
  • stackrel"def"= or stackrel Delta =" "("or ":=)
  • x^2+y_1+z_12^34
  • f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n
  • <<a,b>> and {:(x,y),(u,v):}

One paragraph

hat(ab) bar(xy) ulA vet v dots dot y, ubrace(1+2+3+4)_("4 terms") - obrace(2+3)^(n), (cancel((x+1))(x - 2))/(cancel((x+1))(x+3)), color(red)(x^2)+3x+color(green)(4), abc-123.45^(-1.1), d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h, bb{AB3}.bbb(AB].cc(AB).fr{AB}.tt[AB].sf(AB), a//b, sin^(-1)(x), int_0^1f(x)dx, [[a,b],[c,d]] ((n),(k)), (a,b]={x in RR | a < x <= b}, ((a*b))/c, (a/b)/(c/d), sort sort root3x, x/x={(1,if x!=0),("undefined",if x=0):}, x^2 + y_1 + z_12^34, a/b/c/d, stackrel"def"= or stackrel Delta =" "("or ":=), x^2+y_1+z_12^34, f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n, <<a,b>> and {:(x,y),(u,v):}.

A paragraph for each

(Should a single paragraph with AsciiMath generate <math display="block">…</math>?)

hat(ab) bar(xy) ulA vec v dotx ddot y

ubrace(1+2+3+4)_("4 terms") - obrace(2+3)^(n)

(cancel((x+1))(x - 2))/(cancel((x+1))(x+3))

color(red)(x^2)+3x+color(green)(4)

abc-123.45^(-1.1)

d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h

bb{AB3}.bbb(AB].cc(AB).fr{AB}.tt[AB].sf(AB)

a//b

sin^(-1)(x)

int_0^1f(x)dx

[[a,b],[c,d]] ((n),(k))

(a,b]={x in RR | a < x <= b}

((a*b))/c

(a/b)/(c/d)

sqrt sqrt root3x

x/x={(1,if x!=0),("undefined",if x=0):}

x^2 + y_1 + z_12^34

a/b/c/d

stackrel"def"= or stackrel Delta =" "("or ":=)

x^2+y_1+z_12^34

f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n

<<a,b>> and {:(x,y),(u,v):}

Using fenced code blocks

(I am not sure I like this syntax for generating display math)

$$hat(ab) bar(xy) ulA vec v dotx ddot y$$ $$ubrace(1+2+3+4)_("4 terms") - obrace(2+3)^(n)$$ $$(cancel((x+1))(x - 2))/(cancel((x+1))(x+3))$$ $$color(red)(x^2)+3x+color(green)(4)$$ $$abc-123.45^(-1.1)$$ $$d/dx f(x)=lim_(h->0)(f(x+h)-f(x))/h$$ $$bb{AB3}.bbb(AB].cc(AB).fr{AB}.tt[AB].sf(AB)$$ $$a//b$$ $$sin^(-1)(x)$$ $$int_0^1f(x)dx$$ $$[[a,b],[c,d]] ((n),(k))$$ $$(a,b]={x in RR | a < x <= b}$$ $$((a*b))/c$$ $$(a/b)/(c/d)$$ $$sqrt sqrt root3x$$ $$x/x={(1,if x!=0),("undefined",if x=0):}$$ $$x^2 + y_1 + z_12^34$$ $$a/b/c/d$$ $$stackrel"def"= or stackrel Delta =" "("or ":=)$$ $$x^2+y_1+z_12^34$$ $$f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n$$ $$<<a,b>> and {:(x,y),(u,v):}$$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment