[texhax] Composing two commands one inside another

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Fri Aug 13 01:36:02 CEST 2004



Rodolfo Medina wrote:

 > I'll try to be more precise.
 > I use plain TeX, with eplain macros for cross references.
 > Suppose I say
 >
 > \definexref{label}{mouse, cat, }{}
 >
 > and, some lines below,
 >
 > \refn{label}
 >
 > . This expands to:
 >
 > mouse, cat,


Fine, for this you will need \csname ... \endcsname :

\def \definexref #1#2{\expandafter \def \csname label:#1\endcsname {#2}}

     and

\def \refn #1{\csname label:#1\endcsname}


 >
 > . Now, if I define
 >
 > \edef\a#1{Hallo, #1!}
 >
 > and then I say
 >
 > \a{\refn{label}}
 >
 > , I get
 >
 > Hallo, mouse, cat, !
 >
 > Right. But if I define instead
 >
 > \edef\b#1, #2, {Hallo, #1, #2, !}
 >
 > and then I say
 >
 > \b{\refn{label}}
 >
 > I get an error message:
 >
 > ! Paragraph ended before \b was complete.
 >

Of course : your parameter structure for \b requires two distinct parameters,
the first separated by a comma and a space from the second, which is itself
terminated by a comma and a space.

 > I'd need to know a correct way to "put \refn into \b"
 > so to obtain the same expansion I get putting \refn into \a with
 > "\a{\refn{label}}".
 > The idea is that \b should collect the expansion of \refn{label}
 > and go ahead with its own expansion:


Then \b must expect a single parameter, not two
parameters and ancilliary delimiters.

 > the value assumed by the one-argument function \refn
 > should be argument for the two-argument function \b. I also tried with:
 > \edef\c#1{\expandafter\b{\refn{#1}}}
 >
 > and then I said
 >
 > \c{label}
 >
 > but still got an error message:
 >
 > ! Argument of \b has an extra }.


Yes, your \expandafter is causing the open brace following \b
to be expanded; it can't expand, but \expandafter won't look ahead
until it finds something it /can/ expand.

** Phil.



More information about the texhax mailing list