32

I use imakeidx package to generate index in my document. I'd like to add hyperlinks into my Index, but it seems to me that hyperref and imakeidx do not work together. For example, this code doesn't create linkable index:


\documentclass[11pt]{book}
\usepackage[pdftex]{color}

\usepackage{hyperref} \hypersetup{ colorlinks, citecolor=green, filecolor=green, linkcolor=blue, urlcolor=green } \usepackage[makeindex]{imakeidx} \makeindex \begin{document} Text\index{text} \printindex \end{document}

How to fix this problem? Thanks.

lockstep
  • 250,273
Physicsworks
  • 1,315

3 Answers3

55

Load imakeidx before hyperref. Generally, hyperref should be loaded last, though there are some exceptions (see Which packages should be loaded after hyperref instead of before? ).

Torbjørn T.
  • 206,688
3

Packages hyperref and imakeidx can be used together by creating a new command, like the one shown in the attached example. It may combine several commands to provide alternate font together with hyper-reference. To simplify entering the words into the index, command \IN is introduced. Compilation gives 3 page PDF file with the following index.

Index
ENTRY, 1
entryA, 1, 2
entryB, 2

\documentclass[11pt]{book}
\usepackage[pdftex]{color}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=blue}
\usepackage{imakeidx}
\makeindex[columns=1]
\newcommand{\BH}[1]{\large\textbf{\hyperpage{#1}}\normalsize}
\newcommand{\IN}[1]{\index{#1|BH}}

\begin{document}
Text on page 1
\index{entryA|BH}
\IN{ENTRY}
\newpage
Text on page 2 \IN{entryA}\IN{entryC}
\printindex
\end{document}
Werner
  • 603,163
arpi
  • 49
  • 3
    Does this have any advantage over loading imakeidx before hyperref, like in the accepted answer? My understanding is that when you load hyperref, it does similar new commands in the background. – Teepeemm Jul 12 '18 at 16:47
1

You can also change package, and use splitidx instead of imakeidx