# How do I remove spurious parentheses from a macro argument?

I want to store the argument of a macro in a temporary variable, but I know in advance that some people will incorrectly enclose the argument in parentheses as well as braces (long story). Specifically, some users will say something like

 \bernard{abc}


while others will say

\bernard{(abc)}


I want the macro \bernardto store the string abc in the temporary variable in both cases. How do I achieve this?

-
Is Bernard the person? :-D – Matthew Leingang Mar 2 '11 at 0:40
@Matthew - sadly not. Their name is Legion, for they are many. – Ian Thompson Mar 2 '11 at 16:13

\documentclass{minimal}
\makeatletter
\def\bernard#1{\bernard@i#1\@nil}
\def\bernard@i{\@ifnextchar(\bernard@ii\bernard@iii}
\def\bernard@ii(#1)\@nil{\def\bTemp{#1}}
\def\bernard@iii#1\@nil{\def\bTemp{#1}}
\makeatother

\begin{document}
\bernard{(abc)} \bTemp
\bernard{abc}   \bTemp
\end{document}

-
Thanks Herbert. – Ian Thompson Mar 1 '11 at 15:19
Nice. Maybe Ian needs a \newbernard macro that defines a command that takes Bernard-style arguments. – Matthew Leingang Mar 2 '11 at 18:12