TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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
up vote 4 down vote accepted

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.

share|improve this answer
Never heard of \detokenize before. Perfect; thanks. – GregH Jan 18 '12 at 14:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.