22

22Equations and MathJax

22.3

AsciiMath

I’m going to say right from the start that I like AsciiMath, it is straight forward to use and is easy to understand.

AsciiMath itself is a form of notation for writing equations. This for example is the quadratic formulae in AsciiMath form:

`x=(-b +- sqrt(b^2 — 4ac))/(2a)`

The one we all know from O level maths:

`x=(-b +- sqrt(b^2 — 4ac))/(2a)`

Now if I stick that equation into the website and put a back-tick (`) character before and after it, like this:

equation html
<div class="formulae" id="js--e99-01">
    <div class="formulae-container"> 
        <div class="formulae-equ"> 
            `x=(-b +- sqrt(b^2 — 4ac))/(2a)`
        </div> 
        <div class="formulae-num"></div>
    </div>
</div> 
Code 22.4   Full equation HTML

I’ve taken out the heading, number and caption. It gives me this:

`x=(-b +- sqrt(b^2 – 4ac))/(2a)`

Well, I think it is pretty cool.

Look again at the AsciiMath:

x=(-b +- sqrt(b^2 — 4ac))/(2a)

It’s a bit hard to explain, but at an intuitive level you can see exactly how it works, if you wanted to type that equation in as a single line on a computer terminal, I bet you would come up with something similar to the above.

Here is another that shows how it handles big and small brackets:

sum_(i=1)^n i^3=((n(n+1))/2)^2

It looks like this:

`sum_(i=1)^n i^3=((n(n+1))/2)^2`

Obviously, you need to know what names are given to the symbols; the following tables show them all:

22.3.1

AsciiMath mathematical operators

example
AsciiMath Description Apperance AsciiMath Result
+ Plus sign `+` x=a+b `x=a+b`
- Minus sign `-` x=a-b `x=a-b`
xx Times sign `xx` x=axxb `x=axxb`
-: Divide sign `-:` x=a-:b `x=a-:b`
// Division slash `//` x=a//b `x=a//b`
* Dot `*` x=a*b `x=a*b`
** Asterisk `**` x=a**b `x=a**b`
*** Star `***` x=a***b `x=a***b`
sum Sigma (summation) `sum` suma =1+2+... `suma =1+2+...`
prod Pi (product) `prod` proda =(1)(2)... `proda =(1)(2)...`

22.3.2

AsciiMath relational symbols

example
AsciiMath Description Apperance AsciiMath Result
= Equals sign `=` a=b `a=b`
!= Not equals sign `!=` a!=b `a!=b`
< Less than `<` a<b `a<b`
> Greater than `>` a>b `a>b`
<= Less than or equal to `<=` a<=b `a<=b`
>= Greater than or equal to `>=` a>=b `a>=b`
-= Equivalent to `-=` a-=b `a-=b`
~= Approximately equal to `~=` a~=b `a~=b`
~~ Approximately `~~` a~~b `a~~b`
prop Proportional sign `prop` a prop b `a prop b`

22.3.3

AsciiMath brackets

Brackets grow to accommodate fractions and operators that require more than one line.

example
AsciiMath Description Apperance AsciiMath Result
( or ) Normal brackets `(" ")` x=((n(n+1))/2) `x=((n(n+1))/2)`
[ or ] Square brackets `[" "]` x=[(n(n+1))/2] `x=[(n(n+1))/2]`
{ or } Braces `{" "}` x=[(n{n+1})/2] `x=[(n{n+1})/2]`
(: or :) Angle brackets `(:" ":)` x=(:a,b:) `x=(:a,b:)`
|__ or __| Floor brackets `|__" "__|` x=|__a-b__| `x=|__a-b__|`
floor(x) Floor brackets alternative `floor(x)` x=floor(a-b) `x=floor(a-b)`
|~ or ~| Ceiling brackets `|~" "~|` x=|~a-b~| `x=|~a-b~|`
ceil(x) Ceiling brackets alternative `ceil(x)` x=ceil(a-b) `x=ceil(a-b)`
abs(x) Absolute `abs(x)` x=abs(a/b) `x=abs(a/b)`
norm(x) Normal `norm(x)` x=norm(a) `x=norm(a)`

22.3.4

AsciiMath mathematical symbols

example
AsciiMath Description Apperance AsciiMath Result
+- Plus or minus `+-` x=+-2b `x=+-2b`
/ Fraction `" "/" "` x=a/b `x=a/b`
^ To the power `x^n` x=a^b `x=a^b`
sqrt Square root `sqrt` x=sqrta `x=sqrta`
root(n)x nth root `root(n)x` x=root(3)a `x=root(3)a`
int Integral `int` x=a int b `x=a int b`
oint Circular integral `oint` x=a oint b `x=a oint b`
del Partial differential `del` `x=del a`
oo Infinity `oo` x=oo `x=oo`
grad Nabla `grad` (grad*v)=f(v) `(grad*v)=f(v)`
/_ Angle `/_` a/_b `a/_b`
:. Therefore `:.` :.a=b `:.a=b`
:' Because `:'` :'a=b `:'a=b`

22.3.5

AsciiMath double struck letters

example
AsciiMath Description Apperance AsciiMath Result
CC Complex numbers `CC` CC(1,2,3) `CC(1,2,3)`
NN Natural numbers `NN` NN(1,2,3) `NN(1,2,3)`
QQ Rational numbers `QQ` QQ(1,2,3) `QQ(1,2,3)`
RR Real numbers `RR` RR(1.1,2.1,3.1) `RR(1.1,2.1,3.1)`
ZZ Integers numbers `ZZ` ZZ(1,2,3) `ZZ(1,2,3)`

22.3.6

AsciiMath accents and colours

example
AsciiMath Description Apperance AsciiMath Result
hat Caret `hat " "` hatx `hatx`
bar Over bar `bar" "` barx `barx`
ul Under bar `ul" "` ulx `ulx`
vec Vector line `vec" "` vecx `vecx`
dot Dot `dot" "` dotx `dotx`
ddot Double dot `ddot" "` ddotx `ddotx`
overbrace Over brace `overbrace" "` overbrace(1+2) `overbrace(1+2)`
underbrace Under brace `underbrace" "` underbrace(1+2) `underbrace(1+2)`
color(col)() Apply colour `color(red)(x)` color(red)(x) `color(red)(x)`

The colours available (col) are the same as the keyword colours available to HTML, there is a full list here.

22.3.7

AsciiMath arrows

example
AsciiMath Description Apperance AsciiMath Result
uarr darr larr rrarr Up, down, left, right arrow `uarr darr larr rarr` uarrx darrx larrx rarrx `uarrx darrx larrx rarrx`
harr Horizontal arrow `harr` aharrb `aharrb`
to To `to` atob `atob`
>-> Right arrow with tail `>->` a>->b `a>->b`
->> Two headed right arrow `->>` a->>b `a->>b`
|-> Maps to `|->` a|->b `a|->b`
lArr rArr left, right double arrow `lArr rArr` lArrx rArrx `lArrx rArrx`
hArr Horizontal double arrow `hArr` ahArrb `ahArrb`

22.3.8

AsciiMath Greek lowercase letters

example
AsciiMath Description Apperance AsciiMath Result
alpha Lowercase alpha `alpha` f(alpha) `f(alpha)`
beta Lowercase beta `beta` f(beta) `f(beta)`
gamma Lowercase gamma `gamma` f(gamma) `f(gamma)`
delta Lowercase delta `delta` f(delta) `f(delta)`
epsilon Lowercase epsilon `epsilon` f(epsilon) `f(epsilon)`
zeta Lowercase zeta `zeta` f(zeta) `f(zeta)`
eta Lowercase eta `eta` f(eta) `f(eta)`
theta Lowercase theta `theta` f(theta) `f(theta)`
iota Lowercase iota `iota` f(iota) `f(iota)`
kappa Lowercase kappa `kappa` f(kappa) `f(kappa)`
lambda Lowercase lambda `lambda` f(lambda) `f(lambda)`
mu Lowercase mu `mu` f(mu) `f(mu)`
nu Lowercase nu `nu` f(nu) `f(nu)`
xi Lowercase xi `xi` f(xi) `f(xi)`
pi Lowercase pi `pi` f(pi) `f(pi)`
rho Lowercase rho `rho` f(rho) `f(rho)`
sigma Lowercase sigma `sigma` f(sigma) `f(sigma)`
alpha Lowercase alpha `alpha` f(alpha) `f(alpha)`
tau Lowercase tau `tau` f(tau) `f(tau)`
upsilon Lowercase upsilon `upsilon` f(upsilon) `f(upsilon)`
phi Lowercase phi `phi` f(phi) `f(phi)`
chi Lowercase chi `chi` f(chi) `f(chi)`
psi Lowercase psi `psi` f(psi) `f(psi)`
omega Lowercase omega `omega` f(omega) `f(omega)`

22.3.9

AsciiMath Greek uppercase letters

example
AsciiMath Description Apperance AsciiMath Result
Gamma Uppercase gamma `Gamma` f(Gamma) `f(Gamma)`
Delta Uppercase delta `Delta` f(Delta) `f(Delta)`
Theta Uppercase theta `Theta` f(Theta) `f(Theta)`
Lambda Uppercase lambda `Lambda` f(Lambda) `f(Lambda)`
Xi Uppercase xi `Xi` f(Xi) `f(Xi)`
Pi Uppercase pi `Pi` f(Pi) `f(Pi)`
Sigma Uppercase sigma `Sigma` f(Sigma) `f(Sigma)`
Phi Uppercase phi `Phi` f(Phi) `f(Phi)`
Psi Uppercase psi `Psi` f(Psi) `f(Psi)`
Omega Uppercase omega `Omega` f(Omega) `f(Omega)`

22.3.10

AsciiMath logical operators

example
AsciiMath Description Apperance AsciiMath Result
|>< Semi-direct product `|><` N |><_psi `N |><_psi `
><| Semi-direct product `><|` N ><|_psi H `N ><|_psi H`
|><| Join `|><|` N |><| H `N |><| H`
@ Composite `@` N @ H `N @ H`
o+ Circled plus `o+` N o+ H `N o+ H`
ox Circled times `ox` N ox H `N ox H`
o. Circled dot `o.` N o. H `N o. H`

22.3.11

AsciiMath sets and groups

example
AsciiMath Description Apperance AsciiMath Result
^^ Wedge `^^` N ^^ H `N ^^ H`
^^^ Large wedge `^^^` N ^^^ H `N ^^^ H`
vv Vee `vv` N vv H `N vv H`
vvv Large Vee `vvv` N vvv H `N vvv H`
nn Cap `nn` N nn H `N nn H`
nnn Large cap `nnn` N nnn H `N nnn H`
uu Cup `uu` N uu H `N uu H`
uuu Large cup `uuu` N uuu H `N uuu H`
|><| Join `|><|` N |><| H `N |><| H`
in Element of `in` N in H `N in H`
!in Not an element of `!in` N !in H `N !in H`
sub Subset of `sub` N sub H `N sub H`
sube Subset of or equal to `sube` N sube H `N sube H`
supe Superset of or equal to `supe` N supe H `N supe H`
-< Precedes `-<` N -< H `N -< H`
-<= Precedes or equal to `-<=` N -<= H `N -<= H`
>- Supersedes `>-` N >- H `N >- H`
>-= Supersedes or equal to `>-=` N >-= H `N >-= H`

22.3.12

AsciiMath subscripts and superscripts

example
AsciiMath Description Apperance AsciiMath Result
_ Subscript `a_i` x=a_i `x=a_i`
^ Superscript `a^i` x=e^t `x=e^t`

Subscripts and superscripts also work with large operators:

example
AsciiMath Description Apperance AsciiMath Result
int_() Integral with lower limit `int_(lim)` x=aint_(-t)b `x=aint_(-t)b`
int^() Integral with upper limit `int^(lim)` x=aint^(+t)b `x=aint^(+t)b`
int_()^() Integral with upper and lower limits `int_(lim)^(lim)` x=aint
_(-t)^(+t)b
`x=aint
_(-t)^(+t)b`

Where both subscripts and superscripts are applied to an object, the subscript must come first.

22.3.13

AsciiMath text in equation

Text can be added to any equation by surrounding it in quotes ".

example
AsciiMath Description Apperance AsciiMath Result
"anytext" Text string `"anytext"` x="something" `x="something"`

22.3.14

AsciiMath matrices

example
Description AsciiMath Result
Standard matrices (normal) ((a,b),(c,d)) `((a,b),(c,d))`
Standard matrices (square) [[a,b],[c,d]] `[[a,b],[c,d]]`
Column vector (normal) ((a),(b)) `((a),(b))`
Column vector (square) [[a],[b]] `[[a],[b]]`
Complex {(2x,+,17y,=,23),(x,-,y,=,5):}} `{(2x,+,17y,=,23),(x,-,y,=,5):}}`

There are two delimiters for matrices (: and :), these act as invisible brackets to force things to line up.

22.3.15

AsciiMath notes on syntax

AsciiMath (and MathJax) ignore space, add them or remove them as you wish. For example, a prop b and apropb both give `apropb`.



End flourish image