# How to make indexed words clickable in the text?

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?

-

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}
\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? (I did not test with xindy, but at least it works without it, thus some xindy-expert could probably fix it if it does not work with it.)

-
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}‎‎‎}‎‎ –  Vahid Damanafshan Nov 10 '12 at 17:17
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 Nov 10 '12 at 19:14
thanks again, but if I use the \protect, the link to the entry in the Index doesn't work! –  Vahid Damanafshan Nov 10 '12 at 19:54
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 Nov 10 '12 at 20:16
I asked a follow-up question here –  Vahid Damanafshan Nov 10 '12 at 20:50