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 \begin{equation}...\end{equation}. 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:

6.3 Maths Stuff in Text

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


Previous page Next page