Normally, we can add math equations and symbols using LaTeX syntax, starting with \begin{equation}
and ending with \end{equation}
For example, we write an integral calculus formula as:
\begin{equation}
\frac{d}{dx}\sin{x}=\cos{x}
\end{equation}
The output:
In Jupyter notebook, we can easily use a pair of dollar signs $ ... $
instead of \begin{equation}
and \end{equation}
. For example:
$\frac{d}{dx}\sin{x}=\cos{x}$
It renders inline as:
$ \frac{d}{dx}\sin{x}=\cos{x} $
We can also enclose LaTeX code in double dollar signs $$ ... $$
to center-align the expressions. For example:
$$\frac{d}{dx}\sin{x}=\cos{x}$$
It renders as:
$$\frac{d}{dx}\sin{x}=\cos{x}$$Greek letters are widely used mathematical symbols, which comprise a backslash \
and the name of the letter.
We can get a lowercase Greek letter if the first letter of the name is lowercase.
Command | Ouput | Comand | Output | Command | Output | Command | Output |
---|---|---|---|---|---|---|---|
\$\alpha\\$ | $\alpha$ | \$\eta\\$ | $\eta$ | \$\nu\\$ | $\nu$ | \$\sigma\\$ | $\sigma$ |
\$\beta\\$ | $\beta$ | \$\gamma\\$ | $\gamma$ | \$\omega\\$ | $\omega$ | \$\tau\\$ | $\tau$ |
\$\chi\\$ | $\chi$ | \$\iota\\$ | $\iota$ | \$\phi\\$ | $\phi$ | \$\theta\\$ | $\theta$ |
\$\delta\\$ | $\delta$ | \$\kappa\\$ | $\kappa$ | \$\pi\\$ | $\pi$ | \$\xi\\$ | $\xi$ |
\$\digamma\\$ | $\digamma$ | \$\lambda\\$ | $\lambda$ | \$\psi\\$ | $\psi$ | \$\upsilon\\$ | $\upsilon$ |
\$\epsilon\\$ | $\epsilon$ | \$\mu\\$ | $\mu$ | \$\rho\\$ | $\rho$ | \$\zeta\\$ | $\zeta$ |
Some Greek letters have alternate, or variant versions, which can be created by adding var before the name of the letter.
Command | Ouput | Comand | Output | Command | Output |
---|---|---|---|---|---|
\$\varepsilon\\$ | $\varepsilon$ | \$\varpi\\$ | $\varpi$ | \$\vartheta\\$ | $\vartheta$ |
\$\varkappa\\$ | $\varkappa$ | \$\varrho\\$ | $\varrho$ | ||
\$\varphi\\$ | $\varphi$ | \$\varsigma\\$ | $\varsigma$ |
In most cases, we can get an uppercase letter if the first letter is uppercase in the Jupyter Notebook except that upper-case Alpha ($A$), Beta($B$), Mho ($\mho$) and Nabla ($\nabla$).
Command | Ouput | Comand | Output | Command | Output |
---|---|---|---|---|---|
\$A\\$ | $A$ | \$\Phi\\$ | $\Phi$ | \$\Upsilon\\$ | $\Upsilon$ |
\$B\\$ | $B$ | \$\Pi\\$ | $\Pi$ | \$\Xi\\$ | $\Xi$ |
\$\Delta\\$ | $\Delta$ | \$\Psi\\$ | $\Psi$ | \$\mho\\$ | $\mho$ |
\$\Lambda\\$ | $\Lambda$ | \$\Sigma\\$ | $\Sigma$ | \$\nabla\\$ | $\nabla$ |
\$\Omega\\$ | $\Omega$ | \$\Theta\\$ | $\Theta$ |
An accent sign may precede any other symbols to add an accent above it, which includes long and short forms.
Command | Ouput | Comand | Output | Command | Output |
---|---|---|---|---|---|
\$\acute a\\$ | $\acute a$ | \$\dot a\\$ | $\dot a $ | \$\vec a\\$ | $\vec a$ |
\$\bar a \\$ | $\bar a$ | \$\grave a\\$ | $\grave a$ | \$\overline{abc}\\$ | $\overline{abc}$ |
\$\breve a\\$ | $\breve a$ | \$\hat a\\$ | $\hat a $ | \$\widehat{xyz}\\$ | $\widehat{xyz}$ |
\$\ddot a \\$ | $\ddot a$ | \$\tilde a\\$ | $\tilde a$ | \$\widetilde{xyz}\\$ | $\widetilde{xyz}$ |
Tip: \imath
is used to avoid the extra dot over the lower-case i and j when you put accents on them.
$\hat i$
: $\hat i$
$\hat \imath$
: $\hat \imath$
The most widely used big symbols, also known as big operators can be easily generated using LaTeX in Jupyter notebook.
Command | Ouput | Comand | Output | Command | Output |
---|---|---|---|---|---|
\$\bigcap\\$ | $\bigcap$ | \$\biguplus\\$ | $\biguplus$ | \$\iiint\\$ | $\iiint$ |
\$\bigcup\\$ | $\bigcup$ | \$\bigvee\\$ | $\bigvee$ | \$\iiint\\$ | $\iiiint$ |
\$\bigsqcup\\$ | $\bigsqcup$ | \$\bigwedge\\$ | $\bigwedge$ | \$\idotsint\\$ | $\idotsint$ |
\$\bigodot\\$ | $\bigodot$ | \$\coprod\\$ | $\coprod$ | \$\oint\\$ | $\oint$ |
\$\bigoplus\\$ | $\bigoplus$ | \$\int\\$ | $\int$ | \$\prod\\$ | $\prod$ |
\$\bigotimes\\$ | $\bigotimes$ | \$\iint\\$ | $\iint$ | \$\sum\\$ | $\sum$ |
The following table summarizes the convenient ways to generate these most commonly used symbols or operators to express mathematic relations.
Command | Ouput | Comand | Output | Command | Output | Command | Output |
---|---|---|---|---|---|---|---|
\$\approx\\$ | $\approx$ | \$\geqslant\\$ | $\geqslant$ | \$\ni\\$ | $\ni$ | \$\subseteq\\$ | $\subseteq$ |
\$\because\\$ | $\because$ | \$\in \\$ | $\in $ | \$\notin\\$ | $\notin$ | \$\supset\\$ | $\supset$ |
\$\div \\$ | $\div $ | \$\leq\\$ | $\leq$ | \$\not\subset\\$ | $\not\subset$ | \$\supseteq\\$ | $\supseteq$ |
\$\equiv\\$ | $\equiv$ | \$\leqq\\$ | $\leqq$ | \$\nsubseteq\\$ | $\nsubseteq$ | \$\therefore\\$ | $\therefore$ |
\$\forall\\$ | $\forall$ | \$\leqslant\\$ | $\leqslant$ | \$\nsupseteq\\$ | $\nsupseteq$ | \$\times\\$ | $\times$ |
\$\geq\\$ | $\geq$ | \$\mp\\$ | $\mp$ | \$\pm\\$ | $\pm$ | \$\triangleq\\$ | $\triangleq$ |
\$\geqq\\$ | $\geqq$ | \$\neq \\$ | $\neq $ | \$\subset\\$ | $\subset$ |
$\not\subset$ is $\not\subset$
rather than $\nsubset$
To make subscripts and superscripts, use the Underscore _
and Caret ^
symbols, respectively.
$y_i = x_i^3+b$
It renders as:
$y_i = x_i^3+b$
$\frac{a}{b}$
The output:
$\frac{a}{b}$
Fractions can be arbitrarily nested:
$\frac{x - \frac{1}{x}}{b}$
produces:
$\frac{x - \frac{1}{x}}{b}$
Warning: special care needs to be taken to put brackets around fractions.
$(\frac{x - \frac{1}{x}}{b})$
renders as:
$(\frac{x - \frac{1}{x}}{b})$
Note: The obvious way produces brackets that are too small.
The solution is to precede the bracket with \left
and \right
to inform the parser that those brackets encompass the entire object:
$\left(\frac{x - \frac{1}{x}}{b}\right)$
produces:
$\left(\frac{x - \frac{1}{x}}{b}\right)$
Mainly it's a difference of size:
\frac
: means that the actual context implies the decision above\dfrac
: means that the fraction is set in displaystyle, which creates a 'large' fraction\tfrac
: means that the fraction is set in textstyle, which create a 'small' fraction $\frac{a}{b}$ vs. $\dfrac{a}{b}$ vs. $\tfrac{a}{b}$
$\frac{a}{b}$ vs. $\dfrac{a}{b}$ vs. $\tfrac{a}{b}$
\frac{}{}
is the same as \tfrac{}{}
, while it is the same as \dfrac{}{}
when in the \displaystyle
environment.
$\dfrac{a}{b}$
$\displaystyle \frac{1}{2}$
are
$\dfrac{a}{b}$
$\displaystyle \frac{a}{b}$
\binom{}{}
is commonly used for binomial coefficients
The binomial coefficient is defined by the next expression:
$$\binom{n}{k} = \frac{n!}{k!(n-k)!}$$
Binomial coefficient can be fraction:
$\binom{1/3}{-2/3}$
$\binom{1/3}{-2/3}$
It can be created with the \genfrac{#1}{#2}{#3}{#4}{#5}{#6}
, which represents the most general command for defining fractions with optional delimiters, line thickness, and specified style.
$\genfrac{}{}{0}{}{e}{f}$
$\genfrac{(}{)}{0pt}{0}{a}{b}$
render as:
$\genfrac{}{}{0}{}{e}{f}$
$ \genfrac{(}{)}{0pt}{0}{a}{b} $
The commonly used matrix types include:
Type | LATEX markup | Renders as |
---|---|---|
Plain | ```\begin{matrix} |
a & b & c \
x & y & z
\end{matrix}|\begin{matrix} a & b & c \\ x & y & z \\ \end{matrix}|
|Parentheses;<br>round brackets |
\begin{pmatrix}
a & b & c \\
x & y & z
\end{pmatrix}|$\begin{pmatrix} a & b & c\\x & y & z\\\end{pmatrix}$|
|Brackets;<br>square brackets|
\begin{bmatrix}
a & b & c\\
x & y & z
\end{bmatrix}|$\begin{bmatrix} a & b & c\\x & y & z\\\end{bmatrix}$|
|Braces;<br>curly brackets|
\begin{Bmatrix}
a & b & c\
x & y & z
\end{Bmatrix}|$\begin{Bmatrix} a & b & c\\x & y & z\\\end{Bmatrix}$|
|Braces;<br>curly brackets|
\begin{Bmatrix}
a & b & c\
x & y & z
\end{Bmatrix}|$\begin{Bmatrix} a & b & c\\x & y & z\\\end{Bmatrix}$|
|Pipes;<br> Vertical bars|
\begin{vmatrix}
a & b & c\\
x & y & z
\end{vmatrix}|$\begin{vmatrix} a & b & c\\x & y & z\\\end{vmatrix}$|
|Double <br>pipes|
\begin{Vmatrix}
a & b & c\
x & y & z
\end{Vmatrix}```|$\begin{Vmatrix} a & b & c\\x & y & z\\\end{Vmatrix}$|
To create matrices with different delimiters by adding them manually to a plain matrix
Type | LATEX markup | Renders as |
---|---|---|
Ceiling brackets |
```$\left\lceil |
\right\rceil$```|$\left\lceil \begin{matrix} a & b & c \\ x & y & z \\ \end{matrix}\right\rceil$ | |Angle <br>brackets |```$\left\langle \begin{matrix} a & b & c \\ x & y & z \end{matrix} \right\rangle$```|$\left\langle \begin{matrix} a & b & c \\ x & y & z \\ \end{matrix}\right\rangle$ | |Mixed |```$\left\langle \begin{matrix} a & b & c \\ x & y & z \end{matrix} \right\rvert$```|$\left\langle \begin{matrix} a & b & c \\ x & y & z \\ \end{matrix}\right\rvert$ |
line: \ldots
diagonal: \ddots
vertical: \vdots
LaTax
$$
\begin{bmatrix}
x_{11} & x_{12} & x_{13} & \dots & x_{1n} \\
x_{21} & x_{22} & x_{23} & \dots & x_{2n} \\
\ldots &\ldots &\ldots &\ldots &\ldots \\
x_{d1} & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}
=
\begin{bmatrix}
x_{11} & x_{12} & x_{13} & \dots & x_{1n} \\
x_{21} & x_{22} & x_{23} & \dots & x_{2n} \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
x_{d1} & x_{d2} & x_{d3} & \dots & x_{dn}
\end{bmatrix}
$$
\hdotsfor{n}
does not work in Jupyter notebook.
Let's insert an inline matrix here:
$\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}$,
but it looks bigger than the text, so let's make it smaller by using
$\big(\begin{smallmatrix}
a & b\\
c & d
\end{smallmatrix}\big)$.
It renders:
Let's insert an inline matrix here:
$\begin{pmatrix}
a & b\\
c & d
\end{pmatrix}$,
but it looks bigger than the text, so let's make it smaller by using
$\big(\begin{smallmatrix}
a & b\\
c & d
\end{smallmatrix}\big)$.
We can also use \bigl
and \bigr
Let's see a bmaxtrix for example:
Let's insert an inline matrix here:
$\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}$,
but it looks bigger than the text, so let's make it smaller by using
$\bigl[\begin{smallmatrix}
a & b\\
c & d
\end{smallmatrix}\bigr]$.
The outputs are as follows:
Let's insert an inline matrix here:
$\begin{bmatrix}
a & b\\
c & d
\end{bmatrix}$,
but it looks bigger than the text, so let's make it smaller by using
$\bigl[\begin{smallmatrix}
a & b\\
c & d
\end{smallmatrix}\bigr]$.
Matrices and other arrays can be produced in LaTeX using the \textbf{array}
environment.
Let's produce a $3 \times 3$ matrix:
$$
\left( \begin{array}{ccc}
a & b & c \\
d & e & f \\
g & h & i \end{array} \right)
$$
produces:
{ccc}
represents that the entries of the column should be centred. If the c
were replaced by l
then all the entries will be left-justified, and r
would produce a column with all entries right-justified.
To produce a table-like matrix or array as follows:
$$
\begin{array}{lcc}
\mbox{Items} & \mbox{Variable Operation} & \mbox{Outputs} \\
\mbox{First variable} & x & 2 \\
\mbox{Second varaible} & y & 4 \\
\mbox{Sum} & x + y & 6 \\
\mbox{Difference} & x - y & -2 \\
\mbox{Multiply} & x*y & 8 \end{array}
$$
The output looks like:
use the array environment to produce multi-line formulae
$$
|x| = \left\{ \begin{array}{ll}
x-1 & \mbox{if $x \geq 0$};\\
x+1 & \mbox{if $x < 0$}.\end{array} \right.
$$
generates:
Radicals can be produced with the \sqrt[]{}
command. The base can be provided inside square brackets.
Notice: the base must be a postive integer and cannot include layout commands such as fractions or sub/superscripts. If the base is 2, it ([2]) can be omited.
The base 2:
$\sqrt{x+a}$
produces:
$\sqrt{x+a}$
The bases other than 2:
$\sqrt[3]{x+a}$
produces:
$\sqrt[3]{x+a}$
The \sum
,\lim
and \int
commands insert the sum, limit and integral symbols respectively, with \limits or \displaystyle specified using the caret (^) and underscore (_).
Typical notation:
$\sum_{i=0}^\infty x_i$
$\int_a^b$
$\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
render as:
$\sum_{i=0}^\infty x_i$
$\int_a^b$
$\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
\limits specified:
$\sum\limits_{i=0}^\infty x_i$
$\int\limits_a^b$
$\lim\limits_{x \to a} \frac{f(x) - f(a)}{x-a}$
produce:
$\sum\limits_{i=0}^\infty x_i$
$\int\limits_a^b$
$\lim\limits_{x \to a} \frac{f(x) - f(a)}{x-a}$
\displaystyle specified:
$\displaystyle\sum_{i=0}^\infty x_i$
$\displaystyle\int_a^b$
$\displaystyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
render as follows:
$\displaystyle\sum_{i=0}^\infty x_i$
$\displaystyle\int_a^b$
$\displaystyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
The \displaystyle specified
has the same results with \limits specified
, but \displaystyle specified
has a better display with a bigger and bold font.
Modifier | Example | Rendered |
---|---|---|
\tiny | \$\tiny a^{x+1}\\$ | $\tiny a^{x+1}$ |
\Tiny | \$\Tiny a^{x+1}\\$ | $\Tiny a^{x+1}$ |
\scriptsize | \$\scriptsize a^{x+1}\\$ | $\scriptsize a^{x+1}$ |
\small | \$\small a^{x+1}\\$ | $\small a^{x+1}$ |
normal | \$a^{x+1}\\$ | $a^{x+1}$ |
\normalsize | \$\normalsize a^{x+1}\\$ | $\normalsize a^{x+1}$ |
\large | \$\large a^{x+1}\\$ | $\large a^{x+1}$ |
\Large | \$\Large a^{x+1}\\$ | $\Large a^{x+1}$ |
\LARGE | \$\LARGE a^{x+1}\\$ | $\LARGE a^{x+1}$ |
\huge | \$\huge a^{x+1}\\$ | $\huge a^{x+1}$ |
\Huge | \$\Huge a^{x+1}\\$ | $\Huge a^{x+1}$ |
\footnotesize
does not work in Jupyter notebook.
normal: $ \lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
displaystyle: $\displaystyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
scriptstyle: $ \scriptstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
scriptscriptstyle: $\scriptscriptstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
textstyle: $\textstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
normal: $ \lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
displaystyle: $\displaystyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
scriptstyle: $ \scriptstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
scriptscriptstyle: $\scriptscriptstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
textstyle: $\textstyle\lim_{x \to a} \frac{f(x) - f(a)}{x-a}$
Table of the predefined math alphabets:
LaTex | Font type | Example |
---|---|---|
default | Modern Roman or Latin Modern | $a^{x+1}$ |
\mathrm | roman | $\mathrm a^{x+1}$ |
\mathbf | bold roman | $\mathbf a^{x+1}$ |
\mathsf | sans serif | $\mathsf a^{x+1}$ |
\mathit | text italic | $\mathit a^{x+1}$ |
\mathtt | typewriter | $\mathtt a^{x+1}$ |
\mathcal | calligraphic | $\mathcal a^{x+1}$ |
For more, please refer to Math Font Selection in LaTeX and Unicode.
It is also possible to change the colors of the formula by adding \color{}
at the beginning.
$$\color{red}{x = {-b \pm \sqrt{b^2-4ac} \over 2a}}$$
$$\color{blue}{x = {-b \pm \sqrt{b^2-4ac} \over 2a}}$$
$$\color{rgb(60, 179, 113)}{x = {-b \pm \sqrt{b^2-4ac} \over 2a}}$$
$$\color{#ee82ee}{x = {-b \pm \sqrt{b^2-4ac} \over 2a}}$$
We can use LaTeX mathematical equations in HTML tags, and then we can formate them in terms of font types, size, color and alignment.
To formate the equation in HTML, put the style attribute inside the html tags. For example:
<p style='text-align: center;
font-family:Time New Roman;
font-size:2.0em; color:red;'>
$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$
</p>
The output looks like:
$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$
$$
x = {-b \pm \sqrt{b^2-4ac} \over 2a} \tag{11.1} \label{eq:special}
$$
It can be refered to equation \eqref{eq:special}.