I am trying to create links from \index
commands to corresponding index entries. When hyperref
package is loaded, page numbers in index are, by default, linked to the page on which \index
command for that entry appears. But it does not work another way around (forward-linking).
When checking correctness of index
, it would be useful if I could click on indexed word in PDF (#2
in ati
macro in MWE below) and it would take me to the place in the index in which corresponding entry appears. Actual index has many pages, so it is not sufficient to just determine page number where index starts, because given entry can actually appear few pages later.
My first idea was to add label to index entry and then create hyperlink from indexed word. Attempt in doing so is reflected in commented atiwl
macro below. Unfortunately, this didn't compile. (Even if it did, there would be a problem with adding unique labels to each entry). Second idea to test if using label
could work was to add one label directly to .ind
file, like this:
\item Index entry 1, \hyperpage{1}\label{linkedentry}
Altought it compiled, resulting link did not work in PDF.
MWE:
\documentclass{book}
\usepackage{blindtext}
\usepackage{makeidx}
\makeindex
\def \ati#1#2{#2\index{#1}} % "Add to index" macro
% \def \atiwl#1#2{\hyperlink{linkedentry}{#2}\index{#1\label{linkedentry}}} % "Add to index with label" macro
\usepackage{hyperref}
\begin{document}
\blindtext
Some text and \ati{Index entry 1}{indexed term}.
\blindtext
Some text and \ati{Index entry 2}{another indexed term}.
% \blindtext
% Some text and \atiwl{Entry with label}{some indexed text}.
\printindex
\end{document}
I am not sure if this is relevant to the solution, but I use texindy
as index processor. And actually, I use splitidx
package and accompanying splitindex
command line tool, because I need many indexes. In MWE, though, I used makeidx
to make it more universal for other people with the same problem.
Is there any way to create link from #2
in ati
macro to corresponding index entry?
\hyperlink
and\hypertarget
must be protected!