# Create command that displays input exactly

I want to create a command whose argument is used within a \label{} command. I also want a boolean switch that turns on/off the display of this label for editing purposes. Here is pseudo-code for what I'd like to do:

\newcommand{\foo}[1]{%
\refstepcounter{foocount}\label{#1}%
... do other things ... %
\ifthenelse{\boolean{showlabel}}%
{DISPLAY #1}%
{}%
}


The problem is in the DISPLAY #1 part. I want to display the label no matter what the label contains. For instance, many of my labels have the form "ex:function_continuous_everywhere" but the underscores causes math-mode errors. Using variations of \verbatim has its own set of issues.

Is there a slick way of doing this? I know I could change all my labels, but I'd rather not.

-
You can look at the package showkeys that shows labels automatically. – egreg Jan 18 '12 at 14:04
@egreg: Very nice. That does the trick, too. – GregH Jan 18 '12 at 14:54

You can use \texttt{\detokenize{#1}} for the DISPLAY #1 part. This will convert the argument into text (e.g. the _ are turned into normal characters and are no longer math shift sequences) and typesets it in teletyper font.
Note that \detokenize is an e-TeX primitive, so very old or outdated LaTeX distributions won't have it.