Indexing – How to Selectively Remove the Comma in an Index Entry in LaTeX

idxlayoutindexingmakeindexpdftex

In an index, I would like to be able to remove the comma that immediately precedes the page number for certain entries only.

Consider the MWE

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

\begin{document}
\Large
    
Some words.\index{HEADING@\textbf{HEADING}!01@\textbf{\color{red}{\textit{So entfernen Sie das Komma?---}}}}\index{HEADING@\textbf{HEADING}!02@\textbf{\color{red}{\textit{But I want the comma to remain here.}}}}
    
\idxlayout{columns=1}
\printindex
\end{document}

which produces the output

enter image description here

QUESTION: How may I remove the comma following Komma?— in the first entry, while retaining the comma in the second entry?

Thank you.

Best Answer

Just uses a macro that discards it:

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex
\usepackage{idxlayout}
\usepackage{xcolor}

\newcommand\textbfnocomma[2]{\textbf{#1}}
\begin{document}
\Large
    
Some words.\index{HEADING@\textbf{HEADING}!01@\textbfnocomma{\color{red}{\textit{So entfernen Sie das Komma?---}}}}\index{HEADING@\textbf{HEADING}!02@\textbf{\color{red}{\textit{But I want the comma to remain here.}}}}
    
\idxlayout{columns=1}
\printindex
\end{document}

enter image description here

Related Question