# [texhax] TeX Frequently Asked Questions -- question label "gethelp"

Steffen van Bakel svb at doc.ic.ac.uk
Fri May 2 00:47:19 CEST 2008

Dear all,

I've encountered something unexpected, that perhaps you all could shed
a light on.  When writing

\def\Group#1{{#1}}
\newenvironment{mygroup}{\collectbody \Group}{}

\def\commandA#1(#2){#1(#2)-D}
\def\commandB#1#2#3{#1({#2(#3)})}
\def\commandC#1#2#3{#1(\bgroup#2(#3)\egroup)}
\def\commandD#1#2#3{#1(\begingroup#2(#3)\endgroup)}
\def\commandE#1#2#3{#1(\begin{mygroup}#2(#3)\end{mygroup})}

I get unexpected behaviour

\expandafter \commandA \commandB A B C	\\	% gives A(B(C))-D
\expandafter \commandA \commandC A B C \\	% gives A(B(C)-D)
\expandafter \commandA \commandD A B C \\	% gives A(B(C)-D)
\expandafter \commandA \commandE A B C \\	% gives A(B(C)-D)

I consider only the first result correct, and all the others wrong!
In particular, I am looking to have the second version produce the
first version's result, but I can't get it to work.

What is happening here?  Am I making a (perhaps rather stupid) mistake?

Steffen van Bakel