
Metafont (1984) - Tomte
http://tug.ctan.org/systems/knuth/dist/mf/mf.web
======
svat
If all you have is a few seconds, take a look at
[https://www.metaflop.com/modulator](https://www.metaflop.com/modulator) —
play with the sliders, or click "flop it!" a few times.

That's the best very-quick introduction today to the basic ideas behind
Metafont I think, and the best less-short one is Knuth's “The Concept of a
Meta-Font” (1982) — this 25-page paper (in large font so it's really not very
long) is IMO not just a great read but a brilliant _performance_
([https://s3-us-
west-2.amazonaws.com/visiblelanguage/pdf/16.1/...](https://s3-us-
west-2.amazonaws.com/visiblelanguage/pdf/16.1/the-concept-of-a-meta-font.pdf))

BTW the submitted link here goes to the “raw” .web source code of the METAFONT
program, but that was meant to be read in typeset form:
[http://texdoc.net/texmf-
dist/doc/generic/knuth/mf/mf.pdf](http://texdoc.net/texmf-
dist/doc/generic/knuth/mf/mf.pdf)

~~~
dhosek
An even better presentation (although lacking bug fixes after publication) is
volume D of _Computers & Typesetting_, _Metafont: The Program_. It's not just
the output of weave (which is what's in the linked mf.pdf file), but also
includes "mini-indexes" for quick cross-referencing of parts of the code.

I'd also note that while TeX is primarily the work of Knuth, MF was more of a
collaboration between Knuth and his grad student John Hobby (who also wrote
MetaPost) and Hobby should be recognized as a co-author of MF.

~~~
dhosek
I should also recognize David Fuchs as the creator of the GF file format which
is TeX's output format and the author of some of the auxiliary tools around
MF. Tom Rokicki was not part of the original team, but he created the PK
format for bitmap fonts which offered even greater compression than GF and
became the standard for distributing bitmap fonts for TeX (for a long time
even, after GF was created, a lot of device drivers required PXL fonts which
were uncompressed bitmaps, which, especially in 1980s computing, were resource
heavy).

Neenie Billawalla was an important figure in the development of MF as well.
She created the calligraphic uppercase letters in the CM math set and the
Pandora typeface which was, as I recall, the first non-CM type family created
using MF84 (Euler Math predates it, but iirc was created using MF79 and didn't
take advantage of the parameterization capable with MF so each size was
separately digitized). I'm sure there were other important figures in the
development of MF and the surrounding technologies back in the 80s, and I
apologize if I've left anyone out.

------
drfuchs
That's the source code; there's also the 360-page user manual, The Metafont
Book, published by Addison-Wesley, in both soft and hard-cover. Unhappily out
of print; softcover ISBN 0201134446 9780201134445; hardcover 0201134454
9780201134452 at places like AbeBooks.com.

At the time, the idea that a type designer would use a computer as part of the
design process (or even at all) was pretty radical. And the notion that you
were expected to design a parameterized version of your font, that would
produce both regular and bold, in any point size, from a single source where
you specified control point coordinates with multiple linear equations in
multiple unknowns, was also a challenge. (And, no, it isn't acceptable to do
that algorithmically.)

Ultimately, the biggest impediment seemed to be Metafont's "stroke with a
brush" model was at odds with how designers lived in an "outline" world. The
combination of this calligraphic orientation on top of needing to be
comfortable with linear algebra and computer programming, account for
Metafont's lack of popularity, I believe.

~~~
Tomte
I agree that the "brush with a stroke" is the first thing you see when you
look at Metafont and the first examples in the Metafontbook, but in real
projects (like Computer Modern) you're using the brush to draw an outline, so
there isn't much difference anymore (except for the fact that you're moving a
shape across the outline instead of a zero-dimensional point, and that is
unconventional, but really helps).

~~~
drfuchs
Fair enough, but they sure groused about it at the time.

~~~
dhosek
Wait, I just noticed your id. drfuchs as in _David_ Fuchs? The inventor of the
GF file format? I don't remember if we ever met in person back in the day but
hi!

~~~
drfuchs
Yes, that would be me. Usually folks bring up DVI, but thanks for the GF
shout-out! For the record, as a real user of Metafont, all of your comments on
this page are more informed than mine. (And, hi, Don!)

~~~
dhosek
I remember when I wrote DVIview for VM/CMS being jealous of the fact that your
initials were valid hex and mine weren't.

(And for those not in the know, David also created the DVI format.)

------
Tomte
Metafont is a really nice program for designing typefaces. There are two
stand-out features:

(1) You specify control points on the outline, not outside (as with Bezier
curves). That's something Peter Karow already did with Ikarus, but it didn't
prevail.

(2) You write programs. Obviously that was a non-starter for the type-designer
profession, which is much more programming friendly today, but back then it
wasn't.

Oh, and read up on the "hinting" mechanisms in Metafont, it's lightyears ahead
of Type 1 hints and TrueType instructions.

Obviously, today it's long in the tooth: 128 glyphs are way to few, the fact
that it creates bitmap fonts is en vogue, either.

Still, a fantastic tool from which you can still learn a lot.

~~~
drfuchs
Metafont's "charext" feature allows for more than 128 glyphs, though it's kind
of a cheat, as it puts artificial constraints on character dimensions. But it
would be much less trouble to modify Metafont to properly handle larger
character sets than it was to get TeX to.

Concerning bitmaps, it's ironic that window systems ultimately display bitmaps
on the screen, yet they keep the pathway from font-outline to their character-
bitmap cache internal. There's no way to tell MacOS, for instance, that you
want to plug in your own provider, that it can call whenever it first wants
the bitmap for a given font glyph at a given size. Too bad this API is hidden;
it must exist internally in MacOS, Windows, etc.

~~~
dhosek
IIRC, MF 2.0 at least boosted 128 to 256. At the time, the only character sets
which went beyond 256 characters were CJK character sets which had uniform
character dimensions for all characters so the limitation was not a problem.

~~~
drfuchs
You're absolutely correct; I should have said "more than 256". It's difficult
to modify TeX to handle larger character sets, but Metafont could, using that
weird hack that all characters of a given "mod 256" had to have the same
dimensions (no doubt simply due to the limitations of TFM format).

------
sjnu
Rendered version:
[https://tex.loria.fr/fontes/mf.pdf](https://tex.loria.fr/fontes/mf.pdf)

------
kipari
For a more gentle introduction, check out 'The METAFONTbook', also by Donald
E. Knuth. I think that it is still not available in a digital format, but your
local CS-oriented library might have a physical copy.

~~~
enriquto
One of my favorite reads! Somehow, it turns out to be much funnier than the
TeXBook, which is a bit arid. I love when he explains that drawing a beautiful
S is wickedly difficult. And the metafont language is quite slick.

~~~
Tomte
The character S also has its own chapter in Knuth's "Digital Typography":
[https://www-cs-faculty.stanford.edu/~knuth/dt.html](https://www-cs-
faculty.stanford.edu/~knuth/dt.html)

The half-tone chapter is also quite cool.

~~~
dhosek
I remember when the half-tone article was first published in _TUGboat_. In
those days when scanners were exotic equipment not easily accessible, the
illustrations were amazing to see (and to recreate).

------
daffy
I'd be interested in hearing about experiences with Metafont from those of you
who have put effort into it. How far did you get and how much time did you
spend? Any advice for others who would like to try?

~~~
dhosek
You'll need the Metafontbook and Computer Modern Typefaces. It's worth
spending time looking through the MF source for other typefaces in CTAN.

Drawing characters/symbols on graph paper is helpful for being able to
determine what points should be.

MF is a really nice language to work with. It's macro-based like TeX, but
because it's not intertwining with text presentation, it doesn't feel as
awkward as TeX programming does. Among other things, it's effectively an
algebraic solver system.

~~~
dhosek
If it's available, gftodvi is a useful tool as well. It creates a large bitmap
with annotations of locations on it (it was used for the illustrations in
_Computer Modern Typefaces_ ). It would be so much nicer to use with
contemporary previewing capabilities than things were back in 1990 when I had
to send my gftodvi output to the Xerox printer in the basement of the computer
center, hope it didn't crash the printer and get my printout half an hour
later.

------
teekert
Wow, never heard of this before but recently I mistyped mv as mf and got stuck
vim-style. I wish I had this hardware arduino kill button for mf :), btw
ctrl-z did the trick, found it after Googling for a long time.

~~~
account42
Ctrl+D (EOF) works for most weird interpreters.

~~~
teekert
Nope, in this case it was ctrl-z

------
daffy
Are there any Metafont projects going on?

~~~
jimhefferon
You sometimes see a person do some things with mf but these days most folks
want vector output, not bitmaps.

Today, most of the use of these ideas is in drawing technical graphics. For
instance, for his drawings Knuth uses MetaPost, which is very much like
MetaFont but outputs vectors (there are some additions to take advantage of
PostScript).

Another example of mp involves LuaTeX (briefly, TeX but where you can write in
the scripting language Lua). The folks who have developed it have brought
MetaPost in as a ready-made drawing library. See
[https://www.tug.org/TUGboat/tb29-3/tb93hagen-
mplib.pdf](https://www.tug.org/TUGboat/tb29-3/tb93hagen-mplib.pdf) for
instance.

Finally, still another example of the use of these ideas is the stand alone
graphics production program _Asymptote_
[https://en.wikipedia.org/wiki/Asymptote_(vector_graphics_lan...](https://en.wikipedia.org/wiki/Asymptote_\(vector_graphics_language\))
which aims to lift to 3D the algorithms that Knuth put into MetaFont to make
beautiful curves. (I use this system.)

~~~
daffy
But the bitmaps can be of any resolution, can't they? Is there any really
cogent reason to prefer vector output?

~~~
jimhefferon
File size is one, since the output documents only hold the one font, whether
it is for body text or section headers.

Another reason is magnify-ability, or zoom in-ability. Authors are annoyed
when they produce a graphic, and then include it in a document, say expanded
to 120% of its original size or shrunk to 75%, and it contains jaggie letters.
Similarly, readers are annoyed to blow up a map and find that the town names
are hard to read.

Still another is that one set of fonts will do for essentially all documents,
so on your hard drive you don't need a set at 10 pts, another set at 11, etc.
The space these take up is less of an issue than it used to be, but it is an
administrative annoyance.

Another issue impacted me a lot since I put stuff up for download. You have to
maintain a number of outputs for the dpi-ness of various output devices, so
that people reading on a screen use a different output file than people using
a printer. In addition, Knuth has settings called things like _blacker_ to
tune the output for the physical output device engine, so you may want to
maintain output file versions tuned for a number of different vendor's
devices. Besides, at some point printers just became vector devices.

Basically, the market has spoken.

~~~
daffy
Right, so: if one intends to sell a font, Metafont may not be a good idea, but
if the purpose is to make a font for one's own use in book typography, and one
is otherwise inclined to Metafont, then these concerns needn't stand in one's
way.

And perhaps it would be possible to make a vector-outputting version, if this
has already been done for MetaPost.

~~~
lifepillar
There is MetaType1 [0], which is MetaPost-based.

[0]
[https://wiki.contextgarden.net/MetaType1](https://wiki.contextgarden.net/MetaType1)

------
martinclayton
Slightly off-topic, but I've got a copy of Knuth's Computer Modern Typefaces
(Book E in the Computers And Typesetting series). I don't think many people
get to see this book. You can see where some of Kunth's time went. Here's a
quote from the preface:

"Another piece of luck came my way in 1984, when I learned that the original
bronze patterns used to make the molds of Monotype 8A were in San Francisco.
For years I had been working with indirect and imprecise information about the
fonts that had stimulated this work. First I had worked from photographic
blowups of letterpress original pages from The Art of Computer Programming;
then Richard Southall had prepared enlargements from original proofs he had
located in England. At last I found the actual 80-year-old patterns that had
generated the metal type. The present owner of these patters, Mr. Othmar
Peters, kindly consented to let me borrow them while I was preparing the final
draft of Computer Modern, and I learned much by measuring them with calipers."

~~~
Tomte
You also get to see how "real typefaces" are produced using Metafont (namely,
doing outlines and then filling them), which may not be crystal clear when
reading the Metafontbook alone.

(I also like the book for a much simpler reason: it got me my Knuth cheque)

~~~
daffy
Does this have prose in addition to the source code; or can you get the same
information from looking at the code distributed with texlive?

~~~
Tomte
You're getting an introduction, including an explanation of the parameters:
[https://www.2uo.de/image2.jpeg](https://www.2uo.de/image2.jpeg)

Then short prose every now and then:
[https://www.2uo.de/image1.jpeg](https://www.2uo.de/image1.jpeg)

But it's mostly the listings you can see on CTAN, as well. I actually
misremembered and thought there was more explanation in the book.

What's really nice is that all glyphs are shown on a grid, next to their
programs:

[https://www.2uo.de/image0.jpeg](https://www.2uo.de/image0.jpeg)

~~~
daffy
Sounds like it may be worth buying. But I'll see how far I get with the
Metafontbook first.

~~~
dhosek
If you're interested in MF, Volume E is really not optional.

