\DeclarePairedDelimiter
is a very specific command in the mathtools
package for opening and closing delimiters (e.g. parentheses, brackets, braces) where you want the option to automatically resize them.
For example, it allows you to replace \lfloor
...\rfloor
with \floor{
...}
and \left\lfloor
...\right\rfloor
with \floor*{
...}
.
Other common examples are:
\DeclarePairedDelimiter\paren{(}{)} % (parentheses)
\DeclarePairedDelimiter\ang{\langle}{\rangle} % <angle brackets>
\DeclarePairedDelimiter\abs{\lvert}{\rvert} % |absolute value|
\DeclarePairedDelimiter\norm{\lVert}{\rVert} % ||norm||
\DeclarePairedDelimiter\bkt{[}{]} % [brackets]
\DeclarePairedDelimiter\set{\{}{\}} % {braces}
As in the other example, I get commands that have fixed size, or that scale with the expression. See the mathtools
documentation for more information about this command.
\newcommand
, however, is much more general, allowing for a much broader class of shortcuts. For example, if I'm writing about combinatorics, then I would type combinatorics
a lot. I could shorten this by writing \newcommand{\cbs}{combinatorics}
, and then whenever I type \cbs
in the document, it's expanded out to combinatorics
. There's no need to relate it to delimiters. [1]
You can also declare commands with arguments: for example, \newcommand{\dfr}[2]{d #1/d #2}
defines a command for derivatives; then, I can call \dfr{f}{x}
to get df/dx and \dfr{f}{y}
to get df/dy. See the Wikibooks page on macros for more information.
You can use \newcommand
to make delimiters, e.g. \newcommand{\floor}[1]{\lfloor #1 \rfloor}
, though then you don't get both a version that scales and one that doesn't. The point is that \newcommand
is so much more general than \DeclarePairedDelimiter
, but doesn't handle scaling automatically.
Finally, for, "is this the best way to do it?" I would say that since you want to use the functionality that \DeclarePairedDelimiter
offers, you may as well use it, so yes, you're doing it right.
[1]: A more useful example would be to define a \newcommand
for something that you might go back and change later. For example, if you have a piece of notation that you use a lot but haven't finalized, defining a \newcommand
for it means when you change it, you only have to change it once. For example, in definitions, I italicize the word being defined, so I can use \newcommand{\term}[1]{\textit{#1}}
and then call \term{word being defined}
. Then, if later on I decide I want to underline definitions, all I have to do is update the \newcommand
in a single place in the document.