Извините, если я дал понять, что с litl есть какая-то магия… На самом деле важно было, чтобы фрагменты, которые нужно сместить, имели собственную разметку (но тогда вы меняете хук, чтобы он находился перед соответствующим маркером).
Теперь, то, что \hfill (и \leaders) отбрасывается при переносе строки, — это очень полезная функция, а не ошибка — это предотвращает появление пробела в начале/конце перенесенной строки. Нет необходимости рассматривать такие случаи как исключения, нам просто нужно «научить» TeX…
Однако вопрос, на который нужно ответить, — это то, что бы вы хотели видеть?
- Никогда не переносить строку перед числом (даже если результат будет ужасным): измените конец sethook на:
litl}{\penalty10000\hfill}
- Полностью пустая строка / строка из точек перед числом:
litl}{\unskip\penalty500\hbox{}\penalty10000\hfill}
В обоих этих случаях, если вы используете \leaders, поместите дополнительный фрагмент перед ним.
Пояснение:
То, что они делают, — это дает алгоритму переноса строк дополнительные инструкции.
Я также добавил \unskip, который удаляет предшествующий пробел, если он есть — это более полезно для кода на основе \leaders и предотвращает появление пробела между точками и предшествующим словом.
\penalty 500 означает, что строку можно перенести там, но это далеко от идеала. А \hbox{} — это просто объект нулевой ширины, который нельзя отбросить. \penalty10000 говорит, что стоимость переноса строки здесь «бесконечна». Таким образом, в обоих этих версиях TeX не имеет права переносить строку в (сразу перед) заполнителем, и поэтому он не может быть отброшен обычным процессом.
Sorry if I implied there was something magic with litl… what was really important was that the bits that needed to be offset needed to have their own markup (but then you change the hook to be before whatever the relevant marker is.
Now, \hfill (and \leaders) getting discarded if there’s a line-break is a very useful feature, not a bug - it stops there being a space at the start/end of a broken line. There’s no need to treat things as exceptions, we just need to educate TeX…
The question that needs to be answered, though, is what would you like to happen?
- Never ever break the line before the number (even if the result is horrible): change the end of the sethook to be:
litl}{\penalty10000\hfill}
- A whole blank line / line of dots before the number:
litl}{\unskip\penalty500\hbox{}\penalty10000\hfill}
In both of these, if you are using the \leaders, put the extra bit in front of that instead.
Explanation:
What these are doing is giving the line-breaking algorithm some extra instructions.
I’ve also added \unskip which removes a preceding space if there is one - that’s more useful for the \leaders-based code, and stops there being a space between the dots and the preceding word.
The \penalty 500 means the line can be broken there, but it’s a long way from ideal. and \hbox{} is just a zero-width thing that it can’t discard. \penalty10000 says the cost of breaking the line here is ‘infinite’. Thus for both of these versions, TeX is not allowed to break the line at (just before) the fill, and thus it cannot be discarded by the normal process.