Metafont: Difference between revisions
done |
Moved section on PS Type 1 to late in the article |
||
Line 34: | Line 34: | ||
After running Metafont, typically one uses the gftopk program to convert the NNNNgf files to pk (packed) format (.NNNNpk). The pk format was introduced to reduce file size as well as speed up typesetting, since it can be read faster.<ref>{{cite web |url=https://www.tug.org/TUGboat/tb06-3/tb13pk.pdf |title= Softwar info|date=1986 |website= www.tug.org|format=PDF|access-date=2019-08-09}}</ref> |
After running Metafont, typically one uses the gftopk program to convert the NNNNgf files to pk (packed) format (.NNNNpk). The pk format was introduced to reduce file size as well as speed up typesetting, since it can be read faster.<ref>{{cite web |url=https://www.tug.org/TUGboat/tb06-3/tb13pk.pdf |title= Softwar info|date=1986 |website= www.tug.org|format=PDF|access-date=2019-08-09}}</ref> |
||
⚫ | |||
⚫ | 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 [[Encapsulated PostScript|EPS]] 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]]s.{{NoteTag|Technically, Metafont ''does'' generate vector outlines as an intermediate step of rasterising a stroke, but those intermediate outlines are tailored to the current raster resolution and non-simple as curves, so they are very far from being usable as Type 1 outlines. An effect of the non-simplicity is spurious pixels on the concave side of a stroke that get a value of 2 rather than 1, however the automatic culling of pictures being shipped out as glyphs in a font normally prevents this from showing up in the final bitmap.}} |
||
⚫ | * The Polish [[JNS team]] developed [[METATYPE1]]<ref>{{cite web|url=http://www.ctan.org/tex-archive/fonts/utilities/metatype1/|title=CTAN: tex-archive/fonts/utilities/metatype1|publisher=}}</ref> (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 [[TeX|GUST]] typeface foundry to produce a modernized and extended variant of [[Computer Modern]], called [[Latin Modern]]. |
||
⚫ | * [[mf2pt1]],<ref>{{cite web|url=http://www.ctan.org/tex-archive/support/mf2pt1/|title=CTAN: tex-archive/support/mf2pt1|publisher=}}</ref> 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]], 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 (typeface)|Minion Pro]]. |
||
⚫ | * [[MetaFog]]<ref>{{Cite web|url=http://www.tug.org/TUGboat/Articles/tb16-3/tb48kinc.pdf|title=R. J. Kinch, "MetaFog: converting Metafont shapes to contours", ''TUGboat'' '''16(3)''', 233–43 (1995)}}</ref> 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.<ref>K. Píška, 2004</ref> |
||
⚫ | The common approach to generate Type 1 fonts with pen strokes remains to generate a high-resolution bitmap and then using an [[autotracer]], implemented by packages such as [[mftrace]]<ref>[http://lilypond.org/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'.</ref> and [[TeXtrace]]<ref>[http://pts.szit.bme.hu/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.</ref> |
||
==Use== |
==Use== |
||
Line 97: | Line 88: | ||
The resulting PDF file should look like this: |
The resulting PDF file should look like this: |
||
[[File:Tex mf beta.pdf|187px]] |
[[File:Tex mf beta.pdf|187px]] |
||
⚫ | |||
⚫ | 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 [[Encapsulated PostScript|EPS]] 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]]s.{{NoteTag|Technically, Metafont ''does'' generate vector outlines as an intermediate step of rasterising a stroke, but those intermediate outlines are tailored to the current raster resolution and non-simple as curves, so they are very far from being usable as Type 1 outlines. An effect of the non-simplicity is spurious pixels on the concave side of a stroke that get a value of 2 rather than 1, however the automatic culling of pictures being shipped out as glyphs in a font normally prevents this from showing up in the final bitmap.}} |
||
⚫ | * The Polish [[JNS team]] developed [[METATYPE1]]<ref>{{cite web|url=http://www.ctan.org/tex-archive/fonts/utilities/metatype1/|title=CTAN: tex-archive/fonts/utilities/metatype1|publisher=}}</ref> (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 [[TeX|GUST]] typeface foundry to produce a modernized and extended variant of [[Computer Modern]], called [[Latin Modern]]. |
||
⚫ | * [[mf2pt1]],<ref>{{cite web|url=http://www.ctan.org/tex-archive/support/mf2pt1/|title=CTAN: tex-archive/support/mf2pt1|publisher=}}</ref> 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]], 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 (typeface)|Minion Pro]]. |
||
⚫ | * [[MetaFog]]<ref>{{Cite web|url=http://www.tug.org/TUGboat/Articles/tb16-3/tb48kinc.pdf|title=R. J. Kinch, "MetaFog: converting Metafont shapes to contours", ''TUGboat'' '''16(3)''', 233–43 (1995)}}</ref> 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.<ref>K. Píška, 2004</ref> |
||
⚫ | The common approach to generate Type 1 fonts with pen strokes remains to generate a high-resolution bitmap and then using an [[autotracer]], implemented by packages such as [[mftrace]]<ref>[http://lilypond.org/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'.</ref> and [[TeXtrace]]<ref>[http://pts.szit.bme.hu/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.</ref> |
||
==See also== |
==See also== |
Revision as of 17:21, 11 August 2019
Developer(s) | Donald Knuth |
---|---|
Stable release | 2.7182818
/ January 2014 |
Operating system | Cross-platform |
Type | Computer language |
License | Permissive |
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 glyphs—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 . Another characteristic is that 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. Finally, 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.
Mode of operation
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 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 sizes from 5pt to 17pt, with the stroke widths the same in all sizes (rather than increasing as the font is scaled up) and aspect ratios widening in the smaller sizes for increased legibility. 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.
Curves in Metafont are defined as cubic splines rather than quadratic, for greater versatility at the cost of more complex arithmetic.[1]
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. Most TeX distributions are configured so that any fonts not currently available at the required resolution are generated by calls to Metafont. The fonts are then stored for later reuse.
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.
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 TeX font metric information, which is the information TeX needs. Usually metafont has to be told to generate this file.
- NAME.log – Log file output from processing
After running Metafont, typically one uses the gftopk program to convert the NNNNgf files to pk (packed) format (.NNNNpk). The pk format was introduced to reduce file size as well as speed up typesetting, since it can be read faster.[2]
Use
While well-known type designers, such as Hermann Zapf, 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."[3] Jonathan Hoefler 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."[4]
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.[5]
History
Donald Knuth 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, where the number asymptotically approaches e with each revision.[6]
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
draw z1..z3..z6{z2-z6}..z5..{z4-z2}z4..cycle;
endchar;
end
This yields the following glyph:
The above example will be processed with a command line such as:[7]
mf '\mode=ljfour; mode_setup; input beta.mf'; gftopk beta.600gf beta.600pk
Then it can be used in a LaTeX file such as[7] (all files should dwell in the same directory or the TeX system should be informed about them using appropriate methods):
\documentclass{article}
\newfont{\letterbeta}{beta}
\newcommand{\otherbeta}{{\letterbeta B}}
\begin{document}
Let’s try having a strange \otherbeta\ here.
\end{document}
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 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 curves.[note 1]
- The Polish JNS team developed METATYPE1[8] (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, called Latin Modern.
- mf2pt1,[9] 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, 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[10] 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.[11]
The common approach to generate Type 1 fonts with pen strokes remains to generate a high-resolution bitmap and then using an autotracer, implemented by packages such as mftrace[12] and TeXtrace[13]
See also
Notes
- ^ Technically, Metafont does generate vector outlines as an intermediate step of rasterising a stroke, but those intermediate outlines are tailored to the current raster resolution and non-simple as curves, so they are very far from being usable as Type 1 outlines. An effect of the non-simplicity is spurious pixels on the concave side of a stroke that get a value of 2 rather than 1, however the automatic culling of pictures being shipped out as glyphs in a font normally prevents this from showing up in the final bitmap.
References
- ^ Knuth, Donald (January 25, 2000). "Interview: Donald E. Knuth" (Interview). Interviewed by Advogato. Retrieved January 13, 2016.
...the mathematics is really simple for a quadratic. The corresponding thing for a cubic is six times as complicated...
- ^ "Softwar info" (PDF). www.tug.org. 1986. Retrieved 2019-08-09.
- ^ CSTUG, Charles University, Prague, March 1996, Questions and Answers with Prof. Donald E. Knuth, reproduced in TUGboat 17 (4) (1996), 355–67. Citation is from page 361. Available online at [1]
- ^ Hoefler, Jonathan. "Knuth's idea that letters start with skeletal forms is flawed. But his work is important and had lasting impact". Twitter. Retrieved 18 August 2018.
- ^ Knuth, Donald (1982). "The Concept of a Meta-Font" (PDF). Visible Language. 16 (1): 3–27.
- ^ "Knuth: Computers and Typesetting".
- ^ a b Christophe Grandsir. "METAFONT Tutorial".
- ^ "CTAN: tex-archive/fonts/utilities/metatype1".
- ^ "CTAN: tex-archive/support/mf2pt1".
- ^ "R. J. Kinch, "MetaFog: converting Metafont shapes to contours", TUGboat 16(3), 233–43 (1995)" (PDF).
- ^ K. Píška, 2004
- ^ 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'.
- ^ 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.
Sources
- Donald Knuth: Metafont: The Program, Addison-Wesley 1986. ISBN 0-201-13438-1
- Donald Knuth: The Metafontbook, Addison-Wesley 1986. ISBN 0-201-13444-6 . The source code of the book in TeX (and a needed macro) is available online on CTAN.
- Donald Knuth: The Metafont source code is written in the WEB programming language, and includes very extensive documentation about the algorithms used in Metafont.
- Yannis Haralambous, "Fonts and Encodings", O'Reilly 2007, ISBN 0-596-10242-9, 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)