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 would like to redefine the command PrintDescribeMacroof doc.sty in order to create a label that I can link to using hyperref.

However whenever I add a label to the command I get an error

\ifcsdef{PrintDescribeMacro}
   {\def\PrintDescribeMacro#1{%
   \label{doc:desc:#1}%
   \strut \MacroFont %
   \color{doctools@ColorCodeNames} \string #1\ }}{}

because the label is created with a different content than what I expect

\newlabel{doc:desc:\unhbox \voidb@x \relax \begingroup \catcode `\spacefactor 
\@m 11\relax \par }{{1}{3}{Commands provided by doc.sty and ltxdoc}{MacroName.1}{}}

Any better idea how to modify the commands of doc.sty?

share|improve this question
    
I know this is an old question; did you make any progress? If so, please add your solution. Or make a minimal example of what you're trying to do. –  egreg Jul 6 '13 at 21:08
    
I have created a sty file called doctools (see code.google.com/p/latexthesistemplate/source/browse/trunk/…) which defines this command without the label. So no, there was no progress. –  Matthias Pospiech Jul 8 '13 at 16:41
add comment

1 Answer

You need to allow for the fact that #1 here is a command, and so when it gets written to the .aux file it may expand. You could use \string, but you'd still have an issue when reading back the command. A simplistic approach is to turn into a string and then gobble the \

\documentclass{article}
\usepackage{doc}
\usepackage{color}
\usepackage{hyperref}
\makeatletter
\renewcommand{\PrintDescribeMacro}[1]{%
 \label{doc:desc:\expandafter\@gobble\string#1}%
 \strut
 \MacroFont
 \color{red}%
 \string #1\ %
}
\makeatother
\begin{document}
\DescribeMacro{\foo}
\end{document}

Note that this may go wrong if you pass something other than a command name here (say a single active char): I guess a fuller fix would include a test for this.

share|improve this answer
add comment

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.