Edit: I'm leaving this answer up for “academic purposes” but, consider Lev Bishop's answer for an easier solution than mine.
Over the years I've evolved my own solution which I think turned out quite nice. It gives you a command which you can call like
\newdelimcommand{parens}{(}{)}
which in turn will define for you a \parens
command which you can then use as \parens{thing}
to produce something like (thing)
where, moreover, the parenthesis automatically resize. In fact you can use the command in three different ways
\parens{thing} % automatic resize
\parens*{thing} % no resize
\parens[big]{thing} % use the specified size
For the latter option you can use auto
(the default), base
(no resize), or one of the sizes: big
, Big
, bigg
, Bigg
.
Furthermore, inside of thing
you can use the commands \ldelim
, \rdelim
, and \mdelim
to create even more delimiters with the appropriate size selected by the given options. This allows, for example, to use \mdelim
to automagically resize a “middle” bar. (See example at the end of the code).
For this to work you have to drop the following code in a .sty file and include it in your main .tex file with \usepackage
.
\RequirePackage{amsmath}
% delim sizing options
\let\delim@autol\left \let\delim@autor\right \let\delim@autom\middle
\let\delim@basel\relax \let\delim@baser\relax \let\delim@basem\relax
\let\delim@bigl\bigl \let\delim@bigr\bigr \let\delim@bigm\big
\let\delim@Bigl\Bigl \let\delim@Bigr\Bigr \let\delim@Bigm\Big
\let\delim@biggl\biggl \let\delim@biggr\biggr \let\delim@biggm\bigg
\let\delim@Biggl\Biggl \let\delim@Biggr\Biggr \let\delim@Biggm\Bigg
% default definitions
\newcommand\ldelim{\relax}
\newcommand\rdelim{\relax}
\newcommand\mdelim{\relax}
% the actual command
\newcommand\delim@command[4]{{% #1 size #2 ldelim #3 rdelim #4 content
\def\ldelim{\csname delim@#1l\endcsname}%
\def\rdelim{\csname delim@#1r\endcsname}%
\def\mdelim{\csname delim@#1m\endcsname}%
\ldelim#2#4\rdelim#3}}
% a factory to define new delimiter commands
\newcommand{\newdelimcommand}[3]{% #1 name #2 ldelim #3 rdelim
\expandafter\newcommand\csname delim@#1@st\endcsname[1]{% ##1 content
\delim@command{base}{#2}{#3}{##1}}%
\expandafter\newcommand\csname delim@#1@ns\endcsname[2][auto]{%
% ##1 size ##2 content
\delim@command{##1}{#2}{#3}{##2}}%
\expandafter\DeclareRobustCommand\csname#1\endcsname{%
\@ifstar{\csname delim@#1@st\endcsname}{\csname delim@#1@ns\endcsname}%
}%
}
% syntactically named delimiters
\newdelimcommand{braces}{\lbrace}{\rbrace}
\newdelimcommand{angles}{\langle}{\rangle}
\newdelimcommand{verts}{\lvert}{\rvert}
\newdelimcommand{Verts}{\lVert}{\rVert}
\newdelimcommand{brackets}{[}{]}
% semantically named delimiters
\newcommand{\set}{\braces}
\newcommand{\abs}{\verts}
\newcommand{\size}{\verts}
\newcommand{\norm}{\Verts}
\newcommand{\tuple}{\angles}
% Automagic `such that' for set comprehension. Inside an automagic
% delimiter command, the vertical bar will resize appropriately
% Example:
% \set{ x \in W \st x > 0 }
\newcommand{\st}{\;\mdelim\vert\;}
I've been thinking to eventually release this (and other bits of code) as a proper style file. But for the time being here it is for you to copy&paste. :)
(
and)
with\left(
andright)
since it can cause spacing problems. For details see this answer.