索引中存在多个 see 或 seealso 实例的问题

索引中存在多个 see 或 seealso 实例的问题

怀疑我在这里遗漏了一些明显的东西。我有多个相同的实例seeseealso索引条目。这是无法避免的。

有时它们被适当压缩,但有时却没有。我使用的是 imakeidx,但问题与 makeidx 相同,并且也抵制删除临时文件和运行次数。它以各种方式表现出来,很难产生一个显示所有效果的 MWE。

然而这个 MWE:

\documentclass{article}
%\usepackage{imakeidx}
%\indexsetup{othercode=\footnotesize}
%\makeindex[intoc=true,title=My Index,columnsep=25pt]

\usepackage{makeidx}
\makeindex

\begin{document}
text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text\index{cat|see{pig}}text\index{cat|see{pig}}
text\index{dog|see{pig}}text\index{dog|see{pig}}
text\index{Smith John|see{Smith Jack}} text\index{Smith John|see{Smith Jack}}
text\index{Blundell!Jack|see{Blundell John}} text\index{Blundell!Jack|see{Blundell John}}
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}\index{Fuchs!Annie|see{Blogs Annie}}
\clearpage
text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text\index{cat|see{pig}}text\index{cat|see{pig}}
text\index{dog|see{pig}}text\index{dog|see{pig}}
text\index{Smith John|see{Smith Jack}}text\index{Smith John|see{Smith Jack}}
text\index{Blundell!Jack|see{Blundell John}} text\index{Blundell!Jack|see{Blundell John}}
text\index{Blundell!Peter} text\index{Blundell!Peter}
text\index{Blundell!Aubrey} text\index{Blundell!Aubrey}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}\index{Fuchs!Annie|see{Blogs Annie}}
\clearpage
text\index{cat}text\index{cat}
text\index{cat|see{pig}}text\index{cat|see{pig}}
text\index{dog|see{pig}}text\index{dog|see{pig}}
text\index{Smith John|see{Smith Jack}}text\index{Smith John|see{Smith Jack}}
text\index{Blundell!Aubrey} text\index{Blundell!Aubrey}
text\index{Blundell!Jack|see{Blundell John}} text\index{Blundell!Jack|see{Blundell John}}
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}\index{Fuchs!Annie|see{Blogs Annie}}
\clearpage
text\index{cat}text\index{cat}
text\index{cat|see{pig}}text\index{cat|see{pig}}
text\index{dog|see{pig}}text\index{dog|see{pig}}
text\index{Blundell!Aubrey} text\index{Blundell!Aubrey}
text\index{Smith John|see{Smith Jack}}text\index{Smith John|see{Smith Jack}}
text\index{Blundell!Jack|see{Blundell John}} text\index{Blundell!Jack|see{Blundell John}}
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}\index{Fuchs!Annie|see{Blogs Annie}}
\clearpage
text\index{cat}text\index{cat}
text\index{cat|see{pig}}text\index{cat|see{pig}}
text\index{dog|see{pig}}text\index{dog|see{pig}}
text\index{Blundell!Aubrey} text\index{Blundell!Aubrey}
text\index{Smith John|see{Smith Jack}}text\index{Smith John|see{Smith Jack}}
text\index{Blundell!Jack|see{Blundell John}} text\index{Blundell!Jack|see{Blundell John}}
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}\index{Fuchs!Annie|see{Blogs Annie}}
\printindex
\end{document}

生产

在此处输入图片描述

如图所示,cat 和 dog 的索引都得到了复制(但后者只有部分复制,因为中间有实际索引条目)。同一条目的实际索引条目并不总是产生效果所必需的,例如,我在较大的文档中看到以下内容,但在 MWE 中没有:

在此处输入图片描述

我究竟做错了什么?

答案1

see功能没有什么特别的,它只是一个 Makeindex 的页面格式化命令,来自生成的.ind文件:

\item dog, 1, \see{pig}{1}, 2, \see{pig}{2--5}

\item Smith John, \see{Smith Jack}{1--5}

“Smith John”条目中的 仅出现一次,这纯属偶然see。原因是条目合并到页面范围。页面在输出中不可见,因为宏\see会丢弃页面的第二个参数。

可以通过对文件进行后处理来修复此问题.idx。以下 Perl 过滤器脚本将每个see索引条目的页码替换为$seepagenumber默认值 9999,从而将该see条目添加到页面列表的末尾(如果有更多页面,则增加 9999)。

perl 脚本fix-see.pl充当过滤器。这意味着它从标准输入读取并写入标准输出:

#!/usr/bin/env perl
use strict;
use warnings;

my $seepagenumber = 9999;

while (<>) {
    s/{[^{}*]}$/{$seepagenumber}/ if /\|see{/;
    print;
}
__END__

命令序列例如文件test.tex如下:

pdflatex test
./fix-see.pl <test.idx >test.idx-fixed
makeindex test.idx-fixed
pdflatex test

结果:

结果

LaTeX 中的解决方案makeindex

可以通过在写入索引条目时更改 TeX 中条目的页码来避免使用 Perl 脚本see。索引写入命令 ( latex.ltx/package makeidx) 的标准定义示例:

\usepackage{makeidx}
\makeindex

\newcommand*{\seepagenumber}{9999}

\makeatletter
\CheckCommand*{\@wrindex}[1]{%
  \protected@write\@indexfile{}{%
    \string\indexentry{#1}{\thepage}%
 }%
 \endgroup
 \@esphack
}
\renewcommand*{\@wrindex}[1]{%
  \protected@edef\idx@text{#1}%
  \expandafter\idx@test@see\idx@text|see\@nil{#1}%
}
\def\idx@test@see#1|see#2\@nil#3{%
  \protected@write\@indexfile{%
    \ifx\\#2\\%
    \else
      \let\thepage\seepagenumber
    \fi
  }{%
    \string\indexentry{#3}{\thepage}%
  }%
  \endgroup
  \@esphack
}
\makeatother

软件包版本imakeidx

\usepackage{imakeidx}
\indexsetup{othercode=\footnotesize}
\makeindex[intoc=true,title=My Index,columnsep=25pt]

\newcommand*{\seepagenumber}{9999}

\makeatletter
\CheckCommand\imki@wrindexentrysplit[3]{%
  \expandafter\protected@write\csname#1@idxfile\endcsname{}%
    {\string\indexentry{#2}{#3}}%
}
\CheckCommand\imki@wrindexentryunique[3]{%
  \protected@write\@indexfile{}%
    {\string\indexentry[#1]{#2}{#3}}%
}

\newif\if@IndexEntryWithSee
\renewcommand\imki@wrindexentrysplit[3]{%
  \@DoesEntryContainsSee{#2}%
  \expandafter\protected@write\csname#1@idxfile\endcsname{%
    \if@IndexEntryWithSee
      \let\thepage\seepagenumber
    \fi
  }{%  
    \string\indexentry{#2}{#3}%
  }%
}   
\renewcommand\imki@wrindexentryunique[3]{%
  \@DoesEntryContainsSee{#2}%
  \protected@write\@indexfile{%
    \if@IndexEntryWithSee
      \let\thepage\seepagenumber
    \fi
  }{%  
    \string\indexentry[#1]{#2}{#3}%
  }%
}   
\newcommand*{\@DoesEntryContainsSee}[1]{%
  \protected@edef\@IndexEntryText{#1}%   
  \expandafter\@CheckForSee\@IndexEntryText|see\@nil
}
\def\@CheckForSee#1|see#2\@nil{%
  \ifx\\#2\\%
    \@IndexEntryWithSeefalse
  \else
    \@IndexEntryWithSeetrue
  \fi
}
\makeatother

结果

答案2

带有see或 的条目seealso应该只出现一次,并且位于文档末尾,紧接着之前\printindex

\documentclass{article}
%\usepackage{imakeidx}
%\indexsetup{othercode=\footnotesize}
%\makeindex[intoc=true,title=My Index,columnsep=25pt]

\usepackage{makeidx}
\makeindex

\begin{document}

text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}
\clearpage

text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}
\clearpage

text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}
\clearpage

text\index{cat}text\index{cat}
text\index{dog}text\index{dog}
text
text\index{Blundell!Peter} text\index{Blundell!Peter}
\index{Blogs!Peter!results}\index{Blogs!Annie!results}
\clearpage

\index{cat|seealso{pig}}
\index{dog|seealso{pig}}
\index{Smith John|see{Smith Jack}}
\index{Fuchs!Annie|see{Blogs Annie}}
\index{Blundell!Jack|see{Blundell John}}

\printindex
\end{document}

在此处输入图片描述

相关内容