Automatic delimiter sizes in LaTeX

I recently read a math book in which delimiters never adjusted to the size of their content or the level of nesting. This isn’t unusual in articles, but books usually pay more attention to typography.

Here’s a part of an equation from the book:

\varphi^{-1} (\int \varphi(f+g) \,d\mu)

Larger outer parentheses make the equation much easier to read, especially as part of a complex equation. It’s clear at a glance that the function φ-1 applies to the result of the integral.

\varphi^{-1} \left(\int \varphi(f+g) \,d\mu\right)

The first equation was typeset using

    \varphi^{-1} ( \int \varphi(f+g) \,d\mu )

The latter used left and right to tell LaTeX that the parentheses should grow to match the size of the content between them.

    \varphi^{-1} \left( \int \varphi(f+g) \,d\mu \right)

You can use \left and \right with more delimiters than just parentheses: braces, brackets, ceiling, floor, etc. And the left and right delimiters do not need to match. You could make a half-open interval, for example, with \left( on one side and \right] on the other.

For every \left delimiter there must be a corresponding \right delimiter. However, you can make one of the pair empty by using a period as its mate. For example, you could start an expression with \left[ and end it with \right. which would create a left bracket as tall as the tallest thing between that bracket and the corresponding \right. command. Note that \right. causes nothing to be displayed, not even a period.

The most common example of a delimiter with no mate may be a curly brace on the left with no matching brace on the right. In that case you’d need to open with \left\{. The backslash in front of the brace is necessary to tell LaTeX that you want a literal brace and that you’re not just using the brace for grouping.

9 thoughts on “Automatic delimiter sizes in LaTeX

  1. I love left and right, however a lot of people on the (excellent) LaTeX stack exchange find it distracting as they will match each other, but not other brackets in the same equation or document, so they advocate using manual bracket sizing.

  2. I used to be a left and right junky, but have slowly transitioned to using (bigl, bigm, bigr), (Bigl, Bigm, Bigr), (biggl,biggm,biggr), and (Biggl,Biggm,Biggr) almost exclusively. Now, don’t get me wrong: there are indeed cases where elastic delimiters are preferable, but you can often come up with a nicer end result (IMHO) by choosing the sizes manually.

    There is also the in the DeclarePairedDelimiter macro offered by the mathtools package. With this you can use, for example, DeclarePairedDelimiter{ket}{lvert}{rangle} to define a ket macro. Macros defined with DeclarePairedDelimiter should have nice kerning, and take an optional parameter to allow manual delimiter sizes: e.g., one can typeset ket{varpsi} vs. ket[bigg]{varpsi^varphi}.

  3. I always wondered why the size of the parenthesis is not automatic in math latex, at least as an option.

  4. alfC: If the sizes were automatic, you wouldn’t have as much control.

    For example, suppose you had a rule that whenever you see a ‘[‘, you wait until you see the next ‘]’ and make the two brackets as big as the largest thing in between. What if the mate to your bracket isn’t another bracket but a parenthesis (as in half-open intervals) or an angle bracket (as in quantum bra-ket notation)? Or what if there isn’t a mate because you just wanted a ‘[‘ and it’s not a delimiter?

    These situations are kind of uncommon; usually you want your delimiters to come in matching pairs and size automatically. But fine-grained control by default is consistent with the spirit of TeX.

  5. To add to the discussion, let me highlight the ever-so-useful middle tag. For instance, to write a conditional probability where the sizes of all delimiters (including the conditional bar) match:

    Pleft( X = 100 ,middle|, Y = 10 right) = 0.2

    Unfortunately, middlemid doesn't seem to work, which is why I included the extra horizontal space with ,. I don't know why this is.

Comments are closed.