3

I want to make the indexed words into hyperlinks to the entries in the "Index" (something similar to the glossaries package).
I'm using xindy on TL2012 and here is my code:

\documentclass{article}

\usepackage{makeidx}
\makeindex

\usepackage{hyperref}

\begin{document}

Lorem\index{Alpha} ipsum dolor sit amet, consectetur\index{alpha}
adipiscing elit. Proin ullamcorper\index{gnat} quam magna, quis
convallis\index{gnus!good} sapien. Donecat ligula vel dolor
varius\index{bites!vegetable} lobortis id ut orci\index{gnat!size
of}. Maecenas commodo fringilla elit\index{Alphabet}, et pellentesque
purus ornare vitae.  Aenean non metus ipsum. Lorem\index{gnat!anatomy}
ipsum dolor sit amet, consectetur adipiscing\index{alphas} elit. Ut
mauris lorem, accumsan a sagittis ut, rutrum fringilla arcu. Cras
ullamcorper faucibus\index{alpha bet} quam id molestie.

\printindex

\end{document}

How can I do that?

1 Answer 1

4

Generally the indexed words do not necessarily appear in the text at all (for example there can be a fox in the text and an \index{animals} next to it). Therefore I'm not sure whether I understand your question right.

\documentclass{article}

\usepackage{makeidx}
\makeindex

\usepackage{hyperref}

\begin{document}

Lorem\index{Alpha@\hypertarget{Alpha.ind}{}Alpha}\href{\#Alpha.ind}{Alpha}
ipsum dolor sit amet, consectetur 
\index{alpha@\hypertarget{alpha.ind}{}alpha}\href{\#alpha.ind}{alpha}
adipiscing elit. Proin ullamcorper 
\index{gnat@\hypertarget{gnat.ind}{}gnat}\href{\#gnat.ind}{gnat} quam magna, quis
convallis
\index{gnus!good@\hypertarget{gnusgood.ind}{}good}\href{\#gnusgood.ind}{good} quam magna, ...

\printindex

\end{document}

Does this accomplish what you intended? (This works without xindy, but with it there can be problems.)

5
  • thanks, this is exactly what I was looking for. Just one more thing: Why do I get errors when redefining the \index command as below? ‎\let\oldindex\index‎ ‎\renewcommand*{\index}[1]{‎‎ \oldindex{#1‎@\hypertarget{#1‎‎.‎ind}{}#1}\href{\##1‎.‎ind}{#1}‎‎‎}‎‎ Commented Nov 10, 2012 at 17:17
  • 1
    You need to \protect \hypertarget, otherwise it will break: \let\oldindex\index \renewcommand*{\index}[1]{\oldindex{#1@\protect\hypertarget{#1.ind}{}#1}\href{\##1.ind}{#1}}. This redefinition is practical, but it does not work for index entries with subentries, e.g.\index{gnus!good}. Either use \oldindex{gnus!good@\hypertarget{gnusgood.ind}{}good}\href{\#gnusgood.ind}{good} or feel free to ask a follow-up-question about how to achieve that.
    – Stephen
    Commented Nov 10, 2012 at 19:14
  • thanks again, but if I use the \protect, the link to the entry in the Index doesn't work! Commented Nov 10, 2012 at 19:54
  • 1
    That's a pity. Without xindy this worked for me, and at the moment I have no idea how to fix it. Because neither index entries with subentries could be used this way, imho it would be appropriate to ask a follow up question "Why does \let\oldindex... not work?".
    – Stephen
    Commented Nov 10, 2012 at 20:16
  • I asked a follow-up question here Commented Nov 10, 2012 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .