Минимизируйте переносы с помощью ragged2e

Минимизируйте переносы с помощью ragged2e

Почти каждое руководство по LaTeX рекомендует \RaggedRightиспользовать ragged2eпакет вместо встроенного \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неизбежен из-за длинного тире.

решение2

"Рваность" \RaggedRightможет быть настроена длиной \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}

Результат

Связанный контент