[Tex/LaTex] Converting Text to Title Case

capitalization

is there a way to automatically format a text in title-case? Something like typing:

\somemagiccommand{the table, the ass and the stick}

which would yield:

The Table, the Ass and the Stick

I have searched the internet but have found nothing that would make this more efficient than doing the casing manually…

Best Answer

enter image description here

\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}