Minimiza las separaciones de palabras con ragged2e

Minimiza las separaciones de palabras con ragged2e

Casi todas las guías de LaTeX recomiendan \RaggedRightel ragged2epaquete en lugar del \raggedright. Pero siempre me he sentido frustrado por demasiadas palabras con guiones \RaggedRight. Entiendo que obtendré algunos (donde \raggedrightno da ninguno), pero obtengo demasiados.

Decidí comparar \RaggedRightcon justificación completa y constantemente encuentro que obtengo más guiones \RaggedRightque con justificación completa, lo cual no esperaría. En el siguiente ejemplo, solo obtengo una separación de palabras con justificación completa (y eso es solo en un punto de separación de palabras creado manualmente para resolver un overfull \hbox), pero obtengo siete con \RaggedRight. (El texto es de Moby Dick, que es de dominio público).

¿Puedo reducir la separación de palabras que obtengo \RaggedRightpara que sea comparable con la que obtengo con una justificación completa?

\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}

Respuesta1

Algunas palabras sobre el salto de línea. TeX asigna una maldad a cada línea, según la cantidad de estiramiento del pegamento en ella. En una configuración irregular a la derecha, solo hay pegamento estirable a la derecha ( \rightskip), lo que tiene como consecuencia que este pegamento (si es finito) generalmente se estirará más de lo indicado. El valor predeterminado \RaggedRighttiene un estiramiento "óptimo" de como máximo 2 em, pero es muy probable que las líneas no puedan alcanzar esto cerca del margen derecho, por lo que se espera una gran maldad. Con el valor predeterminado \hyphenpenaltyde 50, a TeX le resultará más barato, para minimizar los deméritos totales, separar guiones para acercarse al margen.

Si hacemos que la separación de palabras sea menos conveniente, el estiramiento del pegamento tendrá un impacto más leve en los deméritos totales que la separación de palabras.

Tenga en cuenta que con la configuración estándar \raggedright, la separación de palabras nunca ocurrirá (bueno, casi nunca), porque \rightskiptiene una extensión infinita ( 0pt plus 1fil), por lo que las líneas tendrán cero maldad y los deméritos solo se agregarán desde \linepenalty, por lo que TeX simplemente minimizará el número de líneas.

Encontrar un buen compromiso no es fácil: aumentar el estiramiento \rightskippodría hacer que TeX esté más dispuesto a establecer líneas más cortas. Propongo aumentar el \hyphenpenalty, ya que microtypeeso suele tener un impacto bastante bueno en la configuración de los párrafos.

\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}

ingrese la descripción de la imagen aquí

Resultado: con la penalización por separación de palabras predeterminada, tres palabras se dividen con guiones; con la mayor penalización por separación de palabras, solo uno.

lo mismo sinmicrotype

ingrese la descripción de la imagen aquí

Resultado: con la penalización por separación de palabras predeterminada, se separan siete palabras; con la mayor penalización por separación de palabras, solo dos.

En todos los casos, el guión preciselyes inevitable debido al guión.

Respuesta2

La "irregularidad" de \RaggedRightse puede configurar por la longitud \RaggedRightRightskip, que se inserta en el extremo derecho de una línea, cuando TeX divide el párrafo. El valor predeterminado es 0pt plus 2em, lo que significa que la línea puede ser completa o corta con hasta 2 em de espacio en blanco en el lado derecho.

Aumentar el valor 2.8emreduce el número de guiones a uno a costa de un lado derecho del párrafo más irregular.

\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}

Resultado

información relacionada