Two things I understand and one thing I don't:
I often use \csname to create user-defined tokens. For instance, the following code uses \expandafter to expand everything between \csname and \endcsname before \gdefing the result:
\newcommand{\mycommand}[1]{%
\expandafter\gdef\csname #1\endcsname{Here is #1 printed.}%
}
\begin{document}
\mycommand{abc} % Creates a macro \abc
Demonstration: \abc % Prints Demonstration: Here is abc printed.
\end{document}
I wanted to do something similar by using \mycommand{abc} to create a macro \Abc (note the capital letter). Unfortunately, \uppercase cannot be used inside \csname. (I'm guessing some parts expand to TeX primitives?) But I found a somewhat related answer from Heiko Oberdiek (http://newsgroups.derkeiler.com/Archive/Comp/comp.text.tex/2006-02/msg01220.html) and created the following, which I don't entirely understand.
It should create a new uppercase token, and I think it is working, since I can then \let it to another macro and it does not error.
\newcommand{\mycommand}[1]{%
\uppercase\expandafter{\expandafter\csname #1}\endcsname% Creates token
}%
\def\temp{if it worked}
\let\Abc\temp% Now \Abc expands to something other than \relax
\begin{document}
\mycommand{abc}% Creates \Abc
This lets you see \Abc.% Prints This lets you see if it worked.
\end{document}
So my question is: how can I create an uppercase token and define the expansion at the same time? (Basically, I want to combine both of the above approaches.) Here are two ways I have tried (both return Error: extra \endcsname).
\newcommand{\mycommand}[1]{%
\expandafter\gdef% I think this tries to do \gdef\uppercase = bad
\uppercase\expandafter{\expandafter\csname #1}\endcsname{the macro #1 expanded}%
}%
\mycommand{abc}
Use \Abc. % Should print Use the macro abc expanded.
or
\newcommand{\mycommand}[1]{%
\expandafter\gdef\expandafter{%
\uppercase\expandafter{\expandafter\csname #1}\endcsname}{the macro #1 expanded}%
}%
\mycommand{abc}
Use \Abc. % Should print Use the macro abc expanded.

\Abcto take arguments? I cannot write\endcsname#1because#1has another meaning here :\ – iago-lito Mar 26 '17 at 20:56Illegal parameter number in definition of \mycommandaux. (I have to say that I am doing this from inside a\newcommand, so that my base level already is##1and I am shifting to###1).. – iago-lito Mar 26 '17 at 21:09#1at definition time. I added the variants. – egreg Mar 26 '17 at 21:09\newcommand*the macro will not accept multiple paragraphs as argument. – egreg Mar 26 '17 at 21:28