# hyperref causes problem with doc.sty

Try the following code. Without hyperref everything is fine and there’s the right entry in the index. With hyperref this entry disappears. (The codeline entries which are not shown here ar not touched by using hyperref)

\documentclass{ltxdoc}

%\usepackage{hyperref}
\usepackage{doc}

\EnableCrossrefs
\CodelineIndex

\begin{document}
Test\DescribeMacro{\name}

\PrintIndex
\end{document}


Is there a way to use both packages?

-

The hypdoc package is available specifically to augment doc with hyperref abilities. Thus you should simply use

\usepackage{hypdoc}


in place of

\usepackage{doc}
\usepackage{hyperref}


This adds a few additional bells-and-whistles to the overall set up, so it's better than interfacing the two packages yourself.

-
Oh, nice. I didn't know there's such a package. –  Andrey Vihrov Sep 20 '11 at 10:29
Thanks, but that does’t solve the problem completely. I had to add \hyperpage{#1}to the \usage macro to get links for index entries of \DescribeMacro/\DescribeEnv. Could this be a bug? –  Tobi Sep 20 '11 at 11:07

The MakeIndex program, which is used to process the .ind file, expects index entries of form

\index{<item>|<cmd>}


which means to format the page number of item with \<cmd>.

If you look at the .ind file generated with hyperref, you will see that the index entry command really is

\indexentry{name=\verb!*+\name+|usage|hyperpage}{1}


That is, there are two formatting commands \usage and \hyperpage — one from doc and one from hyperref! This confuses MakeIndex and it doesn't produce output. The solution is to redefine \usage to include \hyperpage in it, and tell hyperref not to override index commands:

\documentclass{ltxdoc}

\usepackage[hyperindex=false]{hyperref}

\EnableCrossrefs
\CodelineIndex

\let\oldusage=\usage
\renewcommand{\usage}[1]{\oldusage{\hyperpage{#1}}}

\begin{document}

\DescribeMacro{\name}
Test

\PrintIndex

\end{document}


You might also want to add hyperlinks to the page numbers of change history in a similar way:

\let\oldglossary=\glossary
\renewcommand{\glossary}[1]{\oldglossary{#1|hyperpage}}

-
Thanks Andrey. I used Josephs answer but your answer about \hyperpage helped too :-) –  Tobi Sep 20 '11 at 11:09