指向书籍封面的索引条目

指向书籍封面的索引条目

我想要书中某一页和书封的索引条目。答案位于创建索引条目的固定页码无法处理文本引用。使索引条目引用页码以外的内容看起来比我只需要一次的用例复杂得多。

这个 MWE(不是绝对最小但可能很有趣)生成正确的 .ilg 文件

\indexentry{molasses}{1} 
\indexentry{molasses}{cover}

但不是正确的索引。

\documentclass[10pt]{article}

\usepackage{makeidx}
\makeindex

\begin{document}
The story headlined in the Boston Post on the cover of this book tells
of a January 15th, 1919 disaster in Boston's North End. 
Chuck Lyons retold the story in \emph{History Today} in 2009,
describing how a tank of molasses ruptured, ``releasing two million
gallons of molasses in a 15 foot high, 160 foot wide wave.''
Wikipedia adds that 
``Several blocks were flooded to a depth of 2 to 3 feet.''
\index{molasses}
\makeatletter
\protected@write\@indexfile{}{\string\indexentry{molasses}{cover}}
%\protected@write\@indexfile{}{\string\indexentry{molasses}{0}}
\makeatother

Several years later the auditor appointed to decide on compensation
recommended 

\begin{quotation}
\ldots around \$300,000 in damages, equivalent to around \$30
million today, with about \$6,000 going to the families of those
killed, \$25,000 to the City of Boston, and \$42,000 to the Boston
Elevated Railway Company.
\end{quotation}


\begin{enumerate}
\item How long was the wave?

\item
Estimate the number of blocks that could be covered two to three feet
deep.

\item
Is Lyons's inflation calculation correct?

\item
Estimate the number of families that lost loved ones.
How much would each receive, in today's dollars? How does that amount
compare to damage awards in similar cases today?
\end{enumerate}

In this short document, the index should include the line


molasses, cover, 1

A hack solution is fine since this only happens once.


\printindex

\end{document}

答案1

如果你查看你的文件filename.ilg,你会发现错误消息:

!! Input index error (file = 274651.idx, line = 2):
   -- Illegal Roman number: position 2 in cover.

这给了你关于这个问题的提示:显然,\indexentry总是期望一个数字,或者最多一个罗马数字。

您可以使用以下解决方法:该包makeidx提供了以特定样式设置页码的命令。例如,\index{molasses|textbf}将以粗体打印相应的页码。因此,让我们定义一种新的“样式”(即带有单个参数的命令,该参数格式化该参数):

\newcommand{\coverpage}[1]{cover}

然后以下行在索引中添加所需的条目:

\index{molasses|coverpage}

相关内容