我的目标是找出子子项之间是否有分页符,如果是,则重复该项目和子项目。具体来说,我试图让我的一个makeindx
索引的主条目和子条目在我正在发布的书中的每个新偶数页的顶部重复。我曾尝试使用repeatindex
为此设计的 -package,但它已经过时了,现在产生了太多问题。
我的问题是:
- 如何检测索引中的子条目之间或子子条目之间的分页符;
- 一旦检测到,如何在新页面的顶部重复主条目和子条目,或者如果分页符发生在子条目之间而不是子子条目之间,则仅重复主条目;
- 如何选择仅对偶数页执行此操作,并且仅在几个 imakeidx 索引之一中执行此操作。
梅威瑟:
\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\usepackage[splitindex]{imakeidx}
\makeindex[options= -s index_style2.ist, intoc,name=A,title=\mbox{Appendix A},columns=1]
\makeatletter
\newcommand{\Dotfill}{\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern \z@}
\makeatother
\newcommand{\testing}{Testing, \emph{testing}, one, two, three, three, four (\emph{1, 2, 3, 4})}
\begin{document}
\frontmatter
\mainmatter
\chapter{The First Chapter}
I could place some placeholder text here, but you get the idea.
\index[A]{\testing!1@One!A}\index[A]{\testing!1@One!B}\index[A]{\testing!1@One!C}\index[A]{\testing!1@One!D}\index[A]{\testing!1@One!E}\index[A]{\testing!1@One!F}\index[A]{\testing!1@One!G}\index[A]{\testing!1@One!H}\index[A]{\testing!1@One!I}\index[A]{\testing!1@One!J}\index[A]{\testing!1@One!K}\index[A]{\testing!1@One!L}\index[A]{\testing!1@One!M}\index[A]{\testing!1@One!N}\index[A]{\testing!1@One!O}\index[A]{\testing!1@One!P}\index[A]{\testing!1@One!Q}\index[A]{\testing!1@One!R}\index[A]{\testing!1@One!S}\index[A]{\testing!1@One!T}\index[A]{\testing!1@One!U}\index[A]{\testing!1@One!V}\index[A]{\testing!1@One!X}\index[A]{\testing!1@One!Y}\index[A]{\testing!1@One!Z}\index[A]{\testing!2@Two!A}\index[A]{\testing!2@Two!B}\index[A]{\testing!2@Two!C}\index[A]{\testing!2@Two!D}\index[A]{\testing!2@Two!E}\index[A]{\testing!2@Two!F}\index[A]{\testing!2@Two!G}\index[A]{\testing!2@Two!H}\index[A]{\testing!2@Two!I}\index[A]{\testing!2@Two!J}\index[A]{\testing!2@Two!K}\index[A]{\testing!2@Two!L}\index[A]{\testing!2@Two!M}\index[A]{\testing!2@Two!N}\index[A]{\testing!2@Two!O}\index[A]{\testing!2@Two!P}\index[A]{\testing!2@Two!Q}\index[A]{\testing!2@Two!R}\index[A]{\testing!2@Two!S}\index[A]{\testing!2@Two!T}\index[A]{\testing!2@Two!U}\index[A]{\testing!2@Two!V}\index[A]{\testing!2@Two!X}\index[A]{\testing!2@Two!Y}\index[A]{\testing!2@Two!Z}\index[A]{\testing!3@Three!A}\index[A]{\testing!3@Three!B}\index[A]{\testing!3@Three!C}\index[A]{\testing!3@Three!D}\index[A]{\testing!3@Three!E}\index[A]{\testing!3@Three!F}\index[A]{\testing!3@Three!G}\index[A]{\testing!3@Three!H}\index[A]{\testing!3@Three!I}\index[A]{\testing!3@Three!J}\index[A]{\testing!3@Three!K}\index[A]{\testing!3@Three!L}\index[A]{\testing!3@Three!M}\index[A]{\testing!3@Three!N}\index[A]{\testing!3@Three!O}\index[A]{\testing!3@Three!P}\index[A]{\testing!3@Three!Q}\index[A]{\testing!3@Three!R}\index[A]{\testing!3@Three!S}\index[A]{\testing!3@Three!T}\index[A]{\testing!3@Three!U}\index[A]{\testing!3@Three!V}\index[A]{\testing!3@Three!X}\index[A]{\testing!3@Three!Y}\index[A]{\testing!3@Three!Z} \index[A]{\testing!4@Four!A}\index[A]{\testing!4@Four!B}\index[A]{\testing!4@Four!C}\index[A]{\testing!4@Four!D}\index[A]{\testing!4@Four!E}\index[A]{\testing!4@Four!F}\index[A]{\testing!4@Four!G}\index[A]{\testing!4@Four!H}\index[A]{\testing!4@Four!I}\index[A]{\testing!4@Four!J}\index[A]{\testing!4@Four!K}\index[A]{\testing!4@Four!L}\index[A]{\testing!4@Four!M}\index[A]{\testing!4@Four!N}\index[A]{\testing!4@Four!O}\index[A]{\testing!4@Four!P}\index[A]{\testing!4@Four!Q}\index[A]{\testing!4@Four!R}\index[A]{\testing!4@Four!S}\index[A]{\testing!4@Four!T}\index[A]{\testing!4@Four!U}\index[A]{\testing!4@Four!V}\index[A]{\testing!4@Four!X}\index[A]{\testing!4@Four!Y}\index[A]{\testing!4@Four!Z}
\backmatter
\indexprologue{\small Description of Appendix A goes here. And I'm making this description slightly longer, so that the page break between pages three and four actually occurs in the middle of several subsubentries.}
\printindex[A]
\end{document}
该index_style2.ist
文件包含:
delim_0 "] \\Dotfill "
delim_1 " \\Dotfill "
delim_2 " \\Dotfill "
答案1
据我所知,从 tex 源的“视角”确定断点是(不容易?)不可能的。这与 TeX 的异步输出例程有关,它以块为单位(通常是段落)“读取”文本,然后“决定”将块的哪些部分放在哪个页面上。换句话说,您无法挂接到(子)子条目宏的定义中来“询问”它们是放在分页符上还是分页符之后,因为当 TeX 解析并完全展开这些宏时,它还不知道这些宏的完全展开内容将放在哪里。
然而,有办法可以挂钩分页符本身。
一种方法是使用阿特别格什包和\AtBeginShipout{\ifodd\thepage\testing\fi}
之前的宏\printindex[A]
。
不使用外部包的另一种方法是通过页面样式(绘制页眉和页脚)。
为此,我们创建了一个名为 的新页面样式index
。页面样式是用 -前缀定义的ps@
,所以我们需要\makeatletter
。由于我们只想更改偶数页的页眉,我们将文档类提供的任何内容加载为默认页面样式,以便奇数页和所有页脚保持原样。之后,我们只重新定义在偶数页上打印页眉的宏。在其中,我们将\testing
-宏的内容放在第一行的高度。我们新页面样式的完整定义是:
\makeatletter
\def\ps@index{%
%% load original page style:
\ps@headings
%% redefine the style of head on even pages:
\renewcommand*{\@evenhead}{%
%% this part is from the original definition
%% (taken from scrbook.cls)
\set@tempdima@hw\hss\hb@xt@ \@tempdima{\vtop{%
\hb@xt@ \@tempdima{{\headfont\strut\leftmark\hfil}}%
\if@hsl \vskip 1.5\p@ \hrule \fi
%% this is the new part.
%% go back to the left egde of the type area:
\par
%% go down to the first line of the type area:
\vskip\dimexpr\headsep+\dp\strutbox\relax
%% print the \testing macro without stretching the header itself:
\smash{\rlap{\hb@xt@\hsize{\testing\hss}}}%
}% /vbox
}% /hbox
}% /@evenhead
}
\makeatother
对于打印的索引,我们需要切换到新的页面样式。这可以通过\pagestyle{}
宏来完成,该宏获取新样式的名称(不带ps@
-prefix)作为参数。
\pagestyle{index}
最后,我们需要为重复行留出空间。我们通过将\topskip
页面类型区域上第一行的高度值扩展为主文本字体的行高来实现此目的:
\advance\topskip\baselineskip
这有几个缺点:首先,每页上的索引都比其他文本低一行,尽管重复行只在偶数页上添加。如果索引的主体(即没有“标题行”的条目)调整到相同的高度,我发现排版会更令人满意。
其次,如果重复文本变得更加复杂,您可能需要在不同点调整值,一次在定义中\@evenhead
,第二次在行中\advance\topskip
。
完整代码如下:
\documentclass[10pt, paper=156mm:235mm, BCOR=12mm, headings=optiontotocandhead, headings=openany]{scrbook}
\usepackage[splitindex]{imakeidx}
\makeindex[options= -s index_style2.ist, intoc,name=A,title=\mbox{Appendix A},columns=1]
\makeatletter
\newcommand{\Dotfill}{\leavevmode \leaders \hb@xt@ 0.75em{\hss .\hss }\hfill \kern \z@}
\makeatother
\newcommand{\testing}{Testing, \emph{testing}, one, two, three, three, four (\emph{1, 2, 3, 4})}
\makeatletter
\def\ps@index{%
\ps@headings
\let\old@evenhead\@evenhead%
\renewcommand*{\@evenhead}{%
\set@tempdima@hw\hss\hb@xt@ \@tempdima{\vtop{%
\hb@xt@ \@tempdima{{\headfont\strut\leftmark\hfil}}%
\if@hsl \vskip 1.5\p@ \hrule \fi
\par
\vskip\dimexpr\headsep+\dp\strutbox\relax
\smash{\rlap{\hb@xt@\hsize{\testing\hss}}}%
}% /vbox
}% /hbox
}% /@evenhead
}
\makeatother
\begin{document}
\frontmatter
\mainmatter
\chapter{The First Chapter}
I could place some placeholder text here, but you get the idea.
\index[A]{\testing!1@One!A}\index[A]{\testing!1@One!B}\index[A]{\testing!1@One!C}\index[A]{\testing!1@One!D}\index[A]{\testing!1@One!E}\index[A]{\testing!1@One!F}\index[A]{\testing!1@One!G}\index[A]{\testing!1@One!H}\index[A]{\testing!1@One!I}\index[A]{\testing!1@One!J}\index[A]{\testing!1@One!K}\index[A]{\testing!1@One!L}\index[A]{\testing!1@One!M}\index[A]{\testing!1@One!N}\index[A]{\testing!1@One!O}\index[A]{\testing!1@One!P}\index[A]{\testing!1@One!Q}\index[A]{\testing!1@One!R}\index[A]{\testing!1@One!S}\index[A]{\testing!1@One!T}\index[A]{\testing!1@One!U}\index[A]{\testing!1@One!V}\index[A]{\testing!1@One!X}\index[A]{\testing!1@One!Y}\index[A]{\testing!1@One!Z}\index[A]{\testing!2@Two!A}\index[A]{\testing!2@Two!B}\index[A]{\testing!2@Two!C}\index[A]{\testing!2@Two!D}\index[A]{\testing!2@Two!E}\index[A]{\testing!2@Two!F}\index[A]{\testing!2@Two!G}\index[A]{\testing!2@Two!H}\index[A]{\testing!2@Two!I}\index[A]{\testing!2@Two!J}\index[A]{\testing!2@Two!K}\index[A]{\testing!2@Two!L}\index[A]{\testing!2@Two!M}\index[A]{\testing!2@Two!N}\index[A]{\testing!2@Two!O}\index[A]{\testing!2@Two!P}\index[A]{\testing!2@Two!Q}\index[A]{\testing!2@Two!R}\index[A]{\testing!2@Two!S}\index[A]{\testing!2@Two!T}\index[A]{\testing!2@Two!U}\index[A]{\testing!2@Two!V}\index[A]{\testing!2@Two!X}\index[A]{\testing!2@Two!Y}\index[A]{\testing!2@Two!Z}\index[A]{\testing!3@Three!A}\index[A]{\testing!3@Three!B}\index[A]{\testing!3@Three!C}\index[A]{\testing!3@Three!D}\index[A]{\testing!3@Three!E}\index[A]{\testing!3@Three!F}\index[A]{\testing!3@Three!G}\index[A]{\testing!3@Three!H}\index[A]{\testing!3@Three!I}\index[A]{\testing!3@Three!J}\index[A]{\testing!3@Three!K}\index[A]{\testing!3@Three!L}\index[A]{\testing!3@Three!M}\index[A]{\testing!3@Three!N}\index[A]{\testing!3@Three!O}\index[A]{\testing!3@Three!P}\index[A]{\testing!3@Three!Q}\index[A]{\testing!3@Three!R}\index[A]{\testing!3@Three!S}\index[A]{\testing!3@Three!T}\index[A]{\testing!3@Three!U}\index[A]{\testing!3@Three!V}\index[A]{\testing!3@Three!X}\index[A]{\testing!3@Three!Y}\index[A]{\testing!3@Three!Z} \index[A]{\testing!4@Four!A}\index[A]{\testing!4@Four!B}\index[A]{\testing!4@Four!C}\index[A]{\testing!4@Four!D}\index[A]{\testing!4@Four!E}\index[A]{\testing!4@Four!F}\index[A]{\testing!4@Four!G}\index[A]{\testing!4@Four!H}\index[A]{\testing!4@Four!I}\index[A]{\testing!4@Four!J}\index[A]{\testing!4@Four!K}\index[A]{\testing!4@Four!L}\index[A]{\testing!4@Four!M}\index[A]{\testing!4@Four!N}\index[A]{\testing!4@Four!O}\index[A]{\testing!4@Four!P}\index[A]{\testing!4@Four!Q}\index[A]{\testing!4@Four!R}\index[A]{\testing!4@Four!S}\index[A]{\testing!4@Four!T}\index[A]{\testing!4@Four!U}\index[A]{\testing!4@Four!V}\index[A]{\testing!4@Four!X}\index[A]{\testing!4@Four!Y}\index[A]{\testing!4@Four!Z}
\backmatter
\pagestyle{index}
\advance\topskip\baselineskip
\indexprologue{\small Description of Appendix A goes here. And I'm making this description slightly longer, so that the page break between pages three and four actually occurs in the middle of several subsubentries.}
\printindex[A]
\end{document}
输出结果如下: