pdftex – How to Universally Remove Commas from Each Index Entry in LaTeX

idxlayoutimakeidxindexingmakeindexpdftex

This question extends the one recently posed in How to Selectively Remove the Comma in an Index Entry

In the above post, it was answered that by inserting \newcommand\textbfnocomma[2]{\textbf{#1}} into the preamble, an index entry comma can be removed with the command \textbfnocomma.

I am presently working on producing an index of quotations where the said comma seems to be a little out of place; and so, I would like to see what the index looks like with all such commas removed.

Consider the code,

\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{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!03@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!04@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!05@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!06@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
    
\idxlayout{columns=1}
\printindex
\end{document}

which produces the Index:

enter image description here

QUESTION: Is it possible, and if so, how may I easily remove the comma from all index entries without resorting to removing them all individually with the preamble command described above? No textindy please.

Thank you.

Best Answer

You need to adjust the delim_1 field of makeindex, since the page numbers you list is at level 1. From makeindex.hlp:

 delim_0          ", "
                          Delimiter to be inserted between  a
                          level  0  key  and  its  first page
                          number (default: comma followed  by
                          a blank).

 delim_1          ", "
                          Delimiter to be inserted between  a
                          level  1  key  and  its  first page
                          number (default: comma followed  by
                          a blank).

 delim_2          ", "
                          Delimiter to be inserted between  a
                          level  2  key  and  its  first page
                          number (default: comma followed  by
                          a blank).

 delim_n          ", "
                          Delimiter to  be  inserted  between
                          two  page  numbers for the same key
                          in any level (default:  comma  fol-
                          lowed by a blank).

 delim_r          "--"
                          Delimiter to  be  inserted  between
                          the   starting   and   ending  page
                          numbers of a range.

 delim_t          ""
                          Delimiter to be inserted at the end
                          of a page list.  This delimiter has
                          no effect on entries which have  no
                          associated page list.

In short, include/change the following in your preamble:

\begin{filecontents*}[overwrite]{\jobname.ist}
delim_1 " "
\end{filecontents*}

\makeindex[options=-s \jobname.ist]

The above code writes a file \jobname.ist - a makeindex style file - and changes the default value of delim_1 to " " - a regular space (from ", "). Then, to use this newly-created style file, pass the option -s \jobname.ist to your call to \makeindex. If you have page numbers at multiple levels, just add delim_0, delim_2, ... to the .ist.

enter image description here

\documentclass{book}

\begin{filecontents*}[overwrite]{\jobname.ist}
delim_1 " "
\end{filecontents*}

\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex[options=-s \jobname.ist]
\usepackage{idxlayout}
\usepackage{xcolor}

\begin{document}
\large
    
Some words.
\index{HEADING@\textbf{HEADING}!02@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!03@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!04@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!05@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
\index{HEADING@\textbf{HEADING}!06@\textbf{\color{red}{\textit{How to universally remove the comma?}}}}
    
\idxlayout{columns=1}
\printindex

\end{document}
Related Question