I would like to include \allowbreak
in an \index
entry but I can't get it to work. The \allowbreak
is changed to \penalty \z@
in the .idx file, which corrupts the generated index.
How can I solve this?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI would like to include \allowbreak
in an \index
entry but I can't get it to work. The \allowbreak
is changed to \penalty \z@
in the .idx file, which corrupts the generated index.
How can I solve this?
You are probably calling \index
in the argument to another command; here's an emulation:
\documentclass{article}
\usepackage{makeidx}
\makeindex
\begin{document}
a\index{abcdef@abc\allowbreak def}
% now do the call in the argument of a command
\textbf{g\index{ghijkl@ghi\allowbreak jkl}}
% now use the proper input
\textbf{m\index{mnopqr@mno\protect\allowbreak pqr}}
\printindex
\end{document}
This produces the following .idx
file
\indexentry{abcdef@abc\allowbreak def}{1}
\indexentry{ghijkl@ghi\penalty \z@ jkl}{1}
\indexentry{mnopqr@mno\allowbreak pqr}{1}
The same problem with \allowbreak
turned into \penalty \z@
would happen if you have something like
\newcommand{\indexword}[1]{#1\index{#1}}
and do
\indexword{abc\allowbreak def}
Using \protect\allowbreak
will do also in this case. However, sorting of index entries with \allowbreak
in them will probably give wrong results.
\protect\allowbreak
? – egreg Jul 28 '15 at 21:02