×Top 20 recent searches

Formatting information
An introduction to typesetting with LATEX

Fonts and layouts

 
Copyright © 2010 Silmaril Consultants, version 5.6 (2011-10-26)

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.

ToC8.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 them 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.

  • Longer 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 within the page there will be 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.

ToC8.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,
  nohead,nofoot]{geometry}

Bear in mind when using the geometry package that you only need to specify some of either the margins or the text height/width. Because it knows the paper size already, if you give it the text width and the left-hand margin, for example, it can work out the right-hand margin. A new feature introduced in 2010 is the \newgeometry command, which lets you reset the margin settings in mid-document. This isn't something you want to do very often, but until now it had been very difficult to do.

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. There are a lot of packages available to do various aspects of this, far too many to list here: search CTAN to find what you need.

Changing the spacing of section headings for the whole document can be done with the sectsty or section packages, 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 aware that it will not look pretty.

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 \hspace{1in} will insert a 1″ space like this\hspace*{1in}in 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.5. 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 used as the width of a single digit in many 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 inter-letter spacing (incorrectly called ‘tracking’) as an aid to justification and it is almost always wrong to do so (and looks it). While it is of course possible to change letterspacing in LATEX (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.1

  1. This does not apply for the German technique in blackletter type of using letter-spacing instead of (non-existent) italics. The defaults in the soul package were designed to cater for this.

ToC8.1.2 Headers and footers

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 — this is the default;

empty

for nothing at all, not even a page number — use this when you are doing one-page documents like posters or handouts, where a page number is not meaningful;

headings

for running heads based on the current chapter and section — this is common for articles, books, and reports, so that every page is identifiable even if printed or copied separately;

myheadings

which lets you use your own [re]programmed definitions of how to use the \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 to get specialist running heads is to use the fancyhdr package, which lets you redefine the left-hand, centre, and right-hand page headers and footers for both odd-numbered and even-numbered 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 typeset version of this document can be used as an example: for the whole story you have to read the documentation.

\pagestyle{fancy}\fancyhead{}
\renewcommand\headrulewidth{.1pt}
\fancyhead[LO,RE]{\footnotesize\sffamily\lite\leftmark}
\fancyhead[LE,RO]{\footnotesize\sffamily\lite\itshape
                  \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}
    \renewcommand{\headrulewidth}{0pt}}

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.

ToC8.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.

!!!   Web browser fonts

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.

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
Sample of cmr
Computer Modern Sans cmss
Sample of cmss
Computer Modern Typewriter cmtt
Sample of cmtt
Pandora panr
Sample of panr
Pandora Sans pss
Sample of pss
Pandora Typewriter pntt
Sample of pntt
Universal uni
Sample of uni
Concrete ccr
Sample of ccr
Éıreannach eiad
Sample of eiad
Rustic rust
Sample of rust
Uncial uncl
Sample of uncl
Dürer cdr
Sample of cdr
Fraktur yfrak
Sample of yfrak
Gothic ygoth
Sample of ygoth
Schwäbische yswab
Sample of yswab

Latin-alphabet typefaces (PostScript Type 1) from Adobe


Avant Garde pag
Sample of pag
Bookman pbk
Sample of pbkUses Avant Garde as the sans-serif and Courier for monospace.
Courier pcr
Sample of pcr
Helvetica phv
Sample of phv
New Century Schoolbook pnc
Sample of pncUses Helvetica as the sans-serif font and Courier for monospace.
Palatino ppl
Sample of pplUses Avant Garde as the sans-serif and Courier for monospace.
Symbol psy
Sample of psy
Times New Roman ptm
Sample of ptmUses Helvetica as the sans-serif font and Courier for monospace. Mathematical symbols for Times are available both free and commercially.
Zapf Chancery pzc
Sample of pzc
Zapf Dingbats pzd
Sample of 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
Sample of bch
Nimbus Roman unm
Sample of unm
Nimbus Sans unms
Sample of unms
URW Antiqua uaq
Sample of uaq
URW Grotesk ugq
Sample of ugq
Utopia put
Sample of putRemoved from recent distributions as it is not free.

Non-Latin-alphabet typefaces (METAFONT)


Cypriot cypr
Sample of cypr
Etruscan etr
Sample of etr
Linear `B' linb
Sample of linb
Phoenician phnc
Sample of phnc
Runic fut
Sample of fut
Bard zba
Sample of zba

!!!   What types of font?

Just to make it clear: standard LATEX uses only METAFONT and PostScript Type 1 fonts. pdfLATEX can use TrueType fonts as well, but needs special configuring to do so. XETEX can use almost any type of font you have installed.

You should note that these are just the defaults installed with all versions of LATEX. There are hundreds more listed in Palle Jørgensen's comprehensive LATEX Font Catalog published by the Danish TEX Users Group at http://www.tug.dk/FontCatalogue/.

ToC8.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, the bookman package makes the default rm font-family Bookman (pbk), but leaves the sans-serif (sf) and monospace (tt) families untouched. Equally, the package helvet changes the default sans-serif family to Helvetica2 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, but they are for text work only, as they leave mathematics in Computer Modern:

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.3

newcent

changes to New Century Schoolbook/Helvetica/Courier.

palatino

changes to Palatino/Avant Garde/Courier.

If you use mathematics, there are two fairly complete implementations of non-CM typefaces in the mathptmx (Times) and mathpazo (Palatino) packages. The whole business of math fonts is perpetually under revision in any case, as mathematicians are perpetually inventing new symbols, which take a while to appear in typefaces. The American Mathematical Society (AMS) and other organisations are involved with a project called Styx, which is expected eventually to define the complete suite of mathematical characters in a rational and extensible manner — but don't hold your breath.

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 Helvetica typeface family has a notoriously large x-height, making it hard to match with other typefaces at the same nominal size. The helvet package therefore has a scaled option that lets you reduce the optical size slightly so that the font sits more easily with others: \usepackage[scaled=0.86]{helvet}, for example.
  2. 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.

ToC8.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.

!!!   Grouping

This is a different way of using curly braces to how we have used them before: see the panel ‘Grouping’ in section 8.2.2 — It limits the effect of a simple command (see section 2.3.1) 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).4

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.

  1. Test for the observant reader: in what typeface will the colon (:) in the example be set?

ToC8.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 (see Table 8.1).

Table 8.1Typeface styles, families, shapes, and series
Type style Command Example (using Computer Modern)
Upright \upshape*
Italic \itshape
Slanted \slshape*
Small Capitals \scshape*
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.

!!!   Commands without arguments

Remember back in section 2.3.1 seeing simple commands with no arguments? The commands above affect all following text, so to restrict their effect, group them in curly braces along with the text you want affected.

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.5

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.

  1. Although if you're a typographer wanting to experiment with typewriter typefaces with and without serifs, you can use METAFONT to do exactly this kind of thing. But that's way outside the scope of this document.

ToC8.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, here's 12pt Computer Modern, and {\font\cmbig=cmr5 at12pt\cmbig here's 5pt Computer Modern scaled up to 12pt}, and {\font\cmsmall=cmr17 at12pt\cmsmall here's 17pt Computer Modern scaled down to 12pt} 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

!!!   Commands without arguments (again)

The commands above affect all following text, so to restrict their effect, group them in curly braces along with the text you want affected.

The inter-line spacing gets reset in proportion, but only gets applied at the end of the pararaph, so if you have a whole paragraph or list item to be set in Large type, there needs to be a \par before the closing curly brace, otherwise the default line-spacing will be used.

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 you can use the fix-cm package to override the step sizes, and use the \fontsize command:

\fontsize{22}{28}\selectfont This is 22pt type 6pt leaded

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

!!!   Ordinal superscripts

Don't use them in normal text. Superscripted ordinals (like 21st) are a historical relic of Victorian typography. They are unnecessary and are never used in modern professional typesetting. They were re-introduced by Microsoft Word apparently because some Americans like their wordprocessing to look old-fashioned.

If you want to try and mimic low-quality wordprocessing, or if you are trying to make a typographic fac-simile of Victorian typsetting, use the \textsuperscript command from the textcomp package. Do not use math mode for text superscripts.

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).

!!!   Step-sized fonts

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. Many other fonts follow this pattern: if you need to use fonts at arbitrary other sizes there is a package fix-cm which lets you override the default steps.

ToC8.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
Use of a letter as a word Who knocked the L out of London?
Decoration FREE UPGRADE!!!

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.

!!!   Warning from the past

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.

ToC8.2.6 Colour

You can typeset anything in LATEX in any colour you want using the xcolor package. First, you need to add the command \usepackage{xcolor} 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 (computer and 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, xcolor provides a 64-colour palette of predefined color names. These represent approximately the colours in the big box of 64 Crayola colouring pencils much favoured by artists and designers. To get this palette, use \usepackage[dvipsnames]{xcolor}.

Now if you want the Crayola colour Crimson, you can use it as a colour name:

\color{Crimson}
\textcolor{Crimson}{some red text}

The biggest selection of predefined colours is available with the svgnames option: this defines all the colours defined by the Scalable Vector Graphics (SVG) standard for web graphics (so it's good for compatibility).

As some of the predefined 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 colour names specified by the option you loaded the package with. To use these names with pdfLATEX, you may need to use the pdftex option to the xcolor package, depending on the version of TEX you have installed.

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 decimal fractions, 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}

(To get the fractional value, divide the integer decimal 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: midblue looks like this if you're reading in colour.

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

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

However, combining colours is an art and a skill: using conflicting colours like Magenta on midblue is as good a warning as any to learn about colour models and palettes before trying to use them!

ToC8.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.

ToC8.3.1 Installing METAFONT fonts

This is the simplest installation. When you download METAFONT fonts from CTAN, you'll usually find a 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 fonts/source/public/:

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

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

  4. Copy the .sty (style) file to a subdirectory (create it) of tex/latex named after the typeface.

  5. 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).

ToC8.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 may be true for some 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 equipment rather than PDF. In addition, operating system support for scalable fonts is still very poor on Unix systems (including GNU/Linux), despite the advances in recent years, and many rebranded (‘knock-off’ or pirated) TrueType fonts supplied with other systems are of very poor quality, so in many cases it still makes sense to use TEX's built-in support for PostScript. When XETEX becomes the default processor, it will no longer be necessary to install different types of font files separately, as XETEX is able to use all fonts natively from your system's font folder.

Two files are needed for each font: the .afm Adobe Font Metric (AFM) and the .pfb PostScript Font Binary (PFB) files. You must have both for each font before you start. If you only have the near-obsolete .pfa PostScript 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 FontForge font editor (from http://fontforge.sourceforge.net). There are unfortunately still some companies distributing Type 1 fonts in .pfa format (Mathematica is one reported recently).

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 Macs and GNU/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 — lists of the codes used are in the files supplier.map, weight.map, width.map, variant.map, and the various .map files for each foundry):

    Letter Meaning Examples
    f foundry b=Bitstream, m=Monotype, p=Adobe
    nn typeface ba=Baskerville, tm=Times, pl=Palatino
    ss series/shape r=roman, b=bold, i=italic, etc.
    ee encoding 8r=revised TEXBase1, ly=Y&Y's TEX'n'ANSI
    v variant smallcaps, outline, script, etc.

    The fonts/fontname directory in your main (not local) installation directory of TEX has files for several foundries giving fully-formed names like these for common fonts (e.g. ptmr8r is [Adobe] Post­Script Times Roman in an 8–bit revised TEX encoding; bgslly is Bitstream Gill Sans Light in Y&Y's TEX'n'ANSI encoding [LY1]).6 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 lists in the fonts/map/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 font/map/fontname directories have ready-made maps 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.

  3. Decide on your encoding

    Encoding is needed because Adobe fonts store their characters in different places to the TEX standard. This is what tripped me up the first few times until someone pointed me at Y&Y's7TEX'n'ANSI encoding which at the time was the only one that included the glyphs I want where I expected them to be.8 Now, however, I recommend using the 8r encoding for all PostScript fonts. The encoding vector file 8r.enc should be in your main (not local) TEX installation directory in fonts/enc/dvips/base.

    To avoid having to type the long path each time below, just copy this file to the temporary directory where you're doing all this stuff.

  4. Convert .afm files to .tfm

    The afm2tfm and vptovf programs are standard TEX utilities in the bin directory of your mainTEX installation.

    In a command window, type:

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

    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 8r (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 capitalV 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 needs these to convert from Adobe's encoding to its own.

    vptovf zorkly.vpl zorkly.vf zorkly.tfm
    vptovf zorklyc.vpl zorklyc.vf zorklyc.tfm
  7. Make directories to hold the files

    Under your local directory there should be a fonts directory, and in it there should be afm, tfm, type1, and vf subdirectories. 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). On my computer, this means:

    	      cd /usr/local/share/texmf/fonts mkdir -p afm/zfonts/zork
    	      mkdir -p tfm/zfonts/zork mkdir -p type1/zfonts/zork
    	      mkdir -p vf/zfonts/zork cd /tmp

    Or if you're lazy:

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

    For Microsoft Windows users, you may have to do this in the MikTEX directories.

    The mkdir command exists in Windows as well, but 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 localdir/fonts/afm/zfonts/zork/
    cp *.tfm localdir/fonts/tfm/zfonts/zork/
    cp *.pfb localdir/fonts/type1/zfonts/zork/
    cp *.vf localdir/fonts/vf/zfonts/zork/

    where localdir is the prefix of your local TEX installation directory. 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.9 There should be a personal configuration file for your use of LATEX called 10local.cfg, in your login folder in a subfolder called .texmf-config/updmap.d. All it needs is an entry for our new font, using the three-letter font family abbreviation (the first three letters of the Karl Berry fontname (here ‘zor’):

    Map zor.map

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

    1. Open 10local.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 localdir/dvips/config/zfonts
    2. Use your editor to open (create) the file dvips/config/zfonts/zor.map.

    3. Insert the line:

      rzorkly Zork-Blackface "TeXnANSIEncoding ReEncodeFont" <texnansi.enc <foo.pfb
    4. Save and close the file.

    You get the full font name (here, ‘Zork-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 local tex/latex/psnfss directory.

    2. Insert the following lines:

      % foozork - created from foo for Zork
      \def\fileversion{1.0}
      \def\filedate{2010/12/03}
      \def\docdate{2010/12/03}
      \NeedsTeXFormat{LaTeX2e}
      \ProvidesPackage{foozork}[\filedate\space\fileversion\space 
       Zfonts Ordinary PSNFSS2e package]
      \RequirePackage[T1]{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.).

      • The T1 option to the fontenc package is the name used for the interface to the 8r 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 that 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{T1}\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 eefnn.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 t1zor.fd for the T1 (8r) encoding and the zor short font name.

    1. Use your editor to open (create) tex/latex/psnfss/t1zor.fd

    2. Enter the following lines:

      \ProvidesFile{t1zor.fd}[2010/03/03 v0.1 manual 
                    font definitions for LY1/zor.]
      
      \DeclareFontFamily{T1}{zor}{}
      
      \DeclareFontShape{T1}{zor}{k}{n}{<-> zorkly}{}
      \DeclareFontShape{T1}{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 fonts/map/fontname/weight.map and fonts/map/fontname/width.map. The rules for combining weight and width need care: read the documentation for the fontname package. 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.

    texhash

    (or whatever your installation calls it). Then run updmap to add the map file:

    updmap --enable Map=zor.map

    This updates the maps for dvips, pdfLATEX, and others. Finally, run the TEX indexer program again so that it can find the map in its new location.

    texhash

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 use the commands you added at the end of step 10:

This is {\zorkfamily ZORK} or \textzork{ZORK}
  1. Confusingly, Bitstream fonts (and others from similar sources) mostly have different names from the original fonts, to avoid copyright issues, so what they call Humanist 521 is actually Gill Sans. Until recently, US law only allowed the names of typefaces to be copyrighted, not the font designs themselves, leading to widespread piracy.
  2. Y&Y, Inc has ceased trading and their TEX distribution is not longer available, although there is email support at http://lists.ucc.ie/lists/archives/yandytex.html, and their encoding files continue to be used.
  3. The only one I had problems with is ‘Å’, which for some weird reason isn't catered for in this encoding.
  4. The configuration file for dvips is config.ps and there are others for other drivers (e.g. PDF): they get their entries from the program updmap which reads map files for each typeface. The configuration file for updmap is updmap.cfg, and that in turn is updated by the program updmap-sys. But hopefully you won't need to know that.