# modifying PrintDescribeMacro of doc.sty

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?

-
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

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.

-