# How to build a conditional based on a resize paramater

I would like to define my own macro that accepts an optional parameter such as \big, \Big, etc that apply that if it is specified, otherwise apply the auto resizing \left, \right pair.

So, how do I get the following to work for the case where the optional parameter is specified.

I see that if I change the syntax to accept only \bracc[big]{1, 2} instead of \bracc[\big]{1, 2} (i.e., remove the \), then I can use

\csname#1\endcsname\{#2\csname#1\endcsname\}

which works fine but I would rather be able to specify \big (i.e, with the \) instead.

## Code:

\documentclass{article}
\usepackage{xstring}
\usepackage{xparse}

\NewDocumentCommand{\bracc}{O{} m}{%
\IfEq{#1}{}{%
\left\{#2\right\}%
}{%
#1\{#2#1\}%
}%
}%

\begin{document}
$\bracc{1, 2}$
%$\bracc[\big]{1, 2}$% How to get this case to work?
\end{document}
-
Of course only after composing the question do I find a solution. So am leaving this here in case someone else finds it useful. I will post an answer if one does not show up in a while. –  Peter Grill Feb 25 '13 at 19:41
Probably a good reference: Removing a backslash from a character sequence –  Werner Feb 25 '13 at 19:46
I don't see the need for xstring here: an o-type argument and \IfNoValueTF{#1}{<without option>}{<with option>} should suffice, shouldn't it? –  cgnieder Feb 25 '13 at 19:57
@Werner: Thanks. I need that for another problem of mine. –  Peter Grill Feb 25 '13 at 19:58
@cgnieder: Yeah that was the solution I came up with just after composing the question. You can post it an answer if you want -- don't think there is going to be anything easier than that. –  Peter Grill Feb 25 '13 at 19:59

You don't need any packages for this, also you should (effectively) use \bigl and \bigr if \big is specified:

\documentclass{article}

\newcommand\bracc[2][\left]{%
\ifx\left#1\else\mathopen\fi#1\{%
#2%
\ifx\left#1\right\else\mathclose\expandafter#1\fi\}%
}%

\begin{document}
$\bracc{1, 2}$

$\bracc[\big]{1, 2}$% How to get this case to work?
\end{document}
-