example:math:syntax

Maths syntax

LaTeX, via KaTeX

Delimiters: $…$ (inline), $$…$$ (display), also \(…\) and \[…\].

Inline: $e^{i\pi} + 1 = 0$

Display:

$$\sum_{i=1}^{n} i^3 = \left(\frac{n(n+1)}{2}\right)^2$$

$$\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}$$

Matrices and cases:

$$A = \begin{pmatrix} a & b \\ c & d \end{pmatrix} \qquad |x| = \begin{cases} x & x \ge 0 \\ -x & x < 0 \end{cases}$$

Built-in macros

Defined in the KaTeX plugin's configuration — add your own there:

\NN $\NN$ \ZZ $\ZZ$ \QQ $\QQ$ \RR $\RR$ \CC $\CC$

Chemistry (mhchem)

$\ce{CO2 + C -> 2 CO}$ renders as $\ce{CO2 + C -> 2 CO}$

$$\ce{SO4^2- + Ba^2+ -> BaSO4 v}$$

AsciiMath

Delimiter: backticks. Rendered to MathML on the server, so it is in the page source and needs no JavaScript.

Input Output
`x_(1,2)=(-b+-sqrt(b^2-4a c))/(2a)` `x_(1,2)=(-b+-sqrt(b2-4a c))/(2a)`
`sum_(i=1)^n i^3` `sum_(i=1)n i3`
`int_0^1 x^2 dx` `int_01 x2 dx`
`lim_(x->0) sin(x)/x = 1` `lim_(x→0) sin(x)/x = 1`
`((a,b),(c,d))` `1)`
`AA x in RR, EE y in QQ` `AA x in RR, EE y in QQ`
`A uu B nn C` `A uu B nn C`
`root(3)(x)` `root(3)(x)`

Starting an expression with a space switches it to display style: ` sum_(i=1)^n i^3` gives ` sum_(i=1)^n i^3`

Local differences from Jipsen's reference

This implementation is server-side PHP, and differs slightly from the original JavaScript:

  • Only backticks are recognised — not $$…$$ (that belongs to KaTeX here).
  • Text is written „like this”, not text{like this}.
  • Angle brackets are (: and :); « and » mean much-less/greater-than.
  • No LaTeX-style aliases (\alpha etc.) — write alpha.
  • / binds loosely after lim: write `lim_(x->0) {:sin(x)/x:}`, not `lim_(x->0) sin(x)/x`.

Escaping

To show the delimiters literally, wrap them in '''' or a code block: * `not math` and $not katex$%%

  • Code blocks are left alone automatically.

Regression fixture

AsciiMath corpus renders 33 AsciiMath expressions — handy for checking that nothing broke after an upgrade.

1)
a,b),(c,d
example/math/syntax.txt · ostatnio zmienione: przez 127.0.0.1