2.9 索引
目前只有 LaTeX/PDF 输出支持索引。要在书籍之后打印索引,你可以在 LaTeX 导言 (preamble) 中使用 LaTeX 软件包 makeidx (请参阅第 4.1 节):
或者,你也可以使用 imakeidx 软件包:
这个软件包提供了格式化索引的额外功能,例如:
在上面的例子中,intoc=true
将在目录中包含一个索引条目,columns=3
将把索引格式转为三列,columnseprule=true
将在相邻的索引列之间显示一条线。最后,options=-s latex/indexstyles.ist
将使用位于 latex/indexstyles.ist
的索引样式文件中包含的额外格式化选项。imakeidx 软件包中还有许多其他的功能,请参阅其文档以了解更多细节。
2.9.1 插入索引条目
索引条目可以通过在书籍正文中使用 \index{}
命令创建,例如:
类似的,可以为某项插入一个子条目:
Git\index{Version Control!Git} is a
popular version control system.
上面的例子将会在索引的 “Version Control” 下方添加一个 “Git” 条目。
要创建一个出现在项目子条目底部的 “see also” 条目(没有页码),首先在 LaTex 导言 (preamble) 文件中调用 \makeindex
的下方添加如下内容:
% to create a "see also" that appears at the bottom of the
% subentries and with no page number, do the following:
% \index{Main entry!zzzzz@\igobble|seealso{Other item}}
\newcommand{\ii}[1]{{\it #1}}
\newcommand{\nn}[1]{#1n}
\def\igobble#1{}
然后,在你的书籍中使用 \index{Main entry!zzzzz@\igobble|seealso{Other item}}
语法。 举个例子: