
Dies ist eine Fortsetzung vonIn jedem Indexeintrag automatisch einen Punkt nach der letzten Seitenzahl hinzufügen
Betrachten Sie das 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}
Dadurch wird die Indexausgabe erzeugt:
Da die Indexeinträge in Absatzform angezeigt werden, möchte ich, dass nur auf die letzte Seitenzahl jedes Eintrags ein Punkt folgt. (In diesem Fall würde also beispielsweise „Noch ein weiterer Indexeintrag, 1.;“ als „Noch ein weiterer Indexeintrag, 1;“ angezeigt.)
Wie kann der obige Code geändert werden, um dies zu erreichen?
Danke schön.
Antwort1
Definieren Sie einen neuen Befehl \checknextchar
, um zu testen, ob auf die Seitennummer subitem
oder folgt subsubitem
. Wenn nicht, fügen Sie einen Punkt hinzu. Verwenden Sie dann \\checknextchar
als Schlüsselwert fürdelim_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}