New LaTeX users are often suprised that macro definitions containing non-letters, such as
\newcommand{\cul8r}{Goodbye!}
fail to compile. The reason is that the TeX macro language, unlike
most programming languages, allows
nothing but letters in macro names.
There are a number of techniques for defining a macro with a name like
\cul8r. Unfortunately, none of the techniques is particularly
good:
\csname…\endcsname to define and invoke the
macro:
\expandafter\newcommand\csname cul8r\endcsname{Goodbye!}
I said, ``\csname cul8r\endcsname''.
\newcommand{\DefineRemark}[2]{%
\expandafter\newcommand\csname rmk-#1\endcsname{#2}%
}
\newcommand{\Remark}[1]{\csname rmk-#1\endcsname}
...
\DefineRemark{cul8r}{Goodbye!}
...
\Remark{cul8r}
\catcode`8 = 11
\newcommand{\cul8r}{Goodbye!}
I said, ``\cul8r''.
\cul8r can be used directly
\setlength{\paperwidth}{8in} tells us:
! Missing number, treated as zero.8
\cul which must always be followed by
“8r”:
\def\cul8r{Goodbye!}
I said, ``\cul8r''.
\cul8r can be used directly
\cul is followed by anything other
than “8r”, with a confusing diagnostic —
\cul99 produces:
! Use of \cul doesn't match its definition.
<*> \cul9
9
(which would confuse someone who hadn’t even realised there
was a definition of \cul in the document).
\cul, if any;
as a result, the technique cannot be used to define both a
\cul8r and, say, a \cul123 macro in the same
document.
\@ and @ in macro names for
more information.
Note that analogous use of technique 3 in this example would give us
\begingroup
\catcode`8 = 11
\gdef\cul8r{Goodbye!}
\gdef\later{\cul8r}
\endgroup
I said, ``\later''.
which works, but rather defeats the object of the exercise.
(\later has the “frozen” catcode for ‘8’, even though the value
has reverted to normal by the time it’s used; note, also, the use of
the primitive command \gdef, since \newcommand can’t make a
macro that’s available outside the group.)
Recommendation: Either choose another mechanism (such as
\DefineRemark above), or choose another name for your macro, one
that contains only ordinary letters. A common approach is to use
roman numerals in place of arabic ones:
\newcommand{\culVIIIr}{Goodbye!}
which rather spoils the intent of the joke implicit in the example
\cul8r!
This answer last edited: 2009-06-03
This question on the Web: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=linmacnames