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. |
\coloneqq | The 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}Compiled with pdfLaTeX from TeX Live 2023.
Pitfalls
- A command made with
\DeclarePairedDelimiterkeeps the delimiters at normal size. Only the starred form\abs*{...}scales them, with\leftand\right. showonlyrefscounts\eqrefonly. An equation that you cite with\refstays without a number, and the reference prints empty.- With
showonlyrefsthe numbers are correct after three LaTeX runs, one more than ordinary references need.
Related pages
- Package
amsmath - How-to Absolute value and norm in LaTeX
- How-to Large brackets in LaTeX
- How-to Piecewise functions in LaTeX
- How-to Number equations in LaTeX
- How-to Exponents and subscripts in LaTeX
- How-to Underbrace and overbrace in LaTeX
- How-to Box around an equation in LaTeX