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.

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?

share|improve this question

2 Answers 2

up vote 13 down vote accepted

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.

share|improve this answer
    
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}}
share|improve this answer
    
Thanks Andrey. I used Josephs answer but your answer about \hyperpage helped too :-) –  Tobi Sep 20 '11 at 11:09

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.