0

I would ask if it is possible to set a global option to prevent line break before a specific character, in my case – (especially in the index).

In my index formatted in a single paragraph I use – as a delimiter and it is often printed at the beginning of the line.

I refer to the index as defined in the answer to this question: idxlayout customized delimiters.

Here is an 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}

I think that it muset be changed here:

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

and here:

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

Thank you!

qwertxyz
  • 542
  • 1
    It would be much easier to understand what you are asking if you could add an example. A shot in the dark -- is that character typed after a space? In that case, would preceding it by ~ (unbreakable space) be feasible? – barbara beeton Apr 08 '20 at 20:33
  • Thank you for your answer. You could see my previous question, where I added an MWE: https://tex.stackexchange.com/questions/477447/idxlayout-customized-delimiters. The problem is that often it prints the delimiter (–) at the beginning of the line – qwertxyz Apr 08 '20 at 21:49
  • Oh, this is in an index. I spaced through that important detail. Obviously my suggestion wouldn't work. If there is an .ist file involved, that's where I would look, but I'm not sufficiently experienced in that to be much help. If you put that information, at least the link to the earlier question, in the question itself, someone else can pick it up. – barbara beeton Apr 08 '20 at 22:29
  • you are putting a space before it \newcommand*{\indexsubsdelimb}{ — } use a non break space \newcommand*{\indexsubsdelimb}{~— } – David Carlisle Apr 08 '20 at 23:03
  • 2
    but you should at the very least put a link to your previous question into this, you can not expect people to know you asked a question previously with a relevant example. – David Carlisle Apr 08 '20 at 23:04
  • Thank you, I added the link. I don't use any more \newcommand{\indexsubsdelimb}{ — } and I think that it must edited this line: \newcommand{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else --- \fi} – qwertxyz Apr 09 '20 at 09:16
  • @DavidCarlisle I tried your solution in this way \newcommand*{\indexsubsdelimb}{\iffirstsubsubitem\unskip\firstsubsubitemfalse\ \else~--- \fi} but it doesn't work – qwertxyz Apr 09 '20 at 09:23
  • @DavidCarlisle I had another question related to the customization of my index, where I inserted the same MWE: https://tex.stackexchange.com/questions/536929/customized-style-of-index-with-idxlayout-package-and-abshang-option. – qwertxyz Apr 09 '20 at 12:33

0 Answers0