Suboptimal LaTeX #3: mathematical environments

Written on March 3, 2014

We have seen some generic mistakes and suggestions, and how to correctly use spacing in your papers. Today we will try to shine some light on how to choose the proper mathematical environment, which is in itself a complicate issue.

The source for all figures in this post is in this writeLaTeX.

First of all, some suggestion about typesetting mathematics: amsmath is a must, and you should read its documentation. Another package whose documentation is really useful to read is mathtools. You will learn for example of the useful family of commands around \mathclap (but do not abuse them).

What environments not to use

This is a pet peeve of mine, after having to deal most of the time with authors using almost exclusively eqnarray. This results in a lot of pain for the typesetter, other than a suboptimal output. Since this is intended to be a short guide, I will send the interested to this article for the explanation of why you should not use it. The summary is that eqnarray is really just a slightly modified array environment, and the simplicity of its implementation causes a lot of inconsistencies.

What environments to use

So, what should you use? The short answer is: any of the amsmath environments, that you can read in the previously linked documentation. But maybe you want some more direct help in choosing.

Example of inner and outer environments

The first thing to know is that amsmath environment can be categorized in two sets: outer and inner environments. Outer environments, like equation, align and multline are indeed the external building block of your display, whereas inner environments can be used to give the proper alignment to specific parts of the display. A way of think of this is that each line of an outer environments is an “equation”, hence needs an equation number, whereas lines in an inner environment do not define new “equations”. You can see an example in the figure, even if the best way to do something like that is using the cases environment.

Outer environment usually have a starred version (for example, align* for align) that behaves exactly the same but does not write equation numbers. Instead of equation*, you can use \[ ... \].

An algorithm

To understand what environment I need, I usually start counting how many equations I want (by thinking: “if I wanted to have equation numbers in this block, how many of them would I want?”):

  • if the answer is one, then I look at how many lines the equation is composed of;
  • for one equation, one line, I use equation;
  • for one equation, multiple lines, I either use multline (when there is a long member that needs wrapping) or equation wrapping the inner environment split (when there is a chain of equality signs).

  • if there are more equations, I usually use align, and rarely gather when the equations have no easy alignment.
Showcase of math environments

There are some subtleties in this procedure: for example, I prefer equation and split over align because of the vertically centered equation number. Note also that if you have a lot of short equations, you can use align to put more of them in a single line, keeping the alignment, just using more ampersands.

The most important problem to me is that there isn’t an easy way to provide alignment of the equations defined in the outer environment if you used an inner environment to write them. For example, the best way to write two equations with two lines each, would be to use an align containing two split or multline; but then there is no way of aligning the two equality signs of the two main equations (except for some hack). Therefore, in these cases I heavily hearted use a single align.

Part of this series

  1. Suboptimal LaTeX #1: intro
  2. Suboptimal LaTeX #2: spacing
  3. Suboptimal LaTeX #3: mathematical environments
  4. Suboptimal LaTeX #4: mathematics
  5. Suboptimal LaTeX #5: miscellanea

See also

  1. How to take lecture notes with LaTeX
  2. LaTeX class for lecture notes
If you liked this post, please share it with your friends: