# Using macro parameter # after control sequence character \

I'm making a new command like which goes kind of like this:

\newcommand\mycommand[1]{\#1section}


So, what I what is to type \mycommand{sub}{blah} to output \subsection{blah} and \mycommand{subsub}{blah} to output \subsubsection{blah}. Is this even possible?

\csname allows to construct command sequence names:
\newcommand*{\mycommand}[1]{\csname#1section\endcsname}

If the constructed command is not defined, then it does not throw an error. Instead, the constructed command has the meaning \relax.
• Nice, so \csname allows you to construct command sequence names, but is there anything that allows you to construct variables defined with \def? – Skeleton Bow Jul 4 '17 at 20:02
• @SkeletonBow The "command sequence names" are just command tokens that start with the escape char (backslash). Macros (defined by \def, \newcommand, ...) belong to them. – Heiko Oberdiek Jul 4 '17 at 20:04
• @SkeletonBow Probably, a missing \expandafter: \expandafter\def\csname ...\endcsname – Heiko Oberdiek Jul 4 '17 at 20:09