Parentheses, brackets, absolute values, and norms

How to use delimiters correctly

These are a few very common mistakes when using delimiters:

  • Don't use | or \vert for absolute values!

    Instead use \lvert ... \rvert from the amsmath package. Even better, define a command \abs which uses these, for example using \DeclarePairedDelimiter. Compare:

    \[
      b+|-a| 
      \qquad 
      b+\vert -a\vert 
      \qquad 
      b+\lvert -a\rvert
    \] 
    $$b+|-a| \qquad b+\vert -a\vert \qquad b+\lvert -a\rvert$$

    Why do | and \vert look so bad?
    Consider the following two expressions:
    \[b+x-ay \qquad b+(-a)\]
    
    $$b+x-ay \qquad b+(-a)$$

    Note that these two expressions differ only in that x and y in the first one have been replaced by ( and ) in the second one. However, the spacing is very different: In the second expression the minus sign is much closer to the a and to the opening parenthesis than it is to the a and the x in the first one. Essentially, TeX recognizes that the minus sign is a binary operator in the first expression and a unary operator in the second and adjusts the spacing accordingly.

    How does TeX know when to do this? Every symbol in a mathematical expression in TeX has a class, the letters a, b, x, and y are classfied as ordinary symbols, whereas ( is classified as an opening symbol and ) as a closing symbol. TeX uses the classes of the surrounding symbols to determine the class of the -. If it is surrounded by ordinary symbols, it is classified as a binary operator, otherwise as a unary operator.

    The issue with using | as a delimiter is that TeX has no way of knowing whether this symbol is intended as an opening or closing delimiter so | is simply classfied as an ordinary symbol by TeX. This is why $b+|-a|$ results in the symbols having the same spacing as for $b+x-ay$ instead of the correct spacing as in $b+(-a)$. Essentially, TeX wrongly assumes that the minus sign in $b+|-a|$ is used as a binary operator (subtracting a from |). The same issue arises whenever the same symbol is used for both the opening and closing delimiter, i.e., with \vert or \Vert and \| for norms.

    To fix this, you could explicitly tell TeX to consider | as either an opening or closing symbol, using \mathopen|...\mathclose|, or, much preferably, just use \lvert and \rvert from the amsmath package (which are essentially defined that way).

  • Don't use ||, \|, or \Vert for norms!

    Instead use \lVert ... \rVert. Even better, define a command \norm which uses these, for example using \DeclarePairedDelimiter. Compare:

    \[
      u+||-v||
      \qquad
      u+\|-v\|
      \qquad 
      u+\Vert -v\Vert 
      \qquad 
      u+\lVert -v\rVert
    \] 
    $$u+||-v|| \qquad u+\|-v\|\qquad u+\Vert -v\Vert \qquad u+\lVert -v\rVert$$

    Why do \| and \Vert look so bad?
    For the same reason that | and \vert look bad, see above.
  • Don't use \big, \Big etc. to get bigger delimiters!

    Instead use, e.g., \bigl( ... \bigr). Compare:

    \[
      b-\bigg(\frac a2\bigg)
      \qquad\qquad 
      b-\biggl(\frac a2\biggr)
    \] 
    $$b-\bigg(-\frac a2\bigg) \qquad\qquad b-\biggl(-\frac a2\biggr)$$

    Why do \big, \Big, etc. look so bad?
    As explained above, | and \vert end up giving wrong spacing in certain situations because they are considered ordinary symbols, rather than opening or closing symbols. A similar thing happens with \big, \Big, etc. These commands tell TeX to make the following symbol bigger but additionally turn it into an ordinary symbol. This happens even for symbols like ( and ) which are considered opening resp. closing symbols when used on their own.
  • Don't use \left and \right!

    Instead use either
    • the manual variants \bigl/\bigr, \Bigl/\Bigr and so on,
    • the \mleft and \mright commands from the mleftright package, or
    • the starred variant of a command defined using \DeclarePairedDelimiter from the mathtools package.

    Compare:

    \[
      \sin\left(x\right).
      \qquad\qquad 
      \sin(x).
    \] 
    $$\sin\left(x\right)\,. \qquad\qquad \sin(x).$$

    Why do \left and \right look so bad?

    As explained above, | and \vert end up giving wrong spacing in certain situations because they are considered ordinary symbols, rather than opening or closing symbols. A similar thing happens with \left and \right. These commands wrap the entire expression as an inner formula, so $\sin\left(x\right)$ ends up being equivalent to $\sin\mathinner{(x)}$. Unfortunately, the spacing rules of TeX introduce additional space, for example, between operators like \sin and inner formulas or between inner formulas and punctuation.

    This issue can be corrected by hand by introducing additional empty opening and closing symbols as in \mathopen{}\left(...\right)\mathclose{}. The mleftright package and the starred commands defined using the \DeclarePairedDelimiter command essentially automate this solution.

These are the best ways to use delimiters:

  • Use the \DeclarePairedDelimiter command from the mathtools package!

    This command should be used in the preamble and takes three arguments: A command name, an opening delimiter, and a closing delimiter. The command name can be used on its own with one argument, which wraps the contents in the delimiters. It can also take \big, \Big, \bigg, or \Bigg as an optional argument, which produces delimiters of the corresponding sizes (equivalent to using \bigl/\bigr and so on). Finally, there is a starred variant, which produces auto-sized delimiters (equivalent to using \mleft/\mright from the mleftright package).
    \DeclarePairedDelimiter{\br}{[}{]}
    ...
    \[
      \br{x+y}
      \qquad
      \br[\big]{\tfrac12}
      \qquad
      \br*{\sum_{i=1}^n a_i}
    \]
    $$ [x+y] \qquad \bigl[\tfrac12\bigr] \qquad \Biggl[\sum_{i=1}^n a_i\Biggr] $$

    For convenience, you may want to define some shorter commands for the manually sized options:

    \DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
    \newcommand{\bnorm}[1]{\norm[\big]{#1}}
    \newcommand{\bbnorm}[1]{\norm[\Big]{#1}}
    \newcommand{\bbbnorm}[1]{\norm[\bigg]{#1}}
    \newcommand{\bbbbnorm}[1]{\norm[\Bigg]{#1}}
    This way, sizing delimiters up or down is just a matter of adding or deleting some bs.

  • Use the commands \bigl/\bigr etc., if you have to!

    The commands defined using \DeclarePairedDelimiter are sufficient in most cases and give the same results as using the manual sizing commands \bigl/\bigr and so on. However, one occasion where they do not work is when there is a line break in the middle of the enclosed expression. In this case, use the manual sizing commands directly.

Here is code for defining all common delimiters:

Code for common delimiters
\usepackage{mathtools}

\DeclarePairedDelimiter{\pr}{(}{)}
\newcommand{\bpr}[1]{\pr[\big]{#1}}
\newcommand{\bbpr}[1]{\pr[\Big]{#1}}
\newcommand{\bbbpr}[1]{\pr[\bigg]{#1}}
\newcommand{\bbbbpr}[1]{\pr[\Bigg]{#1}}

\DeclarePairedDelimiter{\br}{[}{]}
\newcommand{\bbr}[1]{\br[\big]{#1}}
\newcommand{\bbbr}[1]{\br[\Big]{#1}}
\newcommand{\bbbbr}[1]{\br[\bigg]{#1}}
\newcommand{\bbbbbr}[1]{\br[\Bigg]{#1}}

\DeclarePairedDelimiter{\cu}{\{}{\}}
\newcommand{\bcu}[1]{\cu[\big]{#1}}
\newcommand{\bbcu}[1]{\cu[\Big]{#1}}
\newcommand{\bbbcu}[1]{\cu[\bigg]{#1}}
\newcommand{\bbbbcu}[1]{\cu[\Bigg]{#1}}

\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\newcommand{\babs}[1]{\abs[\big]{#1}}
\newcommand{\bbabs}[1]{\abs[\Big]{#1}}
\newcommand{\bbbabs}[1]{\abs[\bigg]{#1}}
\newcommand{\bbbbabs}[1]{\abs[\Bigg]{#1}}

\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\newcommand{\bnorm}[1]{\norm[\big]{#1}}
\newcommand{\bbnorm}[1]{\norm[\Big]{#1}}
\newcommand{\bbbnorm}[1]{\norm[\bigg]{#1}}
\newcommand{\bbbbnorm}[1]{\norm[\Bigg]{#1}}

\DeclarePairedDelimiter{\ang}{\langle}{\rangle}
\newcommand{\bang}[1]{\ang[\big]{#1}}
\newcommand{\bbang}[1]{\ang[\Big]{#1}}
\newcommand{\bbbang}[1]{\ang[\bigg]{#1}}
\newcommand{\bbbbang}[1]{\ang[\Bigg]{#1}}
This defines commands

  • \pr (for parentheses),
  • \br (for brackets),
  • \cu (for curly braces),
  • \abs (for absolute values),
  • \norm (for norms),
  • and
  • \ang (for angled brackets)
and corresponding convience commands such as \bpr, \bbpr, \bbbpr, \bbbbpr, and \pr* for successively bigger and autosized variants respectively:
\[
  \pr{x},\, 
  \bpr{\tfrac12},\, 
  \bbpr{\bigcup\{A_i \colon i\in\N\}},\, 
  \bbbpr{\frac12},\,
  \bbbbpr{\sum_{i=1}^n a_i},\, 
  \pr*{\begin{matrix}1&2\\3&4\\5&6\end{matrix}}
\]
$$ (x),\, \bigl(\tfrac12\bigr),\, \Bigl(\bigcup\{A_i \colon i\in\mathbb N\}\Bigr),\, \biggl(\frac12\biggr),\, \Biggl(\sum_{i=1}^n a_i\Biggr),\, \left(\begin{matrix}1&2\\3&4\\5&6\end{matrix}\right) $$

Note that if you introduce notation such as \norm, \floor, or \ceil via a definition in your document, you will probably want to add a \cfadd to the declaration of the delimiter, so you can automatically reference the definition wherever the notation is used. E.g., for the norm the declaration might look like this:

Code for declaring norm delimiters using \cfadd
\DeclarePairedDelimiter{\norm}{\lVert\cfadd{def:norm}}{\rVert}
\newcommand{\bnorm}[1]{\norm[\big]{#1}}
\newcommand{\bbnorm}[1]{\norm[\Big]{#1}}
\newcommand{\bbbnorm}[1]{\norm[\bigg]{#1}}
\newcommand{\bbbbnorm}[1]{\norm[\Bigg]{#1}}
When copying the code above, change the label in the \cfadd to the label of the corresponding definition in your document.

Here are some more specialized delimiters:

Code for specialized delimiters
\DeclarePairedDelimiter{\ceil}{\lceil}{\rceil}
\newcommand{\bceil}[1]{\ceil[\big]{#1}}
\newcommand{\bbceil}[1]{\ceil[\Big]{#1}}
\newcommand{\bbbceil}[1]{\ceil[\bigg]{#1}}
\newcommand{\bbbbceil}[1]{\ceil[\Bigg]{#1}}

\DeclarePairedDelimiter{\floor}{\lfloor}{\rfloor}
\newcommand{\bfloor}[1]{\floor[\big]{#1}}
\newcommand{\bbfloor}[1]{\floor[\Big]{#1}}
\newcommand{\bbbfloor}[1]{\floor[\bigg]{#1}}
\newcommand{\bbbbfloor}[1]{\floor[\Bigg]{#1}}

\DeclarePairedDelimiter{\rnd}{\lceil}{\rfloor}
\newcommand{\brnd}[1]{\rnd[\big]{#1}}
\newcommand{\bbrnd}[1]{\rnd[\Big]{#1}}
\newcommand{\bbbrnd}[1]{\rnd[\bigg]{#1}}
\newcommand{\bbbbrnd}[1]{\rnd[\Bigg]{#1}}

\DeclarePairedDelimiterXPP\pnorm[2]{}\lVert\rVert{_{#1}}{#2}
\newcommand{\bpnorm}[2]{\pnorm[\big]{#1}{#2}}
\newcommand{\bbpnorm}[2]{\pnorm[\Big]{#1}{#2}}
\newcommand{\bbbpnorm}[2]{\pnorm[\bigg]{#1}{#2}}
\newcommand{\bbbbpnorm}[2]{\pnorm[\Bigg]{#1}{#2}}

\DeclareFontFamily{U}{matha}{\hyphenchar\font45}
\DeclareFontShape{U}{matha}{m}{n}{
<-6> matha5 <6-7> matha6 <7-8> matha7
<8-9> matha8 <9-10> matha9
<10-12> matha10 <12-> matha12
}{}
\DeclareSymbolFont{matha}{U}{matha}{m}{n}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<-6> mathx5 <6-7> mathx6 <7-8> mathx7
<8-9> mathx8 <9-10> mathx9
<10-12> mathx10 <12-> mathx12
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}

\DeclareMathDelimiter{\vvvert}{0}{matha}{"7E}{mathx}{"17}
\DeclarePairedDelimiter{\tnorm}{\vvvert}{\vvvert}
\newcommand{\btnorm}[1]{\tnorm[\big]{#1}}
\newcommand{\bbtnorm}[1]{\tnorm[\Big]{#1}}
\newcommand{\bbbtnorm}[1]{\tnorm[\bigg]{#1}}
\newcommand{\bbbbtnorm}[1]{\tnorm[\Bigg]{#1}}

\DeclareMathDelimiter{\ldbr}{0}{matha}{"76}{mathx}{"30}
\DeclareMathDelimiter{\rdbr}{0}{matha}{"77}{mathx}{"38}
\DeclarePairedDelimiter{\dbr}{\ldbr}{\rdbr}
\newcommand{\bdbr}[1]{\dbr[\big]{#1}}
\newcommand{\bbdbr}[1]{\dbr[\Big]{#1}}
\newcommand{\bbbdbr}[1]{\dbr[\bigg]{#1}}
\newcommand{\bbbbdbr}[1]{\dbr[\Bigg]{#1}}

\newcommand{\dang}[1]{\langle\mkern-3mu\langle #1\rangle\mkern-3mu\rangle}
\newcommand{\bdang}[1]{\bigl\langle\mkern-4mu\bigl\langle #1\bigr\rangle\mkern-4mu\bigr\rangle}
\newcommand{\bbdang}[1]{\Bigl\langle\mkern-6mu\Bigl\langle #1\Bigr\rangle\mkern-6mu\Bigr\rangle}
\newcommand{\bbbdang}[1]{\biggl\langle\mkern-9mu\biggl\langle #1\biggr\rangle\mkern-9mu\biggr\rangle}
\newcommand{\bbbbdang}[1]{\Biggl\langle\mkern-10mu\Biggl\langle #1\Biggr\rangle\mkern-10mu\Biggr\rangle}

\providecommand\cond{}
\newcommand{\conditionSymbol}[1][]{#1\vert\mathopen{}}
\DeclarePairedDelimiterX\expbr[1]{[}{]}{%
	\renewcommand\cond{\conditionSymbol[\delimsize]}
	#1
}

\NewDocumentCommand{\E}{s m}{\mathbb E\IfBlankTF{#1}{\IfBooleanTF{#1}{\mkern-2mu\expbr*}\expbr{#2}}}
\newcommand{\bE}[1]{\mathbb E\mkern-1mu\expbr[\big]{#1}}
\newcommand{\bbE}[1]{\mathbb E\mkern-1mu\expbr[\Big]{#1}}
\newcommand{\bbbE}[1]{\mathbb E\mkern-2mu\expbr[\bigg]{#1}}
\newcommand{\bbbbE}[1]{\mathbb E\mkern-2mu\expbr[\Bigg]{#1}}

...

\[
  \ceil{x},\;
  \bfloor{\tfrac12},\;
  \bbrnd{\frac ab},\;
  \pnorm2{u+x},\;
  \tnorm{A},\;
  \bdang{{\textstyle \sum_{i=1}^n u_i},v},\;
  \E*{\sum_{i=1}^n X_i \cond Y}
\]
$$\lceil x\rceil,\; \bigl\lfloor \tfrac x2\bigr\rfloor,\; \Bigl\lceil\frac ab\Bigr\rfloor,\; \lVert u+v\rVert_2,\; |\mkern-2mu|\mkern-2mu| A |\mkern-2mu|\mkern-2mu|,\; \bigl\langle\mkern-4mu\bigl\langle {\textstyle \sum_{i=1}^n u_i},v\bigr\rangle\mkern-4mu\bigr\rangle,\; \mathbb{E}\mkern-2mu\Biggl[\sum_{i=1}^n X_i \Biggr\vert Y\Biggr]$$

Unless otherwise noted, all LaTeX snippets on this site are released under the Zero-Clause BSD (0BSD) license. You may copy them into your documents without attribution or including any license. No warranty.