This is not an answer to the question as currently stated. Given some comments of darrelld, I believe that the goal is to define a macro, \TitleCase, which puts its argument in, well, title case. This can be done with varying degrees of robustness, but one way is to read tokens one at a time and convert letters using \uppercase and \lowercase.
Here, \TitleCase@case is at all times either \uppercase or \lowercase: it is set to \uppercase at the very start of the \TitleCase command, and after each space. It is set to \lowercase by any letter.
The result is stored one piece at a time into \TitleCase@tl, and used at the end.
\makeatletter
\newcommand*{\TitleCase@tl}{}
\newcommand*{\TitleCase@case}{}
\newcommand*{\TitleCase@marker}{\TitleCase@marker}
\DeclareRobustCommand{\TitleCase}[1]
{%
\let\TitleCase@tl\empty
\let\TitleCase@case\uppercase
\TitleCase@#1\TitleCase@marker
\TitleCase@tl
}
\newcommand*{\TitleCase@}{\futurelet\@let@token\TitleCase@@}
\newcommand*{\TitleCase@@}
{%
\ifcase 0%
\ifcat\noexpand\@let@token\bgroup 1\fi
\ifx\@let@token\@sptoken 2\fi
\ifx\@let@token\TitleCase@marker 3\fi
\relax
\expandafter\TitleCase@normal
\or \expandafter\TitleCase@group
\or \expandafter\TitleCase@space
\or \expandafter\@gobble
\fi
}
\newcommand{\TitleCase@normal}[1]
{%
\TitleCase@case
{%
\expandafter\def\expandafter\TitleCase@tl\expandafter
{\TitleCase@tl #1}%
}%
\ifcat A\noexpand\@let@token
\let\TitleCase@case\lowercase
\fi
\TitleCase@
}%
\newcommand{\TitleCase@group}[1]
{%
\begingroup
\let\TitleCase@tl\empty
\TitleCase@ #1\TitleCase@marker
\expandafter
\endgroup
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\TitleCase@tl
\expandafter\expandafter\expandafter{%
\expandafter\TitleCase@tl\expandafter{\TitleCase@tl}}%
\TitleCase@
}
\newcommand{\TitleCase@space}
{\afterassignment\TitleCase@space@\let\@let@token= }
\newcommand{\TitleCase@space@}
{%
\let\TitleCase@case\uppercase
\expandafter\expandafter\expandafter\def
\expandafter\expandafter\expandafter\TitleCase@tl
\expandafter\expandafter\expandafter{\expandafter\TitleCase@tl\space}%
\TitleCase@
}
\makeatother
\documentclass{article}
\begin{document}
\section{\TitleCase{helLo, \itshape wo\textup{Rl}D!}}
\end{document}
`to mark your inline code as I did in my edit. – doncherry Aug 7 '11 at 17:31\textitvs\itshapeand all the analogous font-changing commands for example. – Ant Aug 7 '11 at 17:32\textitis much more 'active' because it's changing the font(!) while\Gammaonly prints a character. Also note that 'active' normally mean active characters with (La)TeX, like~. You could of course use a savebox (see\sbox) and measure the width of the resulting text which should be zero for "passive" macros. However, you need to provide the right number of dummy arguments.... – Martin Scharrer♦ Aug 7 '11 at 17:41