
これは、各索引項目の最後のページ番号の後にピリオドを自動的に追加する
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}
これにより、インデックス出力が生成されます。
索引エントリは段落形式で表示されるため、各エントリの最後のページ番号のみに、ページ番号の後にピリオドを付けたいと思います。(この場合、たとえば、「Yet another index entry, 1.;」は、「Yet another index entry, 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}