1

I'm currently using the makeidx package in conjunction with the \hyperref package to create my index. It's working perfectly fine so far, but only the page number next to the index term is clickable.

Is there any way I can make the entire index entry clickable?

My file looks like this:

\documentclass{report}

\usepackage{makeidx}
\usepackage{hyperref}

\makeindex

\begin{document}

This is some text.\index{sample index}

\printindex

\end{document}

The index looks like this:

Page 2

I want the "sample index" text to be clickable aswell (not just the 1).

3
  • 3
    and what should happen if sample index appears on two different pages? i.sstatic.net/wiykhs9Y.png Commented Apr 25 at 13:03
  • @UlrikeFischer good point. but can I do it if I manually ensure that sample index only appears once in the entire document? do I need to use something else besides makeidx? the sample index text could also just link to the first occurence. Commented Apr 25 at 13:10
  • it is difficult with makeindex. Check the glossary package. Commented Apr 25 at 13:41

1 Answer 1

1

If sample index only link to the first occurrence, you could do this:

\documentclass{report}
\usepackage{makeidx}
\usepackage{hyperref}
\usepackage{etoolbox}
\newcounter{dummyindex}
\makeatletter
\patchcmd{\@wrindex}{\@@wrindex #1}{\stepcounter{dummyindex}\phantomsection\label{\thedummyindex:#1}\@@wrindex{\string\hyperref[1:#1]{#1}}}{}{}
\makeatother

\makeindex

\begin{document}
This is some text\index{sample index}
\clearpage
Some longer contents to show the example. Make it longer to include at least two lines\index{sample index}. Some longer contents to show the example
\printindex
\end{document}

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.