The mathtools package

Extends amsmath with \DeclarePairedDelimiter, the dcases environment, \coloneqq, matrix columns with a chosen alignment and an option that numbers only the equations you reference.

Loading the package

\usepackage{mathtools}

mathtools loads amsmath, so one \usepackage{mathtools} replaces \usepackage{amsmath}. Options it does not know, such as fleqn, go on to amsmath.

It fills gaps that show up in daily use of amsmath: a command for absolute values and norms whose delimiters grow on request, cases with fractions in display size, right-aligned matrix columns for negative numbers, and \mathclap for a wide subscript below a sum.

Main commands

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}Defines \abs{x}. \abs*{...} scales the delimiters to the content, \abs[\big]{...} sets a fixed size.
\begin{dcases} ... \end{dcases}cases whose lines are set in display style, so fractions keep their full size.
\coloneqqThe definition sign := with the colon centred on the equals sign.
\begin{pmatrix*}[r] ... \end{pmatrix*}Matrix with right-aligned columns; l and c work the same way.
\mathclap{1 \le i \le j \le n}Sets the content with zero width, so a long subscript does not push the neighbouring symbols apart.
\shortintertext{and}A line of text between two lines of align, with less vertical space than \intertext.
\mathtoolsset{showonlyrefs}Prints an equation number only where \eqref points to the equation.

Complete example

\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\begin{document}
\[
  \abs{x} \coloneqq
  \begin{dcases}
    x  & \text{if } x \geq 0, \\
    -x & \text{if } x < 0,
  \end{dcases}
  \qquad
  \abs*{\frac{a}{b}} \leq \norm[\big]{v}
\]
\[
  A = \begin{pmatrix*}[r]
    1   & -2 \\
    -30 & 4
  \end{pmatrix*},
  \qquad
  S = \sum_{\mathclap{1 \leq i \leq j \leq n}} x_{ij}
\]
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023.

Pitfalls

Related pages