Idxlayout段落表單---為某些頁碼新增句點

Idxlayout段落表單---為某些頁碼新增句點

這是後續在每個索引條目的最後頁碼後自動新增句點

考慮 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來測試頁碼是否後面接著subitemsubsubitem,如果沒有則加入句點。然後用作\\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}

在此輸入影像描述

相關內容