Inserting Equations


Objectives


By the end of the chapter you will be able to:

  • insert mathematics into blocks of text
  • typset numbered equations
  • use fractions, indices and integrals
  • insert matrices
  • align equations one over the other
  • format long equations

Mathematics in text blocks


To use mathematical symbols or equations within a paragraph you need to enclose the formulae in dollar signs. This tells LaTeX to use math mode and typset it as mathematics. For example,

'Where $\alpha$ is defined as $2k_1$' becomes 'Where α is defined as 2k1'.

Notice that the greek letter alpha is also in math mode. The underscore puts 1 as a subscript to the k. To use a subscript of more than one character you must enclose the subscript in curly braces.

\eta_{output} becomes ηoutput.

Activity - Create some in text mathematics in one of your chapter files.

Typset numbered equations


To typeset equations on their own line we use the equation environment. By default this numbers each equation according to the chapter it is in. You can also use \label to reference the equation within the text, just the same as figures and tables.

\begin{equation}\label{eq:quad}
f(x) = (2x + y)(x - 2y)
\end{equation}

This is shown in equation \ref{eq:quad}.

To remove the number from the equation replace \begin{equation} with
\begin*{equation}, just like un-numbered chapters. Remember that the in text reference for the above equation is created using \ref{eq:quad}.

Activity - Create a numbered equation in one of your chapter files.


Using fractions, indices and integrals


Fractions are created using:

\frac{numerator}{denominator}

Fractions can used within fractions: \frac{\frac{1}{2}}{x} (1.2)

To place brackets around fractions we use \left and \right with the chosen bracket. This extends the bracket to the height of the fraction.

(\frac{x}{y}) \left(\frac{x}{y}\right) (1.3)

Indices are created using the ^ carot symbol. Indices can contain fractions but the fraction must be within curly braces (just like with subscripts).

x^{\left(\frac{2}{3}\right)} (1.4)

To use an integral with limits we use \int\limits followed by _bottom limit^top limit.

\int\limits_a^b (1.5)

Activity - Input a fraction or an integral into one of your chapter files.

Matrices


Matrices are created using the matrix environment and the & and \\, which were used in the tables. A matrix without delimiters can be created using \begin{matrix}. However, we usually wish to have some brackets around the matrix. The table on the right shows the different possibilities.

$$
\begin{bmatrix}
5 & 6 \\
7 & 8 \\
\end{bmatrix}
$$

The matrix environment needs to be put into math mode using dollar signs. One dollar sign above and below the matrix will put the matrix within a block of text. Two dollar signs top and bottom will put the matrix in the middle of the page and display it like an equation.

Activity - Create a matrix of your choice.


Code Delimiters
pmatrix ( )
bmatrix [ ]
vmatrix | |
Bmatrix { }
Vmatrix || ||

Advanced - Aligning equations


The align environment can be used for equations that are longer than one line or for lining up two equations, one above the other. Here is an example for two equations:

\begin{align}
y &= mx + c\nonumber \\
y &= 2x + 1
\end{align}
The & lines up the equals signs, \\ ends the line and \nonumber prevents the first line from being numbered. Using align* prevents any numbers from being given to either equation. Brackets can also be split over two lines:
$$
f(x) = \left\{
	\begin{array}{lr}
x^2 & : x < 0 \\
x^3 & : x ≥ 0
	\end{array}
\right.
$$
Notice that \right does not have a bracket. It must however be there for LaTeX to compile properly. To prevent a bracket from being shown the bracket is replaced by a dot. This example uses the array environment that allows you to have control over the alignment within each column, just like a table. Notice that the first column is left justified and the second is right justified.

Advanced - Formatting long equations


To use align with a long equation simply break the equation over more than one line using \\ and the line up each piece using &.

\begin{align}
E_{lm} (x,y,z) = &E_o \frac{\omega_o}{\omega(z)} H_l \left(\sqrt{2} \frac{x}{\omega (z)} \right) H_m \left( \sqrt{2} \frac{y}{\omega (z)} \right) \cdot \exp \left[ - \frac{x^2 + y^2}{\omega^2 (z)} \nonumber \right. \\
 &\left. - \frac{ik(x^2 + y^2)}{2R(z)} - ikz + i(l + m + 1) \eta \right]
\end{align}

At first glance this equation is very complicated. Take one line at a time and find where the \\ line break is. The ampersands are next to the E0 and the \left. as this technically starts the second line. The top line is ended by \right. and the first line begins with \left. because LaTeX expects the find a matching bracket on the same line as the first bracket. Using these two codes allows us to break a bracket over two lines in the align environment.

Overview