LaTeX: Adding Your Own Paired Delimiters
I’ve come to use LaTeX extensively for typesetting my Mathematics homework. It just makes things so beautiful. And like the XHTML/CSS split, it really does encourage strong separation of content from presentation. One of the things I first hated about it though, is that I grew quickly tired of using \left and \right with brackets, parentheses, or anything that needed to be automatically be sized to its content.
And, as any good engineering student might, I sought to encourage my own laziness by finding a clever shortcut. After a few minutes of searching Google, I came across the DeclarePairedDelimiter command in the mathtools package. Its usage is fairly self-explanatory, as I’ll let the following demonstrate.
First, you need to load the mathtools package in your document header:
\usepackage{mathtools}
Then you can create your own paired delimiters with the DeclarePairedDelimiter command:
\DeclarePairedDelimiter{\abs}{\lvert}{\rvert}
\DeclarePairedDelimiter{\norm}{\lVert}{\rVert}
\DeclarePairedDelimiter{\innerproduct}{\langle}{\rangle}
Finally, you can use these new commands in math mode to more easily group your expression. (Append an asterisk to make LaTeX automatically insert the necessary \left and \right commands when you need the delimiters to resize according to their content.)
If \(a \lt 0\) and \(b \gt 0\), then \(\abs{a} = -a\),
and so \(\abs*{\frac{a}{b}} = -\frac{a}{b}\).
The norm of a vector \(v\), denoted \(\norm{v}\), is
defined by \(\norm{v} = \sqrt{\innerproduct{v,v}}\).
As a nice bonus, it increases readability of the LaTeX source tremendously, since it gives those grouped expressions some semantic name rather than just being a bunch of formatting. For instance with the above delimiters, \left\lvert \frac{a}{b} \right\rvert is more to type, and a lot less obviously an absolute value, than the simpler \abs*{\frac{a}{b}}.
Happy hacking!