Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
3  
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

1 Answer 1

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

 
discard

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.