## 6 Equations

### 6.1 Maths Environments

In LaTeX it is straightforward to include mathematical equations and notation in your document. Often you will want to do this using one of the maths environments, such as the equation environment, i.e. you will use $$...$$. Everything inside this environment uses a "maths mode", which defines a large number of useful commands and symbols.

Every equation environment contains a single equation, and this is usually numbered. You can use \label{} to reference it in your text just like any other object. If you don't want your equation to be numbered then there's an equivalent non-numbered environment called displaymath (NB not equation*).

If you want to write several equations together then you can use the eqnarray environment. At the end of each equation you start a new line using \\ as usual. The eqnarray environment lets you align equations so that, for example, all of the equals signs "=" line up. To do this, put ampersand "&" signs around the text you want LaTeX to align, e.g.
 \begin{eqnarray} F &=& ma\\ V &=& IR \end{eqnarray} 

Each equation can be labelled separately, just put the label command after the relevant equation. You can also suppress the numbering for any particular equations by adding the command \nonumber after the equation; if you don't want any of the equations to be numbered then use the eqnarray* environment instead.

### 6.2 Maths Commands and Symbols

Almost every conceivable symbol and operation is defined within LaTeX, and we only have time to go into a few here. Some of the most useful for scientists are:

• _{} the text in between the brackets is a subscript, e.g. x_{i+1}=x_i + v_i t; if the subscript is only a single character you can omit the curly brackets.
• ^{} the text in between the brackets is a superscript, e.g. E=mc^{2}; if the superscript is only a single character you can omit the curly brackets, e.g. E=mc^2.
• \lambda typesets the Greek letter lambda. Use \Lambda for the capitalised form. The whole of the Greek alphabet is defined similarly.
• \hat{} puts a "hat" on top of the text, for example you could use \hat{H} for a Hamiltonian operator.
• \frac{}{} is used to typeset a fraction. The numerator is the first argument, and the denominator the second.
• \sum_{i=1}^{N} typesets a summation; the limits can be specified as subscripts and superscripts, as in this example. There's also \prod for products, and
• \int the integral sign; also \oint for loop integrals. Limits are specified as subscripts and superscripts, as for summations.
• \circ makes a small circle, most useful for doing things like 180^\circ to show 180-degrees.
• \times makes a multiplication sign
• \pm plus or minus (\mp for minus or plus)
• \surd the "square-root" sign
• \equiv the "equivalent" sign
• \approx the "approximately equal" sign
• \sim the "of the order of" squiggly line
• \neq the "not equal to" sign
• \nabla the symbol for the vector differential operator "del"
• \partial the partial derivative "curly d"
• \forall the symbol for "for all"!
• \exists the symbol for "there exists"!
• \infty infinity
• \imath special character for the imaginary number i (alternatively \jmath if you use j for this number)
• \hbar h-bar, i.e. Planck's constant over 2.pi
• \ldots gives an ellipsis "..." (also \cdots which puts the dots in the middle of the line, \vdots which has three vertical dots and \ddots which puts three dots diagonally from top-left to bottom-right)
• \cdot makes a single dot
• \Longrightarrow the "implies" arrow
• \sin the sine function (also \cos, \tan, \arcsin etc. as well as \ln, \log, \exp and the hyperbolic functions)
• \sqrt{x} is used for the "square-root" symbol. The mandatory argument is what is to be "rooted"; there's also an optional argument (put in square brackets before the curly ones) which defines the "power" of the root. E.g. the cube-root of two would be \sqrt[3]{2}
• \vert gives a small vertical line
• x \atop y puts "x" above "y"

Sometimes you don't really want to put a full-blown equation in, you just want to include a snippet in your text, or use some maths "ideas" such as superscripts. To do this you can use the dollar sign "$" - anything in between two dollar signs is typeset in maths mode, so for example the Hamiltonian$\hat{H}$is the energy operator. ### 6.4 Brackets, Left and Right There are several different types of brackets in LaTeX, from the ordinary round ones "(" and ")" to the curly "{" and "}" and the square "[" and "]". Unfortunately the curly and square ones are used by LaTeX to specify arguments, so if you want them to actually appear in your equation you need to "escape" them, as it's called, by putting a backslash in front of it, e.g. \{. This method works for any of the special symbols that LaTeX would normally treat as a command, e.g. "%" or "$".

When you're typing equations it's common to find that the default sizes for LaTeX's brackets are too small and they look a bit silly. To tell LaTeX to make brackets as big as a certain bit of an equation you use the \left( and \right) commands. The round bracket here can be replaced by any other bracket, or a full-stop which won't print anything but defines the start of the region. Try comparing
 ( \sum_{i=1}^N x_i p_i ) 
to
 \left( \sum_{i=1}^N x_i p_i \right) 
and you'll see what the \left and \right do!

### 6.5 Matrices

Writing out matrices is a little bit tricky at first, which is why I've devoted a section to it! You need to use the array environment inside the maths one. It's easiest to see with an example:
 

\left(
\begin{array}{ccc}
1 & 2 & 3\\
4 & 5 & 9\\
1 & -8 & 2
\end{array}
\right)

 

The argument to the array environment, ccc, means there are three centred columns (you don't need to specify the number or rows). You can use r or l instead to align any particular column "right" or "left" respectively.

Inside the array environment the columns are separated by "&", just as we used in the eqnarray environment, and new rows are made just using the new line command \\.

The array environment can take an optional argument to specify that the rows should be top-aligned, e.g. \begin{array}{ccc}[t], or use [b] to ensure the rows are bottom-aligned.

### Exercise 6

Add some equations to your document, and reference them in the text. Add a superscript or some greek letters in some of your paragraphs.

### Summary

• To typeset equations you can use the numbered environments equation for one equation, or eqnarray for several, or the corresponding unnumbered environments displaymath and eqnarray*
• You can put superscripts and other maths in text areas by putting dollar signs around them \$
• The \left and \right commands can be used to ensure brackets are the correct size for the material in between them
• The array environment can be used to typeset matrices