I am writing some API documentation, and since I don't like to repeat myself I would like to make some commands and call those for parts that get repeated a lot. However, I am having trouble with characters that need to be escaped in some commands, while they can't be escaped in labels.
I have the following command:
\newcommand{\CommandHeader}[1]
{
\subsection{#1}
\label{command:#1}
\subsubsection*{Name}
#1
}
This works file when I call the command without any special characters
\CommandHeader{ping}
But when I call it with escaped characters, it will result in errors:
\CommandHeader{get\_file} % Gives missing/extra \endcsname errors
\CommandHeader{get_file} % Gives errors everywhere else
So my question is, how do I create a command to which I can pass a name with escaped characters, that works with both types of commands. Also, why is there a difference between these commands anyway?
_? – egreg Jan 29 '16 at 13:23_for now, but since it's API documentation I can imagine this issue coming up with other characters at some point. So I would prefer a generic solution. – Rick de Water Jan 29 '16 at 13:29\labeland\sectionis completely different, while it is possible to make things work (especially for_which is easier than accented letters) it is probably a mistake to do so and the arguments should be kept separate. The argument of\sectionis a string to be typeset in the output, the argument to\labelis essentially an internal command name used for cross referencing so you can not use\_for the same reason you can not use\_in the middle of a counter or environment name. Also unrelated but you are missing%from several lines in your definition. – David Carlisle Jan 29 '16 at 14:07