4

I Declared this in the class file

\newcommand{\fullname}[1]{\gdef\@fullname{#1}}

With \fullname{john doe}

I am trying to get the fullname on class file. The \MakeUperrcase{\@fullname} works, but the \capitalisewords doesn't. I have tried

\capitalisewords\@fullname

and

\capitalisewords{\@fullname}

But the output is always

JOHN DOE

instead of

John Doe

When I checked the \@fullname, it prints

john doe

David Carlisle
  • 757,742
muhrifqii
  • 115

1 Answers1

3

\capitalisewords doesn't expand its argument, so you need to expand the argument first, either as David suggested in the comments:

\expandafter\capitalisewords\expandafter{\@fullname}

or use the shortcut command \xcapitalisewords that does the same thing:

\xcapitalisewords{\@fullname}

The reason why the argument isn't automatically expanded is because the first letter uppercasing mechanism allows for semantic markup that takes a single argument. For example:

\newcommand*{\strong}[1]{\textcolor{red}{\textbf{#1}}}
\capitalisewords{\strong{lorem} ipsum}

This becomes effectively

\strong{\MakeUppercase lorem} \MakeUppercase ipsum

so the semantic markup doesn't interfere with the case-change. If the argument was expanded, this instance would break as you'd end up with

\textcolor{\MakeUppercase red}{\textbf{lorem}} \MakeUppercase ipsum

(It would actually be more complicated than this if \textcolor was also expanded.)

If the argument starts with a control sequence that's not followed by a group, then \capitalisewords assumes it's a character or symbol command (such as \aa), so

\capitalisewords{\aa lorem ipsum}

becomes

\MakeUppercase \aa lorem \MakeUppercase ipsum

This is what's happened in your example, which is why you end up with

\MakeUppercase\@fullname
Nicola Talbot
  • 41,153