0

I need to dynamically create the name of a macro, where part of the name is based on the argument which needs to be capitalized beforehand. The following MWE illustrates my intention:

\documentclass{article}

\usepackage{xstring}

\newcommand{\CommandOne}{bla}
\newcommand{\CommandTwo}{more bla}

\newcommand{\foo}[1]{
  \StrLeft{#1}{1}[\strHead]%
  \StrGobbleLeft{#1}{1}[\strTail]%
  \csname Command\MakeUppercase{\strHead}\strTail\endcsname%
}

\begin{document}

\foo{one}
\foo{two}

\end{document}

However, this produces

! Missing \endcsname inserted.

upon compilation. Why, and how do I fix it?

gablin
  • 17,006
  • 1
    That's because \MakeUppercase isn't expandable, I guess. You could try \tl_upper_case:n from expl3 (I haven't tested your MWE and my suggestion though). – yudai-nkt Jan 04 '18 at 12:26
  • @yudai-nkt: Yes, that should work –  Jan 04 '18 at 13:36
  • the above comments show what you should do, the reason for the error is that the xstring commands are as if you had gone \csname\def\tmp{ZZZ}\tmp\endcsname which does not work, you can not do definitions inside csname, you need \def\tmp{ZZZ}\csname\tmp\endcsname – David Carlisle Jan 04 '18 at 15:35

0 Answers0