(Disclaimer: My personal opinion is that while this might make typing faster, it renders the code far less readable.)
Here is a way: first I define a bunch of paired delimiters by means of \DeclarePairedDelimiter
, which provides for all of them a stared version which scales automatically, and an optional argument to give the size manually; then I introduce the user macro which selects the desired delimiters through an optional argument
\documentclass{article}
\usepackage{mathtools}% loads amsmath
\makeatletter
\newcommand*{\delim@}{\delim@p}% better safe than sorry
\DeclarePairedDelimiter{\delim@p}{(}{)}
\DeclarePairedDelimiter{\delim@b}{[}{]}
\DeclarePairedDelimiter{\delim@B}{\{}{\}}
\DeclarePairedDelimiter{\delim@v}{|}{|}
\DeclarePairedDelimiter{\delim@V}{\|}{\|}
\newcommand*{\delim}[1][p]{\csname delim@#1\endcsname}
\makeatother
\begin{document}
\[
\delim{a+b},
\delim[b]{a+b},
\delim*{\frac{1}{2}},
\delim[B]*{\frac{1}{2}},
\delim[v][\Bigg]{\frac{1}{2}},
\delim[][\Big]{a+b},% or \delim[p][\Big]{a+b}
\delim[F]{a+b}
\]
\end{document}

The first optional argument is p
, b
, and so on. Then you can write a star for automatic scaling, or give the manual size as further optional parameter.
Check out the last two cases: if you want to give only the manual size with round brackets then the first optional parameter should either be empty or be an explicit p
. Furthermore, there is no test on p
, b
, ... If you misspell it, nothing meaningful comes out: \delim[F]{a+b}
gives just a+b
.
If you really want to see how a bunch of nested \if
s would look like, you could do
\newcommand*{\delim}[1][p]{%
\def\@tempa{#1}%
\if#1p\relax
\else
\if#1b\relax
\else
\if#1B\relax
\else
\if#1v\relax
\else
\if#1V\relax
\else
\def\@tempa{p}% if none of pbBvV then fall back to p
\fi
\fi
\fi
\fi
\fi
\csname delim@\@tempa\endcsname
}
which would give parentheses in case of a misspelled/empty argument.