我对此并不乐观,因为这是 TeX 算法的核心部分,但有没有办法切换到“贪婪”的对齐算法?也就是说,不是对整个段落进行处理并优化单词间距,而是尽可能多地将内容放在一行上,必要时使用连字符,对齐,然后移至下一行。
答案1
不:) – David Carlisle 3 小时前
本着永不言败的原则,这将逐行构建段落(首先使用正常设置)....
更新修复插入 parindent 时的小错误
\documentclass{article}
\usepackage{kantlipsum}
\begin{document}
\makeatletter
\def\linebyline#1 {%
\ifx\!#1\else
\setbox\z@\vbox{%
\noindent\unhbox\tw@\unskip\unskip\unpenalty\sporindent#1}%
\let\sporindent\space
\ifdim\ht\z@>\baselineskip
\setbox\z@\vbox{%
\unvbox\z@
\global\setbox1\lastbox
\unskip\unpenalty\unskip\unpenalty
\global\setbox\thr@@\lastbox
\unskip\unpenalty\unskip\unpenalty%<<<<<
}%
\ifdim\ht\z@>\z@\box\z@\fi%<<<<<
\hbox to \hsize{\unhbox\thr@@\unskip\unskip\unpenalty}%
\else
\setbox\z@\vbox{%
\unvbox\z@
\global\setbox\@ne\lastbox
}%
\fi
\setbox\tw@\box\@ne
\expandafter\linebyline
\fi}
\def\linebylinepar#1{{%
\par
\finalhyphendemerits\z@
\clubpenalty\z@
\widowpenalty\z@
\def\sporindent{\hskip\parindent}%
\setbox\tw@\hbox{}%
\@firstofone{\expandafter\linebyline#1} \! \relax
\box\tw@
\par}}
\makeatother
\kantdef\zz{1}
\zz\bigskip\linebylinepar\zz
\begin{minipage}[t]{.27\textwidth}\zz\end{minipage}\qquad
\begin{minipage}[t]{.27\textwidth}\linebylinepar\zz\end{minipage}
\end{document}
答案2
您可以让 TeX 对连续的视觉不兼容的行不那么挑剔,更喜欢连字符,并且对糟糕的间距非常宽容。
\documentclass{article}
\usepackage{kantlipsum}
\begin{document}
\kant[1]
\adjdemerits=-1000000 % demerits for consecutive visually incompatible lines
\hyphenpenalty=-5000 % penalty added for hyphenating
\doublehyphendemerits=-1000000 % demerits for consecutive hyphens
\tolerance=10000 % bad lines are OK
\kant[1]
\end{document}
这是另一次尝试。第三段已使用“贪婪”方法手动拆分,其中考虑到\righthyphenmin=3
。
\documentclass{article}
\usepackage{kantlipsum}
\begin{document}
\kant[1]
\adjdemerits=0 % don't be fussy about consecutive visually incompatible lines
\hyphenpenalty=-5000 % prefer hyphenation
\doublehyphendemerits=-1000000 % consecutive hyphens are OK
\tolerance=50 % be strict as regards to spacing
\linepenalty=9999 % as few lines as possible
\kant[1]
\newcommand{\aline}[1]{\hbox to \textwidth{#1}}
\aline{\indent As any dedicated reader can clearly see, the Ideal of practical reason is a rep-}
\aline{resentation of, as far as I know, the things in themselves; as I have shown else-}
\aline{where, the phenomena should only be used as a canon for our understanding.}
\aline{The paralogisms of practical reason are what first give rise to the architectonic of}
\aline{practical reason. As will easily be shown in the next section, reason would}
\aline{thereby be made to contradict, in view of these considerations, the Ideal of prac-}
\aline{tical reason, yet the manifold depends on the phenomena. Necessity depends on,}
\aline{when thus treated as the practical employment of the never-ending regress in the}
\aline{series of empirical conditions, time. Human reason depends on our sense percep-}
\aline{tions, by means of analytic unity. There can be no doubt that the objects in}
\aline{space and time are what first give rise to human reason.\hfill}
\end{document}
前四行一致,然后 TeX 的算法开始执行。
答案3
将尽可能多的内容放在一行上,必要时使用连字符,对齐,然后移至下一行。
这是一个完全忽略连字符规则的解决方案,只要行满了就会进行连字符连接。
\def\greedybreak#1{#1\ifx#1\blankspace\else\discretionary{-}{-}{}\fi}
\setuppapersize[A5]
\showframe
\starttext
\input ward
\bgroup
\setupalign[normal,verytolerant,stretch]
\handletokens
The Earth, as a habitat for animal life, is in old age and
has a fatal illness. Several, in fact. It would be happening
whether humans had ever evolved or not. But our presence is
like the effect of an old-age patient who smokes many packs
of cigarettes per day---and we humans are the cigarettes.
\with \greedybreak
\endgraf
\egroup
\stoptext
这使
这是略有不同的测试文件的结果。
该算法可以稍微智能一些,以便不在标点符号前使用连字符:)(并\dicretionary
正确使用命令;现在我也将把带有连字符的图像留在行首)。