假设我想替换索引中页面之间的分隔符,以便使用分号代替逗号。以下代码运行良好。
\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}
然而,一旦我取消对该hyperref
页面的注释,事情就变得奇怪了。
我们得到日志条目
(./testidx3.ind) [4] (./testidx3.aux) )pdfTeX warning (dest): name{page.1;2} has been referenced but does not exist, replaced by a fixed one
追根溯源,我们发现在生成的
.ind
文件中\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}
罪魁祸首当然是\hyperpage{1; 2}
。似乎依赖于标准的分隔符选择,以便一次性\hyperref
传递页面范围,而不是将其列为。\hyperpage
\hyperpage{1}; \hyperpage{2}
问题:关于如何解决这个问题,您有什么想法吗?
答案1
我没有看到用户界面,但是这个可以工作:
\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}