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:



\newcommand{\CommandTwo}{more bla}

  \csname Command\MakeUppercase{\strHead}\strTail\endcsname%




However, this produces

! Missing \endcsname inserted.

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

  • 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
    Commented Jan 4, 2018 at 12:26
  • @yudai-nkt: Yes, that should work
    – user31729
    Commented Jan 4, 2018 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 Commented Jan 4, 2018 at 15:35


Browse other questions tagged .