简而言之,以下是 TeX 的换行方法(就我所理解的):
如果
\pretolerance
为正数,则尝试将段落分成几行,不插入任意连字符,并且不良程度不超过\pretolerance
。如果方法 1 失败,则允许连字符,并且尽量不要超过 的不良程度
\tolerance
。如果方法 2 失败且
\emergencystretch
结果为肯定,则将每行文本的“可容忍”空白量增加 ,再试一次\emergencystretch
。
第 96 页电子书Knuth 报告的实验表明“第一次(不使用连字符)的成功率超过 90%”对于“相当宽”的线,但对于“非常窄”的线,很快就会失败。他还表示,第一遍已经完成了“为了节省时间”。我对此的解释如下:
对于不使用连字符换行失败的情况,实际上可以通过以下方法节省时间:省略第一遍(即设置
\pretolerance=-1
)。也有可能(尽管对于平均词长较短的语言来说可能性不大)第一次通过就会成功,但允许连字会导致解决方案的糟糕程度较小。
100
尽管如此,Knuth 还是选择了的默认值\pretolerance
,他肯定认为“尝试不使用连字符”所节省的时间是值得的,考虑到他采用这些设置时的平均处理能力。
我不知道 TeX 的换行算法的默认设置是否随着时间的推移而改变。但以前节省的大量净时间现在可能已经不重要了吗?
那么:让 TeX 尝试不使用连字符进行换行是否仍然值得?或者现在最好采用\pretolerance=-1
默认设置?
答案1
它不会对现代机器的性能产生任何严重影响,我也可以保证旧机器的性能。根据您的设置,超过 50% 的文本通常会通过第一遍。以下是两个测试的图表(红色数字表示糟糕程度):
测试使用 Wilson 在 Git 上发布的代码进行。我个人建议让 \pretolerance 保持在 100,这样可能会更快(因为在大多数情况下您不会强制其他传递)。
\documentclass{article}
\usepackage{xcolor}
%%% Code from GIT posted by Wilson
\frenchspacing
\fussy
\makeatletter
\newbox\trialbox
\newbox\linebox
\newcount\maxbad
\newcount\linebad
\newcount\bestbad
\newcount\worstbad
\newcount\overfulls
\newcount\currenthbadness
\def\trypar#1\par{%
\showtrybox{\linewidth}{#1\par}%
}
\newcommand\showtrybox[2]{%
\currenthbadness=\hbadness
\maxbad=0\relax
\setbox\trialbox=\vbox{%
\hsize#1\relax#2%
\hbadness=10000000\relax
\eatlines
}%
\hbadness=10000000\relax
\setbox\trialbox=\vbox{%
\hsize#1\relax#2%
\printlines
}%
\noindent\usebox\trialbox\par
\hbadness=\currenthbadness
}
\newcommand\trybox[2]{%
\currenthbadness=\hbadness
\maxbad=0\relax
\setbox\trialbox=\vbox{%
\hsize#1\relax#2\par
\hbadness=10000000\relax
\eatlines
}%
\hbadness=\currenthbadness
}
\def\eatlines{%
\begingroup
\setbox\linebox=\lastbox
\setbox0=\hbox to \hsize{\unhcopy\linebox\hss}%
\linebad=\the\badness\relax
\ifnum\linebad>\maxbad\relax \global\maxbad=\linebad\relax \fi
\ifvoid\linebox\else
\unskip\unpenalty\eatlines
\fi
\endgroup
}
\def\printlines{%
\begingroup
\setbox\linebox=\lastbox
\setbox0=\hbox to \hsize{\unhcopy\linebox}%
\linebad=\the\badness\relax
\ifvoid\linebox\else
\unskip\unpenalty\printlines
\ifhmode\newline\fi\noindent\box\linebox\showbadness
\fi
\endgroup
}
\def\showbadness{%
\makebox[0pt][l]{%
\ifnum\currenthbadness<\linebad\relax
\ifnum\linebad=1000000\relax\expandafter\@gobble\fi
{\quad\color{red}\rule{\overfullrule}{\overfullrule}~{\footnotesize\sffamily(\the\linebad)}}%
\fi
}%
}
\makeatother
\begin{document}
\hbadness=-1
\begin{minipage}[t]{4.5cm}
\trypar\hyphenpenalty=500\looseness=1
In olden times when wishing
still helped one, there lived a
king whose daughters were all
beautiful, but the youngest was so
beautiful that the sun itself,
which has seen so much, was
astonished whenever it shone in
her face. Close by the king's
castle lay a great dark forest,
and under an old lime-tree in the
forest was a well, and when
the day was very warm, the
king's child went out into the
forest and sat down by the side
of the cool fountain, and when she was bored she
took a golden ball, and threw it up on a high and caught it, and this
ball was her favorite plaything. \par
\end{minipage}
\hspace{2cm}
\begin{minipage}[t]{4.5cm}
\trypar\hyphenpenalty=10000\looseness=1
In olden times when wishing
still helped one, there lived a
king whose daughters were all
beautiful, but the youngest was so
beautiful that the sun itself,
which has seen so much, was
astonished whenever it shone in
her face. Close by the king's
castle lay a great dark forest,
and under an old lime-tree in the
forest was a well, and when
the day was very warm, the
king's child went out into the
forest and sat down by the side
of the cool fountain, and when she was bored she
took a golden ball, and threw it up on a high and caught it, and this
ball was her favorite plaything. \par
\end{minipage}
\end{document}