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:

  ... do other things ... %
  {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.

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

1 Answer 1


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.

  • Never heard of \detokenize before. Perfect; thanks.
    – GregH
    Jan 18, 2012 at 14:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .