使用 ragged2e 最小化連字符

使用 ragged2e 最小化連字符

幾乎所有 LaTeX 指南都推薦使用\RaggedRightragged2e而不是內建的\raggedright.但我一直對太多帶有連字符的單字感到沮喪\RaggedRight。我知道我會得到一些(\raggedright沒有得到),但我得到太多。

我決定與完整的理由進行比較\RaggedRight,並始終發現我得到的連字符\RaggedRight比完整​​的理由更多,這是我沒想到的。在下面的範例中,我只得到一個具有充分理由的連字符(並且僅在手動創建的連字符點來解決overfull \hbox),但我得到了七個連字符\RaggedRight。 (文本來自《莫比迪克》,屬於公共領域。)

我可以減少我得到的連字號,\RaggedRight以便它與我得到的有充分理由的結果具有可比性嗎?

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}

% 1 hyphenated word with no ragged right
% 7 hyphenated words with \RaggedRight from ragged2e

\begin{document}
\RaggedRight
Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.
\end{document}

答案1

關於斷線的一些話。 TeX 根據每條線中膠水的拉伸量為每條線分配一個壞度。在參差不齊的右側設定中,右側 ( \rightskip) 處只有可拉伸的膠水,其結果是該膠水(如果有限)通常會比規定的拉伸程度更大。預設情況下,\RaggedRight「最佳」拉伸最多為 2 em,但線條很可能無法達到右邊距附近的長度,因此預計會有很高的壞度。使用預設值\hyphenpenalty50,TeX 會發現為了盡量減少總缺點,使用連字符來更接近邊緣會更便宜。

如果我們使連字變得不太方便,那麼黏合拉伸對總缺點的影響將比連字產生的影響更小。

請注意,使用標準\raggedright設置,連字永遠不會發生(嗯,幾乎不會發生),因為\rightskip具有無限拉伸 ( 0pt plus 1fil),因此行的壞度為零,並且缺點只會從 中添加\linepenalty,因此TeX 只會最小化行數。

要找到一個好的折衷方案並不容易:增加 的伸展\rightskip可能會讓 TeX 更願意設定較短的行。我建議增加\hyphenpenalty, 相反,microtype這通常對段落設置有很好的影響。

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{microtype}
\usepackage{ragged2e}

\begin{document}
\newcommand\incipit{Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.}

\RaggedRight

\noindent With \texttt{microtype}

\bigskip

\noindent\texttt{\string\hyphenpenalty=50}

\incipit

\bigskip

\noindent\texttt{\string\hyphenpenalty=500}

\hyphenpenalty=500

\incipit

\end{document}

在此輸入影像描述

結果:使用預設的連字符懲罰,三個單字被連字符;隨著連字符懲罰的增加,只有一個。

不帶也一樣microtype

在此輸入影像描述

結果:使用預設的連字符懲罰,七個單字被連字符;隨著連字符懲罰的增加,只有兩個。

precisely在所有情況下,由於破折號的存在,連字符 in是不可避免的。

答案2

的「不規則」\RaggedRight可以透過 length 來配置\RaggedRightRightskip,當 TeX 中斷段落時,它會插入到行的右端。預設值為0pt plus 2em,這表示該行可以是全行或短行,右側最多有 2em 的空白。

增加該值可將2.8em連字符數量減少到一個,但代價是段落右側更加參差不齊。

\documentclass{article}
\usepackage[textwidth=4.0in]{geometry}
\usepackage{ragged2e}

\setlength{\RaggedRightRightskip}{0pt plus 2.8em}

\begin{document}
\RaggedRight
Call me Ishmael. Some years ago---never mind how long
precise\-ly---having little or no money in my purse, and nothing
particular to interest me on shore, I thought I would sail about a
little and see the watery part of the world. It is a way I have of
driving off the spleen and regulating the circulation. Whenever I
find myself growing grim about the mouth; whenever it is a damp,
drizzly November in my soul; whenever I find myself involuntarily
pausing before coffin warehouses, and bringing up the rear of
every funeral I meet; and especially whenever my hypos get such an
upper hand of me, that it requires a strong moral principle to
prevent me from deliberately stepping into the street, and
methodically knocking people's hats off---then, I account it high
time to get to sea as soon as I can. This is my substitute for
pistol and ball. With a philosophical flourish Cato throws himself
upon his sword; I quietly take to the ship. There is nothing
surprising in this. If they but knew it, almost all men in their
degree, some time or other, cherish very nearly the same feelings
towards the ocean with me.
\end{document}

結果

相關內容