LaTeX forum ⇒ MakeIndex, Nomenclature, Glossaries and Acronymsshowidx and hyperref problems

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
ballchri
Posts: 4
Joined: Wed Jul 22, 2009 4:01 am

showidx and hyperref problems

Postby ballchri » Mon Apr 05, 2010 12:03 pm

I am having problems using the showidx and hyperref together. If either package is removed, everything works as I would expect. If both packages are present, then the results are not what I expect, which is index entries shown in the margin and hyperlinks in the (correct) index. Minimal example:
  1. \documentclass[12pt]{article}
  2. \usepackage{makeidx}
  3. \usepackage{showidx}
  4. \usepackage{hyperref}
  5. \makeindex
  6. \begin{document}
  7.  
  8. \section{The section}\index{Section}
  9. \printindex
  10. \end{document}

The problem is that in this example, the index entry is not shown in the margin and in the index itself the entry is wrong. A partial fix is to put the showidx package after the hyperref package
  1. \documentclass[12pt]{article}
  2. \usepackage{makeidx}
  3. \usepackage{hyperref}
  4. \usepackage{showidx}
  5. \makeindex
  6. \begin{document}
  7.  
  8. \section{The section}\index{Section}
  9. \printindex
  10. \end{document}

which will cause the document to create the index correctly and the entry in the side margin, but without the hyperlink. To completely fix the problem the document needs to be compiled using
  1. \documentclass[12pt]{article}
  2. \usepackage{makeidx}
  3. \usepackage{hyperref}
  4. %\usepackage{showidx}
  5. \makeindex
  6. \begin{document}
  7.  
  8. \section{The section}\index{Section}
  9. \printindex
  10. \end{document}

until the index has the hyperlinks, then uncomment the showidx package to get the index entries in the margin. This however is a nuisance, which leads to my questions:
1) Is there a way of using showidx and hyperref to get entries in the margin and hyperlinks without modifying the source code?
2) Why does the order of hyperref and showidx make a difference?

ballchri
Posts: 4
Joined: Wed Jul 22, 2009 4:01 am

Postby ballchri » Sun Jan 24, 2016 9:16 am

Seems this was solved a LONG time ago...

https://groups.google.com/forum/#!msg/comp.text.tex/fof9f-cln-I/7nrC2grJclcJ
  1. %%% cut %%% test.tex %%% cut %%%
  2. \documentclass{article}
  3. \usepackage{makeidx}
  4. \usepackage{hyperref}
  5.  
  6. \makeatletter
  7. \ifHy@hyperindex
  8. \def\HyInd@ParenLeft{(}%
  9. % Hook in \HyInd@@wrindex
  10. \let\HyInd@showidx\@empty
  11. % Hook in \HyInd@@wrindex for package showidx
  12. \def\HyInd@showidx#1{%
  13. \@showidx{#1}%
  14. \if@nobreak
  15. \ifvmode
  16. \nobrak
  17. \fi
  18. \fi
  19. }%
  20. % Load package showidx
  21. \let\siOrg@makeindex\makeindex
  22. \let\siOrg@@index\@index
  23. \let\siOrg@@wrindex\@wrindex
  24. \let\siOrg@index\index
  25. \RequirePackage{showidx}
  26. \let\makeindex\siOrg@makeindex
  27. \let\@index\siOrg@@index
  28. \let\@wrindex\siOrg@@wrindex
  29. \let\index\siOrg@index
  30. % rest of hyperref part
  31. \@ifpackageloaded{multind}{%
  32. \let\HyInd@org@wrindex\@wrindex
  33. \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
  34. \def\HyInd@@wrindex#1#2|#3|#4\\{%
  35. \ifx\\#3\\%
  36. \HyInd@org@wrindex{#1}{#2|hyperpage}%
  37. \else
  38. \def\Hy@temp@A{#3}%
  39. \ifx\Hy@temp@A\HyInd@ParenLeft
  40. HyInd@org@wrindex{#1}{#2|#3hyperpage}%
  41. \else
  42. \HyInd@org@wrindex{#1}{#2|#3}%
  43. \fi
  44. \fi
  45. }%
  46. }{%
  47. \def\@wrindex#1{\@@wrindex#1||\\}
  48. \def\@@wrindex#1|#2|#3\\{%
  49. \ifx\\#2\\%
  50. \protected@write\@indexfile{}{%
  51. \string\indexentry{#1|hyperpage}{\thepage}%
  52. }%
  53. \else
  54. \def\Hy@temp@A{#2}%
  55. \ifx\Hy@temp@A\HyInd@ParenLeft
  56. \protected@write\@indexfile{}{%
  57. \string\indexentry{#1|#2hyperpage}{\thepage}%
  58. }%
  59. \else
  60. \protected@write\@indexfile{}{%
  61. \string\indexentry{#1|#2}{\thepage}%
  62. }%
  63. \fi
  64. \fi
  65. \endgroup
  66. \HyInd@showidx{#1}%
  67. \@esphack
  68. }%
  69. }%
  70. \fi
  71. \makeatother
  72.  
  73. \makeindex
  74. \begin{document}
  75. \section{Hello World}
  76. Hello\index{Hello} World\index{World}
  77. \newpage
  78. \index{abc}
  79. abc def
  80. \printindex
  81. \end{document}
  82. %%% cut %%% test.tex %%% cut %%%


Return to “MakeIndex, Nomenclature, Glossaries and Acronyms”

Who is online

Users browsing this forum: No registered users and 1 guest