• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL

Chapter 3. Basic Formatting Tools > 3.1. Phrases and paragraphs

3.1. Phrases and paragraphs

In this section we deal with small text fragments and explain how they can be manipulated and highlighted in a consistent manner by giving them a visual appearance different from the one used for the main text.

We start by discussing how to define commands that take care of the space after them, then show a way to produce professional-looking marks of omission.

For highlighting text you can customize the font shape, weight, or size (see Section 7.3.1 on page 338). Text can also be underlined, or the spacing between letters can be varied. Ways for performing such operations are offered by the four packages relsize, textcase, ulem, and soul.

The remainder of this section then turns to paragraph-related issues, such as producing large initial letters at the start of a paragraph, modifying paragraph justification, altering the vertical spacing between lines of a paragraph, and introducing rectangular holes into it, that can be filled with small pictures, among other things.

3.1.1. xspace—Gentle spacing after a macro

The small package xspace (by David Carlisle) defines the \xspace command, for use at the end of macros that produce text. It adds a space unless the macro is followed by certain punctuation characters.

The \xspace command saves you from having to type \ or {} after most occurrences of a macro name in text. However, if either of these constructs follows \xspace, a space is not added by \xspace. This means that it is safe to add \xspace to the end of an existing macro without making too many changes in your document. Possible candidates for \xspace are commands for abbreviations such as “e.g.,” and “i.e.,”.


Notice the use of the \@ command to generate the correct kind of space. If used to the right of a punctuation character, it prevents extra space from being added: the dot will not be regarded as an end-of-sentence symbol. Using it on the left forces LaTeX to interpret the dot as an end-of-sentence symbol.

Sometimes \xspace may make a wrong decision and add a space when it is not required. In such cases, follow the macro with {}, which will suppress this space.


3.1.2. ellipsis, lips—Marks of omission

Omission marks are universally represented by three consecutive periods (also known as an ellipsis). Their spacing, however, depends on house style and typographic conventions, and significant difference are observed. In French, according to Hart [63] or The Chicago Manual of Style [38], “points de suspension” are set close together and immediately follow the preceding word with a space on the right:

C’est une chose... bien difficile.

In German, according to the Duden [44], “Auslassungspunkte” have space on the left and right unless they mark missing letters within a word or a punctuation after them is kept:

Du E... du! Scher dich zum ...!

Elsewhere, such as in British and American typography, the dots are sometimes set with full word spaces between them and rather complex rules determine how to handle other punctuation marks at either end.

LaTeX offers the commands \dots and \textellipsis to produce closely spaced omission marks. Unfortunately, the standard definition (inherited from plain TeX) produces uneven spacing at the left and right—unsuitable to typeset some of the above examples properly. The extra thin space at the right of the ellipsis is correct in certain situations (e.g., when a punctuation character follows). If the ellipsis is followed by space, however, it looks distinctly odd and is best canceled as shown in the example below (though removing the space in the second instance brings the exclamation mark a bit too close).


This problem is addressed in the package ellipsis written by Peter Heslin, which redefines the \dots command to look at the following character to decide whether to add a final separation. An extra space is added if the following character is listed in the command \ellipsispunctuation, which defaults to “,.:;!?”. When using some of the language support packages that make certain characters active, this list may have to be redeclared afterwards to enable the package to still recognize the characters.

The spacing between the periods and the one possibly added after the ellipsis can be controlled through the command \ellipsisgap. To allow for automatic adjustments depending on the font size use a font-dependent unit like em or a fraction of a \fontdimen (see page 428).


For the special case when you need an ellipsis in the middle of a word (or for other reasons want a small space at either side), the package offers the command \midwordellipsis. If the package is loaded with the option mla (Modern Language Association style), the ellipsis is automatically bracketed without any extra space after the final period.

If one follows The Chicago Manual of Style [38], then an ellipsis is set with full word spaces between the dots. For this, one can deploy the lips package1 by Matt Swift. It implements the command \lips, which follows the recommendations in this reference book. For example, an ellipsis denoting an omission at the end of a sentence should, according to [38, §10.48–63], consist of four dots with the first dot being the sentence period.2 The \lips command implements this by interpreting “\lips.” like “.\lips”, as can be seen in the next example.

1 lips is actually part of a larger suite of packages. If used on a stand-alone basis, you also have to load the package moredefs by the same author.

2 Not that the authors of this book can see any logic in this.


The \lips command looks for punctuation characters following it and ensures that in case of ,:;?!)']/ the ellipsis and the punctuation are not separated by a line break. In other cases (e.g., an opening parenthesis), a line break would be possible. The above list is stored in \LPNobreakList and can be adjusted if necessary. To force an unbreakable space following \lips, follow the command with a tie (~).

When applying the mla option the ellipsis generated will be automatically bracketed and a period after the \lips command will not be moved to the front. If necessary, \olips will produce the original unbracketed version.


3.1.3. amsmath—Nonbreaking dashes

The amsmath package, extensively discussed in Chapter 8, also offers one command for use within paragraphs. The command \nobreakdash suppresses any possibility of a line break after the following hyphen or dash. A very common use of \nobreakdash is to prevent undesirable line breaks in usages such as “p-adic” but here is another example: if you code “Pages 3–9” as Pages 3\nobreakdash--9 then a line break will never occur between the dash and the 9.

This command must be used immediately before a hyphen or dash (-, --, or ---). The following example shows how to prohibit a line break after the hyphen but allow normal hyphenation in the following word (it suffices to add a zero-width space after the hyphen). For frequent use, it’s advisable to make abbreviations, such as \p. As a result “dimension” is broken across the line, while a break after “p-” is prevented (resulting in a overfull box in the example) and “3–9” is moved to the next line.


3.1.4. relsize—Relative changes to the font size

Standard LaTeX offers 10 predefined commands that change the overall font size (see Table 7.1 on page 342). The selected sizes depend on the document class but are otherwise absolute in value. That is, \small will always select the same size within a document regardless of surrounding conditions.

However, in many situations it is desirable to change the font size relative to the current size. This can be achieved with the relsize package, originally developed by Bernie Cosell and later updated and extended for LaTeX2ε by Donald Arseneau and Matt Swift.

The package provides the declarative command \relsize, which takes a number as its argument denoting the number of steps by which to change the size. For example, if the current size is \Large then \relsize{-2} would change to \normalsize. If the requested number of steps is not available then the smallest (i.e., \tiny) or largest (i.e., \Huge) size command is selected. This means that undoing a relative size change by negating the argument of \relsize is not guaranteed to bring you back to the original size—it is better to delimit such changes by a brace group and let LaTeX undo the modification.

The package further defines \smaller and \larger, which are simply abbreviations for \relsize with the arguments -1 and 1, respectively. Convenient variants are \textsmaller and \textlarger, whose argument is the text to reduce or enlarge in size. These four commands take as an optional argument the number of steps to change if something different from 1 (the default) is needed.


In fact, the above description for \relsize is not absolutely accurate: it tries to increase or decrease the size by 20% for each step and selects the LaTeX font size command that is closest to the resulting target size. It then compares the selected size and target size. If they differ by more than the current value of \RSpercentTolerance (interpreted as a percentage), the package calls \fontsize with the target size as one of the arguments. If this happens it is up to LaTeX’s font selection scheme to find a font matching this request as closely as possible. By default, \RSpercentTolerance is an empty macro, which is interpreted as 30 (percent) when the current font shape group is composed of only discrete sizes (see Section 7.10.3), and as 5 when the font shape definition covers ranges of sizes.

Using a fixed factor of 1.2 for every step may be too limiting in certain cases. For this reason the package additionally offers the more general declarative command \relscale{factor} and its variant \textscale{factor}{text}, to select the size based on the given factor, such as 1.3 (enlarge by 30%).

There are also two commands, \mathsmaller and \mathlarger, for use in math mode. LaTeX recognizes only four different math sizes, of which two (\displaystyle and \textstyle) are nearly identical for most symbols, so the application domain of these commands is somewhat limited. With exscale additionally loaded the situation is slightly improved: the \mathlarger command, when used in \displaystyle, will then internally switch to a larger text font size and afterwards select the \displaystyle corresponding to that size.


These commands will attempt to correctly attach superscripts and subscripts to large operators. For example,


Be aware that the use of these commands inside formulas will hide the true nature of the math atoms inside the argument, so that the spacing in the formula, without further help, might be wrong. As shown in following example, you may have to explicitly use \mathrel, \mathbin, or \mathop to get the correct spacing.


Due to these oddities, the \mathlarger and \mathsmaller commands should not be trusted blindly, and they will not be useful in every instance.

3.1.5. textcase—Change case of text intelligently

The standard LaTeX commands \MakeUppercase and \MakeLowercase change the characters in their arguments to uppercase or lowercase, respectively, thereby expanding macros as needed. For example,


will result in “ON 2ND AUGUST 2004”. Sometimes this will change more characters than desirable. For example, if the text contains a math formula, then uppercasing this formula is normally a bad idea because it changes its meaning. Similarly, arguments to the commands \label, \ref, and \cite represent semantic information, which, if modified, will result in incorrect or missing references, because LaTeX will look for the wrong labels.


The package textcase by David Carlisle overcomes these defects by providing two alternative commands, \MakeTextUppercase and \MakeTextLowercase, which recognize math formulas and cross-referencing commands and leave them alone.


Sometimes portions of text should be left unchanged for one reason or another. With \NoCaseChange the package provides a generic way to mark such parts. For instance:


If necessary, this method can be used to hide syntactic information, such as


thereby preventing tabular and ll from incorrectly being uppercased.

All this works only as long as the material is on the top level. Anything that is inside a group of braces (other than the argument braces to \label, \ref, \cite, or \NoCaseChange) will be uppercased or lowercased regardless of its nature.


In the above case you could avoid this pitfall by taking the formula out of the argument to \textbf and moving \emph inside the argument to \NoCaseChange. In other situations this kind of correction might be impossible. In such a case the (somewhat cumbersome) solution is to hide the problem part inside a private macro and protect it from expansion during the case change; this method works for the standard LaTeX commands as well, as shown in the next example.


Some classes and packages employ \MakeUppercase internally—for example, in running headings. If you wish to use \MakeTextUppercase instead, you should load the textcase package with the option overload. This option will replace the standard LaTeX commands with the variants defined by the package.

3.1.6. ulem—Emphasize via underline

LaTeX encourages the use of the \emph command and the \em declaration for marking emphasis, rather than explicit font-changing declarations, such as \bfseries and \itshape. The ulem package (by Donald Arseneau) redefines the command \emph to use underlining, rather than italics. It is possible to have line breaks and even primitive hyphenation in the underlined text. Every word is typeset in an underlined box, so automatic hyphenation is normally disabled, but explicit discretionary hyphens (\-) can still be used. The underlines continue between words and stretch just like ordinary spaces do. As spaces delimit words, some difficulty may arise with syntactical spaces (e.g., "2.3 pt"). Some effort is made to handle such spaces. If problems occur you might try enclosing the offending command in braces, since everything inside braces is put inside an \mbox. Thus, braces suppress stretching and line breaks in the text they enclose. Note that nested emphasis constructs are not always treated correctly by this package (see the gymnastics performed below to get the interword spaces correct in which each nested word is put separately inside an \emph expression).


Alternatively, underlining can be explicitly requested using the \uline command. In addition, a number of variants are available that are common in editorial markup. These are shown in the next example.


The redefinition of \emph can be turned off and on by using \normalem and \ULforem. Alternatively, the package can be loaded with the option normalem to suppress this redefinition. Another package option is UWforbf, which replaces \textbf and \bfseries by \uwave whenever possible.

The position of the line produced by \uline can be set explicitly by specifying a value for the length \ULdepth. The default value is font-dependent, denoted by the otherwise senile value \maxdimen. Similarly, the thickness of the line can be controlled via \ULthickness, which, for some historical reason, needs to be redefined using \renewcommand.

3.1.7. soul—Letterspacing or stealing sheep

Frederic Goudy supposedly said, “Anyone who would letterspace black letter would steal sheep”. Whether true or a myth, the topic of letterspacing clearly provokes heated discussions among typographers and is considered bad practice in most situations because it changes the “grey” level of the text and thus disturbs the flow of reading. Nevertheless, there are legitimate reasons for undertaking letterspacing. For example, display type often needs a looser setting and in most fonts uppercased text is improved this way. You may also find letterspacing being used to indicate emphasis, although this exhibits the grey-level problem.

TeX is ill equipped when it comes to supporting letterspacing. In theory, the best solution is to use specially designed fonts rather than trying to solve the problem with a macro package. But as this requires the availability of such fonts, it is not an option for most users. Thus, in practice, the use of a macro-based solution is usually easier to work with, even though it means dealing with a number of restrictions. Some information about the font approach can be found in the documentation for the fontinst package [74, 75].

The soul package written by Melchior Franz provides facilities for letterspacing and underlining, but maintains TeX’s ability to automatically hyphenate words, a feature not available in ulem. The package works by parsing the text to be letterspaced or underlined, token by token, which results in a number of peculiarities and restrictions. Thus, users who only wish to underline a few words and do not need automatic hyphenation are probably better off with ulem, which is far less picky about its input.


The use of the five main user commands of soul are shown in the next example. In cases where TeX’s hyphenation algorithm fails to find the appropriate hyphenation points, you can guide it as usual with the \- command. If the color package is loaded, \hl will work like a text marker, coloring the background using yellow as the default color; otherwise, it will behave like \ul and underline its argument.


Normally, the soul package interprets one token after another in the argument of \so, \st, and so on. However, in case of characters that are represented by more than one token (e.g., accented characters) this might fail with some low-level TeX error messages. Fortunately, the package already knows about all common accent commands, so these are handled correctly. For others, such as those provided by the textcomp package, you can announce them to soul with the help of a \soulaccent declaration. The alternative is to surround the tokens by braces.


The soul package already knows that quotation characters, en dash, and em dash consist of several tokens and handles them correctly. In case of other syntactical ligatures, such as the Spanish exclamation mark, you have to help it along with a brace group.


The soul package also knows about math formulas as long as they are surrounded by $ signs (the form \(...\) is not supported) and it knows about all standard font-changing commands, such as \textbf. If you have defined your own font-switching command or use a package that provides additional font commands, you have to register them with soul using \soulregister. This declaration expects the font command to be registered as its first argument and the number of arguments (i.e., 0 or 1) for that command to appear as its second argument. Within the soul commands none of the font commands inserts any (necessary) italic correction. If needed, one has to provide it manually using \/.


If you look carefully, you will see that the font commands suppress letterspacing directly preceding and following them, such as between “action” and the colon. This can be corrected by adding \>, which forces a space.


Text inside a brace group is regarded as a single object during parsing and is therefore not spaced out. This is handy if certain ligatures are to be kept intact inside spaced-out text. However, this method works only if the text inside the brace group contains no hyphenation points. If it does, you will receive the package error message “Reconstruction failed”. To hide such hyphenation points you need to put the text inside an \mbox, as shown in the second text line of the next example (TeX would hyphenate this as “Es-cher”—that is, between the “sch” that we try to keep together). You can also use \soulomit to achieve this effect, but then your text will work only when the soul package is loaded.


One of the most important restrictions of the above commands is that they cannot be nested; any attempt to nest soul commands will result in low-level TeX errors. If you really need nesting you will have to place the inner material in a box, which means you lose the possibility to break the material at a line ending.


A few other commands are special within the argument of \so and friends. Spacing out at certain points can be canceled using \< or forced with \> as we saw above. As usual with LaTeX a ~ will produce an unbreakable space. The \\ command is supported, though only in its basic form—no star, no optional argument. You can also use \linebreak to break a line at a certain point, but again the optional argument is not supported. Other LaTeX commands are likely to break the package—some experimentation will tell you what is safe and what produces havoc. The next example shows applications of these odds and ends.


The \sodef declaration allows you to define your own letterspacing commands. It can also be used to overwrite the defaults for \so.

The letterspacing algorithm works by putting a certain inter-letter space between characters of a word, a certain word space between words, and a certain outer space at the beginning and end of the letterspaced text section. The latter space is added only if it is appropriate at that point. The default values for these spaces are adjusted for typesetting texts in Fraktur fonts but with the help of the \sodef declaration it is easy to adjust them for your own needs. The font argument allows you to specify font attributes; in most cases it will be empty. Rather than using explicit dimensions in the other arguments it is advisable to resort to em values, thereby making your definition depend on the current font and its size.


While \so or any new command defined via \sodef simply retrieves and executes its stored definition, the \caps command works somewhat differently. It examines the current font and tries to find it (or a close match) in an internal database. It then uses the letterspacing values stored there. You can extend this database using the \capsdef declaration by providing values for individual fonts or groups of fonts. In this way you can fine-tune the letterspacing—for example, for text in headings. It is even possible to keep several such databases and change them on the fly within a document.


Apart from the first argument, which is totally different, the other arguments to \capsdef are identical to those of \sodef. The first argument, match spec, defines the font (or fonts) to which the current declaration applies.

Its syntax is encoding, family, series, shape, and size separated by slashes using the naming conventions of NFSS. Empty values match anything, so //// matches any font, /ptm///10 matches all Times fonts in 10 points, and OT1/cmr/m/n/ matches Computer Modern (cmr) medium series (m) normal shape (n) encoded in OT1 in any size. It is also possible to specify size ranges. For example, 5-14 means 5pt ≤ size < 14pt and 14- matches all sizes equal or greater 14pt. Refer to the tables in Chapter 7 for details on the NFSS font naming conventions.

As with \sodef, in most declarations the font argument will be empty. On some occasions it may make sense to use \scshape in this place, such as to change the font shape to small caps before applying letterspacing.

Because \caps uses the first matching entry in its database, the order of \capsdef declarations is important. Later declarations are examined first so that it is possible to overwrite or extend existing declarations.


The previous example also contained an interesting combination of \caps and \MakeUppercase: the command \allcaps changes its argument to uppercase and then uses \caps to letterspace the result.


Customized letterspacing for different occasions

With \capsreset the database is restored to its initial state containing only a generic default. You can then add new entries using \capsdef. The current state of the \caps database can be stored away under a name by using \capssave. You can later retrieve this state by recalling it with \capsselect. If you use the capsdefault option when loading the package, then all uses of \caps that have no matching declaration are flagged by underlining the text.


Customizing underlining

The position and the height of the line produced by the \ul command can be customized using either \setul or \setuldepth. The command \setul takes two dimensions as arguments: the position of the line in relation to the baseline and the height of the line. Alternatively, \setuldepth can be used to specify that the line should be positioned below the text provided as an argument. Finally, \resetul will restore the default package settings.


Both \ul and \st use a black rule by default. If you additionally load the color package, you can use colored rules instead and, if desired, modify the highlighting color as demonstrated below:


3.1.8. url—Typesetting URLs, path names, and the like

E-mail addresses, URLs, path or directory names, and similar objects usually require some attention to detail when typeset. For one thing, they often contain characters with special significance to LaTeX, such as ~, #, &, {, or }. In addition, breaking them across lines should be avoided or at least done with special care. For example, it is usually not wise to break at a hyphen, because then it is not clear whether the hyphen was inserted because of the break (as it would be the case with normal words) or was already present. Similar reasons make breaks at a space undesirable. To help with these issues, Donald Arseneau wrote the url package, which attempts to solve most of these problems.


The base command provided by the package is \url, which is offered in two syntax variants: the text argument either can be surrounded by braces (in which case the text must not contain unbalanced braces) or, like \verb, can be delimited by using an arbitrary character on both sides that is not used inside text. (The syntax box above uses ! and = but these are really only examples.) In that second form one can have unbalanced braces in the argument.

The \path command is the same except that it always uses typewriter fonts (\ttfamily), while \url can be customized as we will see below. The argument to both commands is typeset pretty much verbatim. For example, \url{~} produces a tilde. Spaces are ignored by default, as can be seen in the following example.


Line breaks can happen at certain symbols (by default, not between letters or hyphens) and in no case can the commands add a hyphen at the break point. Whenever the text contains either of the symbols % or #, or ends with \, it cannot be used in the argument to another command without producing errors (just like the \verb command). Another case that does not work properly inside the argument of another command is the use of two ^ characters in succession. However, the situation is worse in that case because one might not even get an error but simply incorrect output1 as the next example shows.

1 It depends on the letter that is following. An uppercase F instead of the lowercase f would produce an error.


Even if the text does not contain any critical symbols, it is always forbidden to use such a command inside a moving argument—for instance, the argument of a \section. If used there, you will get the error message


followed by many strange errors. Even the use of \protect will not help in that case. So what can be done if one needs to cite a path name or a URL in such a place? If you are prepared to be careful and only use “safe” characters inside text, then you can enable the commands for use in moving arguments by specifying the option allowmove when loading the package. But this does not help if you actually need a character like “#”. In that case the solution is to record the information first using \urldef and then reuse it later.


The declaration \urldef defines a new command cmd to contain the url-cmd (which might be \url, \path, or a newly defined command—see below) and the text in a way such that they can be used in any place, including a moving argument. The url-cmd is not executed at this point, which means that style changes can still affect the typesetting (see Example 3-1-33 on the facing page). Technically, what happens is that the \catcodes of characters in text are frozen during the declaration, so that they cannot be misinterpreted in places like arguments.


We have already mentioned style changes. For this task the url package offers the \urlstyle command, which takes one mandatory argument: a named style. Predefined styles are rm, sf, tt, and same. The first three select the font family of that name, while the same style uses the current font and changes only the line breaking.

The \url command uses whatever style is currently in force (the default is tt, i.e., typewriter), while \path internally always switches to the tt style. In the following example we typeset a URL saved in \lproject several times using different styles. The particular example may look slightly horrifying, but imagine how it would have looked if the URL had not been allowed to split at all in this narrow measure.


If you studied the previous example closely you will have noticed that the option hyphens was used. This option allows breaking at explicit hyphens, something normally disabled for \url-like commands. Without this option breaks would have been allowed only at the periods, after the colon, or after “//”.

Spaces in the argument

As mentioned earlier spaces inside text are ignored by default. If this is not desired one can use the option obeyspaces. However, this option may introduce spurious spaces if the \url command is used inside the argument of another command and text contains any “\” character. In that case \urldef solves the problem. Line breaks at spaces are not allowed unless you also use the option spaces.

The package automatically detects which font encoding is currently in use. In case of T1 encoded fonts it will make use of the additional glyphs available in this encoding, which improves the overall result.

Appending material at left or right

The package offers two hooks, \UrlLeft and \UrlRight, that by default do nothing but can be redefined to typeset material at the left or right of text. The material is typeset in the same fashion as the text. For example, spaces are ignored unless one uses \ or specifies obeyspaces as an option. If the commands are redefined at the top level, they act on every \url-like command. See Example 3-1-34 on the next page for a possibility to restrict their scope.


Defining URL-like commands

It is sometimes helpful to define your own commands that work similarly to \url or \path but use their own fonts, and so on. The command \DeclareUrlCommand can be used to define a new \url-like command or to modify an existing one. It takes two arguments: the command to define or change and the style-information (e.g., \urlstyle).

In the next example, we define \email to typeset e-mail addresses in rm style, prepending the string “e-mail:” via \UrlLeft. The example clearly shows that the scope for this redefinition is limited to the \email command. If you look closely, you can see that a space inside \UrlLeft (as in the top-level definition) has no effect, while \ produces the desired result.


The url package offers a number of other hooks that influence line breaking, among them \UrlBreaks, \UrlBigBreaks, and \UrlNoBreaks. These hooks can be redefined in the style-information argument of \DeclareUrlCommand to set up new or special conventions. For details consult the package documentation, which can be found at the end of the file url.sty.

3.1.9. euro—Converting and typesetting currencies

To ease the calculations needed to convert between national units and the euro, Melchior Franz developed the package euro. In fact, the package converts arbitrary currencies using the euro as the base unit. The calculations are done with high precision using the fp package written by Michael Mehlich. The formatting is highly customizable on a per-currency basis, so that this package can be used for all kind of applications involving currencies whether or not conversions are needed.


The main command \EURO converts an amount in from-currency into to-currency or, if this optional argument is missing, into euros. The arguments from-currency and to-currency are denoted in ISO currency codes, as listed in Table 3.1 on the facing page. When inputting the amount a dot must separate the integer value from any fractional part, even if the formatted number uses a different convention.


Table 3.1. ISO currency codes of the euro and the 12 euro-zone countries

With the default settings the amount is displayed in the from-currency with the converted value in the to-currency shown in parentheses.


The package options

The package offers a number of options to influence the general style of the output (unless overwritten by the more detailed formatting declarations discussed below). With eco the ISO codes precede the value and no customized symbols are used; with dots a period is inserted between every three-digit group (the default is to use a small space).

By default, integer amounts are printed as such, without adding a decimal separator and a (zero) fractional part. If the table option is specified this behavior is globally changed and either a—(option emdash, also the default), a – (option endash), or the right number of zeros (option zeros) is used.


The more detailed output customizations, which we discuss below, can be placed anywhere in the document. It is, however, advisable to keep them together in the preamble, or even to put them into the file euro.cfg, which is consulted upon loading the package.

The monetary symbols typeset can be adjusted with a \EUROSYM declaration; as defaults the package uses the ISO codes for most currencies. The example below changes the presentation for lira and euro using the currency symbols from the textcomp package. It also uses dots to help with huge lira amounts.


The package is well prepared for new countries to join the euro-zone. In fact, it is well prepared to deal with conversions from and to any currency as long as the conversion rate to the euro is known. To add a new currency use the \EUROADD declaration, which takes three arguments: the ISO currency code, the symbol or text to display for the currency, and the conversion rate to the euro. The next example makes the British pound available. Note the abbreviation \GBP, which makes the input a bit easier.


The conversion rates for the national currencies of the euro-zone countries are fixed (and predefined by the package). With other currencies the rates may change hourly, so you have to be prepared for frequent updates.

The package allows you to tailor the presentation via \EUROFORMAT declarations, either to provide new defaults or to adjust the typesetting of individual currencies. The first argument specifies which part of the formatting should be adjusted, and the second argument describes the formatting.

The main format specifies how the source and target currencies are to be arranged using the reserved keywords \in and \out to refer to the source and target currencies, respectively. In the example below the first line implements a format close to the default, the second line displays the result of the conversion, and the third line does not show the conversion at all (although it happens behind the scenes). The latter is useful if you want to make use of the currency formatting features of the package without being interested in any conversion.


The in and out formats specify how the source and target currencies should be formatted using the reserved keywords \val (monetary amount), \iso (currency code), and \sym (currency symbol if defined; ISO code otherwise).


Perhaps more interesting are the possibilities to influence the formatting of monetary amounts, for which the package offers five declarations to be used in the second argument to \EUROFORMAT. The \round declaration specifies where to round the monetary amount: positive values round to the integer digits and negative values to the fractional digits. For example, \round{-3} means show and round to three fractional digits. The \form declaration takes three arguments: the integer group separator (default \,), the decimal separator (default a comma), and the fractional group separator (default \,).

The first argument can be either all to define the default number formatting or an ISO currency code to modify the formatting for a single currency.


The \minus declaration formats negative values by executing its first argument before the number and its second argument after it (default \minus{$-$}{}). The number itself is typeset unsigned, so that a minus sign has to be supplied by the declaration. The \plus declaration is the analogue for dealing with positive numbers (default \plus{}{}).


The \zero declaration takes three arguments to describe what to do if everything is zero, the integer part is zero, or the fractional part is zero. In the first and third arguments, the decimal separator has to be entered as well, so it should correspond to the default or the value given in the \form command.


3.1.10. lettrine—Dropping your capital

In certain types of publications you may find the first letter of some paragraphs being highlighted by means of an enlarged letter often dropped into the paragraph body (so that the paragraph text flows around it) and usually followed by the first phrase or sentence being typeset in a special font. Applications range from chapter openings in novels, or indications of new thoughts in the text, to merely decorative elements to produce lively pages in a magazine. This custom can be traced back to the early days of printing, when such initials were often hand-colored after the printing process was finished. It originates in the manuscripts of the Middle Ages; that is, it predates the invention of printing.


The package lettrine written by Daniel Flipo lets you create such initials by providing the command \lettrine. In its simplest form it takes two arguments: the letter to become an initial and the follow-up text to be typeset in a special font, by default in \scshape.


The font used for the initial is, by default, a larger size of the current text font. Alternatively, you can specify a special font family by redefining the command \LettrineFontHook using standard NFSS commands. Similarly, the font used for the text in the second argument can be modified by changing \LettrineTextFont.

Because the \lettrine command calculates the initial size to fit a certain number of lines, you need scalable fonts to obtain the best results. As the examples in this book are typeset in Adobe Times and Helvetica by default, we have no problems here. Later examples use Palatino, which is also a scalable Type 1 font. But if you use a bitmapped font, such as Computer Modern, you might have to use special .fd files (see Chapter 7, pages 419ff) to achieve acceptable results.


Many books on typography give recommendations about how to best set large initials with respect to surrounding text. For highest quality it is often necessary to manually adjust the placement depending on the shape of the initial. For example, it is often suggested that letters with a projecting left stem should overhang into the margin. The \lettrine command caters to this need by supporting an optional argument in which you can specify adjustments in the form of a comma-separated list of key/value pairs.

The size of the initial is calculated by default to have a height of two text lines (stored in \DefaultLines); with the keyword lines you can change this value to a different number of lines. There is an exception: if you specify lines=1 the initial is still made two lines high, but instead of being dropped is placed onto the baseline of the first text line.

If you want a dropped initial that also extends above the first line of text, then use the keyword loversize. A value of .2 would enlarge the initial by 20%. The default value for this keyword is stored in \DefaultLoversize. This keyword is also useful in conjunction with lraise (default 0 in \DefaultLraise). In case of an initial with a large descender such as a “Q” you may have to raise the initial to avoid it overprinting following lines. In that case loversize can be used to reduce the height so as to align the initial properly.

With the keyword lhang you specify how much the initial extends into the margin. The value is specified as a fraction—that is, between 0 and 1. Its document default is stored in \DefaultLhang.


The distance between the initial and the following text in the first line is controlled by the command \DefaultFindent (default 0pt) and can be overwritten using the keyword findent. The indentation of following lines is by default 0.5em (stored in \DefaultNindent) but can be changed through the keyword nindent. If you want to specify a sloped indentation you can use the keyword slope, which applies from the third line onward. Again the default value can be changed via the command \DefaultSlope, though it seems questionable that you would ever want anything different than 0pt since a slope is normally only used for letters like “A” or “V”.


The example above clearly demonstrates that the size calculation for the initial does not take accents into account, which is normally the desired behavior. It is nevertheless possible to manually adjust the size using loversize.

To attach material to the left of the initial, such as some opening quote, you can use the keyword ante. It is the only keyword for which no command exists to set the default.

By modifying the default settings you can easily adapt the package to typeset initials the way you like. This can be done either in the preamble or in a file with the name lettrine.cfg, which is loaded if found.

3.1.11. Paragraph justification in LaTeX

For formatting paragraphs LaTeX deploys the algorithms already built into the TeX program, which by default produce justified paragraphs. In other words, spaces between words will be slightly stretched or shortened to produce lines of equal length. TeX achieves this outcome with an algorithm that attempts to find an optimal solution for a whole paragraph, using the current settings of about 20 internal parameters. They include aspects such as trying to produce visually compatible lines, such that a tight line is not followed by one very loosely typeset, or considering several hyphens in a row as a sign of bad quality. The interactions between these parameters are very subtle and even experts find it difficult to predict the results when tweaking them. Because the standard settings are suitable for nearly all applications, we describe only some of the parameters in this book. Appendix B.3.3 discusses how to trace the algorithm. If you are interested in delving further into the matter of automatic paragraph breaking, refer to The TeXbook [82, chap. 14], which describes the algorithm in great detail, or to the very interesting article by Michael Plass and Donald Knuth on the subject, which is reprinted in Digital Typography [98].

The downside of the global optimizing approach of TeX, which you will encounter sooner or later, is that making small changes, like correcting a typo near the end of a paragraph, can have drastic and surprising effects, as it might affect the line breaking of the whole paragraph. It is possible, and not even unlikely, that, for example, the removal of a word might actually result in making a paragraph one line longer. This behavior can be very annoying if you are near the end of finishing an important project (like the second edition of this book) and a correction wreaks havoc on your already manually adjusted page breaks. In such a situation it is best to place \linebreak or \pagebreak commands into strategic places to force TeX to choose a solution that it would normally consider inferior. To be able to later get rid of such manual corrections you can easily define your own commands, such as


rather than using the standard LaTeX commands directly. This helps you to distinguish the layout adjustments for a particular version from other usages of the original commands—a method successfully used in the preparation of this book.

Image Careful with TeX’s idea about infinitely bad

The interword spacing in a justified paragraph (the white space between individual words) is controlled by several TeX parameters—the most important ones are \tolerance and \emergencystretch. By setting them suitably for your document you can prevent most or all of the “Overfull box” messages without any manual line breaks. The \tolerance command is a means for setting how much the interword space in a paragraph is allowed to diverge from its optimum value.1 This command is a TeX (not LaTeX) counter and therefore it has an uncommon assignment syntax—for example, \tolerance=500. Lower values make TeX try harder to stay near the optimum; higher values allow for loose typesetting. The default value is often 200. When TeX is unable to stay in the given tolerance you will find overfull boxes in your output (i.e., lines sticking out into the margin like this). Enlarging the value of \tolerance means that TeX will also consider poorer but still acceptable line breaks, instead of turning the problem over to you for manual intervention. Sensible values are between 50 and 9999. Do not use 10000 or higher, as it allows TeX to produce arbitrarily bad lines (like this one). If you really need fully automated line breaking, it is better to set the length parameter \emergencystretch to a positive value. If TeX cannot break a paragraph without producing overfull boxes (due to the setting of \tolerance) and \emergencystretch is positive, it will add this length as stretchable space to every line, thereby accepting line-breaking solutions that have been rejected before. You may get some underfull box messages because all the lines are now set in a loose measure, but this result will still look better than a single horrible line in the middle of an otherwise perfectly typeset paragraph.

1 The optimum is font defined; see Section 7.10.3 on page 428.

LaTeX has two predefined commands influencing the above parameters: \fussy, which is the default, and \sloppy, which allows for relatively bad lines. The \sloppy command is automatically applied by LaTeX in some situations (e.g., when typesetting \marginpar arguments or p columns in a tabular environment) where perfect line breaking is seldom possible due to the narrow measure.

Unjustified text

While the theory on producing high-quality justified text is well understood (even though surprisingly few typesetting systems other than TeX use algorithms that can produce high quality other than by chance), the same cannot be said for the situation when unjustified text is being requested. This may sound strange at first hearing. After all, why should it be difficult to break a paragraph into lines of different length? The answer lies in the fact that we do not have quantifiable quality measures that allow us to easily determine whether a certain breaking is good or bad. In comparison to its work with justified text, TeX does a very poor job when asked to produce unjustified paragraphs. Thus, to obtain the highest quality we have to be prepared to help TeX far more often by adding explicit line breaks in strategic places. A good introduction to the problems in this area is given in an article by Paul Stiff [154].

The main type of unjustified text is the one in which lines are set flush left but are unjustified at the right. For this arrangement LaTeX offers the environment flushleft. It typesets all text in its scope “flush left” by adding very stretchable white space at the right of each line; that is, it sets the internal parameter \rightskip to 0pt plus 1fil. This setting often produces very ragged-looking paragraphs as it makes all lines equally good independent of the amount of text they contain. In addition, hyphenation is essentially disabled because a hyphen adds to the “badness” of a line and, as there is nothing to counteract it, TeX’s paragraph-breaking algorithm will normally choose line breaks that avoid them.


In summary, LaTeX’s flushleft environment is not particularly well suited to continuous unjustified text, which should vary at the right-hand boundary only to a certain extent and where appropriate should use hyphenation (see the next section for alternatives). Nevertheless, it can be useful to place individual objects, like a graphic, flush left to the margin, especially since this environment adds space above and below itself in the same way as list environments do.

Another important restriction is the fact that the settings chosen by this environment have no universal effect, because some environments (e.g., minipage or tabular) and commands (e.g., \parbox, \footnote, and \caption) restore the alignment of paragraphs to full justification. That is, they set the \rightskip length parameter to 0pt and thus cancel the stretchable space at the right line endings. A way to automatically deal with this problem is provided by the package ragged2e (see next section).

Other ways of typesetting paragraphs are flush right and centered, with the flushright and center environments, respectively. In these cases the line breaks are usually indicated with the \\ command, whereas for ragged-right text (the flushleft environment discussed above) you can let LaTeX do the line breaking itself (if you are happy with the resulting quality).

The three environments discussed in this section work by changing declarations that control how TeX typesets paragraphs. These declarations are also available as LaTeX commands, as shown in the following table of correspondence:


The commands neither start a new paragraph nor add vertical space, unlike the corresponding environments. Hence, the commands can be used inside other environments and inside a \parbox, in particular, to control the alignment in p columns of an array or tabular environment. Note, however, that if they are used in the last column of a tabular or array environment, the \\ is no longer available to denote the end of a row. Instead, the command \tabularnewline can be used for this purpose (see also Section 5.2.1).

3.1.12. ragged2e—Enhancing justification

The previous subsection discussed the deficiencies of LaTeX’s flushleft and flushright environments. The package ragged2e written by Martin Schröder sets out to provide alternatives that do not produce such extreme raggedness. This venture is not quite as simple as it sounds, because it is not enough to set \rightskip to something like 0pt plus 2em. Notwithstanding the fact that this would result in TeX trying hard to keep the line endings within the 2em boundary, there remains a subtle problem: by default, the interword space is also stretchable for most fonts. Thus, if \rightskip has only finite stretchability, TeX will distribute excess space equally to all spaces. As a result, the interword spaces will have different width, depending on the amount of material in the line. The solution is to redefine the interword space so that it no longer can stretch or shrink by specifying a suitable (font-dependent) value for \spaceskip. This internal TeX parameter, if nonzero, represents the current interword space, overwriting the default that is defined by the current font.

By default, the package does not modify the standard LaTeX commands and environments discussed in the previous section, but instead defines its own using the same names except that some letters are uppercased.1 The new environments and commands are given in the following correspondence table:

1 This is actually against standard naming conventions. In most packages mixed-case commands indicate interface commands to be used by designers in class files or in the preamble, but not commands to be used inside documents.


They differ from their counterparts of the previous section not only in the fact that they try to produce less ragged output, but also in their attempt to provide additional flexibility by easily letting you change most of their typesetting aspects.

Overloading the original commands

As typing the mixed-case commands and environments is somewhat tedious, you can overload the original commands and environments, such as \raggedright, with the new definitions by supplying the newcommands option when loading the package.

The package offers a large number of parameters to define the exact behavior of the new commands and environments (see Table 3.2 on the next page). For \RaggedRight or FlushLeft the white space added at the right of each line can be specified as \RaggedRightRightskip, the one at the left can be specified as \RaggedRightLeftskip, the paragraph indentation to use is available as \RaggedRightParindent, and even the space added to fill the last line is available as \RaggedRightParfillskip. Similarly, the settings for \Centering and \RaggedLeft can be altered; just replace RaggedRight in the parameter names with either Centering or RaggedLeft.


Table 3.2. Parameters used by ragged2e

Unjustified setting as the default

To set a whole document unjustified, specify document as an option to the ragged2e package. For the purpose of justifying individual paragraphs the package offers the command \justifying and the environment justify. Both can be customized using the length parameters \JustifyingParindent and \JustifyingParfillskip.

Thus, to produce a document with a moderate amount of raggedness and paragraphs indented by 12pt, you could use a setting like the one in the following example (compare it to Example 3-1-48 on page 104).


Unjustified settings in narrow columns

In places with narrow measures (e.g., \marginpars, \parboxes, minipage environments, or p-columns of tabular environments), the justified setting usually produces inferior results. With the option raggedrightboxes, paragraphs in such places are automatically typeset using \RaggedRight. If necessary, \justifying can be used to force a justified paragraph in individual cases.

The default values

The use of em values in the defaults (see Table 3.2) means that special care is needed when loading the package, as the em is turned into a real dimension at this point! The package should therefore be loaded after the body font and size have been established—for example, after font packages have been loaded.

Instead of using the defaults listed in Table 3.2, one can instruct the package to mimic the original LaTeX definitions by loading it with the option originalparameters and then changing the parameter values as desired.

3.1.13. setspace—Changing interline spacing

The \baselineskip command is TeX’s parameter for defining the leading (normal vertical distance) between consecutive baselines. Standard LaTeX defines a leading approximately 20% larger than the design size of the font (see Section 7.9.1 on page 413). Because it is not recommended to change the setting of \baselineskip directly, LaTeX2ε provides the \linespread declaration to allow for changing \baselineskip at all sizes globally. After \linespread{1.5}\selectfont the leading will increase immediately.1

1 In contrast the obsolete LaTeX 2.09 solution \renewcommand\baselinestretch{1.5} requires a following font size changing command (e.g., \small, \Large) to make the new value take effect.

The package setspace (by Geoffrey Tobin and others) provides commands and environments for typesetting with variable spacing (primarily double and one-and-a-half). Three commands—\singlespacing, \onehalfspacing, and \doublespacing—are available for use in the preamble to set the overall spacing for the document. Alternatively, a different spacing value can be defined by placing a \setstretch command in the preamble. It takes the desired spacing factor as a mandatory argument. In the absence of any of the above commands, the default setting is single spacing.

To change the spacing inside a document three specific environments—singlespace, onehalfspace, and doublespace—are provided. They set the spacing to single, one-and-a-half, and double spacing, respectively. These environments cannot be nested.


For any other spacing values the generic environment spacing should be used. Its mandatory parameter is the value of \baselinestretch for the text enclosed by the environment.


In the above example the coefficient “2.0” produces a larger leading than the “double spacing” (doublespace environment) required for some publications. With the spacing environment the leading is effectively increased twice—once by \baselineskip (which LaTeX already sets to about 20% above the font size) and a second time by setting \baselinestretch. “Double spacing” means that the vertical distance between baselines is about twice as large as the font size.

Since \baselinestretch refers to the ratio between the desired distance and the \baselineskip, the values of \baselinestretch for different document base font sizes (and at two different optical spacings) can be calculated and are presented in Table 3.3.


Table 3.3. Effective \baselinestretch values for different font sizes

3.1.14. picinpar—Making rectangular holes

The package picinpar (created by Friedhelm Sowa based on earlier work by Alan Hoenig) allows “windows” to be typeset inside paragraphs. The basic environment is window. It takes one mandatory argument specified in contrast to LaTeX conventions in square brackets, in the form of a comma-separated list of four elements. These elements are the number of lines before the window starts; the alignment of the window inside the paragraph (l for left, c for centered, and r for right); the material shown in the window; and explanatory text about the contents in the window (e.g., the caption).


If you look at the above example you will notice that the second paragraph is not properly indented. You can fix this defect by requesting an explicit indentation using \par\indent, if necessary.

Centering a window as in the previous example works only if the remaining text width on either side is still suitably wide (where “suitably” means larger than one inch). Otherwise, the package will simply fill it with white space.

The package also provides two variant environments, figwindow and tabwindow. They can format the explanatory text as a caption, by adding a caption number. You should, however, be careful when mixing such “nonfloating” floats with standard figure or table environments, because the latter might get deferred and this way mess up the numbering of floats.

The next example shows such an embedded figure—a map of Great Britain placed inside a paragraph. Unfortunately, the caption formatting is more or less hard-wired into the package; if you want to change it, you have to modify an internal command named \@makewincaption.

  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint