MakeIndex, Nomenclature, Glossaries and Acronymsshowidx and hyperref problems

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

showidx and hyperref problems

Post by ballchri »

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:

Code: Select all

\documentclass[12pt]{article}
\usepackage{makeidx}
\usepackage{showidx}
\usepackage{hyperref}
\makeindex
\begin{document}

\section{The section}\index{Section}
\printindex
\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

Code: Select all

\documentclass[12pt]{article}
\usepackage{makeidx}
\usepackage{hyperref}
\usepackage{showidx}
\makeindex
\begin{document}

\section{The section}\index{Section}
\printindex
\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

Code: Select all

\documentclass[12pt]{article}
\usepackage{makeidx}
\usepackage{hyperref}
%\usepackage{showidx}
\makeindex
\begin{document}

\section{The section}\index{Section}
\printindex
\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?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
ballchri
Posts: 4
Joined: Wed Jul 22, 2009 4:01 am

showidx and hyperref problems

Post by ballchri »

Seems this was solved a LONG time ago...

https://groups.google.com/forum/#!msg/c ... rC2grJclcJ

Code: Select all

%%% cut %%% test.tex %%% cut %%%
\documentclass{article}
\usepackage{makeidx}
\usepackage{hyperref}

\makeatletter
\ifHy@hyperindex
  \def\HyInd@ParenLeft{(}%
% Hook in \HyInd@@wrindex
  \let\HyInd@showidx\@empty
% Hook in \HyInd@@wrindex for package showidx
  \def\HyInd@showidx#1{%
    \@showidx{#1}%
    \if@nobreak
      \ifvmode
        \nobrak
      \fi
    \fi
  }%
% Load package showidx
  \let\siOrg@makeindex\makeindex
  \let\siOrg@@index\@index
  \let\siOrg@@wrindex\@wrindex
  \let\siOrg@index\index
  \RequirePackage{showidx}
  \let\makeindex\siOrg@makeindex
  \let\@index\siOrg@@index
  \let\@wrindex\siOrg@@wrindex
  \let\index\siOrg@index
% rest of hyperref part
  \@ifpackageloaded{multind}{%
    \let\HyInd@org@wrindex\@wrindex
    \def\@wrindex#1#2{\HyInd@@wrindex{#1}#2||\\}%
    \def\HyInd@@wrindex#1#2|#3|#4\\{%
      \ifx\\#3\\%
        \HyInd@org@wrindex{#1}{#2|hyperpage}%
      \else
        \def\Hy@temp@A{#3}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          HyInd@org@wrindex{#1}{#2|#3hyperpage}%
        \else
          \HyInd@org@wrindex{#1}{#2|#3}%
        \fi
      \fi
    }%
  }{%
    \def\@wrindex#1{\@@wrindex#1||\\}
    \def\@@wrindex#1|#2|#3\\{%
      \ifx\\#2\\%
        \protected@write\@indexfile{}{%
          \string\indexentry{#1|hyperpage}{\thepage}%
        }%
      \else
        \def\Hy@temp@A{#2}%
        \ifx\Hy@temp@A\HyInd@ParenLeft
          \protected@write\@indexfile{}{%
             \string\indexentry{#1|#2hyperpage}{\thepage}%
          }%
        \else
          \protected@write\@indexfile{}{%
            \string\indexentry{#1|#2}{\thepage}%
          }%
        \fi
      \fi
      \endgroup
      \HyInd@showidx{#1}%
      \@esphack
    }%
  }%
\fi
\makeatother

\makeindex
\begin{document}
\section{Hello World}
Hello\index{Hello} World\index{World}
\newpage
\index{abc}
abc def
\printindex
\end{document}
%%% cut %%% test.tex %%% cut %%%
Post Reply