LaTeX/Advanced Mathematics

This page outlines some more advanced uses of mathematics markup using LaTeX. In particular it makes heavy use of the AMS-LaTeX packages supplied by the American Mathematical Society.

Equation numbering
The  environment automatically numbers your equation:

You can also use the and  (or  from the  package) commands to label and reference equations, respectively. For equation number 1, results in $$1\,$$ and  results in $$(1)\,$$:

Further information is provided in the labels and cross-referencing chapter.

To have the enumeration follow from your section or subsection heading, you must use the package or use AMS class documents. Then enter

to the preamble to get enumeration at the section level or

to have the enumeration go to the subsection level.

If the style you follow requires putting dots after ordinals (as it is required at least in Polish typography), the command in the preamble will result in the equation number in the above example being rendered as follows: (1.1.1).

To remove the duplicate dot, add the following command immediately after

For a numbering scheme using, use:

in the preamble of the document.

Note: Although it may look like the works by itself, it won't reset the equation number with each new section. It must be used together with manual equation number resetting after each new section beginning, or with the much cleaner.

Subordinate equation numbering
To number subordinate equations in a numbered equation environment, place the part of document containing them in a environment:

Referencing subordinate equations can be done using either of two methods: adding a label after the command, viz. , which will reference the main equation (1.1 above), or adding a label at the end of each line, before the command, which will reference the sub-equation (1.1a or 1.1b above). As shown, it is possible to add both labels in case both types of references are needed. /Override_subsystem=/index

Vertically aligning displayed mathematics
A problem often encountered with displayed environments ( and ) is the lack of any ability to span multiple lines. While it is possible to define lines individually, these will not be aligned.

Above and below
The and  commands  typeset symbols above and below expressions. Without AMS-TeX the same result of   can be obtained with. This can be particularly useful for creating new binary relations:

or to show usage of L'Hôpital's rule:

It is convenient to define a new operator that will set the equals sign with H and the provided fraction:

which reduces the above example to:

If the purpose is to make comments on particular parts of an equation, the and  commands may be more useful. However, they have a different syntax (and can be aligned with the command):

Sometimes the comments are longer than the formula being commented on, which can cause spacing problems. These can be removed using the command :

Alternatively, to use brackets instead of braces use and  commands :

The optional arguments set the rule thickness and bracket height respectively:

The and  commands produce arrows which extend to the length of the text. Yet again, the syntax is different: the optional argument (using  and  ) specifies the subscript, and the mandatory argument (using   and  ) specifies the superscript (which can be left empty by inserting a blank space).

For more extensible arrows, you must use the package:

and for harpoons:

and
The and  environments, available through the  package, are used for arranging equations of multiple lines. As with matrices and tables, specifies a line break, and  is used to indicate the point at which the lines should be aligned.

The environment is used like the  or  environment:

Note that the environment must not be nested inside an  (or similar) environment. Instead, is a replacement for such environments; the contents inside an  are automatically placed in math mode.

suppresses numbering. To force numbering on a specific line, use the command before the line break.

is similar, but automatically numbers each line like the environment. Individual lines may be referred to by placing a before the line break. The or  command can be used to suppress the number for a given line:

Notice that we've added some indenting on the second line. Also, we need to insert the double braces before the + sign, otherwise latex won't create the correct spacing after the + sign. The reason for this is that without the braces, latex interprets the + sign as a unary operator, instead of the binary operator that it really is.

More complicated alignments are possible, with additional 's on a single line specifying multiple "equation columns", each of which is aligned. The following example illustrates the alignment rule of :

Braces spanning multiple lines
If you want a brace to continue across a new line, do the following:

In this construction, the sizes of the left and right braces are not automatically equal, in spite of the use of {{LaTeX/LaTeX|code=\left\{}} and }. This is because each line is typeset as a completely separate equation &mdash;notice the use of and  so there are no unpaired  and  commands within a line (these aren't needed if the formula is on one line). You can control the size of the braces manually with the, , , and commands.

Alternatively, the height of the taller equation can be replicated in the other using the command:

Using aligned braces for piecewise functions
You can also use {{LaTeX/LaTeX|code=\left\{}} and to typeset piecewise functions:

{{LaTeX/Example|code= \[f(x) = \left\{ \begin{array}{lr} x^2 & : x < 0\\ x^3 & : x \ge 0 \end{array} \right. \] $$ f(x) = \left\{ \begin{array}{lr} x^2 & : x < 0\\ x^3 & : x \ge 0 \end{array} \right. $$ }}
 * render=

The environment
The environment allows the writing of piecewise functions:

LaTeX will then take care of defining and or aligning the columns.

Within, text style math is used with results such as:

$$ a = \begin{cases} \int x\, \mathrm{d} x\\ b^2 \end{cases} $$

Display style may be used instead, by using the environment from :

Often the second column consists mostly of normal text. To set it in the normal Roman font of the document, the environment may be used:

Other environments
Although and  are the most useful, there are several other environments that may also be of interest:

There are also a few environments that don't form a math environment by themselves and can be used as building blocks for more elaborate structures:

For example: {{LaTeX/Example|code= \begin{equation} \left.\begin{aligned} B'&=-\partial \times E,\\ E'&=\partial \times B - 4\pi j,      \end{aligned} \right\} \qquad \text{Maxwell's equations} \end{equation} $$ \left.\begin{align} B'&=-\partial \times E,\\ E'&=\partial \times B - 4\pi j, \end{align}\right\}\quad\text{Maxwell}'\text{s equations}\qquad\mathrm{(1.1)} $$ }}
 * render=

Indented Equations
To indent an equation, you can set in the document class and then specify a certain value for the  variable:

Page breaks in math environments
To suggest that LaTeX insert a page break inside an environment, you may use the  command before the line break. Just as with, can take an optional argument between 0 and 4 denoting the level of desirability of a page break. Whereas 0 means "it is permissible to break here", 4 forces a break. No argument means the same as 4.

Alternatively, you may enable automatic page breaks in math environments with. It too can have an optional argument denoting the priority of page breaks in equations. Similarly, 1 means "allow page breaks but avoid them" and 4 means "break whenever you want". You can prohibit a page break after a given line using.

LaTeX will insert a page break into a long equation if it has additional text added using without any additional commands.

Specific usage may look like this:

Page breaks before display maths (of all various forms) are controlled by. Its default 10000 means never break immediately before a display. Knuth (TeXbook chapter 19) explains this as a printers' tradition not to have a displayed equation at the start of a page. It can be relaxed with

Sometimes an equation might look best kept together preceding text by a higher penalty, for example, a single-line paragraph about a single-line equation, especially at the end of a section.

Boxed Equations
For a single equation or alignment building block, with the tag outside the box, use :

If you want the entire line or several equations to be boxed, use a inside an :

There is also the mathtools which is able to box across alignment marks:

Custom operators
Although many common operators are available in LaTeX, sometimes you will need to write your own, e.g. to typeset the argmax operator. The and  commands display custom operators; the   version sets the underscored option underneath like the  operator:

However, if the operator is frequently used, it is preferable to define a new operator that can be used throughout the entire document. The and  commands are specified in the header of the document:

This defines a new command which may be referred to in the body:

Limits
There are defaults for placement of subscripts and superscripts. For example, limits for the lim operator are usually placed below the symbol:

To override this behavior, use the operator:

A lim in running text (inside ) will have its limits placed on the side, so that additional leading won't be required. To override this behavior, use the command.

Similarly one can put subscripts under a symbol that usually has them on the side:

Limits below and under:

To change the default placement of summation-type symbols to the side for every case, add the option to the  package. To change the placement for integral symbols, add to the options. can be used to change the default for named operators like det, min, lim, etc.

To produce one-sided limits, use as follows:

Subscripts and superscripts
You can place symbols in subscript or superscript (in summation style symbols) with :

It's impossible to mix them with typical usage of such symbols:

To add both a prime and a limit to a symbol, one might use the command:

It is very flexible: for example, to put letters in each corner of the symbol use this command:

If you wish to place them on the corners of an arbitrary symbol, you should use from the  package.

But a simple grouping can also solve the problem:

since a math operator can be used with limits or no limits. If you want to change its state, simply group it. You can make it another math operator if you want, and then you can have limits and then limits again.

Multiline subscripts
To produce multiline subscript, use the command:

Text in aligned math display
To add small interjections in math environments, use the command:

Note that any usage of this command does not change the alignment.

Also, in the above example, the command from the  package could have been used instead of  to reduce the amount of vertical white space added between the lines.

Changing font size
There may be a time when you would prefer to have some control over the font size. For example, using text-mode maths, by default a simple fraction will look like this: $$\textstyle \frac{a}{b}$$, whereas you may prefer to have it displayed larger, like when in display mode, but still keeping it in-line, like this: $$\displaystyle \frac{a}{b} $$.

A simple approach is to utilize the predefined sizes for maths elements:

A classic example to see this in use is typesetting continued fractions (though it's better to use the command described in the Mathematics chapter instead of the method provided below). The following code provides an example.

As you can see, as the fractions continue, they get smaller (although they will not get any smaller than in this example, where they have reached the limit). If you want to keep the size consistent, you could declare each fraction to use the display style instead; e.g.

Another approach is to use the command to select your preferred sizes. You can only define sizes for, , etc. One potential downside is that this command sets the global maths sizes, as it can only be used in the document preamble.

But it's fairly easy to use:, where ds is the display size, ts is the text size, etc. The values you input are assumed to be point (pt) size.

Note that the changes only take place if the value in the first argument matches the current document text size. It is therefore common to see a set of declarations in the preamble, in the event of the main font being changed. E.g.,

Forcing \displaystyle for all math in a document
Put

before to force all math to.

Adjusting vertical white space around displayed math
There are four parameters that control the vertical white space around displayed math:

Short skips are used if the preceding line ends, horizontally, before the formula. These parameters must be set after.