# Formatting information

## A beginner's introduction to typesetting with LATEX

### Peter Flynn

#### Silmaril ConsultantsTextual Therapy Division

v. 3.6 (March 2005)

#### Contents

Introduction
Foreword
Preface
References
Index

This edition of Formatting Information was prompted by the generous help I have received from TEX users too numerous to mention individually. Shortly after TUGboat published the November 2003 edition, I was reminded by a spate of email of the fragility of documentation for a system like LATEX which is constantly under development. There have been revisions to packages; issues of new distributions, new tools, and new interfaces; new books and other new documents; corrections to my own errors; suggestions for rewording; and in one or two cases mild abuse for having omitted package X which the author felt to be indispensable to users. ¶ I am grateful as always to the people who sent me corrections and suggestions for improvement. Please keep them coming: only this way can this book reflect what people want to learn. The same limitation still applies, however: no mathematics, as there are already a dozen or more excellent books on the market — as well as other online documents — dealing with mathematical typesetting in TEX and LATEX in finer and better detail than I am capable of. ¶ The structure remains the same, but I have revised and rephrased a lot of material, especially in the earlier chapters where a new user cannot be expected yet to have acquired any depth of knowledge. Many of the screenshots have been updated, and most of the examples and code fragments have been retested. ¶ As I was finishing this edition, I was asked to review an article for The PracTEX Journal, which grew out of the Practical TEX Conference in 2004. The author specifically took the writers of documentation to task for failing to explain things more clearly, and as I read more, I found myself agreeing, and resolving to clear up some specific problems areas as far as possible. It is very difficult for people who write technical documentation to remember how they struggled to learn what has now become a familiar system. So much of what we do is second nature, and a lot of it actually has nothing to do with the software, but more with the way in which we view and approach information, and the general level of knowledge of computing. If I have obscured something by making unreasonable assumptions about your knowledge, please let me know so that I can correct it.

Peter Flynn is author of The HTML Handbook and Understanding SGML and XML Tools, and editor of The XML FAQ.

CHAPTER
 8

# Fonts and layouts

This is the chapter that most users want first, because they come to structured documents from a wordprocessing environment where the only way to convey different types of information is to fiddle with the font and size drop-down menus.

As I hope you have seen, this is normally completely unnecessary in LATEX, which does most of the hard work for you automatically. However, there are occasions when you need to make manual typographic changes, and this chapter is about how to do them.

## 8.1 Changing layout

The design of the page can be a very subjective matter, and also rather a subtle one. Many organisations large and small pay considerable sums to designers to come up with page layouts to suit their purposes. Styles in page layouts change with the years, as do fashions in everything else, so what may have looked attractive in 1991 may look rather dated in 2011.

As with most aspects of typography, making the document readable involves making it consistent, so the reader is not interrupted or distracted too much by apparently random changes in margins, widths, or placement of objects. However, there are a number of different occasions where the layout usually does change, related to the frequency with which the format appears.

• The title page, the half-title, copyright page, dedication, and other one-page preliminaries (if you use them) are usually designed individually, as the information on it only occurs once in that format anywhere in the document.

• The table of contents and other related lists like figures and tables all need to share one design.

• The prelims like Foreword, Introduction, and Preface should likewise follow the same format between them.

• Chapter and Appendix start pages usually share a layout.

• Other (normal) pages have a single layout, but it may specify individual variations to handle tables, lists, figures, sidebars, exercises, footnotes, etc.

If you are going to design a whole document, it's probably a good idea to read a couple of books on layout design first, to get a feel for the conventions which contribute to making the reader comfortable reading.

While unusual or radical layouts have an important role in attention-grabbing, or in making a socio-political statement (WIRED magazine is an obvious recent example), they are usually out of place in business reports, white papers, books, theses, and journals. In ephemera, on the other hand, as in advertising, they are probably critical.

### 8.1.1 Spacing

We mentioned in section 7.3 and elsewhere the existence of the geometry package which lets you change margins. It also lets you set the text-area height and width and a lot of other layout settings: read the documentation for details (see section 5.1.2 for how to read package documentation).

\usepackage[left=2cm,top=1cm,bottom=2cm,right=3cm,


The spacing around the individual textual components (headings, paragraphs, lists, footnotes, etc.) can also be changed on a document-wide basis, as we saw with paragraph spacing and indentation in the text in section 3.6.

Changing the spacing of section headings for the whole document can be done with the sectsty package, designed to let you adjust section-head spacing without having to know about the internal LATEX coding, which is quite complex.

The spacing for lists can be adjusted with the mdwlist package. In both cases the user with highly specific requirements such as a publisher's Compositor's Specification should read the relevant sections in the The LATEX Companion or ask for expert help, as there are many internal settings which can also be changed to fine-tune your design, but which need some knowledge of LATEX's internals.

All the above are for automating changes so that they occur every time in a consistent manner. You can also make manual changes whenever you need:

Flexible vertical space

There are three commands \smallskip, \medskip, and \bigskip. These output flexible (dynamic, or ‘rubber’) space, approximately 3pt, 6pt, and 12pt high respectively, and they will automatically compress or expand a little, depending on the demands of the rest of the page (for example to allow one extra line to fit, or a heading to be moved to the next page without anyone except a typographer noticing the change). These commands can only be used after a paragraph break (a blank line or the command \par).

Fixed vertical space

For a fixed-height space which will not stretch or shrink, use the command \vspace followed by a length in curly braces, e.g. \vspace{18pt} (again, this has to be after a paragraph break). Bear in mind that extra space which ends up at a page-break when the document is formatted will get discarded entirely to make the bottom and top lines fall in the correct places. To force a vertical space to remain and be taken into account even after a page break (very rare), use the starred variant \vspace*, e.g. \vspace*{19pt}.

Double spacing

Double-spacing normal lines of text is usually a bad idea, as it looks very ugly. It is still unfortunately a requirement in some universities for thesis submission, a historical relic from the days of typewriters. Nowadays, 1⅓ or 1½ line spacing is considered acceptable, according to your font size. If your institution still thinks they should have double line spacing, they are probably wrong, and just don't understand that the world has moved on since the typewriter. Show them this paragraph and explain that they need to enter the 21st century and adapt to the features of computer typesetting. If they still insist, use the setspace package,which has commands for double line-spacing and one-and-a-half line spacing, but be prepared for some very ugly output (so warn your supervisor and extern).

The space between lines is defined by the value of the length variable \baselineskip multiplied by the value of the \baselinestretch command. In general, don't meddle with \baselineskip at all, and with \baselinestretch only if you know what you are doing. (Both can, however, safely be used as reference values in commands like \vspace{\baselineskip} to leave a whole line space.)

The value of \baselineskip changes with the font size (see section 8.2.4) but is conventionally set to 1.2 times the current nominal font size. This is a value derived from long experience: only change it if you understand what it means and what effect it will have.

Quite separately, there are some perfectly genuine and normal reasons for wanting wide line spacing, for example when typesetting a proof of a critical or variorum edition, where editors and contributors are going to want to add notes manually by writing between the lines, or where the text is going to be overprinted by something else like Braille, or in advertising or display text for special effects.

Horizontal space

There is a horizontal equivalent to the \vspace command: \hspace, which works in the same way, so I can force a 1″ space like thisin mid-paragraph. There are also some predefined (shorter) spaces available:

• \thinspace (1/6em), which we saw between single and double quotes in the last paragraph in section 2.6. It's also sometimes used between the full point after abbreviations and a following number, as in page references like p. 199, where a word space would look too big, and setting it solid would look too tight.

• \enspace (½em). There is no direct equivalent predefined in LATEX for mid and thick spaces as used by metal typesetters, although it would be possible to define them. The en as a unit is often used as the width of a single digit in some fonts, as a convenience so that tables of figures are easy to line up.

• \quad (1em).

• \qquad (2em).

Beyond this, all horizontal space within paragraphs is automatically flexible, as this is what LATEX uses to achieve justification. Never be tempted to try and change the spacing between letters unless you have some professional training in typography. Some systems use letterspacing (incorrectly called ‘tracking’) as an aid to justification and it is almost always wrong to do so (and looks it). While it is possible to change letterspacing (with the soul package), it should only be done by a typographer, and then only very rarely, as the settings are very subtle and beyond the scope of this book.

LATEX has built-in settings to control the page style of its default page layouts. These are implemented with the \pagestyle command, which can take one of the following arguments.

plain

for a page number centered at the bottom;

empty

for nothing at all, not even a page number;

for running heads based on the current chapter and section;

which lets you use your own reprogrammed definitions of how \markright and \markboth commands, which control how chapter and section titles get into page headers.

The command \thispagestyle (taking the same arguments) can be used to force a specific style for the current page only.

However, the easiest way is to use the fancyhdr package, which lets you redefine the left-hand, centre, and right-hand page headers and footers for both odd and even pages (twelve objects in all). These areas can contain a page number, fixed text, variable text (like the current chapter or section title, or the catch-words of a dictionary), or even a small image. They can also be used to do page backgrounds and frames, by making one of them the top corner of an invisible box which ‘hangs’ text or images down over the whole page.

The settings for the downloadable version of this document can be used as an example: for the whole story you have to read the documentation.

\pagestyle{fancy}\fancyhead{}
\rightmark}
\fancyfoot[C]{}
\fancyfoot[LE,RO]{\setlength{\fboxsep}{2pt}\ovalbox%
{\footnotesize\sffamily\thepage}}
\fancyfoot[LO,RE]{\footnotesize\sffamily\lite\@title}
\fancypagestyle{plain}{\fancyhf{}
\fancyfoot[R]{\setlength{\fboxsep}{2pt}\ovalbox{%
\footnotesize\sffamily\thepage}}
\fancyfoot[L]{\footnotesize\sffamily\lite\@title}


This is probably more complex than most documents, but it illustrates some common requirements:

1. Settings are prefixed by making the \pagestyle ‘fancy’ and setting the \fancyhead to null to zap any predefined values.

2. The thickness of the rule at the top of the page can be changed (or set to 0pt to make it disappear).

3. The header and footer settings are specified with L, C, and R for left, centre, and right; and with O and E for Odd and Even numbered pages. In each setting, the typeface style, size, and font can be specified along with macros which implement various dynamic texts (here, the current chapter and section titles, which LATEX stores in \rightmark and \leftmark).

4. The ‘plain’ variant is used for chapter starts, and resets some of the parameters accordingly.

## 8.2 Using fonts

The default typeface in LATEX is Computer Modern (CM). This typeface was designed by Knuth for use with TEX because it is a book face, and he designed TEX originally for typesetting books. Because it is one of the very few book typefaces with a comprehensive set of fonts, including a full suite of mathematics, it has remained the default, rather than the Times you find in wordprocessors, because until recently the mathematical symbols for Times were a commercial product often unavailable to users of free software.

If you are reading this in a web browser, the above paragraph is only a low-resolution copy because browsers don't usually have the Computer Modern font available. All the rest of this document is set in your current browser serif font, with your current browser sans-serif font for some of the headings and your current browser monospace font for the fixed-width type.

In addition to CM, there are many other METAFONT fonts which can be downloaded from CTAN, including a large collection of historical, symbol, initial, and non-Latin fonts. LATEX also comes with the ‘Adobe 35’ typefaces which are built into laser printers and other DTP systems, and some more fonts donated by the X Consortium. Plus, of course, standard LATEX can use any of the thousands of Type 1 fonts available, and pdfLATEX can use any of the thousands of TrueType fonts as well.

In the following lists, if there is a package available, its name is given in parentheses after the name of the typeface. The font-family name is shown on the right-hand side. If a non-standard font-encoding is needed, its name is shown before the font-family name.

### Latin-alphabet typefaces (METAFONT)

Computer Modern Roman cmr

Computer Modern Sans cmss

Computer Modern Typewriter cmtt

Pandora panr

Pandora Sans pss

Pandora Typewriter pntt

Universal uni

Concrete ccr

Rustic rust

Uncial uncl

Dürer zdu

Fraktur yfrak

Gothic ygoth

Schwäbische yswab

### Latin-alphabet typefaces (PostScript Type 1) from Adobe

Avant Garde pag

Bookman pbk
Uses Avant Garde as the sans-serif and Courier for monospace.
Courier pcr

Helvetica phv

New Century Schoolbook pnc
Uses Helvetica as the sans-serif font and Courier for monospace.
Palatino ppl
Uses Avant Garde as the sans-serif and Courier for monospace.
Symbol psy

Times New Roman ptm
Uses Helvetica as the sans-serif font and Courier for monospace. Mathematical symbols for Times are available both free and commercially.
Zapf Chancery pzc

Zapf Dingbats pzd

As mentioned in section 4.4, the ‘Adobe 35’ fonts can be used with any printer, not just a laser printer or typesetter. The Ghostscript interpreter and the GSview viewer come with a large set of printer drivers, so you just create PostScript output and print from GSview.

Incidentally, the 35 refers to the total number of fonts for the 10 typefaces, including their bold, italic, and bold-italic variants.

Postscript Type 1 fonts have been the mainstay of the graphic arts industries for many years, as they allow much better definition of variance (‘hinting’) than most other formats. However, the font format remains proprietary to Adobe, even though they have released it for public use, which means they could change it without warning. A new format called ‘OpenType’ is designed to overcome this, and some versions of TEX are already able to use OpenType fonts.

### Latin-alphabet fonts (PostScript Type 1) from the X Consortium

Charter bch

Nimbus Roman unm

Nimbus Sans unms

URW Antiqua uaq

URW Grotesk ugq

Utopia put
Removed from recent distributions as it is not free.

### Non-Latin-alphabet typefaces (METAFONT)

BB Dingbats ding

Cypriot cypr

Etruscan etr

Linear B' linb

Phoenician phnc

Runic fut

Bard zba

Just to make it clear: standard LATEX uses only METAFONT and PostScript Type 1 fonts. pdfLATEX can use TrueType fonts as well.

### 8.2.1 Changing the default font family

LATEX expects to work with three font families as defaults:

Font family Code
Roman (serif, with tails on the uprights), the default rm
Sans-serif, with no tails on the uprights sf
Monospace (fixed-width or typewriter) tt

The start-up default for LATEX equates the rm default with the cmr font-family (Computer Modern Roman), sf with cmss, and tt with cmtt. If you use one of the packages listed in the table in section 8.2, it will replace the defaults of the same type: for example, \usepackage{bookman} makes the default rm font-family Bookman (pbk), but leaves the sans-serif (sf) and monospace (tt) families untouched. Equally, \usepackage{helvet} changes the default sans-serif family to Helvetica but leaves the serif (Roman) and monospace families untouched. Using both commands will change both defaults because they operate independently.

However...as it is common to want to change all three defaults at the same time, some of the most common ‘suites’ of typefaces are provided as packages:

times

changes to Times/Helvetica/Courier.

pslatex

same as times but uses a specially narrowed Courier to save space (normal Courier is rather inelegantly wide). This is the preferred setting if you want Times.1

newcent

changes to New Century Schoolbook/Helvetica/Courier.

palatino

changes to Palatino/Avant Garde/Courier.

palatcm

changes the roman to Palatino only, but with CM mathematics

Where no package name is given in the table in section 8.2, it means the font is rarely used as a default by itself except in special cases like users' own homebrew packages. To use such a font you have to specify it manually, or make a little macro for yourself if you use it more than once.

1. The pslatex package is also said to be outdated by some experts because it implements rather long-windedly what can now be done in three commands. However, until these replace the current version, I recommend continuing to use pslatex when you want Times with Helvetica and narrow Courier.

### 8.2.2 Changing the font-family temporarily

To shift to another font family on a temporary basis, use the commands \fontencoding (if needed), \fontfamily, and \selectfont, and enclose the commands and the text in curly braces. Note that this is a different way of using curly braces to how we have used them before: it limits the effect of a change to the material inside the braces.

{\fontfamily{phv}\selectfont
Helvetica looks like this}:
{\fontencoding{OT1}\fontfamily{bch}\selectfont
Charter looks like this}.


Helvetica looks like this: Charter looks like this.

In this example, the \fontencoding command has been used to ensure that the typeface will work even if the sentence is used in the middle of something typeset in a different encoding (like this document).2

In a normal document, of course, random typeface changes like this are rather rare. You select your typeface[s] once at the start of the document, and stick with them.

Most cases where people want to do unusual typeface changes involve things like special symbols on a repetitive basis, and LATEX provides much easier programmable ways to make these changes into shorthand commands (called macros: see Chapter 9). You could, for example, make a macro called \product which would let you typeset product names in a distinct typeface:

Andlinger, Inc., has replaced \product{Splosh} with
\product{SuperSplosh}.


This is one of LATEX's most powerful features. It means that if you needed to change your \product command at some later stage to use a different font, you only have to change three characters in the macro (the font-family name), and you don't need to edit your document text at all! What's more, a macro could do other things at the same time, like add an entry to an index of products.

However, vastly more common are changes to type style, while staying with the same font-family.

### 8.2.3 Changing font style

Within each typeface or font family there are usually several different ‘looks’ to the type design. LATEX distinguishes between font family, font shape, and font series:

Type style Command Example (using Computer Modern)
Upright \upshape*
Italic \itshape
Slanted \slshape*
Small Capitals \scshape* THE QUICK BROWN FOX JUMPS OVER THE
Bold \bfseries*
Bold Extended \bfseries
Sans-serif \sffamily
Monospace \ttfamily
*) Not all typefaces have all variants! Some only have bold and italics.
) Some typefaces do not have both bold and bold extended: by default LATEX uses \bfseries for bold extended.

These ‘shape’, ‘series’, and ‘family’ commands are commutative, so you can combine a shape with a series and/or a family, without the need to use \selectfont:

This gives you {\bfseries\itshape\sffamily bold
italic sans-serif type}, but beware


This gives you bold italic sans-serif type, but beware of pushing your fonts beyond their limits unless you are a typographer. It is not normally meaningful to combine one shape or series class with another of the same class, such as trying to get slanted-italics. It's an impossibility to combine one family with another (such as a seriffed sans-serif typeface!). Slanted plus italics, for example, doesn't make sense, as italics are already slanted (although it is technically possible); and while some typefaces may well possess italic small caps, they are not in common use. Sans-serif and monospace (typewriter) are different fonts, and often different typeface families entirely.3

There is an alternative syntax for the most common type shape and series commands which uses curly braces in the normal ‘argument’ manner:

Type style Command Example
Italic \textit{text} puts text into italics
Slanted \textsl{text} puts text into slanted type*
Small Capitals \textsc{text} puts TEXT into small caps
Bold \textbf{text} puts text into bold type
Sans-serif \textsf{text} puts text into sans-serif type
Monospace \texttt{text} puts text into typewriter type
*) If slanted is available separately from italics.

You can nest these inside one another too:

...\textbf{\itshape\textsf{bold italic
sans-serif type}}...


Underlining isn't a font, and it is extremely rare in typography except for special purposes. If you think you need it, use the ulem package with the normalem option, and the \uline command.

### 8.2.4 Font sizes

LATEX has built into its defaults a set of predefined font size steps corresponding more or less to the traditional sizes available to metal typesetters. This is deliberate, as these sizes have grown up over 500 years of printing as those which go best together for book-work, which is where TEX originated.

These sizes are also reflected in the size steps at which Computer Modern was designed. It often comes as a surprise to new users that many typefaces are not designed as a single font and just scaled up or down, but specially drawn at different sizes to make them more legible.

As an example, , and , and so you can see there really is a significant difference. In general, you probably don't want to go scaling fonts too much beyond their design size because they will start to look very odd.

The default sizes (and the commands that operate them) are based on the use of a 10pt font, which is the normal size for most texts. Using the larger defaults (11pt and 12pt) for the body font will use 11pt and 12pt designs, with other sizes (eg headings) resized to match. The exact sizes used are listed in the macros in the Class Option files size10.clo, size11.clo and size12.clo. TEX's default fonts above 10pt are in fact scaled by a factor of 1.2, as shown in the fourth column of the table below.

Command Example Nominal point size Exact point size
\tiny The quick brown fox jumps over the lazy dog 5 5
\scriptsize The quick brown fox jumps over the laz 7 7
\footnotesize The quick brown fox jumps over the l 8 8
\small The quick brown fox jumps over th 9 9
\normalsize The quick brown fox jumps over 10 10
\large The quick brown fox jumps 12 12
\Large The quick brown fox ju 14 14.40
\LARGE The quick brown fo 18 17.28
\huge The quick brown 20 20.74
\Huge The quick bro 24 24.88

While these ‘shorthand’ commands relieve the beginner of having to worry about the ‘right’ size for a given task, when you need a specific size there is the \fontsize command:

\fontsize{22}{28}\selectfont This is 22pt


‘Leading’ comes from the old metal-type practice of adding a lead strip between lines to increase the spacing.

The \fontsize command takes two arguments: the point size and the baseline distance. The above example gives you 22pt type on a 28pt baseline (i.e. with 6pt extra space or ‘leading’ between the lines).

Computer Modern fonts (the default) come fixed at the named size steps shown in the table, and if you try to use an odd size in between, LATEX will pick the closest step instead. If you really need to use CM at arbitrary sizes there is a package type1cm which lets you override the default steps. If you use PostScript (Type 1) fonts, the step sizes do not apply and the font scaling is infinitely variable.

### 8.2.5 Logical markup

All this playing around with fonts is very pretty but you normally only do it for a reason, even if that reason is just to be decorative. Italics, for example, are used for many things:

Cause Effect
Foreign words ex officio
Scientific names Ranunculus ficaria
Emphasis must not
Titles of documents The LATEX Companion
Product names Corel's WordPerfect
Variables in maths E=mc2
Subtitles or headings How to get started

Humans usually have no problem telling the difference between these reasons, because they can read and understand the meaning and context. Computers cannot (yet), so it has become conventional to use descriptive names which make the distinction explicit, even though the appearance may be the same.

LATEX has some of these built in, like \emph, which provides emphasis. This has a special feature because when the surrounding text is already italic, emphasis automatically reverts to upright type, which is the normal practice for typesetting.

This has a special feature because {\itshape when the
surrounding text is already italic, \emph{emphasis}
automatically reverts to upright type, which is the


This sensitivity to logic is programmed into the definition of \emph and it's not hard to make up other commands of your own which could do the same, such as \foreign or \product.

But why would you bother? In a short document it's probably not important, but if you're writing a long report, or a formal document like an article, a book, or a thesis, it makes writing and editing hugely easier if you can control whole groups of special effects with a single command, such as italicising, indexing, or cross-referencing to a glossary. If a format needs changing, you only have to change the definition, and every occurrence automatically follows suit.

Beware of this ‘vaine conceipt of simple men, which judge things by ther effects, and not by ther causes’. (Edmund Spenser, 1633)  It's hugely more efficient to have control of the cause than the effect.

It also makes it possible to find and act on groups of meanings — such as making an index of scientific names or product names (as in this document) — if they are identified with a special command. Otherwise you'd spend weeks hunting manually through every \textit command to find the ones you wanted. This is the importance of automation: it can save you time and money.

In Chapter 9 we will see how to make your own simple commands like this.

### 8.2.6 Colour

You can typeset anything in LATEX in any colour you want using the color package. First, you need to add the command \usepackage{color} to your preamble (note the US spelling of color!). This makes available a default palette of primary colours: red, green, and blue for the RGB colour model used for emitted light (television screens), and cyan, magenta, yellow, and black for the CMYK colour model used for reflected light (printing).

For the occasional word or phrase in colour, use the command \textcolor with two arguments, the colour name and the text: \textcolor{red}{like this}. There is a \color command as well, for use within groups:

...{\color{blue}some text in blue}...


If you have the PostScript printer driver dvips installed, you also get a separate 64-colour palette of predefined color names. These represent approximately the colours in the big box of Crayola colouring pencils much favoured by artists and designers. This adds a new colour model called ‘named’, so if you want the Crayola colour RubineRed, you can use the \color or \textcolor commands with a preceding optional argument ‘named’:

\color[named]{RubineRed}
\textcolor[named]{RubineRed}{some red text}


As some of the ‘named’ colour names are quite long, you can create a short name of your own for colours you use frequently, using the \definecolor command:

\definecolor{mb}{named}{MidnightBlue}


The \definecolor command needs three arguments: your shorthand name, the name of the colour model, and the colour specification. In the case of the ‘named’ model, the last argument is one of the 64 colour names. To use these names with pdfLATEX, you need to use the pdftex option to the color package.

Using the \definecolor command, you can define any colour you want by giving it a name, specifying which colour model, and providing the Red-Green-Blue (RGB) or Cyan-Magenta-Yellow-Black (CMYK) colour values expressed as decimals, separated by commas. For example, an RGB shade given as (37,125,224) in decimal (#250FE0 in hexadecimal as used on the Web) can be given as

\definecolor{midblue}{rgb}{0.145,0.490,0.882}

(divide each value by 255, the maximum for each of the hues in the Red-Green-Blue colour model). You can then use \textcolor with your new colour name: the midblue looks like this if you're reading in colour.

The color package also provides a colour version of \fbox (see section 6.7.2) called \colorbox:

\colorbox{midblue}{\color{magenta}Magenta on midblue}


Magenta on midblue: you can see how careful you need to be with colours!

## 8.3 Installing new fonts

Different fonts come in a variety of packagings: the three most common used with TEX systems are PostScript fonts, TrueType fonts, and METAFONT fonts. How you install them and where they go depends on how you installed LATEX: all I can deal with here are the standard locations within the TDS.

Typefaces come supplied as one or more font ‘outline’ files and a number of ancillary files:

METAFONT typefaces

have a number of .mf source (outline) files, possibly also some .fd (font definition) files and a .sty (style) file. The .tfm (TEX font metric) files are not needed, as they can be generated from the outlines.

PostScript typefaces

come as a pair of files: a .pfb (PostScript font binary) or .pfa (PostScript font ASCII) outline, and an .afm (Adobe font metric) file. There may also be .inf and other files but these are not needed for use with TEX systems.

TrueType typefaces

are a single .ttf file, which combines outline and metrics in one.

The instructions here assume the use of the New Font Selection Scheme (NFSS) used in LATEXε. If you are running the obsolete LATEX 2.09, upgrade it now.

### 8.3.1 Installing METAFONT fonts

This is the simplest installation. When you download METAFONT fonts from CTAN, you'll usually find a large number of outline files (.mf files) and maybe some other types as well (see below).

1. Create a new subdirectory named after the typeface you're installing in texmf-local/fonts/source/public/:

2. Copy all the .mf files to this directory.

3. Copy the .fd (Font Definition) file[s] and the .sty (style) file to your texmf/tex/latex/mfnfss directory.

4. Run your TEX indexer program (see step 4 in the procedure in section 5.2.2).

That's it. Unlike PostScript fonts, METAFONT fonts can be used to generate the font metric file (.tfm files) automatically on-the-fly the first time the typeface is used, so there should be nothing else to install.

Now you can put a \usepackage command in your preamble with whatever name the .sty file was called, and read the documentation to see what commands it gives to use the font (refer to the last paragraph in section 5.2.1 and step 2).

If the font came without.fd or .sty files, you'll need to find someone who can make them for you (or follow the outline in section 8.3.2, step 11).

#### 8.3.1.1 Pre-generated metrics (optional)

Some METAFONT fonts come with pre-generated .tfm files which you can install if your system is slow at generating them itself:

1. Create a new subdirectory within texmf-local/fonts/tfm/public/ named the same as the one you created for the .mf files above.

2. Copy all the .tfm files into this subdirectory.

3. Run your TEX indexer program (see step 4 in the procedure in section 5.2.2).

#### 8.3.1.2 Pre-generated bitmaps (optional)

In some rare cases, pre-generated packed bitmap fonts (.pk files) are also available from CTAN (normally your previewer and print driver creates these automatically, but you can use the pre-generated ones if you have a very slow system). If you really want to install these, it's a similar procedure to the .tfm files:

1. Create a new subdirectory within texmf-local/fonts/pk/modeless/ named the same as the one you created for the .mf and .tfm files above.

2. Copy all the .nnnpk files into this subdirectory (nnn is a number reflecting the dot-density of the bitmap). On Microsoft systems the files may just end in .pk and be kept in subdirectories named after the dot-density, e.g. dpi360.

3. Run your TEX indexer program (see step 4 in the procedure in section 5.2.2).

### 8.3.2 Installing PostScript fonts

Lots of people will tell you that PostScript fonts and PostScript output are dead and that TrueType or OpenType fonts and PDF output are the way to go. While this is true for many cases, standard LATEX does not work with TrueType fonts and does not produce PDF directly. Only pdfLATEX does that, and there are still many printers whose typesetters and platemakers use PostScript rather than PDF. In addition, operating system support for scalable fonts is still very poor on Unix systems (including Linux), despite the advances in recent years, so in many cases it still makes sense to use TEX's built-in support for PostScript.

Two files are needed for each font: the .afmAdobe Font Metric (AFM) and the .pfbPostScript Font Binary (PFB) files. You must have both for each font before you start. If you only have the near-obsolete .pfaPostScript Font ASCII (PFA) files, it may be possible to generate the .pfb files using the t1binary program from the t1utils suite (see http://gnuwin32.sourceforge.net/packages/t1utils.htm) or the excellent PFAedit font editor (from http://pfaedit.sourceforge.net). There are unfortunately still some companies distributing Type 1 fonts in .pfa format (Mathematica is one reported recently).

The installation method I described in earlier editions has worked perfectly for me for years, but I have updated it here to use the facilities of the updmap program (which comes with your TEX installation). This removes the need for one of the steps I gave before, which required editing the psfonts.map file, as this is now recreated by updmap. The procedure below is not the official way (that's fontinst), but it is the basis for a script I am working on called Gutta-Percha4, which automates the whole process.

I'll repeat this: before you start, make sure you have all the .afm and .pfb files for the typeface you want. In the example below, I'm going to use a single font from an imaginary typeface called Foo, so I have foo.afm and foo.pfb files.

1. Put the files in your temporary directory

This is /tmp on Linux, and should be C:\tmp or C:\temp or even C:\Windows\temp on Microsoft Windows.

2. Decide on the short font name to use inside LATEX.

This is not the full descriptive name (e.g. Baskerville Italic Bold Extended) but an encoded font name in the format fnnsseec, devised by Karl Berry, which stores the same information in no more than eight characters for compatibility with systems which cannot handle long filenames. The letters in the format above have the following meanings (see the fontname documentation on your computer for more details):

Letter Meaning Examples
f foundry b=Bitstream, m=Monotype, p=Adobe
nn typeface ba=Baskerville, tm=Times, pl=Palatino
ss series/shape r=roman, bi=bold italic, etc.
ee encoding 8a=default 8-bit ANSI, ly=Y&Y's TEX'n'ANSI
c [small]caps (this is a literal ‘c’ character, used only if needed)

The texmf/fontname directory in your installation of LATEX has files for several foundries giving fully-formed names like these for common fonts (e.g. ptmr8a is [Adobe] Post­Script Times Roman in an 8–bit ANSI encoding; bgslly is Bitstream Gill Sans Light in Y&Y's TEX'n'ANSI encoding [LY1]).5 Read the documentation in Fontname: Filenames for TEX fonts to find out how to make up your own short names if the foundry and font you want is not shown in the fontname directory.

In this example we'll call our mythical example typeface ‘zork’ (standing for Zfonts Ordinary Bookface, because k is the letter used for Book fonts, b being already the code for bold) and we'll assume the font comes in the two files foo.afm and foo.pfb that I mentioned above.

While the fontname directories have ready-made lists of these names for popular collections of typefaces, making them up requires some knowledge of typographic terms and a careful reading of the fontname documentation.

This is what tripped me up the first few times until someone pointed me at Y&Y's6TEX'n'ANSI encoding which (to me) seems to be the only one that includes the glyphs I want where I want them.7 Your mileage may vary. This encoding is referred to as LY1 within LATEX and the encoding file is in texmf/dvips/base/texnansi.enc. Encoding is needed because Adobe fonts store their characters in different places to the TEX standard.

Copy this encoding file to the temporary directory where you're doing all this stuff. If you're using the 8a or 8r encoding (or some other encoding), then copy that file instead (8a.enc, 8r.enc).

4. Convert .afm files to .tfm

The afm2tfm program is a standard utility in the bin directory of your TEX installation. If it's not, update your installation.

In a command window, type:

afm2tfm foo.afm -v zorkly.vpl -p texnansi.enc \
rzorkly.tfm >zork.id


(Here and elsewhere I have sometimes had to break the line to fit it on the printed page. It's actually all typed as one long line if you omit the backslash.)

This creates a special ‘raw’TEX Font Metric file (hence the special r prefix) that LATEX can use, with a list of all its properties encoded with LY1 (the .vpl or Virtual Property List file). Many people will tell you that virtual fonts are dead and that this is the wrong way to do it, but no-one has ever shown me an alternative that works, so I stick with it.

5. Small caps (optional)

If you want a small caps variant faked up (perhaps because the typeface family doesn't have a special small-caps font), repeat the medicine like this:

afm2tfm foo.afm -V zorklyc.vpl -p texnansi.enc \
rzorkly.tfm >>zork.id


Note the capital V option here. Yes, it does overwrite the rzorkly.tfm created in the first command. Let it. And those are two of the ‘greater-than’ signs before the zork.id filename because we want to append to it, not overwrite it.

6. Create the virtual font

Turn the .vpl files into .vf and .tfm pairs. LATEX uses these to convert from Adobe's encoding to its own.

vptovf zorkly.vpl zorkly.vf zorkly.tfm
vptovf zorklyc.vpl zorklyc.vf zorklyc.tfm


Again, the vptovf program is a standard part of your TEX distribution.

7. Make directories to hold the files

Under your texmf-local directory there should be a fonts directory, and in there there should be afm, tfm, type1, and vf directories. Create them if they do not already exist.

In each of these four, create a directory for the foundry, and within them create a directory for the typeface (using a human-readable typeface name, not the short Karl Berry fontname). In our example, this means:

cd /usr/TeX/texmf-local/fonts
mkdir -p afm/zfonts/ordinary
mkdir -p tfm/zfonts/ordinary
mkdir -p type1/zfonts/ordinary
mkdir -p vf/zfonts/ordinary
cd /tmp


Or if you're lazy like me:

(cd /usr/TeX/texmf-local/fonts;\
for d in afm tfm type1 vf;\
do mkdir -p \$d/zfonts/ordinary;done)


For Microsoft Windows users, the path before texmf-local may look something like C:\Program Files\TeXLive\, depending on how and where you have installed your TEX system.

The -p is a Unix feature: it automatically creates any missing intervening subdirectories. If your directory-making command doesn't do this, you'll have to make the intervening directories by hand first.

8. Copy the files to their rightful places

Copy the four groups of files to the four new directories:

cp *.afm /usr/TeX/texmf/fonts/afm/zfonts/ordinary/
cp *.tfm /usr/TeX/texmf/fonts/tfm/zfonts/ordinary/
cp *.pfb /usr/TeX/texmf/fonts/type1/zfonts/ordinary/
cp *.vf /usr/TeX/texmf/fonts/vf/zfonts/ordinary/


You can of course do all this with a directory window and mouse if you find it easier.

9. Create a font map

The font map is what tells dvips which PFB file to use for which font. The configuration file for dvips is texmf/dvips/config/config.ps and it gets its entries from the program updmap which reads map files for each typeface. The configuration file for updmap is texmf-var/web2c/updmap.cfg8, so it needs an entry for our new font, using the three-letter font family abbreviation (the first three letters of the Berry fontname (here ‘zor’):

Map zor.map


We also have to create this map file (zor.map) in a subdirectory of texmf-local/dvips/config/ named after the foundry, so we need to create texmf-local/dvips/config/zfonts as well.

1. Open /usr/TeX/texmf-var/web2c/updmap.cfg in your editor.

2. At the bottom, add the line: Map zor.map

3. Save and close the file.

The font entries in our zor.map will be on a single line each, with no line-wrapping. Each entry gives the short name of the font, the long (Adobe) name, the PostScript encoding parameters (in quotes), and then two filenames prefixed by input redirects (less-than signs): the encoding file and the PostScript outline file.

1. First create the directory if it doesn't already exist:

mkdir -p /usr/TeX/texmf-local/dvips/config/zfonts

2. Use your editor to open (create) the file /usr/TeX/texmf-local/dvips/config/zfonts/zor.map.

3. Insert the line:

rzorkly Ordinary-Blackface "TeXnANSIEncoding ReEncodeFont" <texnansi.enc <foo.pfb

4. Save and close the file.

You get the full font name (here, ‘Ordinary-Blackface’) from the zork.id which was created back in step 4 when we ran afm2tfm. You must get this exactly right, because it's the ‘official’ full name of the font, and PostScript files using this font need to match it.

10. Create a style file

LATEX needs a style file to implement the interface to the font. Call it after the typeface or something related; in this example we'll call it foozork.sty. In it go some details of the name and date we did this, what version of LATEX it needs, and any other command necessary to operate the font, like the font encoding and whether it is to supersede the current default Roman font.

1. Use your editor to open (create) foozork.sty in your texmf-local/tex/latex/psnfss directory.

2. Insert the following lines:

% foozork - created from foo for Zork
\def\fileversion{1.0}
\def\filedate{2002/12/03}
\def\docdate{2002/12/03}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{foozork}
[\filedate\space\fileversion\space
Zfonts Ordinary PSNFSS2e package]
\RequirePackage[LY1]{fontenc}
\renewcommand{\rmdefault}{zor}
\endinput


Note the following:

• The first argument to \ProvidesPackage  must be the same as this style file name; and that the font family is referred to as zor, being the foundry letter plus the fontname abbreviation. This acts as a prefix for any/all font variants (bold, italic, etc.).

• If you are not using Y&Y encoding, omit the line referring to LY1 font encoding.

• If this is a typewriter font, make the renewed command \rmdefault into \ttdefault.

• If it's a sans-serif font, make it \sfdefault instead.

• Omit the command completely if you don't want the style file to supersede the current defaults but simply to make the font available. If you do this, you probably want to write a new command or two to use it, typically one for grouped use and one for argument use:

\newcommand{\zorkfamily}{\fontencoding{LY1}%
\fontfamily{zor}\selectfont}
\newcommand{\textzork}[1]{{\zorkfamily#1}}

3. Save and close the file.

11. Create the Font Definition file

The last file to create is the font definition (.fd) file. This is named following the pattern eeefnn.fd, using the same conventions as before, by prepending the (lowercase) encoding abbreviation to the foundry letter and fontname abbreviation, so our example would be ly1zor.fd for the LY1 encoding and the zor short font name.

1. Use your editor to open (create) texmf-local/tex/latex/psnfss/ly1zor.fd

2. Enter the following lines:

\ProvidesFile{ly1zor.fd}[2002/03/03 v0.1 manual
font definitions for LY1/zor.]

\DeclareFontFamily{LY1}{zor}{}

\DeclareFontShape{LY1}{zor}{k}{n}{<-> zorkly}{}
\DeclareFontShape{LY1}{zor}{k}{sc}{<-> zorklyc}{}

3. Save and close the file.

FD files typically use one \DeclareFontFamily command which specifies the encoding and the short font name. Then as many pairs of \DeclareFontShape commands as you converted fonts (assuming you did both normal and small caps for each font: see step 5; if you didn't, then only one such command per font is needed here). The arguments to the \DeclareFontShape command to watch are the 3rd (weight/width), 4th (shape), and 5th (font outline name): the rest are static for each .fd file and simply identify the encoding and the font family.

The codes to use are given on pages 414–15 of the The LATEX Companion and should also be in your copies of texmf/fontnames/weight.map and texmf/fontnames/width.map. The rules for combining weight and width need care: RTFM for fontname. There is no shape.map in fontname because it's not part of font file names, it's purely a LATEX creation, so here's what the same book says:

Character Meaning
n normal (upright)
it italic
sl slanted
sc small caps
ui upright italic
ol outline

Add your own for other oddities, but be consistent: I use cu for cursive (scripts), for example, and k for blackletter faces (not to be confused with k as a width for ‘book’).

The default fontspec <-> in the 5th argument in the \DeclareFontShape command means that all sizes are to come from the same font outline (remember if this was a METAFONT font with different design sizes like CM it would be much more complex).

If the face has only a few variants, you can create any other entries for bold, italic, slanted, etc. with the relevant weight and width and shape values pointing at the relevant outline file.

If you want one font to substitute for a missing one (for example italics to substitute for slanted in a typeface which has no slanted variant of its own) give the ssub (‘silent substitution’) command in the fontspec: for example to make all references to sl (slanted) type use an existing italic font, make the 5th argument like this:

{<-> ssub * zor/m/it}


If you find the x-height of a font too big or too small to sort well with another font you are using, you can specify an s (‘scale’) factor in this argument instead: this example will shrink the result to 80% of normal:

{<-> s * [0.8] zorkly}

12. Update the index and the map files

Run your TEX indexer program (see step 4 in the procedure in section 5.2.2) so that updmap can find the files it needs.

Then run updmap (just type updmap). This updates the maps and runs the TEX indexer program again automatically.

Now you can \usepackage{foozork} in your LATEX file to make it the default font. To use the font incidentally instead of as the default, you can say:

This is {\zorkfamily ZORK} or \textzork{ZORK}


### 8.3.3 Installing the Type 1 Computer Modern fonts

Most new distributions of LATEX use the PostScript Type 1 versions of the Computer Modern fonts. If your LATEX installation uses the METAFONT (bitmap) versions of CM, you may want to switch to the Type 1 version, especially if you are going to be using pdfLATEX instead of standard LATEX, because Acrobat Reader makes such a hames of displaying Type3 fonts. GSview and pdfview handle them correctly.

To do this, install one of the sets of CM PostScript fonts. There are several available:

The BaKoMa fonts include the American Mathematical Society (AMS) fonts for extended mathematics, but are more complex to install because they come with a special set of TFM files.

The BlueSky fonts are just PFB and AFM files, and are a drop-in replacement requiring no further changes, as they use the same TFM files as the METAFONT version. Follow the README` file in the downloadable archive for installation instructions.

The Latin Modern and CM-Super fonts are new and I haven't tested them but they are well spoken of. Feedback on this is very welcome.

The TEX Live and TEX Collection distributions use Type 1 versions of Computer Modern by default. There are more details in the FAQ at http://www.tex.ac.uk/cgi-bin/texfaq2html?label=uselmfonts .