2

relates to What are the valid names as labels? .

\newcommand{\keyword}[1]{\textbf{#1}\label{KW:#1}\pageref{KW:#1}}

works just great for almost any text...until one wants \keyword{S\&P~500}. The problem is that label does not allow a \ to be part of the label, but it is the only way to typeset the & character in the text. Is there an \xlabel command that is a little more forgiving, i.e., first stripping or mangling any invalid characters from #1, after expanding it once of course? (I tried changing the catcode of either & or \\ in the macro, but couldn't figure it out. I can't assign to a variable and include it for the same reason that it would contain a \ again.)

ivo Welch
  • 3,766

1 Answers1

3

If you really want to do this use & not \& so

\newcommand{\keyword}[1]{\textbf{\detokenize{#1}}\label{KW:#1}\pageref{KW:#1}}

and

\keyword{S&P 500}
David Carlisle
  • 757,742