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.
-
Put the backslash/bracket pairs ("\[", "\]") and the
begin/end commands for display environments ("\begin{equation}",
"\begin{equation}", etc.) on lines by themselves.
This makes displays stand out visually.
Although TeX does not care about such niceties,
and makes subsequent editing
of the file a lot easier.
-
Place double backslashes (\\) indicating linebreaks in displays either at the
end of a line or on a line by itself.
In the middle of a line, amongst regular tex code, these symbols are much
harder to spot.
-
Insert frequent linebreaks in the source code of displays.
A display set as a single long line is very hard to debug, and a single
editing error on that line can mess up the entire display.
Break the display up into small, logical "chunks" by inserting linebreaks
at appropriate places, e.g., between the numerator and denominator of a
large fraction set with \frac{...}{....}, or
between terms in a formula.
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:
A displayed formula with a range or condition.
Use a single \quad to separate the condition from the formula.
f(i)=i^2\quad (i=1,2,\dots,n)
f(i)=i^2\quad \text{for $i=1,2,\dots,n$}
Two formulas in a single line, separated by a comma.
Again use a \quad to separate the formulas. for example:
f(x)=\cos x, \quad g(x)=\sin x
Two formulas separated by the word "and".
Put \quad before and after "and" (make sure to use \text{and} to force "and"
to be set in text mode):
f(x)=\cos x \quad \text{and}\quad g(x)=\sin x
A continuation line in a multiline display.
Here a \qquad is the appropriate amount of indentation. Align at the equal
sign (or equivalent), and on continuation lines insert a \qquad after the
alignment symbol. If a secondary continuation line is needed, indent
that line by an additional \qquad. Here is an example:
\begin{align*}
S(n) &= \sum_{k=1}^nf(k) +\sum_{k=1}^ng(k) +\sum_{k=1}^ng(k)
\\
&\qquad
+ \sum_{k=1}^n\left(1+k+k^2+\dots + k^k\right)^2
\\
&\qquad\qquad \times \left(1+k^{-1}+k^{-2}+\dots+ k^{-k}\right)^{-2}.
\end{align*}
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:
-
When using \left and \right, make sure that the text enclosed does not contain
a linebreak symbol (e.g., "\\"), or an alignment symbol ("&").
Alignment symbols usually occur near the beginning of a line, so they rarely
interfer with \left-\right pairs. However, in complex multiline displays, it
can happen that the two matching delimiters occur on different lines and thus
cross a linebreak. In this case one has two options: Either use manual sizing,
or use delimiter place holders "\right." and "\left.", placed at the end of
the first line, and near the beginning of the continuation line. The latter
option avoids the problem of crossing linebreaks in between a \left-\right
pair (one still needs to make sure that the pairs do not enclose an
alignment symbol enclosed). However, since the sizing in that case is
determined by the expressions between the two pairs "\left(" and "\right." and
"\left." and "\right)", this only works if those two expressions have
approximately the same height. If that is not the case, the closing
parenthesis would come out smaller; in this case, I would use manual sizing.
-
When using manually sized delimiters, make sure to be consistent in the
sizing. In particular, make sure that matching delimiters are of the same
size.
With auto-sized delimiters, TeX ensures that the sizes of the matching
delimiters are the same. With manually sized delimiters, it is up to the
author to ensure that this is the case; TeX will follow whatever sizing
instruction it is provided with.
-
Avoid using sized delimiters in inline expressions.
Delimiters usually add a bit of additional vertical space, making a bulky
expression even bulkier.
If an inline math formula is large enough so that it looks poor when set with
a normal size delimiter, it probably should not be set inline in the first
place.
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:
-
Right before an equal sign or equivalent (e.g., a "less than"
sign).
In this case, place the alignment symbol (ampersand)
placed before the equal sign,
i.e., " ... + x \\ &= ".
The equal signs (or equivalent) should be aligned.
-
Before a plus or minus sign.
In that case, the continuation
line should be shifted to the right by a \qquad.
If the continuation line is very short, two \qquad's might be better.
-
Between two large "chunks" that are multiplied.
The chunks could be
large parenthesized expression, sums or integrals.
This should be used only as a last resort, and in that case the
preceding line should end with an explicit multiplication symbol
("\times"), the continuation line should begin with
"\times" symbol
and be shifted as far to the right (by preceding it with
a few "\qquad"'s after the alignment symbol).
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:
-
A numbered equation. This is a no-brainer.
If you need to refer back to an equation, the equation needs to be numbered,
and therefore should be set as a display.
- A formula that is excessively long.
If a formula takes up more than about half of a line of space, it
would probably be good to display it.
Formulas set inline should never be longer than one line
(even though tex would accept multiline inline displays and probably
do a reasonably good job in splitting the formula).
- A formula that takes up excessive vertical space. Formulas
that involves complicated sums or integrals with multiple
subscripts or superscripts, or stacked fractions, take up a lot of
vertical space and cause subsequent lines to be moved down, if set
as inline formulas. In these situations, it may be appriopriate to
display the formula. Simple sums, integrals, or fractions, are usually
not a problem; for example, an expression like
"\sum_{k=1}^nk=n(n+1)/2" doesn't need to be displayed. (Note the
"slashed fraction" notation at the end; in an inline context,
this is preferable to a regular fraction notation.)
- A formula that you want to give special emphasis.
Even if a formula would look fine inline from a typesetting point of
view, it may be appropriate to display it for emphasis.
This could be the case, for example,
with an important definition, or a crucial condition/hypothesis
in a theorem.
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 New LaTeX Tips Page
Last modified: Mon 10 Sep 2007 11:32:01 AM CDT
A.J. Hildebrand