Indexing – How to Make Index Recognize an Exclamation Point as Part of an Entry

grammarimakeidxindexingmakeindexsyntax

I would like to add an entry in an index which makes use of an exclamation point as an article of grammar. However (of course), Latex treats it as if I want to begin a subentry.

Consider the following code.

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

\begin{document}
\LARGE
A sentence.\index{Heading@\textbf{Heading}!How to put an exclamation point at the end of this statement!}
\idxlayout{columns=1}
\printindex
\end{document}
 

with the output

enter image description here

I have tried enclosing the exclamation point with $$ but that only yields an error.

QUESTION How may the above code be modified so that, for instance, "How to put an exclamation point at the end of this statement!" will appear as an entry in the index with the exclamation point appended at the end?

Thank you.

Best Answer

You can quote the ! as "!

or you can change makeindex's special characters all of which may be set in a makeindex style. for example the gind.ist that comes with the LaTeX base doc package has

actual '='
quote '!'
level '>'

so that actual is = not @ (as there are lots of @ in command names) and quote is ! rather than " again as " is rather more common in code.

The full set is

enter image description here

from makeindex/ind.pdf

texdoc ind.pdf

(texdoc -l makeindex then select 2 as the default makeindex.pdf isn't so informative)

So here you want

enter image description here

so a one line mlc.ist file:

level '>'

So that ! becomes a normal character and > becomes the index level separator.

If calling makeindex directly you would need makeindex -s mlc.ist but as you are using imakeidx specify the option to \makeindex:

\documentclass{book}
\usepackage{imakeidx}
\let\cleardoublepage\clearpage
\makeindex[options=-s mlc.ist]
\usepackage{idxlayout}

\begin{document}
\LARGE
A sentence.\index{Heading@\textbf{Heading}>How to put an exclamation point at the end of this statement!}
\idxlayout{columns=1}
\printindex
\end{document}
Related Question