Modes of operation
Metafont is most often run as a helper to output device (printer, screen) drivers; in those cases, its job is to generate bitmaps for a font for a specific combination of output device (called a ''mode'' in Metafont) and resolution (visible in the name of the output file, see below). These bitmaps are typically stored for later reuse, so that Metafont does not have to be run every time a document is displayed, but on the other hand TeX distributions with a Metafont component have typically not included any prebuilt bitmap fonts, since they would be rather large in comparison to the sources from which they could be generated. Since Metafont fonts were traditionally the TeX default from which other font formats were exceptions, an incomplete installation of a non-Metafont font can sometimes result in Metafont being called and emitting a confusing "''somefont''.mf not found" error message. Equally important, but not as common, is running Metafont to generate a font metric (TFM) file; a TFM file is only generated if the ''fontmaking'' variable is positive. Traditionally TeX distributions have often come with all TFM files pregenerated (since they are pretty small), but someone installing a Metafont font from sources will have to generate its TFM file before TeX can use it. A third way of operating Metafont is ''proof mode'': if the ''proofing'' variable is positive then the bitmap font file also contains additional information provided viaspecial
commands, in particular the positions and names of points the font designer considered important for the design. If using the separate gftodvi
utility to generate enlarged images of the font glyphs, this information from specials is included; point positions are not limited to pixel resolution.
Metafont can also be run interactively, and has commands for displaying on the screen the images it produces. Knuth has said that he uses Metafont as a kind of desk calculator for solving complicated equations, though he now uses MetaPost for mathematical illustrations.
Metafont can render any kind of graphical output, not just glyphs. However, MetaPost and Output files
Metafont outputs several kinds of files: for a file called NAME.mf, it can output: * NAME.NNNNgf – File with raster output at resolution NNNN (2602 by default). * NAME.tfm – File with.gf
and .pk
. Files for different resolutions are kept apart by placing them in separate directories, named dpi
NNNN, e.g. dpi300/cmr10.pk
.
Language
The Metafont language is an interpreted language for programs that are ''essentially declarative rather than imperative''.Variables and equations
Variables in Metafont can be of eight different types: * Numeric: fixed-point signed numbers with anx2r
is thus not one x
(symbolic), 2
(numeric), and r
(symbolic). Record and Syntax
Metafont has numeric and string constant tokens with mainstream syntaxes; strings are delimited by"
quotes, numeric constants can have decimals but not an exponent part. All other tokens are classified as ''symbolic'', and can be redefined arbitrarily; there is no restriction that tokens with certain meanings must have names consisting of certain characters. At runtime, there can additionally be ''capsule'' tokens, which are effectively constant value tokens of arbitrary type; in the source code those appear as symbolic tokens.
Except where characters are involved in numeric or string constants, the extent of the token containing a particular character depends on to which class the character belongs; unlike ,
, ;
, (
, and )
are "loners" and only form single character tokens. For the character classes <=>:,
, ‘’
(single quotes), +-
, /*\
, !?
, #&@$
, ^~
, , ">/code>,
/code>,
, and .
, as well as the class of underscore together with upper and lower case A–Z, the token consists of the longest consecutive sequence of characters from the same class. Whitespace characters don't contribute tokens. %
starts a comment lasting until end of line.
A notable application of these rules is that #
is frequently appearing as part of variable names in Metafont code, e.g. em#
and pt#
.
Delimiters (such as parentheses) do not have built-in meanings, instead there is a command that turns two symbolic tokens into a pair of matching delimiters, but normally Metafont programs use only the ordinary parentheses. Besides to override priorities in expressions, delimiters are also required around certain kinds of macro arguments.
Graphics
Curves in Metafont are defined as cubic spline
In numerical analysis, a cubic Hermite spline or cubic Hermite interpolator is a spline (mathematics), spline where each piece is a third-degree polynomial specified in Hermite interpolation, Hermite form, that is, by its values and first derivat ...
s, rather than quadratic, for greater versatility at the cost of more complex arithmetic.
Unlike more common outline font formats (such as TrueType
TrueType is an Computer font#Outline fonts, outline font standardization, standard developed by Apple Inc., Apple in the late 1980s as a competitor to Adobe Inc., Adobe's PostScript fonts#Type 1, Type 1 fonts used in PostScript. It has become the ...
or PostScript Type 1), a Metafont font is primarily made up of strokes with finite-width "pens", along with filled regions. Thus, rather than describing the outline of the glyph directly, a Metafont file describes the pen paths. Some simpler Metafont fonts, such as the calligraphic mathematics fonts in the Computer Modern
Computer Modern is the original family of typefaces used by the typesetting program TeX. It was created by Donald Knuth with his Metafont program, and was most recently updated in 1992. Computer Modern and its variants remain very widely used in ...
family, use a single pen stroke with a relatively large pen to define each visual "stroke" of the glyphs. More complex fonts such as the Roman
Roman or Romans most often refers to:
*Rome, the capital city of Italy
*Ancient Rome, Roman civilization from 8th century BC to 5th century AD
*Roman people, the people of Roman civilization
*Epistle to the Romans, shortened to Romans, a letter w ...
text fonts in the Computer Modern family use a small pen to trace around the outline of the visual "strokes", which are then filled; the result is much like an outline font, but with slightly softened corners defined by the pen shape.
Since the font shapes are defined by equations rather than directly coded numbers, it is possible to treat parameters such as aspect ratio, font slant, stroke width, serif
In typography, a serif () is a small line or stroke regularly attached to the end of a larger stroke in a letter or symbol within a particular font or family of fonts. A typeface or "font family" making use of serifs is called a serif typeface ( ...
size, and so forth as input parameters in each glyph definition (which then define not a single font, but a meta-font). Thus, by changing the value of one of these parameters at one location in the Metafont file, one can produce a consistent change throughout the entire font. Computer Modern Roman illustrates many uses of this feature; a typical TeX installation includes a number of versions of the font in pitches from 5 to 17 cpi, with the stroke widths the same in all sizes (rather than increasing as the font is scaled up). In addition, the Computer Modern typewriter and sans-serif
In typography and lettering, a sans-serif, sans serif (), gothic, or simply sans letterform is one that does not have extending features called "serifs" at the end of strokes. Sans-serif typefaces tend to have less stroke width variation than ...
fonts are defined using essentially the same Metafont file as the Roman font, but with different global parameters.
Use
While well-known type designers, such as Hermann Zapf
Hermann Zapf (; 8 November 1918 – 4 June 2015) was a German type designer and calligrapher who lived in Darmstadt, Germany. He was married to the calligrapher and typeface designer Gudrun Zapf-von Hesse. Typefaces he designed include ...
, have collaborated with Knuth to create new fonts using Metafont, the system has not been widely adopted by professional type designers. Knuth attributes this to the fact that "asking an artist to become enough of a mathematician to understand how to write a font with 60 parameters is too much." Jonathan Hoefler
Jonathan Hoefler (; born 1970) is an American type designer. Hoefler founded the Hoefler Type Foundry in 1989, a type foundry in New York.
Early life
Jonathan Hoefler was born on August 22, 1970, in New York City to Doreen Benjamin and Char ...
commented that the Metafont system ultimately became "a technology behind zero of your favourite fonts...Knuth's idea that letters start with skeletal forms is flawed."
The Metafont system allows fonts to be processed in unusual ways; in 1982, Knuth showed how it could be used to morph fonts, with a serif
In typography, a serif () is a small line or stroke regularly attached to the end of a larger stroke in a letter or symbol within a particular font or family of fonts. A typeface or "font family" making use of serifs is called a serif typeface ( ...
font slowly transitioning into a sans-serif
In typography and lettering, a sans-serif, sans serif (), gothic, or simply sans letterform is one that does not have extending features called "serifs" at the end of strokes. Sans-serif typefaces tend to have less stroke width variation than ...
design over the course of a text.
History
Donald Knuth
Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist and mathematician. He is a professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of comp ...
started work on font creation software in 1977, and produced the first version of Metafont in 1979. Due to shortcomings in the original Metafont language, Knuth developed an entirely new Metafont system in 1984, and it is this revised system that is used today; Metafont has a versioning system similar to that of TeX
Tex, TeX, TEX, may refer to:
People and fictional characters
* Tex (nickname), a list of people and fictional characters with the nickname
* Tex Earnhardt (1930–2020), U.S. businessman
* Joe Tex (1933–1982), stage name of American soul singer ...
, where the number asymptotically
In analytic geometry, an asymptote () of a curve is a line such that the distance between the curve and the line approaches zero as one or both of the ''x'' or ''y'' coordinates tends to infinity. In projective geometry and related contexts, ...
approaches '' e'' with each revision.
Example
The following example creates a closed beanlike shape for the character "B" of a font:
%file name: beta.mf
%mode_setup;
% Define a beanlike shape for the character B
beginchar("B",11pt#,11pt#,0);
% Setup coordinates as an equation system
y1=y2=y3=0;
y4=y5=y6=h;
x1=x4=0;
x2=x5=w;
x3=x6=2*w;
% Define pen
pickup pencircle xscaled 0.2w yscaled 0.04w rotated 45;
% Draw the character curve
% z1 is the same as (x1, y1)
draw z1..z3..z6..z5..z4..cycle;
endchar;
end
This yields the following glyph:
The above example will be processed with a command line such as:
mf '\mode=ljfour; mode_setup; input beta.mf';
gftopk beta.600gf beta.600pk
Then it can be used in a LaTeX file such as the following (all files should dwell in the same directory, or the TeX system should be informed about them using appropriate methods):
\documentclass
\newfont
\newcommand
\begin
Let's try having a strange \otherbeta\ here.
\end
The resulting PDF file should look like this:
Producing PostScript Type 1 fonts
There are several tools for converting Metafont programs to PostScript Type 1 fonts. Most make use of MetaPost's ability to convert a subset of Metafont's language into EPS
An extended play (EP) is a Sound recording and reproduction, musical recording that contains more tracks than a Single (music), single but fewer than an album. Contemporary EPs generally contain up to eight tracks and have a playing time of 1 ...
outlines, which can subsequently be converted to PostScript Type 1 fonts. Generating vector outlines of Metafont pen strokes is nontrivial, as the Metafont model of a glyph is a raster image and the exact outlines of most strokes are not Bézier curve
A Bézier curve ( , ) is a parametric equation, parametric curve used in computer graphics and related fields. A set of discrete "control points" defines a smooth, continuous curve by means of a formula. Usually the curve is intended to approxima ...
s.
* The Polish JNS team developed METATYPE1 (based on MetaPost) for creating PostScript Type 1 fonts. Its big disadvantage is that no pens may be used which highly reduces the power of Metafont language. Initially, tool has been used by the Polish GUST typeface foundry to produce a modernized and extended variant of Computer Modern
Computer Modern is the original family of typefaces used by the typesetting program TeX. It was created by Donald Knuth with his Metafont program, and was most recently updated in 1992. Computer Modern and its variants remain very widely used in ...
, called Latin Modern.
* mf2pt1, which is also based on Metapost, was developed by Scott Pakin with some contributions from Werner Lemberg. It also has several limitations detailed in its manual, the most significant one being the restriction that each glyph must be drawn entirely from closed paths. In order to overcome the limitations of mf2pt1, the EPS output by Metapost can be post-processed with FontForge
FontForge is a FOSS font editor which supports many common font formats. Developed primarily by George Williams until 2012, FontForge is free software and is distributed under a mix of the GNU General Public License Version 3 and the 3-clause ...
, which is capable of interpreting complex PostScript paths generated by Metapost from Metafont's elliptic pens, and also capable of removing contour overlaps. Since FontForge supports scripting, this post-processing step can also be automated. This approach was used to produce Type 1 outlines for the MnSymbol mathematical font developed by Achim Blumensath; MnSymbol was designed as a companion to Minion Pro.
* MetaFog is a proprietary converter that can analytically convert pen strokes, but it requires manual post processing to eliminate degenerate cases, and it is not publicly available. It can process only Metapost output.
The common approach to generate Type 1 fonts with pen strokes remains to generate a high-resolution bitmap and then use an autotracer, implemented by packages such as mftrace and TeXtraceTeXtrace
– a collection of scripts for UNIX that convert any TeX font into a Type1 .pfb outline font immediately suitable for use with dvips, pdftex, acroread (and any many other programs). Created by Peter Szabo.
See also
* Ikarus (typography software)
* MetaPost, a vector drawing language derived from Metafont
Notes
References
Sources
* Donald Knuth
Donald Ervin Knuth ( ; born January 10, 1938) is an American computer scientist and mathematician. He is a professor emeritus at Stanford University. He is the 1974 recipient of the ACM Turing Award, informally considered the Nobel Prize of comp ...
: ''Metafont: The Program'', Addison-Wesley 1986.
* Donald Knuth: ''The Metafontbook'', Addison-Wesley 1986. . Th
source code of the book in TeX
(and
needed macro
is available online on CTAN
C mathematical operations are a group of functions in the C standard library, standard library of the C programming language implementing basic mathematical functions. Different C standards provide different, albeit backwards-compatible, sets of ...
.
* Donald Knuth: Th
Metafont source code
is written in the WEB
Web most often refers to:
* Spider web, a silken structure created by the animal
* World Wide Web or the Web, an Internet-based hypertext system
Web, WEB, or the Web may also refer to:
Computing
* WEB, a literate programming system created by ...
programming language, and includes very extensive documentation about the algorithms used in Metafont.
* Yannis Haralambous, "Fonts and Encodings", O'Reilly 2007, , Appendix F: "METAFONT and its derivatives"
* K. Píška, "Creating Type 1 fonts from Metafont sources: comparison of tools, techniques and results", in ''TeX, XML, and Digital Typography'' (Springer-Verlag, Berlin, 2004), Lect. Notes Comput. Sci., Vol. 3130, pp. 240–56
preprint
* Hofstadter, Douglas R.
"Metafont, Metamathematics, and Metaphysics: Comments on Donald Knuth's Article 'The Concept of a Meta-Font'"
''Visible Language'', Vol. XVI no. 4, pp. 309–338 (republished in Hofstadter's book ''Metamagical Themas'', NY: Basic Books, 1985)
External links
The Metafont Tutorial
(PDF). Christophe Grandsire, 2004.
{{Free and open-source typography
Free TeX software
Font formats
Donald Knuth
Cross-platform software
Declarative programming languages
Computer-related introductions in 1977