Adding mathematics to your document

Help Center > LaTeX > Adding mathematics to your document

As with many things in LATEX there are many ways to add mathematics to you documents. I will highlight three ways to add mathematics to your documents so now.

Inline Mathematics

The first is to place the symbols in a pair of dollar signs ($). Add the following text to your document on a new line, just below the line Hello World!:

$\sqrt{x^{5}} + y_{n}$

Your output document should now look like this.

Math Example

The dollar signs are used for placing inline equations in your documents. They should only be used to place short expressions or single variables in your document.

Displayed Mathematics

For longer expressions or equations you should display the mathematics on its own line. To do this use the \[ and \] commands. You can see what a displayed equation looks like by replacing the dollar signs with \[ and \]. Below is the result of this change.

Math Example

The display math environment does more than center the expression on its own line, it also changes the format of many symbols. To emphasize the difference change the expression between the \[ and \] to:

\sum_{i=1}^{\infty} x_{i}

Then try the same expression with

dollar signs around the expression. Notice where the limits are in each case.

Multi-line Mathematics

If you must break an equation over multiple lines, the best place to do so is at an equals sign (=). LATEX has an environment for multi-line equations. To see an example of a multi-line equation, in your document between the \begin{document} and \end{document} commands, type the following:


\begin{eqnarray}
\varphi(x) & = & \varphi(x_{1} +\cdots+ x_{k} \\
& = & \varphi(x_{1} +\cdots+ \varphi(x_{k})\\
& = & \sin(x_{1}z) +\cdots+ \sin(x_{k})
\end{eqnarray}

The result is displayed below

Multiline Example

In the eqnarray environment everything before the first ampersand (&) is aligned to the right, everything between the ampersands is center aligned, and everything after of the second ampersand is aligned to the left. Each line except the last must end with two backslashes (\\), and there must be exactly two ampersands per line.

It should be noted that there are numbers at the end of each line. These numbers can be referenced using the \label and \ref commands. To use \label and \ref, place the command \label{EqDesc} on the line you wish to reference, just before the double backslash. Then later in the document (outside of the eqnarray environment) place the command \ref{EqDesc}. The word inside the curly braces can be any string of characters you want (excluding spaces or other special characters), but should be short and descriptive. The result of doing so is shown below.


\begin{eqnarray}
\varphi(x) & = & \varphi(x_{1} +\cdots+ x_{k}\
label{EqDesc} \\
	& = & \varphi(x_{1} +\cdots+ \varphi(x_{k})\\
	& = & \sin(x_{1}z) +\cdots+ \sin(x_{k}
\end{eqnarray}

We can now reference line \ref{EqDesc}.

Multiline Example

You can also add numbers to displayed equations by using \begin{equation} and \end{equation} instead of \[ and \]. For displayed equations the \label command should be placed on the same line as the \begin{equation} command.

The numbers at the end of the lines can be removed by placing an asterisks (*) in the environment's commands. That is change \begin{eqnarray} and \end{eqnarray} to \begin{eqnarray*} and \end{eqnarray*}. Make sure you also remove your \label and \ref commands. Many commands have star forms, which change how the commands behave. It is beyond the scope of this class to go in depth on the star form.

last modified on 10/19/2007 15:40