It's worth noting that there are internal LaTeX commands for this purpose:
\@namedef{NAME}{...}
defines \NAME as a command. These are thin wrappers around the TeX primitive \def, so if you want to have arguments, you need to use the plain syntax, e.g., for a three-argument command:
\@namedef{NAME}#1#2#3{...}
This would be equivalent¹ to \newcommand*{\NAME}[3]{...} or \NewDocumentCommand{\NAME}{mmm}{...} \newcommand without the * or \NewDocumentCommand specifying +m instead of m would be accomplished using:
\long\@namedef{NAME}...
Depending on your needs, this might be a more appropriate method.
And to expand on John Kormylo's answer, here's the much simpler² equivalent that uses \NewDocumentCommand instead of \newcommand:
\NewDocumentCommand{\NewNameDocumentCommand}{m}
{%
\expandafter\NewDocumentCommand\csname #1\endcsname
}
Not exactly in that \newcommand checks to see if the command exists with \@ifdefinable before it actually does the definition, while \@namedef doesn't care.
Mostly because \NewDocumentCommand uses a more flexible method of distinguishing between long and short arguments than \newcommand and thus doesn't have a * form. That said, if we wanted to precisely replicate John's definition with \newcommand for the definitions, we could write:³
\NewDocumentCommand{\Newcommand}{sm}
{%
\IfBooleanTF{#1}%
{\expandafter\newcommand\expandafter*\csname #2\endcsname}%
{\expandafter\newcommand\csname #2\endcsname}%
}
Comparing the two definitions should make it clear why I'm such a big proponent of \NewDocumentCommand over \newcommand, especially since the former has been part of the LaTeX kernel for almost a year now.
\@ifstar) You may need\expandafter\newcommand\expandafter*\csname.... – John Kormylo Aug 30 '21 at 13:50\barneeds to change, because it is of course already defined in LaTeX. – Steven B. Segletes Aug 30 '21 at 13:54