0

Suppose I want to replace the delimiters between pages in my index, so that instead of commas I use semicolons. The following code works well.

\documentclass{article}

\begin{filecontents}{\jobname.mst} delim_n "; " \end{filecontents} \usepackage{imakeidx}

%\usepackage{hyperref}

\makeindex

\begin{document} Some words. A test. \index{words} \index{phrases|see{words}} \newpage Words and sentences.\index{words}\index{sentences} \newpage Sentences.\index{sentences}

\index{sentences|seealso{words}} \printindex \end{document}

However, once I uncomment the hyperref page, things get weird.

  1. We get the log-entry

     (./testidx3.ind) [4] (./testidx3.aux) )pdfTeX warning (dest):
      name{page.1;2} has been referenced but does not exist, replaced by a fixed one
    
  2. Tracing the source, we find that in the generated .ind file

     \begin{theindex}
    

    \item phrases, \hyperindexformat{\see{words}}{1}

    \indexspace

    \item sentences, \hyperpage{2}; \hyperindexformat{\seealso{words}}{3}; \hyperpage{3}

    \indexspace

    \item words, \hyperpage{1; 2}

    \end{theindex}

The culprit is of course \hyperpage{1; 2}. It seems that \hyperref is relying on the standard choice of delimiters to allow a page range to be passed to \hyperpage in one go, instead of having it listed as \hyperpage{1}; \hyperpage{2}.

Question: Any ideas on how to work around this?

Willie Wong
  • 24,733
  • 8
  • 74
  • 106

1 Answers1

1

I don't see an user interface, but this here could work:

\documentclass{article}

\begin{filecontents}[overwrite]{\jobname.mst} delim_n "; " \end{filecontents} \usepackage{imakeidx}

\usepackage{hyperref} \makeatletter \def@commahyperpage#1{@@commahyperpage#1; ;\} \def@@commahyperpage#1; #2;#3\{% \ifx\#2\% \HyInd@pagelink{#1}% \else \HyInd@pagelink{#1}; \HyInd@pagelink{#2}% \fi } \makeatother \makeindex

\begin{document} Some words. A test. \index{words} \index{phrases|see{words}} \newpage Words and sentences.\index{words}\index{sentences} \newpage Sentences.\index{sentences}

\index{sentences|seealso{words}} \printindex \end{document}

Ulrike Fischer
  • 327,261
  • A few follow-up questions: (a) would this break other calls to \hyperpage that use the comma syntax? (b) I am a bit surprised that the lack of recursion works; why is it that for two-consecutive pages I get \hyperpage{1; 2} but for non-consecutive ones it outputs \hyperpage{1}; \hyperpage{3}? – Willie Wong Feb 24 '21 at 21:12
  • (a) I have no idea, I simply looked where the commas are and replaced them by ;, you will have to test if this breaks something. (b) is probably makeindex doing. – Ulrike Fischer Feb 24 '21 at 21:17
  • I'll accept this. It helped me learn a bit more how indexing works, and that I was asking the wrong question. Thanks! – Willie Wong Feb 24 '21 at 22:27