AsciiMath is an easy-to-write markup language for mathematics. Try it:
Download AsciiMath.php from GitHub and include it in your project.
require_once ('asciimath.php');
$am = new AMserver();
Some versions of Chrome don't offer a Math font by default. Include this link in your header:
<link href="https://fonts.googleapis.com/css2?family=STIX Two Math" rel="stylesheet">
Add mathematics anywhere in your web pages:
$euler = "e^i pi + 1 = 0";
echo "<p>Euler's Identity is {$am->parseMath($euler)}.</p>";
$am->parseMath($formula, $inline) has a second boolean parameter which defaults true. Inline formulas render directly within a sentence. Set false to render block (or display) formulas as centered, standalone paragraphs. This is equivalent to MathJax's \[ and \( brackets.
Most AsciiMath symbols attempt to mimic in text what they look like
rendered, like oo for `oo`. Many symbols can also be
displayed using a TeX alternative, but a preceeding backslash is not
required.
| Type | TeX alt | See |
|---|---|---|
| + | ||
| - | ||
| * | cdot | |
| ** | ast | |
| *** | star | |
| // | ||
| setminus | backslash | |
| xx | times | |
| -: | div | |
| |>< | times | |
| ><| | rtimes | |
| |><| | bowtie | |
| @ | circ | |
| o+ | oplus | |
| ox | otimes | |
| o. | odot | |
| sum | ||
| prod | ||
| ^^ | wedge | |
| ^^^ | bigwedge | |
| vv | vee | |
| vvv | bigvee | |
| nn | cap | |
| nnn | bigcap | |
| uu | cup | |
| uuu | bigcup | |
| dag | dagger | |
| ddag | ddagger | |
| hbar | ||
| frown |
| Type | Tex alt | See |
|---|---|---|
| 2/3 | frac{2}{3} | |
| 2^3 | ||
| sqrt x | ||
| root(3)(x) | ||
| int | ||
| oint | ||
| del | partial | |
| grad | nabla | |
| +- | pm | |
| O/ | emptyset | |
| oo | infty | |
| aleph | ||
| :. | therefore | |
| :' | because | |
| |...| | |ldots| | |
| |cdots| | ||
| vdots | ||
| ddots | ||
| |\ | | ||
| |quad| | ||
| /_ | angle | |
| frown | ||
| /_\ | triangle | |
| diamond | ||
| square | ||
| |__ | lfloor | |
| __| | rfloor | |
| |~ | lceiling | |
| ~| | rceiling | |
| CC | ||
| NN | ||
| RR | ||
| ZZ | ||
| "hi" | text(hi) |
| Type | TeX alt | See |
|---|---|---|
| = | ||
| != | ne | |
| < | lt | |
| > | gt | |
| <= | le | |
| >= | ge | |
| mlt | ll | |
| mgt | gg | |
| -< | prec | |
| -<= | preceq | |
| >- | succ | |
| >-= | succeq | |
| in | ||
| !in | notin | |
| sub | subset | |
| !sub | ||
| sup | supset | |
| !sup | ||
| supe | supseteq | |
| !supe | ||
| sube | supseteq | |
| !sube | ||
| -= | equiv | |
| !-= | notequiv | |
| -= | equiv | |
| ~= | cong | |
| ~~ | approx | |
| prop | propto | |
| rightleftharpoons |
| Type | TeX alt | See |
|---|---|---|
| and | ||
| or | ||
| not | neg | |
| => | implies | |
| if | ||
| <=> | iff | |
| AA | forall | |
| EE | exists | |
| :|: | ||
| _|_ | bot | |
| TT | top | |
| |-- | vdash | |
| |== | models | |
| square | ||
| diamond |
| Type | TeX alt | See |
|---|---|---|
| ( x+y ) | ||
| [x+y] | ||
| {x+y} | ||
| |:x+y:| | ||
| <x+y> | ||
| {x+y} | ||
| (:x+y:) | ||
| <<x+y>> | ||
| {:x+y) | ||
| (x+y:} | ||
| abs(x) | ||
| floor(x) | ||
| ceil(x) | ||
| norm(vecx) |
| Type | TeX alt | See |
|---|---|---|
| uarr | uparrow | |
| darr | downarrow | |
| rarr | rightarrow | |
| -> | to | |
| >-> | rightarrowtail | |
| ->> | twoheadrightarrow | |
| >->> | twoheadrightarrowtail | |
| |-> | mapsto | |
| larr | leftarrow | |
| harr | leftrightarrow | |
| rArr | Rightarrow | |
| lArr | Leftarrow | |
| hArr | Leftrightarrow |
| Type | TeX alt | See |
|---|---|---|
| hat x | ||
| bar x | overline x | |
| ul x | underline x | |
| vec x | ||
| tilde x | ||
| dot x | ||
| ddot x | ||
| overset(x)(=) | ||
| underset(x)(=) | ||
| ubrace(1+2) | underbrace(1+2) | |
| obrace(1+2) | overbrace(1+2) | |
| overarc(AB) | overparen(AB) | |
| color(red)(x) | ||
| cancel(x) |
| Type | See | Type | See |
|---|---|---|---|
| alpha | |||
| beta | |||
| gamma | Gamma | ||
| delta | Delta | ||
| epsilon | |||
| varepsilon | |||
| varepsilon | |||
| zeta | |||
| eta | |||
| theta | Theta | ||
| vartheta | |||
| iota | |||
| kappa | |||
| lambda | Lambda | ||
| mu | |||
| nu | |||
| xi | Xi | ||
| pi | Pi | ||
| rho | |||
| sigma | Sigma | ||
| tau | |||
| upsilon | |||
| phi | Phi | ||
| varphi | |||
| chi | |||
| psi | Psi | ||
| omega | Omega |
| Type | TeX alt | See |
|---|---|---|
| bb "AaBbCc" | mathbf "AaBbCc" | |
| bbb "AaBbCc" | mathbb "AaBbCc" | |
| cc "AaBbCc" | mathcal "AaBbCc" | |
| tt "AaBbCc" | mathtt "AaBbCc" | |
| fr "AaBbCc" | mathfrak "AaBbCc" | |
| sf "AaBbCc" | mathsf "AaBbCc" | |
| sfit "AaBbCc" | ||
| bbsf "AaBbCc" | ||
| bbcc "AaBbCc" | ||
| bbfr "AaBbCc" | ||
| bbit "AaBbCc" | ||
| bbsfit "AaBbCc" | ||
| bold "AaBbCc" | ||
| italic AaBbCc" | ||
| a quad b | ||
| a qquad b | ||
| a enspace b | ||
| a thinspace b | ||
| a mspace(20) b |
Function names are treated as constants:
sin, cos, tan, sec, csc, cot,
arcsin, arccos, arctan, sinh, cosh, tanh, sech, csch, coth, exp, log, ln,
det, dim, mod, gcd, lcm, lub, glb, min, max, f, g.
[[a,b]] yields
[(a,b)(c,d)] yields
((a),(b)) yields
[[a,b],[c,d]] yields
Augmented matrices: [[a,b,|,c],[d,e,|,f]] yields
Matrices can be used for layout: {(2x,+,17y,=,23),(x,-,y,=,5):} yields
Complex subscripts: lim_(N->oo) sum_(i=0)^N yields
Subscripts must come before superscripts: int_0^1 f(x)dx yields
Derivatives: f(x) = dy/dx yields
For variables other than x,y,z, or t you will need grouping symbols: (dq)/(dp) yields
ubrace(1+2+3+4)_("4 terms") yields
obrace(1+2+3+4)^("4 terms") yields
> and
< characters with spaces so that the html parser does not
confuse it with an opening or closing tag!| x^2+y_1+z_12^34 | subscripts as in TeX, but numbers are treated as a unit | |
| sin^-1(x) | function names are treated as constants | |
| d/dxf(x)=lim_(h->0)(f(x+h)-f(x))/h | complex subscripts are bracketed, displayed under lim | |
| \frac{d}{dx}f(x)=\lim_{h\to 0}\frac{f(x+h)-f(x)}{h} | standard LaTeX notation is an alternative | |
| f(x)=sum_(n=0)^oo(f^((n))(a))/(n!)(x-a)^n | f^((n))(a) must be bracketed, else the numerator is only 'a' | |
| f(x)=\sum_{n=0}^\infty\frac{f^{(n)}(a)}{n!}(x-a)^n | standard LaTeX produces a similar result | |
| int_0^1f(x)dx | subscripts must come before superscripts | |
| [[a,b],[c,d]]((n),(k)) | matrices and column vectors are simple to type | |
| x/x={(1,if x!=0),("undefined",if x=0):} | piecewise defined functions are based on matrix notation | |
| a//b | use //// for inline fractions | |
| (a/b)/(c/d) | with brackets, multiple fraction work as expected | |
| a/b/c/d | without brackets the parser chooses this particular expression | |
| ((a*b))/c | only one level of brackets is removed; * gives standard product | |
| sqrt sqrt root3x | spaces are optional, only serve to split strings that should not match | |
| << a,b >> and {:(x,y),(u,v):} | angle brackets and invisible brackets | |
| (a,b)={x in RR | a < x < = b} | grouping brackets don't have to match | |
| abc-123.45^-1.1 | non-tokens are split into single characters, but decimal numbers are parsed with possible sign | |
| [[a,b,|,c],[d,e,|,f]] | augmented matrices | |
| {(2x,+,17y,=,23),(x,-,y,=,5):} | Matrices can be used for layout | |
| lim_(N->oo) sum_(i=0)^N | Complex subscripts | |
| (dq)/(dp) | For variables other than x,y,z, or t you will need grouping symbols |