LaTeX/Fonts

Font families
There are hundreds—if not thousands—of typefaces, or font families. Common examples include Times, Courier, and Helvetica. These families can generally be grouped into three main categories: serif, sans serif, and monospaced. LaTeX commands generally refer to these with the shorthand rm, sf, and tt respectively.

By default, LaTeX uses Computer Modern, a family of typefaces designed by Donald Knuth for use with TeX. It contains serif, sans serif, and monospaced fonts, each available in several weights and optical sizes.

The bodies of LaTeX documents are set in Roman (serif) type by default, but this can be changed by setting the family default:

where   is any of the following:

Emphasizing text
Tex recognizes two types of markup commands: There are variation of the visual markup for a specific font. The above are commonly used elements. For reference on the items see section Font styles
 * Semantic - -- by default italise font. Can be overwritten by . Replace textbf per requirements/preferences.
 * Visual - which actually applies required formatting:
 * Family -
 * Weight - - bold,  - medium
 * Shape -, ,

To add some emphasis to a word or a phrase, use the command, which usually italicizes the text.

The command is dynamic: if you emphasize a word which is already in an emphasized sentence, it will be reverted to the upright font.

Text may be emphasized more heavily through the use of boldface, particularly for keywords the reader may be trying to find when reading the text. As bold text is generally read before any other text in a paragraph or even on a page, it should be used sparingly. It may also be used in place of italics when using sans-serif typefaces to provide a greater contrast with unemphasized text. Bold text can be generated with the command.

Font styles
Typefaces usually come in various styles and weights, such as italic and bold. The following table lists the commands you will need to access typical font shapes.

Note: Paragraph breaks are not allowed inside the command forms.

Generally, one should prefer the commands over their equivalent switches because the former automatically corrects spacing immediately following the end of the selected style.

You may have noticed the absence of underline—this is because underlining is a byproduct of the typewriter era, and is not recommended when bold and italic type is available instead. However, underlining can be useful in some cases, such as to draw attention to changes during editing. Although underlining is available via the command, text underlined in this way will not break properly. Instead, use the command from the  package or  command from the  (underline emphasis) package. By default, the latter package also overrides to underline instead of italicize the text. In the likely case that this is not your intent, use the option, i.e. . Both packages also provide strikethrough text with  or, respectively.

Built-in sizes
To scale text relative to the default body text size, use the following commands:

These commands change the size within a given scope. For instance will change the size of only, and does not affect the font in the rest of the document. It will work for most parts of the text.

These commands cannot be used in math mode. However, part of a formula may be set in a different size by using an command containing the size command. The new size takes effect immediately after the size command; if an entire paragraph or unit is set in a certain size, the size command should include the blank line or the which delimits the unit.

By default, is 10 points, but this can be changed in the  declaration, e.g.. Note that not every document class has unique sizes for all of the above size commands.

Points in TeX follow the standard American point system in which 1 pt is approximately 0.3513$\overline{6}$ mm. The standard point size used in most modern computer programs (known as the desktop publishing point or PostScript point) has 1 pt equal to approximately 0.352$\overline{7}$ mm while the standard European point size (known as the Didot point) had 1 pt equal to approximately 0.37597151 mm (see: point (typography)).

Arbitrary sizes
The ... commands are often enough for your needs, but you may occasionally want an arbitrary font size. This is done with. For example:

sets the current font size to 5cm with 5.5 centimeter leading.

If you are using the latex or pdflatex engines, you may get a warning similar to the following: LaTeX Font Warning: Font shape `OT1/cmr/m/n' in size <142.26378> not available (Font)             size <24.88> substituted on input line 103. This is because these older engines only support a fixed set of sizes—between 5 and 17 point. When he designed Computer Modern, Knuth created individual font files for these sizes, each with stroke widths and spacing optimized for that particular size. To avoid distorting them, scaling these fonts is disabled by default.

This issue is avoided when using lualatex or xelatex, which use Latin Modern - a vectorized version of Computer Modern - as the default font family. This still provides individual files at each of the original optical sizes, but will automatically scale the closest one when asked for an arbitrary size.

Using alternative fonts
When TeX was originally designed in the late 1970s, vector-based fonts didn't exist in any common format - PostScript wouldn't be released until 1982. Consequently, TeX was designed to use its own font system, METAFONT. Over time, TeX (and LaTeX) were extended to support PostScript fonts, and modern LaTeX engines also support the TrueType (TTF) and OpenType (OTF) fonts found on modern systems.

Using TTF and OTF fonts
If you are using <tt>lualatex</tt> or <tt>xelatex</tt>, you can use TTF and OTF fonts with the package:

The option allows you to use the standard TeX ligatures mentioned in the Text Formatting chapter instead of Unicode characters that are unlikely to be on your keyboard. For example, <tt>---</tt> can be used to create em dashes (—), quotes can be typed instead of, and so on.

The package is extremely configurable. See the manual for details, but some basics are covered below.

Selecting font files
Different weights and styles of a given typeface are usually stored as separate font files. A typical typeface might offer four files to represent its normal weight, italics, bold, and bold italics. Given a typefaces's name, can generally deduce the names of the individual files. However, many typefaces come in more than two weights—some versions of Futura, for example, comes in light, book, medium, demi, bold, and extra bold weights. Sometimes small caps are stored as separate files as well.

We might want to hand-pick weights to achieve a certain look or better match the weights of other fonts in our document. Continuing to use Futura as an example, say we want to use the "book" weight for our default weight, "demi" for bold, and the font files are named: Our font setup might resemble:
 * <tt>Futura-Boo</tt> for upright book weight
 * <tt>Futura-BooObl</tt> for oblique book weight
 * <tt>FuturaSC-Boo</tt> for small caps, book weight
 * <tt>Futura-Dem</tt> for upright demi(bold)
 * <tt>Futura-DemObl</tt> for oblique demibold

Note that instead of typing out <tt>Futura-Boo</tt>, <tt>Futura-BooObl</tt>, and so on, we can use <tt>*</tt> to insert the base name.

Controlling font features
The OpenType (OTF) format allows type designers to embed font features that can be turned on and off, such as:
 * Alternate versions of glyphs
 * Lining and "oldstyle" figures, each with tabular and proportional spacing
 * Up to three sets of ligatures: standard, contextual, and historical
 * Superscript and subscript glyphs
 * Small caps (in the same file as the standard upper and lowercase characters)

All of these features can be turned on and off using different options. If we wanted to set our body text in Linux Libertine with oldstyle, proportionally-spaced figures, for example, we might set up our fonts as follows:

Features can be turned on and off using. Say you wanted to set a table in lining, tabular figures:

Changing fonts in latex and pdflatex
If you are not using one of the Unicode-aware engines, font selection is more complicated. (See the discussion of encoding below.) Useful resources for <tt>latex</tt> and <tt>pdflatex</tt> font configuration include:


 * The Latex Font Catalogue
 * LaTeX font commands
 * How to change fonts in Latex
 * Understanding the world of TEX fonts and mastering the basics of fontinst
 * Font installation the shallow way "For one-off projects, you can cut corners with font installation (i.e. fontinst) and end up with a more manageable set of files and a cleaner TEX installation. This article shows how and why"

Font encoding
Digitising human language is a complicated topic that has evolved significantly since TeX's inception.

Unicode
Today, text is usually represented in computer systems using Unicode. Briefly, LuaLaTeX and XeLaTeX use these tools to render Unicode-encoded input files (LuaLaTeX accepts UTF-8 files, while XeLaTeX is a bit more flexible and also accepts UTF-16 and UTF-32) into PDF documents.
 * A Unicode text file is made of a series of code points, each of which can represent a character to be drawn, an accent or other diacritical mark to combine with an adjacent character, or some non-printing character, such as instruction to print subsequent text right-to-left.
 * One or more of these code points combines to represent a grapheme cluster or glyph, the shapes within a font that we informally call "characters".
 * Modern font formats such as TrueType and OpenType contain encoding tables which map code points to the glyphs the font file contains.

TeX encodings
The original TeX and LaTeX, designed long before the advent of Unicode, use a very different scheme. When using <tt>latex</tt> or <tt>pdflatex</tt>, you must choose an input encoding, which the engine uses to interpret your file, and an output encoding, which the engine uses to map your inputs to glyphs. The default font encoding is OT1, the encoding of the original Computer Modern fonts. It contains only 128 characters, many from ASCII, but leaving out some others and including a number that are not in ASCII. When accented characters are required, TeX creates them by combining a normal character with an accent. While the resulting output looks correct, this approach has some caveats compared to Unicode-based approaches:


 * It prevents automatic hyphenation from working inside words containing accented characters.
 * Searches for words with accents in PDFs will fail.
 * Extracting (e.g., via copy-paste) the umlaut 'Ä' via a PDF viewer actually extracts the two characters ''.
 * Some Latin letters cannot be created with this approach, to say nothing about letters of non-Latin alphabets such as Greek or Cyrillic.

To overcome these shortcomings, several other 8-bit output encodings were created. Extended Cork (EC) fonts in T1 encoding contains letters and punctuation characters for most European languages that use Latin alphabets. The LH font set contains letters necessary to typeset documents in languages using Cyrillic script. Because of the large number of Cyrillic glyphs, they are arranged into four font encodings—T2A, T2B, T2C, and X2. The CB bundle contains fonts in LGR encoding for the composition of Greek text. By using these fonts you can improve/enable hyphenation in non-English documents. Another advantage of using new CM-like fonts is that they provide fonts of CM families in all weights, shapes, and optically scaled font sizes.

All this is not possible with OT1; that's why you may want to change the font encoding of your document.

Note that different fonts support different output encodings. The default Computer Modern font does not support T1, for example. You will need Computer Modern Super or Latin Modern, which are Computer Modern-like fonts with T1 support. If you have none of these, it is quite frequent (depends on your TeX installation) that <tt>tex</tt> chooses a Type3 font such as the Type3 EC, which is a bitmap font. Bitmap fonts look rather ugly when zoomed or printed.

The package tells LaTeX what font encoding to use. Font encoding is set with:

where is the font encoding. It is possible to load several encodings simultaneously.

There is nothing to change in your document to use CM Super fonts (assuming they are installed), they will get loaded automatically if you use T1 encoding. For <tt>lmodern</tt>, you will need to load the package after the T1 encoding has been set:

The package (almost European) is obsolete. It provided some workarounds for hyphenation of words with special characters. These are not necessary any more with fonts like lmodern. Using the ae package leads to text encoding problems in PDF files generated via <tt>pdflatex</tt> (e.g. text extraction and searching), besides typographic issues.

PDF fonts and properties
PDF documents have the capability to embed font files. It makes them portable, hence the name Portable Document Format.

Many PDF viewers have a Properties feature to list embedded fonts and document metadata.

Many Unix systems make use of the poppler tool set which features <tt>pdfinfo</tt> to list PDF metadata, and <tt>pdffonts</tt> to list embedded fonts.