Metafont Vs Metapost: Understanding The Differences

Defining the Differences Between Metafont and Metapost

Metafont: A font design system for creating vector fonts

Metafont is a computer font design system created by Donald Knuth that uses a specialized programming language to mathematically describe font shapes. The main purpose of Metafont is to design high-quality digital vector fonts that can be output as font files and used in digital typesetting systems like TeX.

The key idea behind Metafont is that it represents fonts not simply as predesigned glyphs, but with parameterized descriptions of letterforms using curves, strokes, and fills. This allows font designers to precisely tune the appearance of fonts in typographically advanced ways, adjusting things like stroke weight, serifs, and other font features.

Metapost: A graphics programming language for drawing illustrations

In contrast to the font-focused Metafont, Metapost is a more general-purpose postscript-like graphics programming language developed by John Hobby. It uses a syntax similar to Metafont but is focused more on flexibly drawing all sorts of diagrams, charts, graphs, and illustrations rather than specifically building fonts.

The output of Metapost is vector-based PDF, SVG, or PostScript graphics code. This makes it well-suited for integrating graphics, diagrams, and illustrated material into LaTeX-based documents. It has tools for drawing and connecting lines, shapes, positioning text labels, and layering graphical elements to build up complex illustrations. The nature of the graphics code output also makes Metapost drawings scalable without losing quality.

Metafont Overview

Designed by Donald Knuth for mathematically describing font shapes

Metafont was designed in the late 1970s by Stanford professor Donald Knuth, creator of the digital typesetting system TeX. After developing a system for high-quality digital typesetting, Knuth turned his attention to designing a counterpart system for developing the font files that would feed TeX’s typesetting capabilities.

The core challenge Knuth intended Metafont to solve was finding a way that font designers could precisely specify the shapes of glyphs in fonts mathematically rather than just designing static glyph images. By using a programming language and precise vector curves controlled by parameters, Metafont allowed font designers to tune the stroke shapes, weights, sizes, and other attributes to achieve optically refined letterforms.

Uses its own programming language to define glyph shapes with curves and strokes

Central to Metafont is its own specialized Metafont programming language. In Metafont code, the font designer writes parameterized definitions of each individual glyph. This code precisely describes in an abstract way the pen strokes and filled shapes that make up each letterform, using variables to tune the glyph attributes.

Some of the main elements of the Metafont language include ways to specify lines, curves, stroke edges, fill color, and relative positioning. Designers can utilize things like Bézier curves, circular pen motions, and stroke weight changes to achieve ideal typographic glyph shapes. The output is a vector font file defining glyphs with these vector curves and shapes.

Outputs font files that can be used in TeX typesetting

Once a font has been fully defined in Metafont code, Metafont processes this specialized code and converts it into standard digital font files. The font file output, containing the vector glyph definitions, can then be used in TeX or other typesetting systems to render the glyphs onto pages.

Common font formats output by Metafont include PK (Packed), GF (Generic Font), and PFB (Postscript Font Binary). These vector font files contain the curves, shapes, sizes, and other font attributes coded by the font designer. Typesetting software reads this file to render the custom Metafont-designed glyphs correctly at any scale or resolution.

Metapost Overview

Developed by John Hobby as a graphics companion to Metafont

Metapost was created in the early 1990s by John D. Hobby, an electrical engineer and expert in font design and digital typography. Hobby had been involved in some of the early developments of PostScript at Adobe and wanted to create something similar pairing with Donald Knuth’s Metafont system.

Thus, the syntax of Metapost incorporates many ideas familiar from the PostScript language. However, the focus is less on describing complete documents and more on flexibly drawing 2D vector graphics of all kinds that could integrate into larger documents.

Uses similar syntax but focuses on drawing general graphics and illustrations

Metapost code resembles Metafont in using a text-based programming language, but focused on crafting illustrations ranging from diagrams to graphs to sketches. For this, it includes a wide library of functions for shapes, lines, fills, text labels, coordinate transforms, layering, clipping, and color definitions.

The code is procedural, executing a series of drawing commands like adding standard shapes, applying transforms and shading, stroking paths, and incorporating text blocks. The user defines drawings step-by-step, parameterizing attributes to adjust the graphics flexibly to their needs. The output is a combination of vector PDF or SVG graphics code along with any rastered elements.

Can output vector image formats or integrate with LaTeX documents

A key advantage of Metapost over working directly with PostScript code is its ability to output in modern standardized graphics formats. The primary outputs are PDF, SVG, and PostScript – all vector-based for scaling – making Metapost drawings ideal for publishing needs.

Metapost also enables easy integration into LaTeX documents. LaTeX users frequently need to incorporate charts, diagrams, illustrations etc. alongside LaTeX’s beautiful typesetting of text. By outputting LaTeX integration code, Metapost graphics can be neatly placed, flowing with the LaTeX document’s text.

Key Differences

Metafont makes fonts, Metapost makes graphics

The most essential difference between Metafont and Metapost comes down to their separate use cases. Metafont is optimized specifically for designing parameterizable vector font files. Metapost covers a broader range of vector 2D graphics like diagrams and charts beyond just fonts.

Metafont outputs fonts, Metapost outputs SVG and PDF graphics

Following directly from their separate purposes, the output deliverables from Metafont versus Metapost tools differ substantially. After processing, Metafont generates font files containing the vector glyph definitions to render letterforms in texts.

Metapost, in contrast, outputs PDF, SVG, and related graphics file formats to flexibly integrate illustrations into documents. The graphics contain any combination of vector shapes, text elements, rasterized components and shading/gradient fills the user included in the Metapost code.

Metafont has specialized font design commands, Metapost has more general drawing tools

Comparing the code side-by-side, Metafont includes niche vocabulary tailored specifically to typography and font design. This includes terminology related to glyph shapes, pens, strokes, spline curves, kerning, ligatures, weighting, and similar font-specific attributes.

Metapost covers a broader range of illustration elements reusing PostScript drawing functions. While its code resembles Metafont, developers focused Metapost more on flexibility than specialization. As a result, Metapost lacks Metafont’s depth in fonts but offers wider graphics application.

When to Use Each

Use Metafont for designing fonts and typefaces from scratch

Metafont excels when you need to build custom vector font files, crafting typographic letterforms, glyph shapes, and font attributes like kerning pairs from the ground up. Its specialized vocabulary gives font designers fine control over the curve and stroke shapes that make quality typefaces.

If you have high-level custom font design needs like making math symbol fonts, expanding font families with new weights/variants, or porting obscure archival typefaces, then reach for Metafont’s font-centric toolset.

Use Metapost for drawing diagrams, charts, graphs to include in LaTeX docs

Metapost fits best when dropping illustrations into LaTeX-based articles, reports, papers etc and its convenient LaTeX integration hooks streamline this. It also adds value for programmatically generating families of diagrams e.g data visualizations, circuit diagrams, medical illustrations etc with repetitive elements, layers and annotations.

Essentially, turn to Metapost whenever you need to produce this sort of graphics content, don’t want to write PostScript directly, and don’t require fine font design control that Metafont adds.

Example Metafont Code for Designing a Glyph

For demonstration, here is some sample Metafont code defining the vector outline for an uppercase A letterform:

beginchar("A", 1em#, 1em#, 0);
  pickup pencircle xscaled 0.15w yscaled 0.2w rotated 45;

  path stroke z1eft, z1right, z2left, z2right, crossbar;
  z1eft = (0,0) .. (0.7w,0) .. (0.5w, 0.7h); 
  z1right = (w,0) .. (0.3w,0) .. (0.5w,0.7h);
  z2left = (0,h) .. (0.3w,h) .. (0.5w, 0.3h);
  z2right = (w, h) .. (0.7w,h) .. (0.5w,0.3h); 
  crossbar = (0.3w, 0.7h) -- (0.7w, 0.3h);
  fill stroke z1left .. crossbar .. z1right .. cycle; 
  fill stroke z2left .. crossbar .. z2right .. cycle;

Some visible features here are the use of parameterized paths controlled by variables like w and h, reuse of common paths in both the inner and outer A shape, and strokes combined with filled shapes to compose the glyph. When processed through Metafont, this code produces instructions in a font file for rendering the letterform.

Example Metapost Code for Drawing a Graph

In contrast, here is sample Metapost code to generate a simple line graph plotting a mathematical function:

  % Axes and labels
  draw (0,0) -- (12cm,0) 
      labeled("x", 12cm); 
  draw (0,0) -- (0,8cm)  
      labeled("y", 0, 8cm);
  % Function plot  
  draw plot(1cm*t, 2*sin(90*t)) 
      scaled 6cm shifted (1cm, 2cm); 
  % Annotate (11cm, 2*sin(90*11cm)) = "$f(x) = 2sin(x)$";

Notice the use of common graphics primitives like axes, labels, plotting functions, and annotations. When processed, Metapost generates a combination of PDF/SVG/PostScript code drawing this line graph including polygons approximating the sine curve.

This example illustrates well how the programming pattern in Metapost differs from Metafont’s specialized glyph definitions, instead using versatile graphics functions.

Leave a Reply

Your email address will not be published. Required fields are marked *