Converting Text to Title Case
You might want mfirstuc
and its command \capitalisewords{}
. In order to keep words like “the” small we must hide it from the mechanism by hiding the space before it. This is done by using \space
instead of an actual space. Alternatively you can tell the parser with \MFUnocap
which words to omit:
\documentclass{article}
\usepackage{mfirstuc}
\begin{document}
\capitalisewords{the table,\space the ass\space and\space the stick}
\MFUnocap{the}\MFUnocap{and}
\capitalisewords{the table, the ass and the stick}
\end{document}
\documentclass{article}
\makeatletter
\def\somemagiccommand#1{%
\let\tc@w\@empty
\protected@edef\tmp{\noexpand\tc@a#1\relax}\expandafter\tc@uc@\tmp}
\def\tc@a{\futurelet\tmp\tc@aa}
\def\tc@aa{%
\ifcat a\noexpand\tmp\expandafter\tc@ab
\else\expandafter\tc@ac\fi}
\def\tc@ab#1{\edef\tc@w{\tc@w#1}\tc@a}
\def\tc@ac{%
\csname tc@@\tc@w\endcsname\expandafter\tc@uc\tc@w
\let\tc@w\@empty
\ifx\tmp\@sptoken\let\next\tc@sp
\else\ifx\tmp\relax\let\next\relax
\else\let\next\tc@nxt
\fi\fi\next}
\def\tc@sp#1{ \tc@a#1}
\def\tc@nxt#1{#1\tc@a}
\def\tc@uc#1{\uppercase{#1}}
\def\tc@uc@#1#2{\uppercase{#1#2}}
\let\tc@@the\@gobbletwo
\let\tc@@and\@gobbletwo
\makeatother
\begin{document}
\somemagiccommand{the table, the ass and the stick}
\end{document}
The stringstrings
package has a \capitalizetitle
macro that does what you want. You need to define words that are not capitalized.