16

I'm working through Knuth's Metafont Book as preparation for learning Metapost and I'm running into some problems working through his "experiments". I've installed the latest TeX Live 2013 distribution on my system but I'm having problems.

Here's the code (contained in file io.mf as recommended by Knuth):

mode_setup;
 em#:=10pt#; cap#:=7pt#;
 thin#:=1/3pt#; thick#:=5/6pt#;
 o#:=1/5pt#;
define_pixels(em,cap);
define_blacker_pixels(thin,thick);
define_corrected_pixels(o);
 curve_sidebar=round 1/18em;
beginchar("O", 0.8em#, cap#, 0); "The letter O";
 penpos1(thick,10); penpos2(.1[thin,thick],90-10);
 penpos3(thick,180+10); penpos4(thin,270-10);
 x1l=w-x3l=curve_sidebar; x2=x4=.5w;
 y1=.49h; y2l=-o; y3=.51h; y4l=h+o;
 penstroke z1e{down}..z2e{right}
            ..z3e{up}..z4e{left}..cycle;
 penlabels(1,2,3,4); endchar;

Now, when running the mf command and loading this file, I get a window that is unfortunately empty. Supposedly a large letter "O" should appear.

$ mf
This is METAFONT, Version 2.718281 (TeX Live 2013)
**io
(io.mf
The letter O [79])
*end
Output written on io.2602gf (1 character, 1724 bytes).
Transcript written on io.log.

$ gftodvi io.2602gf 
gftodvi: fatal: tfm file `gray.tfm' not found.

Then, when trying to use the gftodvi command I get the above error.

  1. Any ideas why my "window" that should display the letter "O" is blank/empty?
  2. How do I resolve the gray.tfm error?
  3. Are the two related?

Note: I'm using Ubuntu 14.04, but the TeXLive installation is NOT from the Ubuntu repository. I used the installer from http://mirror.ctan.org/systems/texlive/tlnet/install-tl-unx.tar.gz and created a local "portable" installation.

acarlow
  • 1,311
  • 6
    Unfortunately, the gray font has been removed from TeX Live, a decision that shouldn't have been made. – egreg Apr 24 '14 at 17:59
  • Strange...how should one work through Knuth's book now? Is there an alternative TeX/Metafont stack that would work? – acarlow Apr 24 '14 at 20:24
  • 1
    If you copy gray.tfm either from CTAN or an old distribution in the same working folder it should work. – egreg Apr 24 '14 at 21:19

2 Answers2

17

TeX Live can generate the missing TFM files automatically:

mktextfm gray
mktextfm black

Documentation: kpathsea, section "2.2.9 mktex scripts".


TeX and friends are using the kpathsea library for the file lookup business. Depending on the configuration, the library runs help programs mktex* to create missing files. For example, mktextfm is triggered, if a .tfm file is not found.

The following older version of this answer uses this indirect triggering.

Older version

The following TeX file test.tex loads the fonts:

\font\gray=gray \gray
\font\black=black \black
\csname @@end\endcsname\end

Run it through tex or latex:

$ tex test
This is TeX, Version 3.14159265 (TeX Live 2014) (preloaded format=tex)
(./test.tex
kpathsea: Running mktextfm gray
mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input gray
This is METAFONT, Version 2.7182818 (TeX Live 2014) (preloaded base=mf)

([TEXMFDIST]/fonts/source/public/knuth-local/gray.mf
([TEXMFDIST]/fonts/source/public/knuth-local/graylj.mf
([TEXMFDIST]/fonts/source/public/knuth-lib/grayf.mf
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]
[17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] [30] [31]
[32] [33] [34] [35] [36] [37] [38] [39] [40] [41] [42] [43] [44] [45] [46]
[47] [48] [49] [50] [51] [52] [53] [54] [55] [56] [57] [58] [59] [60] [61]
[62] [63] [64] [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76]
[77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90] [91]
[92] [93] [94] [95] [96] [97] [98] [99] [100] [101] [102] [103] [104] [105]
[106] [107] [108] [109] [110] [111] [112] [113] [114] [115] [116] [117]
[118] [119] [120] [121] [122] ) ) )
Font metrics written on gray.tfm.
Output written on gray.600gf (123 characters, 13144 bytes).
Transcript written on gray.log.
mktextfm: [TEXMFVAR]/fonts/tfm/public/knuth-local/gray.tfm: successfully generated.
 )
No pages of output.
Transcript written on test.log.

(I have omitted the generation of black.tfm and have replaced the paths with the name of the search path variable.)

Then gftodvi finds gray.tfm.

Heiko Oberdiek
  • 271,626
11

As pointed out by @egreg, gray.tfm and black.tfm are no longer in TeX Live. This was certainly a problem for someone like me trying to work with the Metafont book, and as far as I can tell the compiled .tfm files are not located on CTAN (at least doing a search for gray.tfm yields nothing.)

Internet searches did, however, lead me to http://metafont.tutorial.free.fr/ which has a PDF explaining how to manually compile the gray (and black) fonts.

On my installation of OSX with TeX Live 2013, the steps were as follows:

  1. I found the "source" file for gray and black by typing $ find /usr/local/texlive -name 'gray.mf' -- this yielded /usr/local/texlive/2013/texmf-dist/fonts/source/public/knuth-local/gray.mf
  2. Since that location is not user writable I had to copy that directory to writable location:

    $ cp -r /usr/local/texlive/2013/texmf-dist/fonts/source/public/knuth-local ~/
    
  3. $ cd ~/knuth-local

  4. The tutorial pdf discusses resolutions, etc. but from what I can tell one should use 600dpi which was the native resolution of the HP LaserJet 4 printer. I imagine almost all laser printers since that era would be 600dpi or greater.

  5. Verify that gray.mf is set to use graylj. This corresponds to the mode ljfour which is set to 600dpi:

    $ cat gray.mf
    
    input graylj % 'standard' gray font is for the laserjet
    
  6. $ mf "\mode=ljfour; input gray.mf" to compile the font.

  7. $ gftopk gray.600gf gray.pk

  8. $ kpsewhich -var-value=TEXMF this revealed that ~/Library/texmf was my "local" directory for changes.

  9. $ mkdir -p ~/Library/texmf/fonts/pk/ljfour/public/misc/dpi600/; cp gray.pk ~/Library/texmf/fonts/pk/ljfour/public/misc/dpi600/

  10. $ mkdir -p ~/Library/texmf/fonts/tfm/public/misc/; cp gray.tfm ~/Library/texmf/fonts/tfm/public/misc/

  11. Repeat steps 5 through 10 for black.mf to use "smoke" mode.

  12. $ texhash

  13. Now, I am able to run gftodvi successfully.

I still have no solution to why I get a blank/empty screen when loading the io.mf file from the ** prompt, however.

As mentioned in my question, my original problem occurred on Ubuntu, and I verified that the steps above also work on Ubuntu (though the TEXMF "local" directory was different.)

All the above steps are described in varying detail in the tutorial pdf (appendix B) found at the above link.

SamB
  • 2,837
acarlow
  • 1,311