# LaTeX Math Formulas: A Cheat Sheet

This article should serve as a very simple cheat sheet for everyone who needs to write LaTeX mathematical formulas in Jupyter Notebooks. It’s by no means complete, as the full description of LaTeX notation takes up hundreds of pages. But I’ve tried to gather the stuff I typically use. Hopefully, it will be useful for you too.

This guide should also be applicable for general LaTeX usage, not only in Jupyter Notebooks.

# Writing LaTeX formulas in Jupyter Notebooks

First off, you need to switch the cell type to Markdown, then you’ll be able to write both Markdown text and embedded math formulas in the LaTeX format:

Inline formulas are delimited by $:

`This is an inline formula: $\alpha=5$`

Multiline formulas are delimited by $$:

`This is a multiline formula: `

$$

\alpha=\begin{cases}

1, & \beta \ge 0 \\

2, & \beta < 0

\end{cases}

$$

# Letters

You can display greek letters just by spelling them out after a backslash:

`Greek letters: $\alpha,\beta,\gamma...$`

To display something known as the “blackboard font”, use `\mathbb{}`

with a letter in curly braces. Probably the most prominent example of using this font in math is the symbol for real numbers:

`Blackboard font: $\mathbb{R}, \mathbb{Z}, \mathbb{D}...$`

Similarly, calligraphic font may be displayed by using `\mathcal{}`

:

`Calligraphic font: $\mathcal{R}, \mathcal{Z}, \mathcal{D}...$`

If you need to display a line over any symbol, use `\bar`

with this symbol in curly braces. You can actually put any expression inside `\bar{}`

:

`Bars over symbols: $\bar{a}, \bar{b}, \bar{c}$`

Similarly, a “hat” over a symbol is displayed by wrapping it with `\hat{}`

:

`Hats over symbols: $\hat{a}, \hat{b}, \hat{c}$`

Finally, a tilde (wavy line) over a symbol is displayed by wrapping it with `\tilde`

:

`Tilde over symbols: $\tilde{a}, \tilde{b}, \tilde{c}$`

I sometimes use arrows and dots over symbols, here’s how to do it:

`Arrows: $\overrightarrow{a}, \overrightarrow{b}, \overrightarrow{c}$`

Dots: $\dot{a}, \dot{b}, \dot{c}$

One useful trick is adding spacing between symbols, the simplest way to achieve this is with a backslash followed by a semicolon, like this: `\;`

`Spacing between symbols: $a\;b\;c$`

Subscripts are written with `_`

after the symbol, followed by the subscript symbol. If you need to wrap more than one symbol in a subscript, use curly braces. In the same way, you can easily achieve subscripts of subscripts:

`Subscripts: $a_b, a_{b1}, a_{b_{c}}$`

Superscripts are similar, but with the `^`

symbol:

`Superscripts: $a^b, a^{b1}, a^{b^{c}}$`

You can combine subscripts and superscripts:

`Subscripts and superscripts: $a^b_c, a^{b1}_{c1}, a^{b^{c}}_{d_{e}}$`

# Other symbols

“Less than” and “greater than” symbols are written as follows:

Less than: $a \le b$Greater than: $a \ge b$

Triple-line equality (equivalence) sign is written as `\equiv`

, approximate is written as `\approx`

:

Equivalence: $A\equiv B$

Approximate: $a\approx b$

The infinity symbol is just `\infty`

:

`Infinity: $a \rightarrow \infty$`

The “nabla” symbol typically used to denote a gradient operation is written as `\nabla`

:

`Nabla (gradient): $\nabla f(x_0,y_0)$`

# Different types of braces

As you may have noticed, curly braces have special meaning in LaTeX, so if you need to display curly braces themselves, you have to escape them with a backslash:

`Curly braces: $\{a+b\}$`

Sometimes you need to wrap an expression in braces, but if its height is more than a single line (for example, it contains fractions), the braces should be scaled to fit the expression height. This is achievable with notation`\left(`

and `\right)`

:

`Large braces: $\left( \frac{a+b}{a-b} \right)$`

Similarly, you can display large square or curly braces (but notice that curly braces still have to be escaped with `\`

):

`Large square braces: $\left[ \frac{a+b}{a-b} \right]$`

`Large curly braces: $\left\{ \frac{a+b}{a-b} \right\}$`

# Math operations

You can write multiplication with a dot symbol or with a cross symbol:

Multiplication with a dot symbol: $a\cdot b$Multiplication with a cross symbol: $a\times b$

Fractions are written with `\frac`

followed by two curly brace blocks: one for the numerator (top part) and one for the denominator (bottom part) of the fraction:

`Fractions: $\frac{a+b}{a-b}$`

For taking a square root, wrap an expression with `\sqrt`

:

`Square root: $\sqrt{a+b+c}$`

# Sums, products, integrals, limits

Sums are written with `\sum`

. Although you can use subscript and superscript notation for limits of a sum, in that way they’ll be written in front of the sum symbol, whereas they are usually written above — this can be achieved with `\limits`

:

`Sums with limits: $\sum\limits_{i=1}^{n}i^2$`

Products are written in a similar manner, with `\prod`

:

`Products with limits: $\prod\limits_{i=1}^{n}i^2$`

Integrals are displayed with `\int`

:

`Integrals with limits: $\int\limits_{-\infty}^{\infty}f(x)dx$`

There’s a special way of writing limits with `\lim`

, but for some reason, in Jupyter Notebook it works only in multiline:

`$$`

\lim_{x\to 0} (1+x)^\frac{1}{x} = e

$$

# Set symbols

Some mathematical symbols are typically associated with sets, for example, union, intersection, subset, and inclusion:

`Set union: $A \cup B$`

`Set intersection: $A \cap B$`

`Subset: $A \subset B$`

Element is included (not included) in the set:

Element is in the set: $a \in A$Element is not in the set: $a \notin A$

Similarity (a single large wavy line) is displayed with `\sim`

:

`Similarity: $A \sim B$`

# Logical operations

Here are some symbols and operations typically used in logical expressions. We’ll start off with “exists” and “for all”:

Exists: $\exists a:a>0$For all: $\forall a:a>0$

Different types of arrows can be easily displayed as follows (notice that double arrows start with a capital letter):

`Arrows: $\leftarrow \rightarrow \leftrightarrow \Leftarrow \Rightarrow \Leftrightarrow$`

# Matrices

Matrix is typically written as follows:

Matrix: $$

\begin{pmatrix}

a & b & c \\

d & e & f \\

g & h & i \\

\end{pmatrix}

$$

# Other multiline expressions

Sometimes you need to display a multiline expression with a large curly brace to the left. In LaTeX, you do it as follows:

- wrap the expression in
`\begin{cases}...\end{cases}`

- write the cases separated by
`\\`

- if cases are formulated as “expression, condition”, you need to separate the expression and the condition with
`&`

, so that they would be aligned across the lines; - you can write the same expression inline (with $), but writing it as multiline (with $$) allows to have more readability:

Cases: $$

f(x)=\begin{cases}

\frac{1}{b-a}, & x\in[a,b] \\

0, & x\notin[a,b]

\end{cases}

$$

# Conclusion

There’s much more to LaTeX as described in this cheat sheet, however, as I said, this is the stuff that I typically use, so it might be relevant for you too. Drop me a comment if you think something else should be on this cheat sheet, and I’ll add it.