have this \newsetter macro that defines a "setter" macro (for lack of a better name) and a @-prefixed macro of the same name that holds the value. This is how is supposed to work:


\@macro     % expands to foo

\@macro     % expands to bar

And this is the \newsetter code:

  \@temptokena=\expandafter{\expandafter\@gobble\string #1}% 
  \expandafter\newcommand\csname @\the\@temptokena\endcsname{}%
    \expandafter\renewcommand\csname @\the\@temptokena\endcsname{##1}}}%

The problem with this code is that it only works in a particular order:


\@firstword\ \@secondword         % expands to Hello World

Whereas the following fails:


\@firstword\ \@secondword         % expands to World, \@firstword is empty

What is wrong here?

1 Answer 1


You have defined \firrstword (for example) as

> \firstword=\long macro:
#1->\expandafter \renewcommand \csname @\the \@temptokena \endcsname {#1}.
l.12 \show\firstword

which means that \firstword does not define \@firstword but a command based on whatever is the current value of \@temptokena. If you use a toks register you need to expand it earlier so \firstword is defined in terms of its value, or simpler do not use the toks register at all:


  \expandafter\newcommand\csname @\expandafter\@gobble\string #1\endcsname{}%
  \expandafter\newcommand\csname\expandafter\@gobble\string #1\endcsname[1]{%
    \expandafter\renewcommand\csname @\expandafter\@gobble\string #1\endcsname{##1}}}%




  • Nice. I had used the token register to avoid processing the argument twice.
    – Ernest A
    Sep 22, 2013 at 19:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .