Basic MathJax and Mathematics
Displaying a formula
For inline formulas, use \$ ... \$
. For display-mode formulas (i.e. multiline, centered formulas which take up their own paragraph), use $$ ... $$
. Various symbols will be displaye differently in inline vs multiline mode.
For example, the equation \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}
renders in inline mode (\$
) as the following: \$\sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6}\$
Meanwhile in display mode ($$
) it displays as: $$ \sum_{i=0}^n i^2 = \frac{(n^2+n)(2n+1)}{6} $$
(Note the $$
also breaks it out into its own lines and centers it.)
New lines: Display formulas can have multiple lines. Insert a line break with \\
.
Grouping
MathJax operates on symbols or groups of symbols. Usually, a MathJax operator that's expecting to do something fancy with some symbols will grab just the very first symbol available and nothing more. For example, a^bc
will be displayed as \$a^bc\$.
If we want to represent that as \$a\$ to the power of \$bc\$ we instead need to group these symbols using curly braces, i.e. { }
. So we'd write a^{bc}
instead: \$a^{bc}\$.
You can get literal curly braces by escaping them: \{foo\}
→ \$ \{foo\} \$
Basic mathematical formatting
Mathematical operations: +
, -
(hyphen), \times
and \div
: \$1 + 2 - 3 \times 4 \div 5\$.
\cdot
for \$ x \cdot y \$
\pm \mp
for \$\pm \mp\$
Comparison:
\gt
and \lt
for \$\gt\$ and \$\lt\$
\ge
or \geq
for \$\ge\$, \geqslant
for \$\geqslant\$.
\le
or \leq
for \$\le\$, \leqslant
for \$\leqslant\$
\approx
\sim
\simeq
for \$\approx \sim \simeq\$
Superscripts and subscripts: use ^
and _
. These can be combined: x_i^2
or x^2_i
renders as \$x_i^2\$.
Fractions:
\frac a b
grabs the next two groups: \$\frac{a+1}{b+1}\$
\dfrac a b
works the same but always occupies two lines of vertical space: \$\dfrac{a+1}{b+1}\$
- You may instead prefer to use
\over
: {a+1 \over b+1}
for \${a+1 \over b+1}\$
Greek letters: Use \alpha
, \beta
, …, \omega
: \$\alpha, \beta \ldots \omega\$. For uppercase \Gamma
, \Delta
, …, \Omega
: \$\Gamma, \Delta, \ldots \Omega\$.
Plain text: Usually all text is treated as symbols, so these are some words
gets rendered as \$these are some words\$ despite the spaces. To tell MathJax to treat it as just ordinary text use \text{stuff}
: \$\text{these are some words}\$.
Floor and ceiling: \lfloor x \rfloor
for \$\lfloor x \rfloor\$, \lceil x \rceil
for \$\lceil x \rceil\$
Equation alignment
You can use the \begin{align} ... \end{align}
environment to align equations over multiple lines. The &
symbol is an alignment marker in this environment. Use \\
to start new lines. The following example aligns on the equals sign:
$$
\begin{align}
a^2 &= b^2 + c^2 \\
a &= \sqrt{b^2 + c^2}
\end{align}
$$
$$
\begin{align}
a^2 &= b^2 + c^2 \\
a &= \sqrt{b^2 + c^2}
\end{align}
$$
Equation sizing
Occasionally the default mathjax sizing may need to be adjusted in order to make things readable. MathJax supports size Latex commands:
\tiny
\scriptsize
\footnotesize
\small
\normalsize
\large
\Large
\LARGE
\huge
\Huge
The commands are listed from smallest to largest. \normalsize
is the default. Note that use of capitalization on some commands.
The a size command is applied within the scope it occurs in.
For example: \${\Large\sqrt{\frac{1}{a_z^x}}}\$
gives \${\Large\sqrt{\frac{1}{a_z^x}}}\$.
As a more practical example, the application \small
allows the following to render without undesired line breaks:
$$f(t)={\small\frac{cos(rt)(gr^2_x+gr^2_y-r_xr^2_zv_y(0)+r_yr^2_zv_x(0)+
r^3_x(-v_y(0))+r^2_xr_yv_x(0)-r_xr^2_yv_y(0)+r^3_yv_x(0))}{r}}$$