25

Possible Duplicate:
Definining commands/abbreviations that contain numbers

I wanted to know if it was possible to define a new command with a name that contains numbers?

e.g. \newcommand{\agent1}{agent~1}

Or even \ag1ent if having a number at the end is problematic.

I couldn't find the answer in the FAQ.

Peutch
  • 2,182

2 Answers2

27

From lshort, section 1.3.3:

[Commands] start with a backslash \ and then have a name consisting of letters only. Command names are terminated by a space, a number or any other ‘non-letter.’

Numbers are thus not allowed as part of a command name.

You
  • 6,713
  • 2
  • 29
  • 27
12

You can always use:

\expandafter\def\csname agent1 \endcsname{agent 1}

and use it as

\csname agent1 \endcsname

Both LaTeX and ConText provide wrappers around this. LaTeX uses \@namedef and \@nameuse as wrappers, while ConTeXt uses \setvalue and \getvalue as wrappers.

Aditya
  • 62,301