TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 7 down vote accepted

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}}}%




share|improve this answer
Nice. I had used the token register to avoid processing the argument twice. – Ernest A Sep 22 '13 at 19:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.