抱歉,如果我暗示 litl 有什麼神奇之處…… 真正重要的是,需要偏移的部分必須有自己的標記(然後您只需將 hook 更改為位於相關標記之前)。
現在,如果發生換行,\hfill(以及 \leaders)被丟棄是一個非常有用的功能,而不是錯誤 - 它防止在換行處的開頭/結尾出現空白。我們不需要將這些情況視為例外,我們只需要教育 TeX……
然而,需要回答的問題是,您希望發生什麼情況?
- 絕對不要在數字前換行(即使結果很糟糕):將 sethook 的結尾更改為:
litl}{\penalty10000\hfill}
- 在數字前留出一整行空白 / 一排點:
litl}{\unskip\penalty500\hbox{}\penalty10000\hfill}
在這些兩種情況中,如果您使用的是 \leaders,請將額外部分放在其前面。
說明:
這些指令的作用是給換行演算法一些額外指示。
我也加入了 \unskip,如果前面有空格則將其移除 - 這對於基於 \leaders 的程式碼更有用,並防止點與前面的單詞之間出現空格。
\penalty 500 表示可以在那裡換行,但離理想狀態還很遠。而 \hbox{} 只是一個零寬度的物件,它無法被丟棄。\penalty10000 表示在此處換行的成本是「無限」的。因此,對於這兩個版本,TeX 不允許在 fill(填充)處(或緊接其前)換行,因此它無法被常規過程丟棄。
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