# Switching a string in a token register to lowercase and processing via the package soul

I would like to store a string in a token register, transform it to all-lowercase, and process the resulting string via the macro \caps provided by the package soul. That is to say, transform the string characters to small capitals and typeset the latter with the ensuing letterspacing.

My problem involves the original string transformation to all-lowercase. I have tried with the TeX primitive \lowercase, with the LaTeX command \MakeLowercase, and with the corresponding command provided by the package textcase. With each alternative, I end up getting a different error message.

Next follows an MWE with one of my tentatives.

\documentclass[12pt]{memoir}

\usepackage{soul}%,textcase}

\newtoks{\toktitle}
\newcommand{\doctitle}[1]{\toktitle={#1}}
% Workaround to have \caps doing its thing on a macro properly,
% as described in the corresponding documentation.
\def\soultitle{\MakeLowercase{\the\toktitle}}
\newcommand{\thetitle}{\caps\soultitle}
% One of my alternatives
%\def\soultitle{\the\toktitle}
%\newcommand{\thetitle}{\caps\MakeLowercase{\soultitle}}

\doctitle{This is the title}

\begin{document}
\pagestyle{empty}
\thetitle
\end{document}


Anyone could possibly provide guidance on this issue? Thanks so much in advance, as usual.

ANSWER: I just need to use the command \soulregister as depicted in the documentation of the package soul. The MWE above would then read as follows:

\documentclass[12pt]{memoir}

\usepackage{soul}

\soulregister{\MakeLowercase}{1}

\newtoks{\toktitle}
\newcommand{\doctitle}[1]{\toktitle={#1}}
% Workaround to have \caps doing its thing on a macro properly,
% as described in the corresponding documentation.
\def\soultitle{\the\toktitle}
\newcommand{\thetitle}{\caps{\MakeLowercase{\soultitle}}}

\doctitle{This is the title}

\begin{document}
\pagestyle{empty}
\thetitle
\end{document}


My apologies. Hope this is useful to somebody nonetheless.

-

You need a few \expandafter to adjust the order of expansion.

\documentclass[12pt]{memoir}

\usepackage{soul}%,textcase}

\newtoks{\toktitle}
\newcommand{\doctitle}[1]{\toktitle={#1}}
% Workaround to have \caps doing its thing on a macro properly,
% as described in the corresponding documentation.

\newcommand{\thetitle}{\expandafter\lowercase\expandafter
{\expandafter\caps\expandafter{\the\toktitle}}}

\doctitle{This is the title}

\begin{document}
\pagestyle{empty}
\thetitle
\end{document}

-
Dear David, you are right. My issue can be solved as you say, but there is also the possibility of using the command \soulregister as I said in my edited post above. Of course, your solution goes straight to the core of the issue. Thank you very much for your attention. – Marcos Jul 7 '12 at 10:40