Math: Displays

General tips

Use the backslash/bracket pair ("\[ ...\]") instead of a double dollar construct ("$$ ... $$") for single line displays.

The double dollar construct, while still widely used, is not part of the "official" LaTeX syntax. Its use is discouraged, and, while in most cases it will work just fine, it does cause problems in certain situations. For example, the "\qedhere" trick described below, does not work with an equation set with double dollar signs. (The backslash/bracket construct is for unnumbered equations. If you want an equation numbered, use the \begin{equation}...\end{equation} environment.)

Use align/align* instead of eqnarray/eqnarray* for multiline displays.

The eqnarray/eqnarray* environments have been superseded and rendered obsolete by the align/align* environments provided by the amsmath package. See below for more on these and related amslatex environments see below.

Set multiline displays using appropriate multiline environments, not by stringing together several single line displays.

Multiline display environments generate the appropriate amount of spacing between the lines of the display and enable alignments. By stringing together single line displays or several individual multiline displays, alignments would get lost, and the spacing would be uneven, with lines belonging to different display environments excessively spaced out because of the extra vertical spacing generated by these environments.

Do not leave blank lines before or after displays, unless you want a paragraph break at that spot.

While multiple spaces are equivalent to a single space in TeX, the same is not true for linebreaks. Two or more successive linebreaks generate a blank line, which in turn is interpreted as a paragraph break. (In fact, one or more blank lines are equivalent to the explicit paragraph breaking command "\par".) A surprisingly common mistake is to surround displays by blank lines in an attempt to make them stand out more. This is wrong, as TeX would then insert a paragraph break before and after the displays, possibly adding unnecessary vertical spacing and indenting the text following the display. The proper way to make a display stand out is by placing the begin/end display commands on lines by themselves (see below).

Format the source code for displays in a manner that makes it easy to read and debug the code.

Displays are the main sources of TeX errors, and hunting down errors in a lengthy display can be very frustrating as TeX usually detects errors only when it reaches the end of the display and thus won't be able to pinpoint the exact location of the error. Here are some tips on writing the code for displays in a manner that makes this tasks easier.

Spacing in displays: Use \quad or \qquad if explicit spacing is needed, do not use backslashed blanks ("\ ") or ties ("~") for spacing, and use math spacing commands like "\," and "\!" very sparingly, if at all.

Explicit spacing commands such as "\," and "\!" are rarely appropriate and should be used sparingly, if at all. In particular, no explicit spacing should be inserted between a formula at the end of a line in a display and a punctuation sign (comma or period).

That said, explicit spacing commands are sometimes needed in displays to separate formulas, to offset text from formulas, or to "indent" continuation lines. In those cases, I recommend using standard units such as "\quad" or "\qquad" rather than multiple instances of single blanks ("\ \ \ "), or ties ("~~~~"). Here are some common situations:

Use "large" delimiters to surround "large" expressions (like sums or fractions).

An expression like "(\sum_{i=1}^na_i)^2", surrounded by ordinary parentheses, looks very poor when typeset. To correct this, one can use either one of the explicit delimiter sizing commands ("\biggl", etc.), or precede the two parentheses by \left and \right and let TeX take care of the sizing. Using manually sized delimiters may require some trial and error to get the appropriate size, so I usually take advantage of the auto-sizing mechanism of TeX, and let TeX do the job. In almost all cases this works very well. Here are some tips on delimiter sizing:

How to break up formulas in multiline displays.

Breaking up overlong lines in displays can be very tricky, and requires a good knowledge of the underlying mathematics as well as a feel for good mathematical typesetting. For that reason, TeX doesn't break formulas, as it does with ordinary text. However, there are some general guidelines. Here are possible breaking points, in decreasing order of desirability:

When to display a mathematical formula or equation.

Formulas set inline are harder to spot, may cause problems with bad linebreaks (which one has to fix by inserting explicit linebreaks), and they may look poor, especially if they involve fractions, sums, integrals, or other "large" objects. On the other hand, one should not indiscriminately display every equation or formula. A judicious choice of what to display can make a a significant difference in the overall appearance and readability of a paper. Here are some guidelines. You should display formulas/equations in the following cases:

Pagebreaks in multiline displays.

By default, TeX does not allow pagebreaks inside display environments such as align. If a paper has many multiline formulas, this may cause "underful vbox" warning messages. If the "badness" of the underful box (as reported by tex in the log file) is less than 2000 or so, this is barely noticeable and I usually leave it alone. However, with larger badness values, especially those above 5000, the text on the offending pages will be excessively spaced out and look very poor.

One way to get around this would be to break up a the multiline display into several smaller displays. However, I recommend against this doing this. In the first place, this makes it nearly impossible to keep the same alignment throughout the entire display. More importantly, however, the vertical spacing in the display would no longer be uniform since TeX adds additional vertical spacing before and after each display.

A better approach is via the "\allowdisplaybreaks" command that explicitly permits breaks in displays. Simply enclose the offending display in a group containing \allowdisplaybreaks:

{\allowdisplaybreaks
\begin{align} 
... 
\end{align}}%
(The comment symbol (%) at the end is needed to prevent spurious spaces in the text following the display.)

The best solution, however, is to prevent this problem by avoiding excessively long displays (say, with five or more lines). It is often not hard to break up a very long display into two, for example by inserting a phrase like "By the Cauchy-Schwarz inequality, the last expression is at most" in the middle of the overlong display, followed by the remaining lines of the display.

Displays ending a proof: the "\qedhere" trick.

If a proof ends with a displayed equation, then "\end{proof}" would normally place the symbol one line below the display, which looks odd. To place the symbol on the same line as the display, add "\qedhere" at the end of the display (right before "\end{equation}", or its equivalent). Note that this does not work if the display is set with double dollar signs or an eqnarray environment (this is one of many reasons to not use these constructs); it will work with the backslash/bracket environments or any of the amsmath display environments.

Recommended display environments


Back to the LaTeX Tips Page

Last modified: Tue 23 Aug 2011 05:48:04 PM CDT A.J. Hildebrand