Metafont is a description language used to define raster fonts. It is also the name of the interpreter that executes Metafont code, generating the bitmap fonts that can be embedded into e.g. PostScript. Metafont was devised by Donald Knuth as a companion to his TeX typesetting system.
One of the characteristics of Metafont is that the points defining the shapes of the —for example top of a stem, or intersection of a stem and crossbar—are defined with geometrical equations; the intent that the three stems of an ‘m’ are equally spaced horizontally might be expressed as if points 1, 2, and 3 are at the bottom ends of the three stems, whereas the intent that they all end on the same vertical position would be .
Metafont is a macro language, where operations such as "draw a lower case top of stem serif at point 4" might appear as one macro instruction (with the point as argument) in the program for a letter. For describing shapes, Metafont has a rich set of path construction operations that mostly relieves the user of having to calculate control points.
Many families of Metafont fonts are set up so that the main source file for a font only defines a small number of design parameters (x-height, em width, slant, vertical stroke width, etc.), then calling a separate source file common for a whole range of fonts to actually draw the individual glyphs; this is the meta aspect of the system.
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 via special 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 Asymptote are preferred for mathematical illustrations. Metafont is most commonly invoked without a direct request from the user. DVI files can only contain references to typefaces, rather than the sets of raster or vector glyphs that other formats like PostScript allow. Consequently, the glyphs in the typefaces need to be accessed whenever a request is made to view, print or convert a DVI file.
After running Metafont, typically one uses the gftopk program to convert the NNNNgf files to pk (packed) format (.NNNNpk). The pk format was primarily introduced to reduce file size (to about half), but expected to also speed up processing since less data would have to be input/output. The GF and PK formats both employ run-length encoding of bitmaps, but make different binary encodings of the run-lengths. The PK format also does some preprocessing of the bitmaps (bounding box, eliding repeated rows) and encodes all rows of a character as one long bit-sequence.
In the TeX Directory Structure standard, filenames are limited to 8+3 characters, so GF and PK files would only have extensions .gf and .pk. Files for different resolutions are kept apart by placing them in separate directories, named dpiNNNN, e.g. dpi300/cmr10.pk.
Unusually, the names of variables are not simple tokens, but sequences of symbolic tokens and numeric indices; the variable name x2r is thus not one alphanumeric token, but a sequence of the three tokens x (symbolic), 2 (numeric), and r (symbolic). Record and array types may be simulated through collections of variables that share a common name prefix, an idiom supported by the type declaration system giving all variables whose names which differ only in numeric indices the same type (as expected for arrays) while keeping variables whole name differ in some symbolic token separate (as expected for records).
A very distinctive feature of Metafont is the use of to define variables. A numeric variable (or component of a pair or transformation variable) may be in the three states known (set), unknown independent (not set), and unknown dependent (not set, but given by a linear expression of one or several independents). When Metafont executes an equation statement, it turns one of the independents involved into a dependent and eliminates it from the expressions for all other dependents; when no independents remain in the expression for a dependent variable, that variable becomes known. Solving linear equation systems thus is a built-in feature of the Metafont language, and the recommended method of assigning most variables (especially those whose values have geometric significance) is to state equations determining their values. Equation systems frequently mix numeric (scalar) equations with pair (vector) equations.
An exception to the above is the class of internal quantity variables. These have names consisting of just one symbolic token, are always numeric, and are always known. They have a more direct internal representation than ordinary variables, making it convenient for primitive operations in Metafont (or extensions thereof) to use them implicitly.
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 TeX, Metafont has fixed character classes. The characters ,, ;, (, and ) are "loners" and only form single character tokens. For the character classes <=>:|, ‘’ (single quotes), +-, /*\, !?, #&@$, ^~, [, ], {}, 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.
Unlike more common outline font formats (such as TrueType 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 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 type 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 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 fonts are defined using essentially the same Metafont file as the Roman font, but with different global parameters.
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 font slowly transitioning into a sans-serif design over the course of a text.
% 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{z2-z6}..z5..{z4-z2}z4..cycle;endchar;
end
The above example will be processed with a command line such as:
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):
\newfont{\letterbeta}{beta}
\newcommand{\otherbeta}
\begin{document}
Let's try having a strange \otherbeta\ here.
\end{document}
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 mftrace – a small Python program that lets you trace a TeX bitmap font into a PFA or PFB font (A PostScript Type1 Scalable Font) or TTF (TrueType) font. It is licensed under the GNU GPL. Created by Han-Wen Nienhuys. Versions prior to 1.0.5 were called 'pktrace'. and TeXtrace TeXtrace – 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.
Producing PostScript Type 1 fonts
See also
Notes
Sources
target="_blank" rel="nofollow"> "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
|
|