考虑MWE:
\begin{filecontents*}{style.ist}
delim_t "."
\end{filecontents*}
\documentclass[12pt]{article}
\usepackage{imakeidx}
%\makeindex
\makeindex[options=-s style.ist]
\newcommand\pagedot[1]{#1.} % Adds a period to a particular entry.
\usepackage[itemlayout=singlepar]{idxlayout}
\begin{document}
This is a sentence.\index{Index entry}
This is another sentence.\index{Yet another index entry}
\newpage
This is another sentence.\index{Yet another index entry!subentry}
\idxlayout{columns=1}
\printindex
\end{document}
这将产生索引输出:
由于索引条目以段落形式显示,因此我希望每个条目的最后一页在页码后面有一个句点。(因此,在这种情况下,例如,“又一个索引条目,1.;”将显示为“又一个索引条目,1;”)
为了实现这一点,如何修改上述代码?
谢谢。
答案1
定义一个新命令\checknextchar
来测试页码后面是否跟subitem
或subsubitem
,如果不是,则添加句点。然后将\\checknextchar
其用作delim_t
\begin{filecontents*}[overwrite]{style.ist}
delim_t "\\checknextchar"
\end{filecontents*}
\documentclass[12pt]{article}
\newcommand{\checknextchar}[1]{%
\ifx\subitem#1\subitem\else\ifx\subsubitem#1\subsubitem\else.\fi\fi%
}
\usepackage{imakeidx}
\makeindex[options=-s style.ist]
\newcommand\pagedot[1]{#1.} % Adds a period to a particular entry.
\usepackage[itemlayout=singlepar]{idxlayout}
\begin{document}
This is a sentence.\index{Index entry}
This is another sentence.\index{Yet another index entry}
This is another sentence.\index{this is another index entry}
\newpage
This is another sentence.\index{this is another index entry!subentry}
This is another sentence.\index{Yet another index entry!subentry}
\newpage
This is another sentence.\index{Yet another index entry!subentry!subsubentry}
\idxlayout{columns=1}
\printindex
\end{document}