防止在特定字符前换行

防止在特定字符前换行

我想问是否可以设置一个全局选项来防止在特定字符之前换行,就我而言 - (特别是在索引中)。

在我的单段落格式化索引中,我使用 - 作为分隔符,并且它通常打印在行的开头。

我参考了该问题的答案中定义的索引:idxlayout 自定义分隔符

以下是 MWE:

\documentclass{article}

\usepackage{fontspec}
\setmainfont{times.ttf}
\usepackage{imakeidx}
\usepackage{polyglossia}

\begin{filecontents*}{colon.ist}
delim_0 ": "
delim_1 ": "
delim_2 ": "
\end{filecontents*}



\usepackage[itemlayout=singlepar]{idxlayout}

\makeatletter
\def\@idxitem{\par\addvspace{5\p@ \@plus 5\p@ \@minus 3\p@}\hangindent 40\p@}
\def\subitem{\par\hangindent 40\p@ \hspace*{20\p@}}
\def\subsubitem{\par\hangindent 40\p@ \hspace*{30\p@}}
\def\indexspace{}
\patchcmd\theindex{\indexname}{\indexname\vspace{12pt}}{}{}
\makeatother

\makeatletter
\newif\iffirstsubitem
\newif\iffirstsubsubitem
\renewcommand{\indexsubsdelim}{ }
\newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi}
\renewcommand{\subitem}{\iffirstsubitem\unskip\firstsubitemfalse, \else --- \fi\firstsubsubitemtrue}%
\renewcommand{\subsubitem}{\indexsubsdelimb}%
\renewcommand{\@idxitem}{\par\setlength{\hangindent}{\ila@hangindent}\firstsubitemtrue}
\makeatother

\makeindex[options=-s colon]

\begin{document}


test

\index{Author!Work1!1,11} 
\index{Author!Work1!9,31}
\index{Author!Work2!2,21} 
\index{Author!Work2!5,12}
\index{Author!Work1!1,11} 
\index{Author!Work1!9,34}
\index{Author!Work2!2,22} 
\index{Author!Work2!5,15}
\index{Author!Work1!1,17} 
\index{Author!Work1!9,38}
\index{Author!Work2!2,27} 
\index{Author!Work2!5,14}

\index{Author2!2,45} 
\index{Author2!4,34}
\index{Author2!6,12} 
\index{Author2!9,4}
\index{Author2!2,41} 
\index{Author2!4,32}
\index{Author2!6,13} 
\index{Author2!9,5}
\index{Author2!2,46} 
\index{Author2!4,37}
\index{Author2!6,18} 
\index{Author2!9,9}


\printindex

\end{document}

我认为这里必须改变:

\newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi}

和这里:

\newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi}

谢谢你!

相关内容