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?
\MakeUppercase
isn't expandable, I guess. You could try\tl_upper_case:n
fromexpl3
(I haven't tested your MWE and my suggestion though).\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