Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document

Formatting Information — An introduction to typesetting with LATEX

Chapter 6: Layouts and fonts

Section 6.2: Using fonts

The default typeface in LATEX is Computer Modern (CM). This typeface was created by Knuth for use with TEX — it is based on a Victorian book typeface, Monotype Series 8, 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 variations on Times you find in wordprocessors, because until recently the mathematical symbols for Times were a commercial product.

LATEX also comes with the popular (some would say overused) ‘Adobe 35’ fonts (see Table 6.3) which are built into PDF readers, laser printers, and other DTP systems, plus some extra fonts donated by the X Consortium and individuals. There are many other fonts designed using METAFONT which can be downloaded from CTAN, including a large collection of historical, symbol, initial, and non-Latin fonts (METAFONT creates Type 3 bitmap fonts for PDFs, but many of them are now available in Type 1 outline format as well).

LATEX can use any of the Type 1 fonts available both free and commercially, and XƎLATEX can use any of the TrueType and OpenType fonts as well.

6.2.1 Setting up fonts for XƎLATEX

Having said that XƎLATEX lets you use all your system fonts (as well as the ones that come with TEX), there is one small piece of preparation to do first: indexing them (properly speaking, cache them). Without doing this, you can still use them but you would have to tell XƎLATEX where to find each one, which is tedious.

The following details are for GNU/Linux systems; details for Apple Mac OS X and Microsoft Windows are still being researched.

  1. Open a Command or Terminal window

  2. Become root by typing sudo su - and giving your password when asked

  3. Run your favourite text editor (eg emacs, vi, kate, gedit, etc)

  4. Create a new file in /etc/fonts/conf.avail called 09-texlive.conf

  5. If you installed TEX from the distribution’s own package repositories, copy and paste this content into the file:

    <?xml version="1.0"?>
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
    <fontconfig>
      <dir>/usr/share/texlive/texmf-dist/fonts/opentype</dir>
      <dir>/usr/share/texlive/texmf-dist/fonts/truetype</dir>
      <dir>/usr/share/texlive/texmf-dist/fonts/type1</dir>
      <dir>/usr/share/texmf/fonts/opentype</dir>
      <dir>/usr/share/texmf/fonts/truetype</dir>
      <dir>/usr/share/texmf/fonts/type1</dir>
      <dir>/usr/share/fonts/opentype</dir>
      <dir>/usr/share/fonts/truetype</dir>
      <dir>/usr/share/fonts/type1</dir>
      <dir>/usr/share/doc</dir>
    </fontconfig>
    	    

    If you installed TEX from the TEX Live distribution from CTAN, copy and paste this content instead:

    <?xml version="1.0"?> 
    <!DOCTYPE fontconfig SYSTEM "fonts.dtd"> 
    <fontconfig> 
      <dir>/usr/local/texlive/2015/texmf-dist/fonts/opentype</dir> 
      <dir>/usr/local/texlive/2015/texmf-dist/fonts/truetype</dir> 
      <dir>/usr/local/texlive/2015/texmf-dist/fonts/type1</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/opentype</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/truetype</dir> 
      <dir>/usr/local/texlive/texmf-local/fonts/type1</dir> 
      <dir>/usr/share/fonts/opentype</dir>
      <dir>/usr/share/fonts/truetype</dir>
      <dir>/usr/share/fonts/type1</dir>
      <dir>/usr/share/doc</dir>
    </fontconfig> 
    	    

    (Change the year to whatever version you installed.)

  6. Save and exit

  7. Soft-link the file to the conf.d directory:

    $ ln -s /etc/fonts/conf.avail/09-texlive.conf /etc/fonts/conf.d/
    	    
  8. Type the command fc-cache -fv and wait a few minutes while it caches your fonts

  9. Type exit and close the window

Note that there appears to be no font.dtd distributed with the system, so it is your responsibility to ensure that the markup shown is correct.

This will allow XƎLATEX to find all your fonts, provided that they are grouped according to typeface, and that they follow the naming convention.

ttotfonts should be here give the font type (extension), path (directory), and naming pattern (see below). You only need to run fc-cache when you have added new fonts (or the very first time you use XƎLATEX).

6.2.2 Changing the default font family with XƎLATEX

A few font packages already detect automatically if you are using XƎLATEX and select the TrueType or OpenType fonts accordingly. TEX comes with a mixture of METAFONT, Type 1, and OpenType/TrueType fonts, but the real virtue of XƎLATEX is that you can use any TrueType or OpenType font installed anywhere on your system, whether it came with TEX or not.

The fontspec package for XƎLATEX provides three commands to select font families: \setmainfont (for the roman face); \setsansfont (for the sans); and \setmonofont (for the typewriter face). These all take one compulsory argument: the name of the typeface:

\usepackage{fontspec}
...
\setmainfont{GFS Bodoni}
\setsansfont{Gill Sans}
\setmonofont{Everson Mono}
	

Most of the time that’s all you need. Unfortunately, not all OT/TT fonts have well-formed names, so there are ways to help XƎLATEX find them. The commands above should find the fonts provided they are installed in your TEX distribution directories or your personal TEX directory.

Both TT and OT fonts are usually named in a pattern where the base name is followed by the variant (regular, italic, bold, bold-italic, etc) separated by a hyphen or underscore character. For example, this is the directory listing of my installation of the Liberation typeface:

  -rw-r--r--  1 peter 152660 May  5  2014 LiberationSerif-BoldItalic.ttf
  -rw-r--r--  1 peter 147132 May  5  2014 LiberationSerif-Bold.ttf
  -rw-r--r--  1 peter 145028 May  5  2014 LiberationSerif-Italic.ttf
  -rw-r--r--  1 peter 152408 May  5  2014 LiberationSerif-Regular.ttf
  -rw-r--r--  1 peter 137420 May  5  2014 LiberationSans-BoldItalic.ttf
  -rw-r--r--  1 peter 137372 May  5  2014 LiberationSans-Bold.ttf
  -rw-r--r--  1 peter 164264 May  5  2014 LiberationSans-Italic.ttf
  -rw-r--r--  1 peter 139764 May  5  2014 LiberationSans-Regular.ttf
  -rw-r--r--  1 peter 129448 May  5  2014 LiberationSansNarrow-BoldItalic.ttf
  -rw-r--r--  1 peter 110560 May  5  2014 LiberationSansNarrow-Bold.ttf
  -rw-r--r--  1 peter 133540 May  5  2014 LiberationSansNarrow-Italic.ttf
  -rw-r--r--  1 peter 113304 May  5  2014 LiberationSansNarrow-Regular.ttf
  -rw-r--r--  1 peter 119064 May  5  2014 LiberationMono-BoldItalic.ttf
  -rw-r--r--  1 peter 105848 May  5  2014 LiberationMono-Bold.ttf
  -rw-r--r--  1 peter 124720 May  5  2014 LiberationMono-Italic.ttf
  -rw-r--r--  1 peter 108492 May  5  2014 LiberationMono-Regular.ttf
	

In this example you can see four families of the Liberation typeface: Serif, Sans, Sans Narrow, and Mono. In each case there is a Regular (roman), Italic, Bold, and Bold Italic variant. XƎLATEX lets you specify the type (extension) of the font, where it is installed, and how the font files names fit the pattern:

\setmainfont{LiberationSerif}[Extension=.ttf,
  Path=/home/peter/texmf/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]
	

The asterisk gets replaced by the font family name you give in the first argument, and the filetype (extension) is added to the end, so that XƎLATEX can construct the whole font name. Repeating this for the sans and mono variants gives us the full set (the Narrow face is an exception and less commonly used):

\setsansfont{LiberationSans}[Extension=.ttf,
  Path=/home/peter/texmf/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]
\setmonofont{LiberationMono}[Extension=.ttf,
  Path=/home/peter/texmf/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]
	

These now automatically fill the LATEX roles of the rm, sf, and tt families. This method can only be used with XƎLATEX.

If you are mixing OpenType or TrueType fonts from different families, there is a useful option keyword Scale which can be set as Scale=MatchLowercase for the sans and mono setups, making them scale to match the roman face.

The documentation for the fontspec package is very extensive and provides a lot of other facilities for managing TT and OT fonts.

6.2.3 Changing the default font family with LATEX and PDFLATEX

To set a typeface as the default family for a whole document, use the relevant package (see Table 6.2 to Table 6.5). For example, to set your whole document in New Century Schoolbook:

\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
...
\usepackage{newcent}
	

Table 6.2: Latin-alphabet typefaces (originally METAFONT)

Computer Modern Romancmr
cmr 
Computer Modern Sanscmss
cmss 
Computer Modern Typewritercmtt
cmtt 
Pandora (pandora) by Neenie Billawalapanr
panr 
Pandora Sanspss
pss 
Pandora Typewriterpntt
pntt 
Universal (uni) by Herbert Bayeruni
uni 
Concrete (concrete)ccr
ccr 
Éıreannach (eiad) by Ivan A Derzhanskieiad
eiad 
Rustic (rustic) by Peter R Wilsonrust
rust 
Uncial (uncial) by Peter R Wilsonuncl
uncl 
Dürer (duerer) by Alan Hoenigcdr
cdr 
Fraktur (oldgerm) by Yannis HaralambousU/yfrak
yfrak 
GothicU/ygoth
ygoth 
SchwäbischeU/yswab
yswab 

In these tables:

  • The full name is shown on the left-hand side.

    If it is available as a package, the package name is given in parentheses. Fonts with mathematical symbols available are prefixed with an asterisk.

  • The short fontname (used in the \fontfamily command) is shown on the right-hand side.

    If a non-standard font encoding is needed, it is shown as a prefix to the fontname, separated by a slash. Font encodings are ways of translating the font designer’s file layout into the Adobe one expected by Postscript and PDF processors.

Table 6.3: The Adobe ‘35’: 10 Latin-alphabet typefaces (35 fonts in PostScript Type 1 format)

Avant Garde (avant)pag
pag 
Bookman (bookman)pbk
pbk 
Courier (courier)pcr
pcr 
Helvetica (helvet)phv
phv 
New Century Schoolbook (newcent)pnc
pnc 
Palatino (mathpazo)ppl
ppl 
SymbolU/psy
psy 
Times Roman (mathptmx)ptm
ptm 
Zapf Chancery (chancery)pzc
pzc 
Zapf Dingbats (pifont)U/pzd
pzd 

PostScript Type 1 fonts were the mainstay of the graphic arts industries for many years, as they allowed very fine definition of variance (‘hinting’) compared with other formats. Despite the advances with OpenType, TrueType, FreeType, and other formats, there are probably still millions if not billions of PostScript fonts installed worldwide. However, the font format remains proprietary to Adobe, even though they have released it for public use, which means that it could change without warning. OpenType was designed to overcome this risk, hence the use of OpenType fonts in XƎLATEX.

Table 6.4: Latin-alphabet fonts (PostScript Type 1) from the X Consortium

Charter (charter)bch
bch 
Nimbus Roman (nimbus)unm
unm.png 
Nimbus Sansunms
unms.png 
URW Antiqua Condensed (urw)uaq
uaq.png 
URW Groteskugq
ugq.png 
Utopia (utopia)put
put 
  • †  The licence for Utopia does not allow it to be distributed automatically to users, but you can download it personally.

You should note that these are just the defaults installed with all full versions of LATEX fonts. 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/, categorised by type (serif, sans, monospace, decorative, etc) with samples and links to the packages on CTAN so that you can install them. However, not all of the zip files are yet in TDS, so refer to Table 3.1 to make sure you put the files in the right places.

LATEX expects to work with three font families available all the time:

Font familyCode
Roman (serif, with tails on the uprights), the defaultrm
Sans-serif, with no tails on the uprightssf
Monospace (fixed-width or typewriter)tt

The default for LATEX equates the rm with the cmr font-family (Computer Modern Roman), the sf with the cmss font-family (Computer Modern Sans-Serif), and the tt with the cmtt font family (Computer Modern Typewriter).

As it is common to want to change all three defaults at the same time, a few of the most popular typeface packages change the default sans-serif and monospace typefaces automatically to make suitable companions (see below), but they are for text work only, as they leave any mathematics in Computer Modern. In these cases you may want to change the new default sans-serif or monospace typeface independently of the roman typeface if you need something different.

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 without mathematics.

newcent

changes to New Century Schoolbook/Helvetica/Courier.

palatino

changes to Palatino/Avant Garde/Courier.

The Helvetica typeface family has a notoriously large x-height (remember Figure 1.5?), 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 fits more easily with others: \usepackage[scaled=0.86]{helvet}, for example.

Table 6.5: Selection of non-Latin-alphabet typefaces (METAFONT)

Cypriot (cypriot)cypr
cypr.png 
Etruscan (etruscan)etr
etr 
Linear ‘B’ (linearb)T1/linb
linb 
Phoenician (phoenician)phnc
phnc 
Runic (runic)fut
fut 
BardU/zba
zba 

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 constantly 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 Stix, which is expected eventually to define a complete suite of mathematical characters in a rational and extensible manner — but don’t hold your breath.

6.2.4 Changing the font-family temporarily with XƎLATEX

To add a new font family, use the command \newfontfamily, which works exactly the same as the commands for setting the main, sans, and mono font families but needs an extra parameter first, to specify the command you want it known by:

\newfontfamily{\tablesfont}{LiberationSansNarrow}[
  Extension=.ttf,
  Path=/home/peter/texmf/fonts/truetype/liberation/,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  ItalicFont=*-Italic,
  BoldItalicFont=*-BoldItalic]
	

Then the new command (here, \tablesfont) can be used to switch to that typeface.

To load a solitary font (that is, not a whole family), there is a command \newfontface, which also works in the same way, by creating a new command to switch to it.

\newfontfamily{\headlinefont}{LobsterTwo-Bold}
[Extension=.otf,Path=/usr/share/fonts/opentype/lobstertwo/]
...
{\centering\headlinefont\fontsize{20}{24}\selectfont
  Lobster Rolls \$3.95\par}
	  

\centering\headlinefont \fontsize{20}{24}\selectfont Lobster Rolls \$3.95

Bear in mind that these new commands are unscoped, so they need to be inside a group (enclosed in curly braces as in the example, or within an environment), otherwise they will apply to the end of the document. See the sidebar ‘Grouping’ for more detail.

See § 6.2.5 if you want to switch from an OpenType/TrueType font to a METAFONT or Type 1 font or family, as you will need to change the encoding.

6.2.5 Changing the font-family temporarily with LATEX and PDFLATEX

To shift to another font family on a temporary basis, there are commands for setting the font encoding and font family. You MUST end these commands with the command \selectfont, which is the trigger to implement them (exactly like you use \maketitle to trigger the creation of the title page after setting up the values).

Font encoding

In XƎLATEX, the default font encoding is EU1, which is inherent to OpenType and TrueType fonts. You will need to use \fontencoding if you want to switch to a non-OTF/TTF font within a XƎLATEX document.

If you are using plain LATEX or PDFLATEX the default font encoding SHOULD be set to T1 as we saw in the step ‘If you are using PDFLATEX (NOT if you are using XƎLATEX)…’. You will only need to use a \fontencoding command if you want to switch to a font with a different encoding (see the tables in § 6.2).

As all the common text fonts that come with LATEX are in T1 encoding, most of the time all you need is the \fontfamily and \selectfont commands:

{\fontfamily{phv}\selectfont Helvetica looks like this};\\
{\fontfamily{bch}\selectfont Charter looks like this}.
          

;

.

These commands, like the ones in § 6.2.4, are called unscoped because they have global effect from that point on. In order to restrict the effect to a smaller scope (a few words, for example), you MUST use both the commands and the text inside a group (enclosed in curly braces as in the example, or within an environment), otherwise they will apply to the end of the document. See the sidebar ‘Grouping’ for more detail.

In a normal document, of course, arbitrary typeface changes like this are rare: people don’t (or at least, shouldn’t) randomly flip from one font to another. You select your default typefaces once, using packages or commands, at the start of the document, and stick with them — bold and italics are handled by the document class or stylesheet packages you use.

However, in advertising or magazines, a wide range of typefaces changes is common, but they are usually part of predefined commands for handling that type of formatting, built into the document class, so it is rare to have to do them manually.

Most cases where people want unusual typeface changes involve things like special symbols or effects on a repetitive basis, and LATEX provides much easier (programmable) ways to make these changes into shorthand commands (called macros: see Chapter 7 ‘Programmability’).

Vastly more common are changes to type style, while staying within the same font-family.

6.2.6 Changing type style

Within each typeface or font family there are usually several different ‘looks’ to the type design. LATEX distinguishes mainly between font shape and font series. Italics is a shape (look carefully: the actual shape of the letters changes, as well as their slope); whereas bold is a series (same shapes, same slope, just thicker strokes).

Table 6.6: Typeface styles, families, shapes, and series (unscoped)

Type styleCommandExample (using Computer Modern)
Upright\upshape*
Italic\itshape
Slanted\slshape*
Small Caps\scshape*
Bold\bfseries*
Extended\bfseries
Sans-serif\sffamily
Monospace\ttfamily
  • These commands are unscoped, so they must be used within a group.

  • *  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.

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

This is {\bfseries\itshape\sffamily bold italic sans-serif type}.
	  

This is bold italic sans-serif type.

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 also an impossibility to combine one family with another (such as seriffed sans-serif type!). Slanted plus italics, for example, doesn’t make sense, as italics are already slanted; and while some typefaces may well possess sans-serif italic small caps, they are not in common use. Sans-serif and monospace (typewriter) are not just different fonts, they are usually different typeface families entirely.

To avoid the problem of forgetting to put curly braces around the commands and text you want formatted, there is an alternative set of scoped commands for the most common type shape and series commands. These use curly braces in the ‘argument’ manner, so their effect applies only to the text in curly braces. These arfe the normal commands for changing the style of a word or phrase.

Table 6.7: Typeface styles, families, shapes, and series (scoped)

Type styleCommandExample (using Computer Modern)
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.

These are commutative too, so you can nest them inside one another:

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

What we know as underlining isn’t a font: it was used in the days of typewriters where italics were not available, and it is extremely rare in typography except for specialist purposes. If you think you need it, use the ulem package with the normalem option, and the \uline command.

6.2.7 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 experience in printing as those which go best together for book-work, which is where TEX originated.

Table 6.8: LATEX font step sizes

CommandExampleNomi­nal point sizeExact point size
\tinyThe quick brown fox jumps over the lazy dog55
\scriptsizeThe quick brown fox jumps over the laz77
\footnotesizeThe quick brown fox jumps over the88
\smallThe quick brown fox jumps over99
\normalsizeThe quick brown fox jumps o1010
\largeThe quick brown fox jumps1212
\LargeThe quick brown fox j1414.40
\LARGEThe quick brown fox1817.28
\hugeThe quick brown2020.74
\HugeThe quick bro2424.88

Note that these are unscoped commands, so they should be used inside a group, either an environment or a set of curly braces terminated with a \par inside the closing brace.

These sizes are also reflected in the size steps at which Computer Modern was designed in the METAFONT program. 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 {\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. Type 1 and other font formats have hinting parameters that allow some scaling to implement the effects of design-sizes, but in general, you probably don’t want to go scaling fonts too far beyond their design size because the spacing 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 default size for book work. Using the larger defaults (11pt and 12pt) for the body font will use 11pt and 12pt designs, with other sizes (such as for headings) rescaled to match. The exact sizes used are listed in the macros in the Class Option files size10.clo, size11.clo and size12.clo. LATEX’s default fonts above 10pt are in fact scaled by a factor of 1.2, as shown in the fourth column of Table 6.8.

While these shorthand commands relieve the beginner of having to worry about the ‘right’ size for a given task, if you need very specific sizes you can use the fix-cm package to override the step sizes. This needs special placement: it has to come at the start of the document, even before the \documentclass command, and must be invoked with the \RequirePackage command normally used only inside packages:

\RequirePackage{fix-cm}
\documentclass[a4paper,12pt]{article}
	  

You can then use the \fontsize command to specify exact sizes. This takes two arguments: the point size and the baseline distance. The example here gives you 22pt type on a 28pt baseline (ie with 6pt extra space or ‘leading’ between the lines).

{\fontsize{22}{28}\selectfont The example here
gives you 22pt type 6pt leaded (that is, with
6pt extra space between the lines, making a
line-height of 28pt).\par}
	  

\fontsize{22}{28}\selectfont The example here gives you 22pt type 6pt leaded (that is, with 6pt extra space between the lines, making a line-height of 28pt).

‘Leading’ comes from the old metal-type practice of adding a strip of typemetal between lines to increase the spacing (so it’s pronounced ‘ledding’ after the metal).

6.2.8 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:

CauseEffect
Foreign wordsex officio
Scientific namesRanunculus ficaria
Emphasismust not
Titles of documentsAccounting in Business
Product namesCorel WordPerfect
Variables in mathsE=mc²
Subtitles or headings

42. How to get started

Use of a letter as a wordWho knocked the L out of London?
DecorationFREE 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.

A 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 and productive 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 retrieving all product names — if they are identified as such. Otherwise you’d spend weeks hunting manually through every \textit command to find the ones you wanted. This is the bottom line of automation: it can save you time and money.

In Chapter 7 ‘Programmability’ we will see how to make your own simple commands to do things like this.

6.2.9 Colour

You can typeset anything in LATEX in any colour you want using the xcolor package. Adding the command \usepackage{xcolor} to your Preamble (note the US spelling of color) 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} to get red like this. There is an unscoped \color command as well, for use within groups:

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

There are several package options for additional colours: two popular ones are dvipsnames, which provides a 64-colour palette of predefined colour names matching the big box of 64 Crayola™ colouring pencils much favoured by artists and designers; and svgnames, which provides the 256 colours defined in the specification for the Scalable Vector Graphics (SVG) drawing and diagramming language. There are others too: see the documentation for the xcolor package.

If you want the Crayola colour Crimson, and you have loaded xcolor with the dvipsnames option, you can use it as a colour name:

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

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 named option you loaded the package with.

Using the \definecolor command, you can also 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 of 255, separated by commas. For example, an RGB colour given as (37,125,224) in decimal integer form can be given as:

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

To get the fractional value, divide the integer 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. Alternatively, use the HTML hexadecimal colour model, the same as used in web pages and CSS stylesheets

\definecolor{midblue}{HTML}{250FE0}
	

The xcolor package also provides two colour versions of \fbox (see § 4.6.2) called \colorbox and \fcolorbox which create a box with a coloured background:

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

The material in the second argument can have its own text colour, as in the example. The \fcolorbox has an extra first argument to specify the colour of the frame or border placed around the box. The border width is controlled by the \fboxrule setting and the separation between rule and content is controlled by \fboxsep setting as we already saw in § 4.6.2.

However, combining colours is an art and a skill: using the command \colorbox{midblue}{\color{magenta}magenta on midblue} to get the effect magenta on midblue illustrates why it is important to learn about colour models and palettes before trying to use them!

  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. 

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