\allowbreak 在 \index 中不起作用

\allowbreak 在 \index 中不起作用

我想包含\allowbreak在一個\index條目中,但我無法讓它工作。.idx 檔案中的 被更改為,這會損壞生成的索引\allowbreak\penalty \z@

我該如何解決這個問題?

答案1

您可能正在\index呼叫另一個命令的參數;這是一個仿真:

\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}

這會產生以下.idx文件

\indexentry{abcdef@abc\allowbreak def}{1}
\indexentry{ghijkl@ghi\penalty \z@ jkl}{1}
\indexentry{mnopqr@mno\allowbreak pqr}{1}

如果你有類似的東西,也會發生\allowbreak同樣的問題\penalty \z@

\newcommand{\indexword}[1]{#1\index{#1}}

並做

\indexword{abc\allowbreak def}

在這種情況下使用\protect\allowbreak也可以。但是,對其中的索引條目進行排序\allowbreak可能會給出錯誤的結果。

相關內容