 |
Department of Engineering |
 |
 |
LaTeX and fonts
Introduction
The main focus of this document is on the use of fonts in LaTeX, though
some wider issues are addressed too.
Typesetting's an old, arcane, aesthetics-ridden subject of which fonts are
a small but surprisingly complex part. Even apparently simple operations
are non-trivial - for example, when a character is enlarged, the
lines are proportionally thinner than when the character is reduced. Rules
for controlling these changes (and
anti-aliasing, kerning etc) are contained in
hints that form part of the font definition.
In consequence,
LaTeX's use of fonts isn't trivial for users or system managers,
but usually isn't too hard either. These notes go way beyond what a standard
LaTeX user needs, but might be useful when something doesn't work as expected.
There are many thousands of fonts. Fonts that share the same name needn't
be the same - the appearance of a
"Garamond" font, for example, might well depend on the supplier.
There are also several font formats. Systems (especially in the past) required separate screen fonts and
printer fonts. Screen fonts are low-resolution, bitmapped images which
don't scale well (so different point-sizes call for different images)
and can take a lot of disc-space. Printer fonts are for the final hardcopy so
they need to be high-resolution. They're often produced from a set of specifications
which can produce different sizes and styles of characters according to requirements. Postscript (a page description language
rich in curve-drawing and filling commands) can be used to define fonts.
Postscript type 1 fonts
were used in the 1980s and continue to be used. ATM (Adobe Type
Manager) is a subset of the postscript interpreter that runs on the computer,
not in the printer. It needs a single bitmap font plus a printer font. ATM scales Type 1 PostScript fonts for screen display and imaging for both
PostScript and non-PostScript printers.
In the early 1990s TrueType emerged so scalable fonts could generate bitmaps
on-demand as though each size had been designed by hand. On Windows such file
have a .ttf suffix. Other formats exist too -
- Postscript Type 3 fonts - fonts that use extra postscript commands
- metafont - a format for describing and generating characters used in the [La]TeX
world.
- OpenType is directly based on Unicode - an international standard for representing a broader character set using two-byte encoding for each letter. This allows the encoding of 64,000 characters
instead of 256. OpenType puts either a PostScript or TrueType outline in a TrueType-style wrapper. Applications and
most operating system functions outside of the font subsystem will no longer care which type of font is in this "wrapper".
- Apple Type Solution (ATS) is on new Macs. It provides
support for various font formats including TrueType, PostScript Type 1, and OpenType.
TrueType is built into most Windows/MacOS systems.
PostScript Type 1 fonts are well-established and supported directly by
most high-end output devices. TrueType (which compared to postscript uses relatively smarter fonts and
a dumber interpreter) allows better hinting than type 1 does.
Unlike TrueType fonts, PostScript fonts require two separate files: one contains the character outlines, and the other contains metrics data. For Windows systems using PostScript, a "PFB" file contains the outlines, while a "PFM" file carries the metrics. The system-independent "AFM" metrics file can be converted to a Windows PFM file. In LaTeX the metric information is in "TFM" files.
More recently, many PostScript Level 2 printers (and all PostScript 3 printers) have TrueType rasterisation built in. However, with some Windows printer
drivers the user must change the printer driver settings in software to take advantage of this feature (downloading TrueType as Type 42).
LaTeX initially used metafont fonts. The TFM files (containing the metrics) and the PK files (containing the shapes) had to be installed beforehand.
Nowadays the TFM and PK files can be created on-demand, and postscript fonts can be used.
![[from .ltx to .ps]](ltxfonts1.png)
LaTeX's use of metafont fonts
When latex processes a source file to produce a DVI file it needs to know
not only the size of each character but also
- how the character might be affected by neighbouring ones ('f' followed by 'i'
may form a ligature, for example)
- how elastic the space around the character is (LaTeX may want to
squeeze a word to fit on a line)
This kind of information is contained in a TeX Font Metrics file (a TFM
file) which is required whatever format the fonts are in.
The DVI files contains the coordinates of the characters but not the font shapes.
When the DVI file is printed out or converted to postscript the shape of each
character can be imparted in 2 ways
- as a bitmap - PK files hold bitmaps at set resolutions. If the
appropriate pk file isn't installed, it's generated from the metafont
definition on-the-fly
- as a postscript character
- leaving the postscript printer or
viewer to render the fonts (though the postscript file can have embedded fonts).
Though originally [La]TeX used metafont-generated fonts (e.g. Computer Modern Roman)
it can also use postscript fonts. There are some standard postscript font sets
- PostScript printers (and Adobe Type Manager) with 13 fonts have -
Courier, Courier-Bold, Courier-BoldOblique, Courier-Oblique, Helvetica, Helvetica-Bold, Helvetica-BoldOblique, Helvetica-Oblique, Symbol, Times-Bold,
Times-BoldItalic, Times-Italic, Times-Roman
- Postscript printers with 17 fonts have - All of the above, plus the following: Helvetica-Narrow, Helvetica-Narrow-Bold, Helvetica-Narrow-BoldOblique, Helvetica-Narrow-Oblique
- Postscript printers with 35 fonts have -
All of the above, plus the following:
ZapfChancery-MediumItalic, ZapfDingbats, AvantGarde-Book, AvantGarde-BookOblique, AvantGarde-Demi, AvantGarde-DemiOblique,
Bookman-Demi, Bookman-DemiItalic, Bookman-Light, Bookman-LightItalic, NewCenturySchlbk-Bold, NewCenturySchlbk-BoldItalic,
NewCenturySchlbk-Italic, NewCenturySchlbk-Roman, Palatino-Bold, Palatino-BoldItalic, Palatino-Italic, Palatino-Roman
Most LaTeX installations support at least the core set of 13 using the packages below. To use (for example)
Helvetica, one just adds \usepackage{helvet}. Note that LaTeX has the
concept of a default Roman font and a default Sans Serif font.
Using \usepackage{helvet} will change the default Sans Serif font
but your document will still use the default Roman font.
| Package | Description |
| avant | AvantGarde font as default sans |
| avantgar | ITC Avant Garde |
| bookman | Bookman font as default roman. Avant Garde as default sans |
| chancery | Zapf Chancery font as default roman |
| charter | default roman |
| courier | default ttdefault |
| helvet | Helvetica font as default sans |
| helvetic | Helvetica-Oblique font as default sans |
| mathpazo | Palatino font as default roman. Math in Palatino where possible |
| mathptmx | Times font as default roman. Math in Times where possible. |
| ncntrsbk | NewCenturySchlbk-Roman |
| newcent | NewCenturySchoolbook font as default roman |
| palatcm | Palatino + Computer Modern math fonts |
| pifont | Pi font support (special characters) |
| utopia | Utopia font as default roman |
| zapfchan | ITC Zapf Chancery as default roman |
These packages are installed on our system in /usr//share/texmf/tex/latex/psnfss/.
There are postscript versions of TeX's original Computer Modern metafont
files.
Every text font in LATEX has five attributes:
- encoding -
This specifies the order that characters appear in the font (e.g. whether the 65th character is 'A'). The most common value for TeX font encoding is OT1. The other predefined option is
T1 (extended TeX). There's also US ASCII (7 bit), ISO Latin-1 (8 bit),
Adobe Standard Encoding, etc.
- family -
The name for a collection of fonts, usually grouped under a common name by the font foundry. For example, `Adobe Times' ptm and Knuth's `Computer Modern
Roman' cmr are font families.
- series -
How heavy or expanded a font is. For example, `medium weight', `narrow' and `bold extended' are all series.
- shape -
The form of the letters within a font family. For example, `italic', `oblique' and `upright' are all font shapes.
- size -
The design size of the font, for example `10pt'.
A sample LaTeX specification is T1 ptm bit 18pt (Adobe Times Bold Italic 18pt)
and (using TeX font naming) ptmbq at 18pt in TeX. There are LaTeX commands to change each
of the attributes.
Fonts for math mode are dealt with rather differently. They have the same 5 attributes
but no commands to change the attributes individually. There's a lack of postscript fonts with mathematical characters.
All the LaTeX files should be under one directory called $TEXMF
in the documentation.
On our system $TEXMF is /usr/share/texmf.
- .tfm - tex font metric. [La]TeX needs the font
metrics to properly layout the page. They're in $TEXMF/fonts/tfm/supplier/fontname/
- .afm - Adobe Font Metrics (files used by Type1 fonts). They're in $TEXMF/fonts/afm/supplier/fontname/
- .pfb - $TEXMF/fonts/type1/supplier/fontname/ -
the type1 font directory
- .ttf - $TEXMF/fonts/truetype/supplier/fontname/ - TrueType fonts
- .pl - property list. This is a human readable version of a tex font metric file.
- .vpl - virtual property list. Human readable version of a virtual font file.
- .fd - font definition. Used to define a family of fonts. Contains information
on how LaTeX font attributes are turned in TeX fonts. They're in $TEXMF/tex/latex/psnfss
- .vf - virtual font. These files contain encoding details, and act as interpreters. TeX treats them as fonts. It's a way of constructing a font from the
characters of various other fonts (you may for example want a virtual font that uses all the characters of another font except that the dollar sign is replace by the euro symbol). They're in $TEXMF/fonts/vf/supplier/fontname/
- .pk - a device dependent bitmap font. These are usually constructed on an as-needed basis (renderings of Type1 and metafont fonts). On modern
systems these generated .pk (and .tfm) files are stored
so that anyone else can subsequently use them. On our system they're in
/public/texfonts.
- .mf - metafont files.
These are installed on our system in $TEXMF/fonts/source. A list of metafont fonts is online.
- .map - files mapping between the (manufacturer name, font name) and the TFM
file. Note that one company's font called X may not have the same
specification as another company's font of the same name.
- $TEXMF/dvips/config/psfonts.map - fontmap file for dvips. This file
is similar in both function and format to ghostscript's Fontmap file. It
maps TeX font codenames to postscript font specifications.
LaTeX packages to support new fonts usually contain detailed installation
details. If you need to go it alone (or something goes wrong) you may
have need of the following
- afm2tfm - This will create a TFM files of raw fonts and vpl files of virtual fonts from an AFM file.
- ttf2tfm - TrueType to TFM
- ttf2afm - TrueType to AFM
- ttf2pt1 - TrueType to AFM and PFB
- vptovf - From a VPL file this creates vf and tfm files for virtual fonts.
- mf - processes a metafont file to produce TFM and PK files
- fontinst is a
utility for font installation, originally written by Alan Jeffrey. Its primary
purpose is to simplify
the installation of PostScript or TrueType fonts for use with (La)TeX
- Use "xdvi -l filename" to list the fonts used by the file
In the configuration files the fonts are codenamed.
The naming scheme is FNW{V}E{n} where:
- F is a one-letter abbreviation for the foundry (m = monotype, p = adobe, b = bitstream, f = free)
- N is a two letter abbreviation for the font name (for example, ag = "avant garde")
- W is the font weight (r = regular, b = bold, l = light d = demibold)
- V is an optional slope variant (i = italic , o = oblique)
- E is an abbreviation for the encoding (almost always 8a which is adobe standard encoding).
- N is an optional width variant (n = narrow)
For example, the font Adobe Garamond demibold is pgad8a.
See the
font naming conventions
- The characters are all there, but spacing is strange - It may be that latex isn't using the TFM file appropriate for the font
you're using.
- The wrong font is used in places (e.g. in verbatim) -
LaTeX will warn you if it performs font substitution but the warnings can
easily be lost amongst other output. For example, output might contain
LaTeX Font Warning: Font shape `LY1/pcr/m/n' undefined
(Font) using `LY1/ptm/m/n' instead on input line 53.
pcr is TeXspeak for Adobe courier. ptm is Adobe times. So
the warning means that times is substituted when courier is requested using LY1 encoding and medium weight, normal (i.e. upright) text. When debugging such problems, it's worth determining why the desired font is needed (in the case above "\usepackage[LY1]{fontenc}" was in the source code, and the verbatim environment was used). Then it helps to
scan the verbose output file carefully. The case above also generated the following in the output log
LaTeX Font Info: No file LY1pcr.fd. on input line 53.
This file (or ly1ptm.fd), is missing from some distributions.
It contains lines like
\DeclareFontShape{LY1}{ptm}{m}{it}{<-> ptmri8y}{}
which map from the LaTeX description of a font to the TeX terminology.
Installing the missing file should solve the problem.
- The main text is ok, but the maths isn't - the free postscript fonts
lack many maths characters. The mathptm package puts the maths into
the postscript Times font and symbol font where possible, otherwise it uses the
metafont-generated characters. There are commercial alternatives, and free alternatives are under development.
- My postscript file looks bad onscreen - perhaps ghostscript's configuration file is wrong. ghostscript will try to use a default font if it doesn't know what to use.
- My postscript file looks ok on screen but fails to print -
ghostscript has support for many more fonts than postscript printers have. Whereas ghostscript might substitute for a missing font, a printer is likely to abort the job.
- My postscript file is ok, but when I convert to PDF the fonts are
slow and ugly - Use postscript fonts in the LaTeX file. See the
TeX FAQ
for details.
On many systems you can get more information on the PATHs etc used by
components of the LaTeX system. E.g.
- xdvi -debug 4000 ...
- dvips -d 6 ...
Output, though very wordy, is also thorough.
The following sites have been useful - thanks go their authors for their help
- anti-aliasing - a way to disguise the jagged lines that appear on low-resolution screens (using grey instead of black, etc).
- glyph - the final letter shapes that appear in the hardcopy
- hinting - The provision of additional information
encoded in the font to help prevent problems caused by scaling, etc.
- italics - a sloping style of a font - not to be confusing with
sloping or oblique text which is a simple mathematical transformation of characters
- kerning - adjustment of space between certain characters - sometimes so
their bounding boxes overlap. For example, the 'o' of 'To' often goes under the crossbar of the 'T'.
- leading - (rhyming with 'wedding') space between lines of type
- ligatures - special characters joining certain characters (fi, ffl etc)
- monospace - a font where each character is the same width. The
alternative is proportional spacing
- orphan - a paragraph's final word or line at the top of a column or page
- Postscript - a page description language, text drawing and graphics drawing being treated uniformly. Most printers support Postscript level 2 nowadays. Level 3 postscript hasn't been out long.
- Type 1 font - a PostScript font specification which included hinting
- Type 3 font - a font drawn using postscript commands, requiring a full PostScript interpreter. Most developers have stopped using this format except in a few special
cases, where special type 3 characteristics (pattern fills inside outlines, for example) have been used. When non-postscript fonts are used in LaTeX
and the resulting file converted to postscript, type 3 fonts are used, which
look especially bad if the postscript file is subsequently converted to PDF.
- rasterisation - An outline font must be represented by the dots of the output device (screen pixels, dots of ink, etc). The process of
converting the outline to a pattern of dots on the grid of the device is called "rasterisation". When there aren't enough dots making up the glyph (such as at small sizes or low resolutions), there can be inconsistencies in the representation of certain letter
features due to different rounding based on how the outline happens to sit on the grid (e.g. when the widths of the letter stems vary when they shouldn't). Worse, key features of the glyphs can disappear at small sizes. Both
PostScript Type 1 and TrueType fonts have a means of dealing with these inconsistencies, called "hinting".
- river - a vertical lining-up of word spaces on a page
- serif - a short stroke at the end of a character's main stroke. A sans serif font (helvetica for example) lacks these strokes
- typeface - a set of characters with the same basic shape for each letter
- Type 42 font - a TrueType font encapsulated in a PostScript wrapper
so that it can be used like other PostScript fonts. Only recent versions of PostScript (starting with Adobe Postscript 2013) know how to deal with
such fonts. Conversion of TrueType into Type 42 can be done by ttfps
- widow - a paragraph's final word alone on a line
PostScript and Adobe are registered trademarks of Adobe Systems Inc.
 |
 |