Equations in Latex
Feb 27, 2011 by mohamed hanoosh
On of the main purpose of using Latex is to write the math symbols and equations. There are lot of ways to write a given math in Latex, but it is better to follow some conventions . Here I describes how to put simple math equations and those spanning multiple line which needs special alignments, in Latex.
To put a math equation inline(ie in the current line), we just have to enclose the equation with a pair of dollar signs( eg: $x = y$). If it is to be put in center of a new line, we can use a pair of square brackets ( eg: \[ x = y \] ).
note: To use the 'align' environment, \usepackage{amsmath} should be added to the preamble.
- A multiple line math derivation which needs all the lines to be vertically aligned on a symbol (say '=' symbol):
\begin{align*}
E[|X|] &= \int_{x} |x| f_X(x) dx \\
&= \int_{|x| \ge a} \! |x| f_X(x) dx + \int_{|x| < a} \! |x| f_X(x) dx \\
&\ge \int_{|x| \ge a} |x| f_X(x) dx \\
&\ge a \int_{|x| \ge a} f_X(x) dx \\
&= a E[|X| \ge a]\\
\therefore \qquad E[|X| \ge a] &\le \frac{E[|X|]}{a}
\end{align*}
Here the ampersand('&') symbol in the first line sets an indentation point. In all lines, the symbol following the '&' symbol would be vertically aligned to the corresponding positions of the first(previous) line. More than one indentation point can be set using more number of '&' symbol. The 'align*' environment is used to prevent numbering of each line. If numbering is needed for each line, then 'align' should be used as the environment. The \qquad command in the last line leaves a horizontal space. - Add details to each step of the derivation:
\begin{align*}
This is an example of using columns in align environment. The double ampersand('&&') symbol is the column separator. The description of a step is written in the same line separated by the column separator.
E[|X|] &= \int_{x} |x| f_X(x) dx \\
&= \int_{|x| \ge a} \! |x| f_X(x) dx + \int_{|x| < a} \! |x| f_X(x) dx \\
&\ge \int_{|x| \ge a} |x| f_X(x) dx &&(\because \text{the removed term is non negative})\\
&\ge a \int_{|x| \ge a} f_X(x) dx &&(\because a \le |x| \text{and it is taken outside})\\
&= a E[|X| \ge a]\\
\therefore \qquad E[|X| \ge a] &\le \frac{E[|X|]}{a}
\end{align*} - Leave horizontal space between different parts of the equation: You would have already seen \! and \qquad in earlier steps. These are used for adding horizontal space in equations. The available commands for adding space are: \!(adds a negative space), \,(adds a small space), \:, \;, \quad, \qquad in the increasing order