# How do I store the upper case counterpart of a string?

I have a string stored in a variable \word, and I want to store its upper case counterpart in another variable \WORD. If I try

 \def\WORD{\MakeUppercase{\word}}
\show\WORD


then the message generated by \show is \MakeUppercase {abc}. Presumably I need to adjust the order of expansion in the first line. How do I do this?

-

In fact, \MakeUppercase expands its argument before uppercasing it, so we can do the following.

\def\word{abcd}
\MakeUppercase{\gdef\noexpand\WORD{\word}}


\noexpand prevents the expansion of \WORD, but \word is expanded. Then \MakeUppercase uppercases the whole definition. The definition must be made global because \MakeUppercase works inside a group.

-
@Bruno - this doesn't seem to work. I get the error ! Undefined control sequence. <argument> \def \WORD {abc} –  Ian Thompson Mar 10 '11 at 9:52
@Ian: right. I get where the problem is: \MakeUppercase tries to expand everything. Let me think a bit. A short solution is to replace \MakeUppercase by \uppercase, but it's not optimal. –  Bruno Le Floch Mar 10 '11 at 10:19
@Ian: that's fixed, and we now don't need all those expandafters. –  Bruno Le Floch Mar 10 '11 at 10:54
Very nice. I taught myself a lot about \expandafter trying to figure out my own solution, only to find out that \MakeUppercase expands its own argument. Putting the \gdef inside the \MakeUppercase had eluded me. –  Matthew Leingang Mar 10 '11 at 13:27
@Matthew: my first (wrong) answer involved some expandafters as well. I'm still wondering why the authors of \MakeUppercase enclosed the whole definition in {...}, rather than using the standard \begingroup...\uppercase{\endgroup...}. –  Bruno Le Floch Mar 10 '11 at 14:11