# Mathematics in LaTeX¶

LaTeX has a math mode designed to format mathematics. It can be invoked on the same line as text by enclosing the mathematics in dollar signs: $your math here$. This is called “inline” math.

The positive real root of $x^4-16=0$ is $x=2$.

The positive real root of $$x^4-16=0$$ is $$x=2$$.

## Basic Typesetting¶

The most common typesetting needs in mathematics is the superscript and the subscript. These can be accessed using the caret ^ and the underscore _.

Consider the sequence $(x_i)$ where $x_i = 2^x$.

Consider the sequence $$(x_i)$$ where $$x_i = 2^x$$.

These only work for a single character, so

A gigabyte contains $2^30$ bytes. Let $x_ij=x_ji$.

actually returns: A gigabyte contains $$2^30$$ bytes. Let $$x_ij=x_ji$$

To tell LaTeX that more than one character should be typeset as a superscript or subscript, enclose the desired text in braces.

A gigabyte contains $2^{30}$ bytes. Consider a matrix $A$ where
$a_{ij}=a_{ji}$.

This gives the desired result: A gigabyte contains $$2^{30}$$ bytes. Let $$a_{ij}=a_{ji}$$.

There is a native equation environment, displaymath, which can be invoked by encasing math inside double dollar signs or $, and$. It can typeset up to one line of math at a time.

\begin{document}
$$e=\sum_{i=0}^\infty \frac{1}{i!}$$
$\sum_{i=0}^\infty x^i = \frac{1}{1-x}$

Both invoke the displaymath environment, and so are nearly identical. The only difference is that $$math$$ makes a call to TeX and $stuff$ makes a call to LaTeX. It is not recommended to use these environments except when minimal control is needed. The environments provided by the amsmath package are much more robust and flexible. The most common replacement environment from amsmath is align, or align* if you do not want individual lines to be numbered. As with all environments, these are opened and closed with \begin{} and \end{}. Just place the desired environment name between the braces. For example:

\begin{align*}
e&=\sum_{i=0}^\infty \frac{1}{i!}\\
&=\lim_{n\rightarrow\infty}\left(1+\frac{1}{n}\right)^n
\end{align*}

produces:

$\begin{split}e&=\sum_{i=0}^\infty \frac{1}{i!}\\ &=\lim_{n\rightarrow\infty}\left(1+\frac{1}{n}\right)^n\end{split}$

Everything that works in displaymath works in align. The main advantage of align is that it can display many lines of mathematics at once, aligning them based on the location of the & in each line.