TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 3 down vote accepted

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.)

share|improve this answer
    
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
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 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
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 Nov 10 '12 at 20:16
    
I asked a follow-up question here – Vahid Damanafshan Nov 10 '12 at 20:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.