抱歉如果我暗示 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.
机器翻译自 English