这可能会很长。
首先,TeX 如何断行是《TeXbook》中整整一章的内容。基本上有一个 \tolerance(设置为 9000,这非常宽松。PlainTeX 将其设置为 200),它决定了特定的段落断行方式是否会被考虑。因此,如果将段落减少一行使得 badness(坏度)> 9000,那么无论你要求多少,它都不会减少段落。增加段落也是如此。TeX 的自然段落长度被选择以最小化 badness。因此,减少或增加段落会使其变差,但这与更好的页面布局相平衡。鉴于 TeX 会最小化段落的 badness,较大的 tolerance 并不坏。它只是说我们真的不希望出现 overfull 或 underfull 行,谢谢。
根据我们的经验,TeX 很少允许段落减少。拥有更多可收缩的空间会有帮助(空格的最小收缩默认值为 66%,因此 95% 实际上使其更不可收缩)。同样,最大拉伸的默认值是 150%,因此 140% 使其更不可拉伸。添加字间距不太可能对断行产生多大影响。它可能会,但实际上它所做的只是吸收一些额外的拉伸,使空格看起来不那么难看。顺便说一句,如果 TeX 断行非常非常糟糕,无论你如何限制最大拉伸,TeX 都会按比例拉伸所有内容以填满该行,超出任何最大值。
这部分是数学的:9000 的 tolerance 需要除以行数以获得平均值。假设段落中有 10 行,因此我们得到每行平均 900 的 badness。TeX 计算 badness 为 100x(实际收缩或拉伸 / 最大收缩或拉伸)^3。这意味着它允许一行平均收缩或拉伸最多为该行总和的 2 倍。因此,它可能会将空格减少到其最小值的一半,或拉伸到其最大值的两倍。显然,这是最坏的情况,TeX 总是选择看起来最好的段落。所以不要担心一切都会比你指定的看起来差得多。在实践中,效果看起来真的很好,通过明智地选择要拉伸的段落,可以以一种未经训练的眼睛不明显的方式修复问题。
为什么 TeX 不能很好地收缩段落?因为通常一行中空格的最大收缩不足以将整整一个单词拉上来,更不用说 2 或 3 个单词了。这取决于你是否愿意让你的最小空格低至空格的 40%,这真的不多。
对于没有单词空格的文字,关键是通过大量插入 ZWSP 字符,为 TeX 提供许多断行位置。
现在关于逐段更改。是的,我们可以逐段更改 glue 的值,但我不知道我们如何为此提供 UI。你想做所有这些工作吗?也许更有帮助的方式是创建一个工具,测量所有可能的段落收缩和拉伸,并让你知道实际发生的值范围。无论如何,我们对改进调整列表周围的整个 UI 有一些想法。
顺便说一句,这里有一个技巧。你总是可以增加标题样式的行数,因为它们不是两端对齐的,所以 TeX 会很乐意使这些行越来越短,以便在段落中有更多行。但它们在页面上也非常显眼。
你确实问了!!
This could get long.
First, how TeX breaks paragraphs is a whole chapter in the TeXbook. Basically there is a \tolerance (set to 9000 which is very generous. PlainTeX sets it to 200) that governs whether a particular way of breaking the paragraph is going to be considered. So if reducing the paragraph by a line makes the badness > 9000 it won’t reduce the paragraph however much you ask it. Likewise for increasing the paragraph. TeX’s natural paragraph length is chosen to minimise the badness. So reducing or increasing the paragraph will make it worse, but that’s balanced against a better page layout. A large tolerance isn’t bad given TeX minimises the badness for a paragraph. It just says we really don’t want over or underfull lines thank you.
In our experience, TeX rarely allows a paragraph to reduce. Have more shrinky spaces helps (the default min shrink for a space is 66% so 95% actually makes it less shrinky). Likewise the default max stretch is 150% so 140% makes it less stretchy. Adding intercharacter spacing is unlikely to make much difference to line breaking. It might but really all it does is soak up some extra stretch from the spaces making them less ugly. BTW if TeX breaks a really really bad line, it doesn’t matter how low you limit the max stretch, TeX will just stretch everything in proportion to fill the line overflowing any maxima.
This bit is mathematical: The 9000 tolerance needs to be divided by the number of lines to get an average. Let’s say there are 10 lines in a paragraph, so we get an average of 900 badness per line. TeX calculates badness as 100x(actual shrink or stretch / maximum shrink or stretch)^3. So that means it can allow a line to shrink or stretch on average up to 2 x the total for the line. Thus it might reduce spaces down to half their minimum or stretch them to twice their maximum. Obviously this is a worst case and TeX always chooses the best looking paragraph it can. So don’t worry that everything will look far worse than you specify. In practise, things look really good and by choosing which paragraphs to stretch wisely, one can fix problems in a way that is not obvious to the untrained eye.
Why does TeX not shrink paragraphs well? Because usually the max shrink of the spaces on a line are insufficient to pull a whole word up let alone 2 or 3. It depends if you are willing to let your min space be down at 40% of a space, which really isn’t much.
For scripts that don’t have word spaces then the key is to give plenty of places for TeX to break lines by inserting ZWSP characters liberally.
Now as to per paragraph changes. Yes we could change the values of the glue paragraph by paragraph, but I don’t know how we would provide a UI for that. Would you want to do all that work? Perhaps a more helpful way is to create a tool that measures all the possible paragraph shrinks and stretches and lets you know the range of values that will actually happen. We have some thoughts on improving the whole UI around adjustment lists anyway.
BTW here’s a tip. You can always increase the line count for a heading style since they aren’t justified, so TeX will happily make those lines shorter and shorter to have more of them in a paragraph. But they are also very noticeable on the page.
You did ask!!
机器翻译自 English