The Ragged2e-package^{∗}

Martin Schröder

Crüsemannallee 3 D-28213 Bremen Martin.Schroeder@ACM.org

                           PGP-Key:  2048 bit / KeyID 292814E5
                        7E86 6EC8 97FA 2995  82C3 FEA5 2719 090E

1999/06/08

Abstract

This package provides new commands and environments for setting ragged text which are easy to configure to allow hyphenation. An earlier attempt to do this was the style raggedright[6] by the same author.

Contents

1 The problem 1

2 Old “solutions” 2 2.1 L^{A}TEX . . . . . . . . . 2 2.2 plain . . . . . . . . . 2

3 Our solution 2

3.1 Usage . . . . . . . . . 2 3.1.1 The macros . . 3 3.1.2 The parameters 3 3.1.3 The environ-

ments . . . . . 5

4 Options 5

5 Required packages 6

6 Acknowledgements 6

1 The problem

L^{A}TEX has three commands (\centering,

\raggedleft, and \raggedright)

and three environments (center, flushleft, and flushright) to typeset ragged text. The environments are based upon the commands (center uses \centering, flushleft \raggedright, and flushright

\raggedleft).

These commands have, however, one serious flaw: they render hyphenation almost impossible, and thus the text looks too ragged, as the following example shows:

∗The version number of this file is v1.02, last revised 1999/06/08.

2 OLD “SOLUTIONS” 2

\raggedright:

“The L^{A}TEX document preparation system is a special version of Donald Knuth’s TEX program. TEX is a sophisticated program designed to produce high-quality typesetting, especially for mathematical text.” [3, p. xiii]

\RaggedRight:

“The L^{A}TEX document preparation system is a special version of Donald Knuth’s TEX program. TEX is a sophisticated program designed to produce high-quality typesetting, especially for mathematical text.” [3, p. xiii]

2 Old “solutions”

2.1 L^{A}TEX

L^{A}TEX defines e. g. \raggedright as follows:

1 ⟨∗latex⟩

2 \def\raggedright{%
3 \let\\=\@centercr
4 \@rightskip\@flushglue
5 \rightskip\@rightskip
6 \leftskip\z@
7 \parindent\z@}

Initially, \@flushglue is defined as

8 \@flushglue = 0pt plus 1fil

9 ⟨/latex⟩

Thus the \rightskip is set to 0pt plus 1fil. Knuth, however warns [2, p. 101]:

“For example, a person

can set \rightskip=0pt

plus 1fil, and every line will be filled with space to the right. But this isn’t a particularly good way to make ragged-right margins, because the infinte stretchability will assign zero badness to lines that are very short. To do a decent job of ragged-right setting, the trick is to set \rightskip so that it will stretch enough to make line breaks possible, yet not too much, because short lines should be considered bad. Furthermore the spaces between words should be fixed so that they do not stretch or shrink.”

2.2 plain

plain TEX defines an special version of \raggedright, which operates the way Knuth describes it; but which can not be used whith L^{A}TEX, because L^{A}TEX redefines

\raggedright.

10 ⟨∗plain⟩

11 \def\raggedright{%
12 \rightskip\z@ plus2em
13 \spaceskip.3333em
14 \xspaceskip.5em\relax}

plain provides also a version of \raggedright for typewriter fonts

15 \def\ttraggedright{%
16 \tt
17 \rightskip\z@ plus2em\relax}

18 ⟨/plain⟩

3 Our solution

3.1 Usage

Since the plain solution can not be used with L^{A}TEX, we have to redefine it and make it possible to configure it for personal preferences.

3.1.1 The macros

\Centering  \Centering, \RaggedLeft, and \RaggedRight can be used in the same
\RaggedLeft
\RaggedRight

way as \centering, \raggedleft, and \raggedright: Just type the

command, and after that the whole text will be set centered, ragged-left or ragged-right. For example, we switched on \RaggedRight on the top of this text, and consequently this text was set ragged-right. The new commands are fully compatible with their counterparts in L^{A}TEX, but implement the plain solution and can be easily configured using the following parameters:

3.1.2 The parameters

Command  Uses

 \Centering    \CenteringLeftSkip, \CenteringRightSkip,
               \CenteringParfillskip, \CenteringParIndent
 \RaggedLeft   \RaggedLeftLeftskip, \RaggedLeftRightskip,
               \RaggedLeftParfillskip, \RaggedLeftParIndent
 \RaggedRight  \RaggedRightLeftskip, \RaggedRightRightskip,
               \RaggedRightParfillskip, \RaggedRightParIndent

 all  \RaggedSpaceskip, \RaggedXSpaceskip

All Parameters can be set with \setlength, e. g.

     \setlength{RaggedRightRightskip}{0pt plus 1em}
sets \RaggedRightRightskip to 0pt plus 1em.
\CenteringLeftskip These are the \leftskips inserted by \Centering, \RaggedLeft, and
\RaggedLeftLeftskip
\RaggedRightLeftskip

\RaggedRight.

“\leftskip (glue at left of justified lines)” [2, p. 274]

\leftskip must be set to a finite value, to make hyphenation possible. Setting it to infinite values like 0pt plus 1fil makes hyphenation almost impossible.

\CenteringRightskip These are the \rightskips inserted by \Centering, \RaggedLeft, and
\RaggedLeftRightskip
\RaggedRightRightskip

\RaggedRight.

“\rightskip (glue at right of justified lines)” [2, p. 274]

\rightskip must be set to a finite value, to make hyphenation possible. Setting it to infinite values like 0pt plus 1fil makes hyphenation almost impossible.

\CenteringParfillskip These are the \parfillskips inserted by \Centering, \RaggedLeft, and
\RaggedLeftParfillskip
\RaggedRightParfillskip

\RaggedRight.

“\parfillskip (additional \rightskip at end of paragraphs)” [2, p. 274]

The normal setting for \parfillskip is 0pt plus 1fil; the parameters are provided for testing combinations of \{left|right}skip and

\parfillskip.
\CenteringParindent These are the \parindents used by \Centering, \RaggedLeft, and
\RaggedLeftParindent
\RaggedRightParindent

\RaggedRight.

“\parindent (width of \indent)” [2, p. 274]

\parindent is the indent of the first line of a paragraph and should be set to 0pt, since indented lines in ragged text do not look good.

\RaggedSpaceskip  \RaggedSpaceskip is the \spaceskip used by \Centering, \RaggedLeft,
and \RaggedRight.

“\spaceskip (glue between words, if nonzero)” [2, p. 274]

If \spaceskip is nonzero, the \spaceskip glue is used for an interword space. The plain solution sets \spaceskip to .3333em so that the spaces between words are fixed. This can only be used with proportional fonts, since with monospaced fonts like cmtt the \spaceskip should be set to the width of a space ‘ ’, which is e. g. .5em in cmtt. So plain provides the command \ttraggedright for monospaced fonts which doesn’t set

\spaceskip.

To solve this problem we use the package eversel to distinguish between monospaced and proportional fonts. If the current font is monospaced (\fontdimen3 = 0pt) we set \spaceskip to the interword space defined by the font (\fontdimen2); otherwise we use \RaggedSpaceskip.^{1}

\RaggedXSpaceskip  \RaggedXSpaceskip is the \xspaceskip used by \Center, \RaggedLeft,
and \RaggedRight.

“\xspaceskip (glue between sentences, if nonzero)” [2, p. 274]

\xspaceskip is the glue between sentences (after elements with a space factor ≥ 2000), if nonzero. Here we also have to distinguish between monospaced and proportional fonts using everysel.

The parameters have the following initial setting:

1This will not allow hyphenation of typewriter fonts; L^{A}TEX disables this by setting \hyphenchar to -1 for the \ttfamily[4].

Parameter  L^{A}TEX setting  Ragged2e setting

\CenteringLeftskip       0pt plus 1fil     0pt plus 2em
\RaggedLeftLeftskip      0pt plus 1fil     0pt plus 2em

\RaggedRightLeftskip     0pt plus 0pt
                         minus 0pt

                                            0pt plus 0pt
                                            minus 0pt

\CenteringRightskip      0pt plus 1fil     0pt plus 2em

\RaggedLeftRightskip     0pt plus 0pt
                         minus 0pt

                                            0pt plus 0pt
                                            minus 0pt

\RaggedRightRightskip    0pt plus 1fil     0pt plus 2em

\CenteringParfillskip    0pt plus 0pt
                         minus 0pt

                                            0pt plus 0pt
                                            minus 0pt
\RaggedLeftParfillskip   0pt plus 0pt
                         minus 0pt

                                            0pt plus 0pt
                                            minus 0pt

\RaggedRightParfillskip  0pt plus 1fil     0pt plus 1fil
\CenteringParindent      0pt               0pt
\RaggedLeftParindent     0pt               0pt
\RaggedRightParindent    0pt               0pt

\RaggedSpaceskip

                         0pt

                                            0.3333em/
                                            \fontdimen2^{2}

\RaggedXSpaceskip        0pt               .5em/0pt^{2}

3.1.3 The environments

Center Center is fully compatible with center, but uses \Centering instead of

\centering.
FlushLeft  FlushLeft is fully compatible with flushleft, but uses \RaggedRight
instead of \raggedright.
FlushRight  FlushRight is fully compatible with flushright, but uses \RaggedLeft
instead of \raggedleft.

E. g. FlushLeft can be used in the same way as flushleft:

    \begin{FlushLeft}

⟨text, which is set ragged-right⟩

    \end{FlushLeft}

4 Options

This package has the following options:

OriginalCommands The L^{A}TEX-commands \centering, \raggedleft, and \raggedright and the L^{A}TEX-environments center, flushleft, and flushright remain unchanged. It is the default.

2For proportional and monospaced fonts.

NewCommands The L^{A}TEX-commands \centering, \raggedleft, and \raggedright and the L^{A}TEX-environments center, flushleft, and flushright are set equal to their counterparts defined by ragged2e. Thus \raggedright invokes \RaggedRight. The original commands can be accessed unter the Names \LaTeX⟨original name⟩, e. g.

     \LaTeXraggedright.

OriginalParameters The parameters used by the commands implemented by ragged2e are initialized with the default settings used by L^{A}TEX.

NewParameters The parameters used by the commands implemented by ragged2e are initialized with the default settings defined by ragged2e. It is the default.

5 Required packages

This package requires the following package:

everysel[5] It is used to distinguish between monospaced and proportional fonts.

6 Acknowledgements

A first version of this package for L^{A}TEX2.09 was named raggedri[6]. Laurent Siebenmann (lcs@topo.math.u-psud.fr) with his style ragged.sty[7] provided the final impulse for this new implementation. Without the constant nagging of Rainer Sieger (rsieger@awi-bremerhaven. de) this package might not be.

References

[1] Johannes Braams, David Carlisle, Alan Jeffrey, Leslie Lamport, Frank Mittelbach, Chris Rowley, and Rainer Schöpf. ltmiscen.dtx. Part of the L^{A}TEX-distribution.

[2] Donald E. Knuth. The TEXBook, volume A of Computers & Typesetting. Addison-Wesley, Reading, MA, USA, 1986.

[3] Leslie Lamport. L^{A}TEX: A Document Preparation System. Addison-Wesley, Reading, MA, USA, first edition, 1986.

[4] Frank Mittelbach and Rainer Schöpf. The file cmfonts.fdd for use with L^{A}TEX 2ε. Part of the L^{A}TEX-distribution.

[5] Martin Schröder. The everysel-package. CTAN:tex-archive/macros/

   latex/contrib/supported/ms/everysel.dtx. L^{A}TEX 2ε package.

[6] Martin Schröder. The raggedri document option. Was in CTAN:

   tex-archive/macros/latex209/contrib/raggedright. L^{A}TEX2.09

style, outdated.

Index 7

[7] Laurent Siebenmann. ragged.sty. CTAN:tex-archive/macros/
generic/ragged/ragged.sty. generic macro file for plain and L^{A}TEX.

Index

Numbers written in italic refer to the page where the corresponding entry is described, the ones underlined to the code line of the definition, the rest to the code lines where the entry is used.

Symbols

\@centercr . . . . . . . . . . . . . . . . . 3 \@flushglue . . . . . . . . . . . . . . . 4, 8 \@rightskip . . . . . . . . . . . . . . . 4, 5 \\ . . . . . . . . . . . . . . . . . . . . . . . . 3

C

Center (environment) . . . . . . . . . 5 \Centering . . . . . . . . . . . . . . . . 2

\CenteringLeftskip . . . . . . . . . . 3
\CenteringParfillskip . . . . . . . 3
\CenteringParindent . . . . . . . . . 3
\CenteringRightskip . . . . . . . . . 3

D

\def . . . . . . . . . . . . . . . . 2, 11, 15

E

environments:

Center . . . . . . . . . . . . . . . . . 5 FlushLeft . . . . . . . . . . . . . . . 5 FlushRight . . . . . . . . . . . . . . 5

F

FlushLeft (environment) . . . . . . 5 FlushRight (environment) . . . . . 5

L

\leftskip . . . . . . . . . . . . . . . . . . 6 \let . . . . . . . . . . . . . . . . . . . . . . 3

P

\parindent . . . . . . . . . . . . . . . . . 7

R

\RaggedLeft . . . . . . . . . . . . . . . . 2

\RaggedLeftLeftskip . . . . . . . . . 3
\RaggedLeftParfillskip . . . . . . 3
\RaggedLeftParindent . . . . . . . . 3
\RaggedLeftRightskip . . . . . . . . 3

\RaggedRight . . . . . . . . . . . . . . . 2 \raggedright . . . . . . . . . . . . . 2, 11

\RaggedRightLeftskip . . . . . . . . 3
\RaggedRightParfillskip . . . . . 3
\RaggedRightParindent . . . . . . . 3
\RaggedRightRightskip . . . . . . . 3
\RaggedSpaceskip . . . . . . . . . . . 4
\RaggedXSpaceskip . . . . . . . . . . 4

\relax . . . . . . . . . . . . . . . . . 14, 17 \rightskip . . . . . . . . . . . 5, 12, 17

S

\spaceskip . . . . . . . . . . . . . . . . 13

T

\tt . . . . . . . . . . . . . . . . . . . . . . 16 \ttraggedright . . . . . . . . . . . . . 15

X

\xspaceskip . . . . . . . . . . . . . . . . 14

Z

\z@ . . . . . . . . . . . . . . . 6, 7, 12, 17

Change History

v1.00

General: New from raggedright

V 1.21 . . . . . . . . . . . . . . . 1 v1.01

General: Documentation im-

proved . . . . . . . . . . . . . . . 1 v1.02

General: Moved to LPPL . . . . . 1