| Want to learn how to tackle those tough AMC/AIME/Olympiad counting and probability problems? Check out Art of Problem Solving's NEW Intermediate Counting & Probability by David Patrick. |
Math
Mode
Display Math
\displaystyle
eqnarray
Additional Packages
Please note: These pages are no longer updated and maintained. We have moved all the information in these pages into the AoPSWiki, which are updated and improved by the AoPS Community. Click here to go to the corresponding page in the AoPSWiki.
LaTeX uses a special math mode to display mathematics. The easiest way to use math mode is to enclose the math in $ signs. For example, open a new source file in TeXnicCenter and type or copy/paste the following:
Save the document (press Ctrl-S or click File, then Save) as 'mymath' (don't include the quote marks in the name) in a folder of your choice. The file will appear in your folder as 'mymath.tex.'
Compile the document just as you compiled your first document. When you view the output file, you should see
![]()
If you remove the $ symbols from your source file then try to compile, you should get 'Missing $ inserted' error messages in the Output window of TeXnicCenter (try it and see - you may have to scroll up in the Output window to see the errors).
Nearly all mathematical items, such as variables, expressions, equations, etc., should be written in math mode. In fact, most math will generate errors if you don't remember to put it in math mode.
As we saw above, when using $math stuff here$ to typeset math, the resulting math expression appears right in the test at the location of the $...$. Sometimes we want to break some of the math out out of the text and give it its own special line. To do so, we use $$math stuff here$$ or \[math stuff here\] to put the math text in math mode:
After you compile this and view it, you should see:
Notice that the equations are on their own lines and are centered. As a matter of style, usually we put this 'display math' on their own lines in the source file, like this:
We can also use
\begin{equation} math \end{equation}
to display mathematics. This approach also creates a label, which we can refer to later if we like. Make sure you read our notes about referencing before using these labels for references - it's much better to use \label and \ref than to refer to the equations by number in your source file.
Notice the (1) out to the right when you compile the above. Once again, rather than typing (1) in your source file to refer to this equation, use LaTeX referencing commands.
Generally, you'll only use \begin{equation} when you need the label.
Sometimes we have complicated expressions that we don't want to put on their own lines, but that don't render well with $...$ mode. For example:
gives us
![]()
That summation symbol is a little ugly. We can make it prettier by using \displaystyle:
This gives us:
Notice that the summation symbol looks much nicer now - adding the \displaystyle at the beginning of your math (inside the $...$) will often make complicated math render more nicely.
One very useful tool in displaying equations well is eqnarray, which allows you to neatly align a string of equations:
Compiling this should give:

There are a few things to notice here. First, the * after eqnarray prevents line numbers from popping up after each line - try removing both of the *s from the source file and compile to see equation numbers. Next, notice that each line is of the form
Math stuff & more math stuff & more math stuff\\
The & symbols separate the columns. There must be three columns (i.e. two & symbols). The \\ tells LaTeX that you are finished with this line and are on to the next. Notice that there's no \\ on the last line; the \end{eqnarray*} tells LaTeX that you're finished. As you see above, you can leave some columns blank. As a style issue, notice that we start a new line in our source file after each \\. We could run all the lines together, but that makes editing very difficult.
Usually, we only use relational symbols like =, >, or < in the middle column; eqnarray aligns these symbols as you see above. That's why we like eqnarray.
Finally, notice that there are no $ symbols or \[..\], yet everything is rendered in math mode. This happens because eqnarray automatically puts everything in math mode - you don't need $...$ or \[...\].
The basic LaTeX program does not include all the math you'll want to use. In order to access all the math functions and symbols we will introduce in the guide pages, you'll have to include a number of packages. We include these packages by using the \usepackage command between the \documentclass line and the \begin{document} line, such as:
The package used above is part of the basic MiKTeX installation, so you don't have to download anything new to include them. Later, you may want to read more about how to include more packages, and how you can create packages of your own.
Finally, one last point of style - notice in that last example that we put the x in math mode by writing $x$ instead of just x. Try compiling with and without the x in math mode and you'll see why. Always put your math in math mode!
If you find you want to do some math typesetting that you can't find on this page, or among our discussions of symbols or commands, try reading this document, which contains some of the really fancy applications of the ams packages.

