![Heiko Oberdiek 的“快速而肮脏的黑客攻击”有什么作用?](https://linux22.com/image/396399/Heiko%20Oberdiek%20%E7%9A%84%E2%80%9C%E5%BF%AB%E9%80%9F%E8%80%8C%E8%82%AE%E8%84%8F%E7%9A%84%E9%BB%91%E5%AE%A2%E6%94%BB%E5%87%BB%E2%80%9D%E6%9C%89%E4%BB%80%E4%B9%88%E4%BD%9C%E7%94%A8%EF%BC%9F.png)
showidx
在我的文档序言中,我有以下与和相关的代码hyperref
,这些代码也出现在本论坛的许多帖子中。
它的用途是什么?
%Begin the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
\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
%
%End the ``quick and dirty hack'' due to Heiko Oberdiek which loads showidx
出现此现象的帖子包括:如何引用索引词,目录、章节目录和附录功能失灵,如何保持相同的数字重述定理?,如何将索引条目显示在与被索引的文本相同的行上,区分前向交叉引用和后向交叉引用。
答案1
它是为了回答这个问题而创建的
hyperref appears to be trashing the index of my article document.
Without hyperref (which I really need), the index, generated
with makeidx package commands \makeindex and \printindex, looks great.
With hyperref, which I tend to load with these options,
\usepackage[plainpages=false,hyperindex]{hyperref}
the index is collapsed from hundreds of entries with various page
numbers down to a single entry
如需了解更多信息,请参阅https://groups.google.com/forum/#!topic/comp.text.tex/fof9f-cln-I
然而经过 18 年的测试,“快速修复”(完整内容如下)仍然需要纠正 hyperref,尤其是与 \documentclass{article} 的 showidx 一起使用时。还请参阅下面@murry 的评论,该评论表明可能还有其他用途
“还有回忆录documentclass,其中 showidx 没有明确加载,而是被模拟memoir
?“- murry
我还包括了 Ulrike 对此的评论,这些评论来自已删除的重复答案,关于其继续使用。
“该 hack 尚未添加到hyperref
,并且取决于加载顺序showidx
或索引中断的超链接。我不认为后者真的是一个问题,因为showidx
文档的最终版本不需要它。我在删除 hack 后(但保留 )在您所链接的 google.groups 中使用 Heiko 的示例进行了测试showidx
。– Ulrike Fischer
这是源测试文件(以防上述链接丢失)
%%% 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 %%%