home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / m / mfbook.tex (.txt) < prev    next >
Texinfo Document  |  1993-03-25  |  939KB  |  18,641 lines

  1. % This manual is copyright (C) 1986 by the American Mathematical Society.
  2. % All rights are reserved!
  3. % The file is distributed only for people to see its examples of TeX input,
  4. % not for use in the preparation of books like The METAFONTbook.
  5. % Permission for any other use of this file must be obtained in writing
  6. % from the copyright holder and also from the publisher (Addison-Wesley).
  7. \let\MFmanual=\!
  8. \loop\iftrue
  9.   \errmessage{This manual is copyrighted and should not be TeXed}\repeat
  10. \pausing1 \input manmac
  11. \ifproofmode\message{Proof mode is on!}\pausing1\fi
  12. % halftitle
  13. \titlepage
  14. \pageno=-1985
  15. \line{\titlefont The {\manual ()*+,-.*}book}
  16. \vfill
  17. \ifproofmode
  18. \rightline{The fine print in the upper right-hand}
  19. \rightline{corner of each page is a draft of intended}
  20. \rightline{index entries; it won't appear in the real book.}
  21. \rightline{Some index entries will be in |typewriter type|}
  22. \rightline{and/or enclosed in \<$\ldots$>, etc;}
  23. \rightline{such typographic distinctions aren't shown here.}
  24. \rightline{An index entry often extends for several pages;}
  25. \rightline{the actual scope will be determined later.}
  26. \rightline{Please note things that should be indexed but aren't.}
  27. \medskip
  28. \rightline{Apology: The xeroxed illustrations are often hard to see;}
  29. \rightline{they will be done professionally in the real book.}
  30. \eject
  31. % title
  32. \pageno=-1 % the front matter is numbered with roman numerals
  33. \font\auth=cmssdc10 scaled\magstep4 % used only on the title page
  34. \font\elevenbf=cmbx10 scaled\magstephalf % ditto
  35. \font\elevenit=cmti10 scaled\magstephalf % ditto
  36. \font\elevenrm=cmr10 scaled\magstephalf % ditto
  37. \titlepage
  38. \line{\titlefont The {\manual ()*+,-.*}book}
  39. ^^{Knuth, Donald Ervin}
  40. ^^{Bibby, Duane Robert}
  41. \vskip 1pc
  42. \baselineskip 13pt \elevenbf
  43. \halign to\hsize{#\hfil\tabskip 0pt plus 1fil&#\hfil\tabskip0pt\cr
  44. \kern1.5mm\auth DONALD \kern+2pt E. \kern+2pt KNUTH&
  45.   \elevenit Stanford University\cr
  46. \noalign{\vskip 12pc}
  47. &\elevenit I\kern.7ptllustrations by\cr
  48. &DU\kern-1ptANE BIBBY\cr
  49. \noalign{\vfill}
  50. &\setbox0=\hbox{\manual77}%
  51. \setbox2=\hbox to\wd0{\hss\manual6\hss}%
  52. \raise2.3mm\box2\kern-\wd0\box0\cr % A-W logo
  53. &ADDISON\kern.1em--WESLEY\cr
  54. &PUBLISHING COMP\kern-.13emANY\kern-1.5mm\cr
  55. \noalign{\vskip.5pc \global\elevenrm}
  56. &Reading, Massachusetts\cr
  57. &Menlo Park, California\cr
  58. &New York\cr
  59. &Don Mills, Ontario\cr
  60. &Wokingham, England\cr
  61. &Amsterdam\enspace$\cdot$\enspace Bonn\cr
  62. &Sydney\enspace$\cdot$\enspace Singapore\enspace$\cdot$\enspace Tokyo\cr
  63. &Madrid\enspace$\cdot$\enspace San Juan\cr}
  64. \eject
  65. % copyright
  66. \titlepage
  67. \eightpoint
  68. \vbox to 8pc{}
  69. \noindent\strut
  70. %The quotation on page xxx is copyright $\copyright$ 19xx by Xxxx,
  71. %and used by permission.
  72. %\medskip
  73. %\noindent
  74. This manual describes \MF\ Version 2.0. Some
  75. of the advanced features mentioned here are absent from earlier versions.
  76. \medskip
  77. \noindent
  78. The joke on page 8 is due to Richard S. ^{Palais}.
  79. \medskip
  80. \noindent
  81. The ^{Wilkins} quotation on page 283 was suggested by Georgia K. M. ^{Tobin}.
  82. \medskip
  83. \noindent
  84. {\manual opqrstuq} is a trademark of Addison\kern.1em--Wesley
  85.  Publishing Company.
  86. \medskip
  87. \noindent
  88. \TeX\ is a trademark of the American Mathematical Society.
  89. \bigskip\medskip
  90. \noindent
  91. {\bf Library of Congress cataloging in publication data}
  92. \medskip
  93. {\tt\halign{#\hfil\cr
  94. Knuth, Donald Ervin, 1938-\cr
  95. \ \ \  The METAFONTbook.\cr
  96. \noalign{\medskip}
  97. \ \ \  (Computers \& Typesetting ; C)\cr
  98. \ \ \  Includes index.\cr
  99. \ \ \  1.~METAFONT (Computer system).\ \ 2.~Type and type-\cr
  100. founding--Data processing.\ \ I.~Title.\ \ II.~Series:\cr
  101. Knuth, Donald Ervin, 1938-\ \ \ \ .\ \ Computers \&\cr
  102. typesetting ; C.\cr
  103. Z250.8.M46K58\ \ 1986\ \ \ \ \ \ \ \ \ 686.2\char13 24\ \ \ \ \ \ 85-28675\cr
  104. ISBN 0-201-13445-4\cr
  105. ISBN 0-201-13444-6 (soft)\cr}}
  106. \vfill
  107. \noindent
  108. {\sl \kern-1pt Seventh printing, revised, February 1992} % paperback
  109. %{\sl \kern-1pt Fourth printing, revised, September 1991} % hardcover
  110. \smallskip
  111. \noindent
  112. Copyright $\copyright$ 1986 by the American Mathematical Society
  113. \smallskip
  114. \noindent
  115. This book is published jointly by the American Mathematical Society
  116. and Addison\kern.1em--Wesley Publishing Company.
  117. All rights reserved. No part of this publication may be reproduced, stored in
  118. a retrieval system, or transmitted, in any form or by any means,
  119. electronic, mechanical, photocopying, recording, or otherwise, without
  120. the prior written permission of the publishers. Printed in the United
  121. States of America. % Published simultaneously in Canada.
  122. \medskip
  123. \noindent
  124. ISBN 0-201-13444-6\par % paperback
  125. %ISBN 0-201-13445-4\par % hardcover
  126. \noindent
  127. 7 8 9 10 11 12 13 14 15--AL--9695949392 % paperback
  128. %4 5 6 7 8 9 10 11 12--AL--9594939291 % hardcover
  129. ^^{Knuth, Donald Ervin}
  130. \eject
  131. % dedication
  132. \titlepage
  133. \vbox to 8pc{}
  134. \rightline{\strut\eightssi To Hermann Zapf:}
  135. ^^{Zapf, Hermann}
  136. \vskip2pt
  137. \rightline{\eightssi Whose strokes are the best}
  138. \vfill
  139. \eject
  140. % blank page
  141. \titlepage
  142. \null\vfill
  143. \eject
  144. % the preface
  145. \titlepage
  146. \def\rhead{Preface}
  147. \vbox to 8pc{
  148. \rightline{\titlefont Preface}\vss}
  149. {\topskip 9pc % this makes equal sinkage throughout the Preface
  150. \vskip-\parskip
  151. \tenpoint
  152. \noindent\hang\hangafter-2
  153. \smash{\lower12pt\hbox to 0pt{\hskip-\hangindent\cmman G\hfill}}\hskip-16pt
  154. {\sc ENERATION} {\sc OF} {\sc LETTERFORMS} \strut by mathematical means
  155. was first tried in the fifteenth century; it became popular in the
  156. sixteenth and seventeenth centuries; and it was abandoned (for good
  157. reasons) during the eighteenth century. Perhaps the twentieth century
  158. will turn out to be the right time for this idea to make a comeback,
  159. now that mathematics has advanced and computers are able to
  160. do the calculations.
  161. Modern printing equipment based on raster lines---in which metal ``type''
  162. has been replaced by purely combinatorial patterns of zeroes and ones
  163. that specify the desired position of ink in a discrete way---makes
  164. mathematics and computer science increasingly relevant to printing.
  165. We now have the ability to give a completely precise definition of letter
  166. shapes that will produce essentially equivalent results on all raster-based
  167. machines. Moreover, the shapes can be defined in terms of variable
  168. parameters; computers can ``draw'' new fonts of characters
  169. in seconds, making it possible for designers to perform valuable experiments
  170. that were previously unthinkable.
  171. \MF\ is a system for the design of alphabets suited to raster-based
  172. devices that print or display text. The characters that you are reading
  173. were all designed with \MF\!, in a completely precise way; and they
  174. were developed rather hastily by the author of the system, who is a rank
  175. amateur at such things. It seems clear that further work with \MF\ has
  176. the potential of producing typefaces of real ^{beauty}. This manual has
  177. been written for people who would like to help advance the art of
  178. mathematical type design.
  179. A top-notch designer of typefaces needs to have an unusually good eye
  180. and a highly developed sensitivity to the nuances of shapes.
  181. A top-notch user of computer languages needs to have an unusual
  182. talent for abstract reasoning and a highly developed ability to
  183. express intuitive ideas in formal terms. Very few people have both
  184. of these unusual combinations of skills; hence the best products of
  185. \MF\ will probably be collaborative efforts between two
  186. people who complement each other's abilities. Indeed, this situation
  187. isn't very different from the way types have been created for many
  188. generations, except that the r\^ole of ``punch-cutter'' is now being
  189. played by skilled computer specialists instead of by skilled
  190. metalworkers.
  191. A \MF\ user writes a ``program'' for each letter or symbol of a typeface.
  192. These programs are different from ordinary computer programs,
  193. because they are essentially {\sl declarative\/} rather than imperative.
  194. In the \MF\ language you explain where the major components of a
  195. desired shape are to be located, and how they relate to each other,
  196. but you don't have to work out the details of exactly where the lines
  197. cross, etc.; the computer takes over the work of solving equations as it
  198. deduces the consequences of your specifications. One of the advantages of
  199. \MF\ is that it provides a discipline according to which the principles
  200. of a particular alphabet design can be stated precisely. The underlying
  201. intelligence does not remain hidden in the mind of the designer; it is
  202. spelled out in the programs. Thus consistency can readily be obtained
  203. where consistency is desirable, and a font can readily be extended to
  204. new symbols that are compatible with the existing ones.
  205. It would be nice if a system like \MF\ were to simplify the task of type
  206. design to the point where beautiful new alphabets could be created in a
  207. few hours. This, alas, is impossible; an enormous amount of subtlety lies
  208. behind the seemingly simple letter shapes that we see every day, and the
  209. designers of high-quality typefaces have done their work so well that we
  210. don't notice the underlying complexity.  One of the disadvantages of \MF\
  211. is that a person can easily use it to produce poor alphabets, cheaply and
  212. in great quantity. Let us hope that such experiments will have educational
  213. value as they reveal why the subtle tricks of the trade are important, but
  214. let us also hope that they will not cause bad workmanship to proliferate.
  215. Anybody can now produce a book in which all of the type is home-made, but
  216. a person or team of persons should expect to spend a year or more on the
  217. project if the type is actually supposed to look right. \MF\ won't put
  218. today's type designers out of work; on the contrary, it will tend to make
  219. them heroes and heroines, as more and more people come to appreciate their
  220. skills.
  221. Although there is no royal road to type design, there are some things that
  222. can, in fact, be done well with \MF\ in an afternoon. Geometric designs
  223. are rather easy; and it doesn't take long to make modifications to letters
  224. or symbols that have previously been expressed in \MF\ form. Thus,
  225. although comparatively few users of \MF\ will have the courage to do an
  226. entire alphabet from scratch, there will be many who will enjoy
  227. customizing someone else's design.
  228. This book is not a text about mathematics or about computers. But if
  229. you know the rudiments of those subjects (namely, contemporary high school
  230. mathematics, together with the knowledge of how to use the text
  231. editing or word processing facilities on your computing machine),
  232. you should be able to use \MF\ with little difficulty after reading
  233. what follows. Some parts of the exposition in the text are more obscure
  234. than others, however, since the author has tried to satisfy experienced
  235. \MF ers as well as beginners and casual users with a single manual.
  236. Therefore a special symbol has been used to warn about esoterica: When you
  237. see the sign
  238. $$\vbox{\hbox{\dbend}\vskip 11pt}$$
  239. at the beginning of a paragraph, watch out for a ``^{dangerous bend}''
  240. in the train of thought---don't read such a paragraph unless you need to.
  241. You will be able to use \MF\ reasonably well, even to design characters like
  242. the dangerous-bend symbol itself, without reading the fine print in such
  243. advanced sections.
  244. Some of the paragraphs in this manual are so far out that they are rated
  245. $$\vcenter{\hbox{\dbend\kern1pt\dbend}\vskip 11pt}\;;$$
  246. everything that was said about single dangerous-bend signs goes double
  247. for these. You should probably have at least a month's experience with
  248. \MF\ before you attempt to fathom such doubly dangerous depths
  249. of the system; in fact, most people will never need to know \MF\
  250. in this much detail, even if they use it every day. After all, it's
  251. possible to fry an egg without knowing anything about biochemistry.
  252. Yet the whole story is here in case you're curious. \ (About \MF\!, not eggs.)
  253. The reason for such different levels of complexity is that people change
  254. as they grow accustomed to any powerful tool. When you first try to use
  255. \MF\!, you'll find that some parts of it are very easy, while other things
  256. will take some getting used to. At first you'll probably try to control
  257. the shapes too rigidly, by overspecifying data that has been copied from
  258. some other medium.  But later, after you have begun to get a feeling for
  259. what the machine can do well, you'll be a different person, and you'll be
  260. willing to let \MF\ help contribute to your designs as they are being
  261. developed. As you gain more and more experience working with this unusual
  262. apprentice, your perspective will continue to change and you will
  263. run into different sorts of challenges.  That's the way it is with any
  264. powerful tool: There's always more to learn, and there are always better
  265. ways to do what you've done before.  At every stage in the development
  266. you'll want a slightly different sort of manual.  You may even want to
  267. write one yourself.  By paying attention to the dangerous bend signs in
  268. this book you'll be better able to focus on the level that interests you
  269. at a particular time.
  270. Computer system manuals usually make dull reading, but take heart:
  271. This one contains {\sc ^{JOKES}} every once in a while. You might actually
  272. enjoy reading it. \ (However, most of the jokes can only be appreciated
  273. properly if you understand a technical point that is being made---so
  274. read {\sl carefully}.)
  275. Another noteworthy characteristic of this book is that it doesn't
  276. always tell the ^{truth}. When certain concepts of \MF\ are introduced
  277. informally, general rules will be stated; afterwards you will find that the
  278. rules aren't strictly true. In general, the later chapters contain more
  279. reliable information than the earlier ones do. The author feels that this
  280. technique of deliberate lying will actually make it easier for you to
  281. learn the ideas. Once you understand a simple but false rule, it will not
  282. be hard to supplement that rule with its exceptions.
  283. In order to help you internalize what you're reading,
  284. {\sc ^{EXERCISES}} are sprinkled through this manual. It is generally intended
  285. that every reader should try every exercise, except for questions that appear
  286. in the ``dangerous bend'' areas. If you can't solve a problem, you
  287. can always look up the answer.
  288. But please, try first to solve it by yourself; then you'll learn more
  289. and you'll learn faster. Furthermore, if you think you do know the solution,
  290. you should turn to Appendix~A and check it out, just to make sure.
  291. \bigskip
  292. \hrule
  293. \line{\vrule\hss\vbox{\medskip\ninepoint
  294. \leftskip=\parindent \rightskip=\parindent
  295. \noindent\strut W{\sc ARNING}: Type design can be hazardous to your other
  296. interests.  Once you get hooked, you will develop intense feelings about
  297. letterforms; the medium will intrude on the messages that you read. And you
  298. will perpetually be thinking of improvements to the fonts that you see
  299. everywhere, especially those of your own design.
  300. \strut\medskip}\hss\vrule}
  301. \hrule
  302. \bigskip
  303. The \MF\ language described here has very little in common with the
  304. author's previous attempt at a language for alphabet design, because
  305. five years of experience with the old system has made it clear that a
  306. completely different approach is preferable. Both languages have
  307. been called \MF; but henceforth the old language should be called
  308. \MF\kern.05em79, and its use should rapidly fade away. Let's keep the name
  309. \MF\ for the language described here, since it is so much better, and
  310. since it will never change again. ^^{MF79}
  311. I wish to thank the hundreds of people who have helped me to formulate
  312. this ``definitive edition'' of \MF\!, based on their experiences with
  313. preliminary versions of the system.  In particular, John ^{Hobby}
  314. discovered many of the algorithms that have made the new language
  315. possible. My work at Stanford has been generously supported by the
  316. ^{National Science Foundation}, the ^{Office of Naval Research}, the ^{IBM
  317. Corporation}, and the ^{System Development Foundation}. I also wish to
  318. thank the ^{American Mathematical Society} for its encouragement and for
  319. publishing the {\sl ^{TUGboat}\/} newsletter (see Appendix~J\null).
  320. Above all, I deeply thank my wife, Jill, for the inspiration, ^^{Knuth, Jill}
  321. understanding, comfort, and support she has given me for more than
  322. 25~years, especially during the eight years that I have been
  323. working intensively on mathematical typography.
  324. \medskip
  325. \line{{\sl Stanford, California}\hfil--- D. E. K.}^^{Knuth, Don}
  326. \line{\sl September 1985\hfil}
  327. } % end of the special \topskip
  328. \endchapter
  329. It is hoped that Divine Justice may find
  330. some suitable affliction for the malefactors
  331. who invent variations upon the alphabet of our fathers.~.\thinspace.\thinspace.
  332. The type-founder, worthy mechanic, has asserted himself
  333. with an overshadowing individuality,
  334. defacing with his monstrous creations and revivals
  335. every publication in the land.
  336. \author AMBROSE ^{BIERCE}, {\sl The Opinionator.~Alphab\^etes\/} %
  337.   (1911) % vol 10 of his collected works, p69
  338.   % probably written originally in 1898 or 1899
  339. \bigskip
  340. Can the new process yield a result that, say,
  341. a Club of Bibliophiles would recognise as a work of art
  342. comparable to the choice books they have in their cabinets?
  343. \author STANLEY ^{MORISON}, {\sl Typographic Design in Relation to
  344.   Photographic Composition\/} (1958) % pp 4--5
  345. \eject
  346. % the table of contents
  347. \titlepage
  348. \vbox to 8pc{
  349. \rightline{\titlefont Contents}
  350. \vfill}
  351. ^^{Contents of this manual, table}
  352. \def\rhead{Contents}
  353. \tenpoint
  354. \begingroup
  355. \countdef\counter=255
  356. \def\diamondleaders{\global\advance\counter by 1
  357.   \ifodd\counter \kern-10pt \fi
  358.   \leaders\hbox to 20pt{\ifodd\counter \kern13pt \else\kern3pt \fi
  359.     .\hss}}
  360. \baselineskip 15pt plus 5pt
  361. \def\\#1. #2. #3.{\line{\strut
  362.     \hbox to\parindent{\bf\hbox to 1em{\hss#1}\hss}%
  363.     \rm#2\diamondleaders\hfil\hbox to 2em{\hss#3}}}
  364. \\1. The Name of the Game. 1.
  365. \\2. Coordinates. 5.
  366. \\3. Curves. 13.
  367. \\4. Pens. 21.
  368. \\5. Running \MF\!\null. 31.
  369. \\6. How \MF\ Reads What You Type. 49.
  370. \\7. Variables. 53.
  371. \\8. Algebraic Expressions. 59.
  372. \\9. Equations. 75.
  373. \\10. Assignments. 87.
  374. \\11. Magnification and Resolution. 91.
  375. \\12. Boxes. 101.
  376. \\13. Drawing, Filling, and Erasing. 109.
  377. \\14. Paths. 123.
  378. \\15. Transformations. 141.
  379. \\16. Calligraphic Effects. 147.
  380. \\17. Grouping. 155.
  381. \\18. Definitions (also called Macros). 159.
  382. \\19. Conditions and Loops. 169.
  383. \\20. More about Macros. 175.
  384. \\21. Random Numbers. 183.
  385. \\22. Strings. 187.
  386. \\23. Online Displays. 191.
  387. \eject
  388. \vbox to 8pc{}
  389. \\24. Discreteness and Discretion. 195.
  390. \\25. Summary of Expressions. 209.
  391. \\26. Summary of the Language. 217.
  392. \\27. Recovering from Errors. 223.
  393. \null
  394. \leftline{\indent\bf Appendices}
  395. \\A. Answers to All the Exercises. 233.
  396. \\B. Basic Operations. 257.
  397. \\C. Character Codes. 281.
  398. \\D. Dirty Tricks. 285.
  399. \\E. Examples. 301.
  400. \\F. Font Metric Information. 315.
  401. \\G. Generic Font Files. 323.
  402. \\H. Hardcopy Proofs. 327.
  403. \\I\hskip 1pt. Index. 345.
  404. \\J. Joining the \TeX\ Community. 361.
  405. \null % 17 lines so far to balance the 23 on the other page
  406. \null % 18
  407. \null % 19
  408. \null % 20
  409. \null % 21
  410. \null % 22
  411. \null % 23
  412. \eject
  413. \endgroup
  414. \beginchapter Chapter 1. The Name of\\the Game
  415. \pageno=1 % This is page number 1, number 1,
  416. This is a book about a computer system called \MF\!, \kern1pt just as
  417. \kern-1pt {\sl The \TeX
  418. book\/} is about \TeX.  \MF\ and \TeX\ are good friends who intend to live
  419. together for a long time.  Between them they take care of the two most
  420. fundamental tasks of typesetting:  \TeX\ puts characters into the proper
  421. positions on a page, while \MF\ determines the shapes of the characters
  422. themselves. ^^{TeX} ^^{METAFONT, the name}
  423. Why is the system called \MF\thinspace? The `-{\manual FONT}\thinspace'
  424. part is easy to understand, because sets of related characters that are
  425. used in typesetting are traditionally known as fonts of type. The
  426. `{\manual META}-' part is more interesting: It indicates that we are
  427. interested in making high-level descriptions that transcend any of the
  428. individual fonts being described.
  429. Newly coined words beginning with `meta-' generally reflect our contemporary
  430. inclination to view things from outside or above, at a more abstract level than
  431. before, with what we feel is a more mature understanding. We now have
  432. metapsychology (the study of how the mind relates to its containing body),
  433. metahistory (the study of principles that control the course of events),
  434. metamathematics (the study of mathematical reasoning), metafiction
  435. (literary works that explicitly acknowledge their own forms), and so on.
  436. A metamathematician proves metatheorems (theorems about theorems);
  437. a computer scientist often works with metalanguages (languages for
  438. describing languages). Similarly, a ^{meta-font} is a schematic description
  439. of the shapes in a family of related fonts; the letterforms change
  440. appropriately as their underlying parameters change.
  441. Meta-design is much more difficult than design; it's easier to draw something
  442. than to explain how to draw it. One of the problems is that different sets
  443. of potential specifications can't easily be envisioned all at once.
  444. Another is that a computer has to be told absolutely everything.
  445. However, once we have successfully explained how to draw something
  446. in a sufficiently general manner, the same explanation will work for
  447. related shapes, in different circumstances; so~the time spent in formulating
  448. a precise explanation turns out to be worth it.
  449. Typefaces intended for text are normally seen small, and our eyes can read
  450. them best when the letters have been designed specifically for the size at
  451. which they are actually used. Although it is tempting to get 7-point fonts
  452. by simply making a 70\% reduction from the 10-point size, this shortcut
  453. leads to a serious degradation of quality. Much better results can be
  454. obtained by incorporating parametric variations into a meta-design.  In
  455. fact, there are advantages to built-in variability even when you want to
  456. produce only one font of type in a single size, because it allows you to
  457. postpone making decisions about many aspects of your design. If you leave
  458. certain things undefined, treating them as parameters instead of
  459. ``freezing'' the specifications at an early stage, the computer will be
  460. able to draw lots of examples with different settings of the parameters,
  461. and you will be able to see the results of all those experiments at the final
  462. size. This will greatly increase your ability to edit and fine-tune the font.
  463. If meta-fonts are so much better than plain old ordinary fonts, why weren't
  464. they developed long ago? The main reason is that computers did not exist until
  465. recently. People find it difficult and dull to carry out calculations with
  466. a multiplicity of parameters, while today's machines do such tasks with ease.
  467. The introduction of parameters is a natural outgrowth of automation.
  468. OK, let's grant that meta-fonts sound good, at least in theory. There's still
  469. the practical problem about how to achieve them. How can we actually
  470. specify shapes that depend on unspecified parameters?
  471. If only one parameter is varying, it's fairly easy to solve the problem in
  472. a visual way, by overlaying a series of drawings that show graphically how
  473. the shape changes. For example, if the parameter varies from 0 to~1, we
  474. might prepare five sketches, corresponding to the parameter values 0,
  475. $1\over4$, $1\over2$, $3\over4$, and~1. If these sketches follow a
  476. consistent pattern, we can readily ^{interpolate} to find the shape for a
  477. value like~$2\over3$ that lies between two of the given ones. We might
  478. even try extrapolating to parameter values like 1$1\over4$.
  479. But if there are two or more independent parameters, a purely visual solution
  480. becomes too cumbersome. We must go to a verbal approach, using some sort
  481. of language to describe the desired drawings. Let's imagine, for example,
  482. that we want to explain the shape of a certain letter `a' to a friend in
  483. a distant country, using only a telephone for communication; our friend
  484. is supposed to be able to reconstruct exactly the shape we have in mind.
  485. Once we figure out a sufficiently natural way to do that, for a particular
  486. fixed shape, it isn't much of a trick to go further and make our verbal
  487. description more general, by including variable parameters instead of
  488. restricting ourselves to constants.
  489. An analogy to cooking might make this point clearer. Suppose you have just
  490. baked a delicious berry pie, and your friends ask you to tell them the
  491. ^{recipe} so that they can bake one too. If you have developed your cooking
  492. skills entirely by intuition, you might find it difficult to record exactly
  493. what you did. But there is a traditional language of recipes in which you
  494. could communicate the steps you followed; and if you take careful measurements,
  495. you might find that you used, say, 1$1\over4$ cups of sugar. The next step,
  496. if you were instructing a computer-controlled cooking machine, would be to
  497. go to a meta-recipe in which you use, say, $.25x$ cups of sugar for $x$
  498. cups of berries; or $.3x+.2y$ cups for $x$~cups of boysenberries and
  499. $y$~cups of blackberries.
  500. In other words, going from design to meta-design is essentially like
  501. going from arithmetic to elementary algebra. Numbers are replaced
  502. by simple formulas that involve unknown quantities. We will see
  503. many examples of this.
  504. A \MF\ definition of a complete typeface generally consists of three
  505. main parts. First there is a rather mundane set of subroutines that take care
  506. of necessary administrative details, such as assigning code numbers
  507. to individual characters; each character must also
  508. be positioned properly inside an invisible ``box,'' so that typesetting
  509. systems will produce the correct spacing. Next comes a more interesting
  510. collection of subroutines, designed to draw the basic strokes characteristic
  511. of the typeface (e.g., the serifs, bowls, arms, arches, and so on).
  512. These subroutines will typically be described in terms of their own special
  513. parameters, so that they can produce a variety of related strokes;
  514. a serif subroutine will, for example, be able to draw serifs of
  515. different lengths, although all of the serifs it draws should have the
  516. same ``feeling.'' Finally, there are routines for each of the characters.
  517. If the subroutines in the first and second parts have been chosen well,
  518. the routines of the third part will be fairly high-level descriptions
  519. that don't concern themselves unnecessarily with details; for example, it
  520. may be possible to substitute a different serif-drawing subroutine without
  521. changing any of the programs that use that subroutine, thereby obtaining
  522. a typeface of quite a different flavor. [A particularly striking example
  523. of this approach has been worked out by John~D. ^{Hobby} and ^{Gu} Guoan
  524. in ``A Chinese Meta-Font,'' {\sl TUGboat\/ \bf5} (1984), 119--136. By
  525. changing a set of 13 basic stroke subroutines, they were able to draw 128
  526. sample ^{Chinese characters} in three different styles (Song, Long Song,
  527. and Bold), using the same programs for the characters.]
  528. A well-written \MF\ program will express the designer's intentions more
  529. clearly than mere drawings ever can, because the language of algebra has
  530. simple ``idioms'' that make it possible to elucidate many visual relationships.
  531. Thus, \MF\ programs can be used to communicate knowledge
  532. about type design, just as recipes convey the expertise of a chef. But
  533. algebraic formulas are not easy to understand in isolation; \MF\ descriptions
  534. are meant to be read with an accompanying illustration, just as the
  535. constructions in geometry textbooks are accompanied by diagrams.
  536. Nobody is ever expected to read the text of a \MF\ program and say,
  537. ``Ah, what a beautiful letter!'' But with one or more enlarged pictures
  538. of the letter, based on one or more settings of the parameters, a reader
  539. of the \MF\ program should be able to say, ``Ah, I~understand how this
  540. beautiful letter was drawn!'' We shall see that the \MF\ system makes it
  541. fairly easy to obtain annotated proof drawings that you can hold in your
  542. hand as you are working with a program.
  543. Although \MF\ is intended to provide a relatively painless way to describe
  544. meta-fonts, you can, of course, use it also to describe unvarying shapes that
  545. have no ``meta-ness'' at all. Indeed, you need not even use it to produce
  546. fonts; the system will happily draw geometric designs that have no relation
  547. to the characters or glyphs of any alphabet or script. The author
  548. occasionally uses \MF\ simply as a pocket calculator, to do elementary
  549. arithmetic in an interactive way. A computer doesn't mind if its
  550. programs are put to purposes that don't match their names.
  551. \endchapter
  552. [Tinguely] made some large, brightly coloured open reliefs,
  553. juxtaposing stationary and mobile shapes.
  554. He later gave them names like\/ %
  555. {\rm Meta-^{Kandinsky}}\kern-1pt\ and\/ {\rm Meta-^{Herbin}}\kern-.5pt,
  556. to clarify the ideas and attitudes %
  557. that lay at the root of their conception.
  558. \author K. G. PONTUS ^{HULT\'EN}, {\sl Jean ^{Tinguely}: M\'eta\/} (1972)
  559.  % translated from German by Mary Whittall, 1975, p46
  560. \bigskip
  561. The idea of a meta-font should now be clear. But what good is it?
  562. The ability to manipulate lots of parameters may be interesting and fun,
  563. but does anybody really need a 6\/{\manual\seventh}\kern1pt-point font
  564. that is one fourth of the way between Baskerville and Helvetica?
  565. \author DONALD E. ^{KNUTH}, {\sl The Concept of a Meta-Font\/} (1982)
  566.  % Visible Language 16, p19
  567. \eject
  568. \beginchapter Chapter 2. Coordinates
  569. If we want to tell a computer how to draw a particular shape, we need a way to
  570. explain where the key points of that shape are supposed to be.
  571. \MF\ uses standard {\sl ^{Cartesian} ^{coordinates}\/} for this purpose:
  572. The location of a point is defined by specifying its $x$~coordinate, which
  573. is the number of units to the right of some reference point, and its
  574. $y$~coordinate, which is the number of units upward from the reference
  575. point. First we determine the horizontal (left/right) component of a
  576. point's position, then we determine the vertical (up/down) component.
  577. \MF's world is two-dimensional, so two coordinates are enough.%
  578. ^^{x coordinate} ^^{y coordinate}
  579. For example, let's consider the following six points:
  580. \displayfig 2a (4.75pc)
  581. \MF's names for the positions of these points are
  582. \begindisplay
  583. $(x_1,y_1)=(0,100)$;&$(x_2,y_2)=(100,100)$;&$(x_3,y_3)=(200,100)$;\cr
  584. $(x_4,y_4)=(0,\hfill0)$;&$(x_5,y_5)=(100,\hfill0)$;&
  585.   $(x_6,y_6)=(200,\hfill0)$.\cr
  586. \enddisplay
  587. Point 4 is the same as the reference point, since both of its coordinates
  588. are zero; to get to point~$3=(200,100)$, you start at the reference point
  589. and go 200~steps right and 100~up; and so on.
  590. \exercise Which of the six example points is closest to the point $(60,30)$?
  591. \answer Point $5=(100,0)$ is closer than any of the others. \ (See
  592. the diagram below.)
  593. \exercise True or false: All points that lie on a given horizontal straight
  594. line have the same $x$~coordinate.
  595. \answer \decreasehsize 15pc
  596. \rightfig A2a (13pc x 5pc) ^9pt
  597. False. But they all do have the same $y$~coordinate.
  598. \exercise Explain where the point $(-5,15)$ is located.
  599. \answer 5 units to the {\sl left\/} of the reference point, and 15 units up.
  600. \exercise What are the coordinates of a point that lies exactly
  601. 60~units below point~6 in the diagram above?
  602. (``Below'' means ``down the page,'' not ``under the page.'')
  603. \answer \restorehsize $(200,-60)$.
  604. In a typical application of \MF\!, you prepare a rough sketch of the shape
  605. you plan to define, on a piece of ^{graph paper}, and you label important
  606. points on that sketch with any convenient numbers. Then you write a \MF\
  607. program that explains (i)~the coordinates of those key points, and
  608. (ii)~the lines or curves that are supposed to go between them.
  609. \MF\ has its own internal graph paper, which forms a so-called ^{raster}
  610. or ^{grid} consisting of square ``^{pixels}.'' ^^{pel, see pixel}
  611. The output of \MF\ will \hbox{specify} that certain of the pixels are ``black''
  612. and that the others are ``white''; thus, the computer essentially converts
  613. shapes into binary patterns like the designs a~person can make when doing
  614. needlepoint with two colors of yarn.
  615. Coordinates are lengths, but we haven't discussed yet what the units of
  616. length actually are. It's important to choose convenient units,
  617. and \MF's coordinates are given in units of pixels.  The little squares
  618. illustrated on the previous page, which correspond to differences
  619. of 10~units in an $x$~coordinate or a $y$~coordinate, therefore represent
  620. $10\times10$ arrays of pixels, and the rectangle enclosed by our six
  621. example points contains 20,000 pixels altogether.\footnote*{We
  622. sometimes use the term ``pixel'' to mean a square picture element,
  623. but sometimes we use it to signify a one-dimensional unit of length.
  624. A square pixel is one pixel-unit wide and one pixel-unit tall.}
  625. Coordinates don't have to be whole numbers. You can refer, for example,
  626. to point $(31.5,42.5)$, which lies smack in the middle of the pixel
  627. whose corners are at $(31,42)$, $(31,43)$, $(32,42)$, and~$(32,43)$.
  628. The computer works internally with coordinates that are integer multiples
  629. of ${1\over65536}\approx0.00002$ of the width of a pixel, so it is
  630. capable of making very fine distinctions. But \MF\ will never make
  631. a pixel half black; it's all or nothing, as far as the output is concerned.
  632. The fineness of a grid is usually called its {\sl ^{resolution}}, and
  633. resolution is usually expressed in pixel units per inch (in America)
  634. or pixel units per millimeter (elsewhere). For example, the type you
  635. are now reading was prepared by \MF\ with a resolution of slightly
  636. more than 700 pixels to the inch, but with slightly fewer than 30 pixels
  637. per~mm. For the time being we shall assume that the pixels are so tiny
  638. that the operation of rounding to whole pixels is unimportant;
  639. later we will consider the important questions that arise when \MF\ is
  640. producing low-resolution output.
  641. It's usually desirable to write \MF\ programs that can manufacture fonts
  642. at many different resolutions, so that a variety of low-resolution printing
  643. devices will be able to make proofs that are compatible with a variety of
  644. high-resolution devices. Therefore the key points in \MF\ programs are rarely
  645. specified in terms of pure numbers like `100'\thinspace; we generally make
  646. the coordinates relative to some other resolution-dependent quantity, so
  647. that changes will be easy to make. For example, it would have been better
  648. to use a definition something like the following, for the six points
  649. considered earlier:
  650. \begindisplay
  651. $(x_1,y_1)=(0,b)$;&$(x_2,y_2)=(a,b)$;&$(x_3,y_3)=(2a,b)$;\cr
  652. $(x_4,y_4)=(0,0)$;&$(x_5,y_5)=(a,0)$;&$(x_6,y_6)=(2a,0)$;\cr
  653. \enddisplay
  654. then the quantities $a$ and $b$ can be defined in some way appropriate to
  655. the desired resolution. We had $a=b=100$ in our previous example, but
  656. such constant values leave us with little or no flexibility.
  657. Notice the quantity `$2a$' in the definitions of $x_3$ and $x_6$; \MF\
  658. understands enough algebra to know that this means twice the value of~$a$,
  659. whatever $a$~is. We observed in Chapter~1 that simple uses of algebra give
  660. \MF\ its meta-ness.  Indeed, it is interesting to note from a historical
  661. standpoint that ^{Cartesian} coordinates are named after Ren\'e
  662. ^{Descartes}, not because he invented the idea of coordinates, but because
  663. he showed how to get much more out of that idea by applying algebraic
  664. methods. People had long since been using coordinates for such things as
  665. latitudes and longitudes, but Descartes observed that by putting unknown
  666. quantities into the coordinates it became possible to describe infinite
  667. sets of related points, and to deduce properties of curves that were
  668. extremely difficult to work out using geometrical methods alone.
  669. So far we have specified some points, but we haven't actually done
  670. anything with them.  Let's suppose that we want to draw a straight line
  671. from point~1 to point~6, obtaining
  672. \displayfig 2b (5pc)
  673. One way to do this with \MF\ is to say
  674. \begindisplay
  675. @draw@  $(x_1,y_1)\to(x_6,y_6)$.
  676. \enddisplay
  677. The `$\to$' ^^{..} here tells the computer to connect two points.
  678. It turns out that we often want to write formulas like `$(x_1,y_1)$', so
  679. it will be possible to save lots of time if we have a special abbreviation
  680. for such things. Henceforth we shall use the notation $z_1$ to stand for
  681. $(x_1,y_1)$; and in general, ^^{z convention}
  682. $z_k$ with an arbitrary subscript will stand for the point $(x_k,y_k)$.
  683. The `@draw@' command above can therefore be written more simply as
  684. \begindisplay
  685. ^@draw@ $z_1\to z_6$.
  686. \enddisplay
  687. Adding two more straight lines by saying, `@draw@ $z_2\to z_5$' and
  688. `@draw@ $z_3\to z_4$', we obtain a design that is slightly reminiscent of
  689. the ^{Union Jack}:
  690. \displayfig 2c (5.5pc)
  691. We shall call this a ^{hex symbol}, because it has six endpoints. Notice
  692. that the straight lines here have some thickness, and they are rounded at
  693. the ends as if they had been drawn with a felt-tip pen having a circular
  694. nib.  \MF\ provides many ways to control the thicknesses of lines and to
  695. vary the terminal shapes, but we shall discuss such things in later
  696. chapters because our main concern right now is to learn about coordinates.
  697. If the hex symbol is scaled down so that its height parameter $b$
  698. is exactly equal to the height of the letters in this paragraph,
  699. it looks like this: `\thinspace{\manual\hexa}\thinspace'. Just for fun,
  700. let's try to typeset ten of them in a row:
  701. \begindisplay
  702. {\manual\hexa\hexa\hexa\hexa\hexa\hexa\hexa\hexa\hexa\hexa}
  703. \enddisplay
  704. How easy it is to do this!\footnote*{Now that authors have
  705. for the first time the power to invent new symbols with great ease, and to
  706. have those characters printed in their manuscripts on a wide variety of
  707. typesetting devices, we must face the question of how much experimentation
  708. is desirable. Will font freaks abuse this toy by overdoing it? Is it wise
  709. to introduce new symbols by the thousands? Such questions are beyond
  710. the scope of this book; but it is easy to imagine an epidemic of
  711. fontomania occurring, once people realize how much fun it is to design
  712. their own characters, hence it may be necessary to perform fontal
  713. lobotomies.} % This joke due to Richard Palais, commenting on draft in 1979
  714. Let's look a bit more closely at this new character.
  715. The {\manual\hexa} is a bit too tall, because it extends above points
  716. 1, 2, and~3 when the thickness of the lines is taken into account;
  717. similarly, it sinks a bit too much below the baseline (i.e., below
  718. the line $y=0$ that contains points 4, 5, and~6). In order to correct
  719. this, we want to move the key points slightly. For example, point~$z_1$
  720. should not be exactly at $(0,b)$; we ought to arrange things so that
  721. the top of the pen is at $(0,b)$ when the center of the pen is at~$z_1$.
  722. We can express this condition for the top three points as follows:
  723. \begindisplay
  724. $"top"\,z_1=(0,b)$;&$"top"\,z_2=(a,b)$;&$"top"\,z_3=(2a,b)$;\cr
  725. \noalign{\vskip\belowdisplayskip
  726. \leftline{similarly, the remedy for points 4, 5, and 6 is to specify
  727.  the equations}
  728. \vskip\abovedisplayskip}
  729. $"bot"\,z_4=(0,0)$;&$"bot"\,z_5=(a,0)$;&$"bot"\,z_6=(2a,0)$.\cr
  730. \enddisplay
  731. The resulting squashed-in character is
  732. \displayfig 2d (4.5pc)
  733. (shown here with the original weight `\thinspace{\manual\hexb}\thinspace'
  734. and also in a bolder version `\thinspace{\manual\hexc}\thinspace').
  735. \exercise Ten of these bold hexes produce `\thinspace{\manual
  736. \hexc\hexc\hexc\hexc\hexc\hexc\hexc\hexc\hexc\hexc}\thinspace'; notice that
  737. adjacent symbols overlap each other. The reason is that each character
  738. has width $2a$, hence point~3 of one character coincides with point~1
  739. of the next. Suppose that we actually want the characters to be
  740. completely confined to a rectangular box of width~$2a$, so that
  741. adjacent characters come just shy of touching (\thinspace{\manual
  742. \hexd\hexd\hexd\hexd\hexd\hexd\hexd\hexd\hexd\hexd}\thinspace).
  743. Try to guess how the point-defining equations above could be modified
  744. to make this happen, assuming that
  745. \MF\ has operations `"lft"' and `"rt"' analogous to `"top"' and `"bot"'.
  746. \answer $"top"\,"lft"\,z_1=(0,b)$; \ $"top"\,z_2=(a,b)$; \
  747. $"top"\,"rt"\,z_3=(2a-1,b)$; \ $"bot"\,"lft"\,z_4=(0,0)$; \
  748. $"bot"\,z_5=(a,0)$; \ $"bot"\,"rt"\,z_6=(2a-1,0)$.
  749. Adjacent characters will be separated by exactly one column of white
  750. pixels, if the character is $2a$ pixels wide, because the right edge of
  751. black pixels is specified here to have the $x$~coordinate $2a-1$.
  752. Pairs of coordinates can be thought of as ``^{vectors}'' or ``displacements''
  753. as well as points. For example, $(15,8)$ can be regarded as a command to
  754. go right~15 and up~8; then point $(15,8)$ is the position we get to after
  755. starting at the reference point and obeying the command $(15,8)$. This
  756. interpretation works out nicely when we consider addition of vectors:
  757. If we move according to the vector $(15,8)$ and then move according to
  758. $(7,-3)$, the result is the same as if we move $(15,8)+(7,-3)=
  759. (15+7,8-3)=(22,5)$. The sum of two vectors $z_1=(x_1,y_1)$ and $z_2=
  760. (x_2,y_2)$ is the vector $z_1+z_2=(x_1+x_2,y_1+y_2)$ obtained by adding
  761. $x$ and $y$ components separately. This vector represents the result of
  762. moving by vector $z_1$ and then moving by vector $z_2$; alternatively,
  763. $z_1+z_2$ represents the point you get~to by starting at point~$z_1$
  764. ^^{addition of vectors}
  765. and moving by vector~$z_2$.
  766. \exercise Consider the four fundamental vectors $(0,1)$, $(1,0)$,
  767. $(0,-1)$, and $(-1,0)$. Which of them corresponds to moving one pixel unit
  768. (a)~to the right? (b)~to the left? (c)~down? (d)~up?
  769. \answer $"right"=(1,0)$; $"left"=(-1,0)$; $"down"=(0,-1)$; $"up"=(0,1)$.
  770. Vectors can be subtracted as well as added; the value of $z_1-z_2$ is simply
  771. $(x_1-x_2,y_1-y_2)$. Furthermore it is natural to multiply a vector
  772. by a single number~$c$: The quantity $c$~times $(x,y)$, which is written
  773. $c(x,y)$, equals $(cx,cy)$. Thus, for example, $2z=2(x,y)=(2x,2y)$ turns
  774. out to be equal to $z+z$. ^^{multiplication of vector by scalar}
  775. In the special case $c=-1$, we write $-(x,y)=(-x,-y)$. ^^{negation of vectors}
  776. Now we come to an important notion, based on the fact that subtraction
  777. is the opposite of addition. {\sl If $z_1$ and $z_2$ are any two points,
  778. then $z_2-z_1$ is the vector that corresponds to moving from $z_1$ to~$z_2$.}
  779. The reason is simply that $z_2-z_1$ is what we must add to~$z_1$ in order
  780. to get~$z_2$: i.e., $z_1+(z_2-z_1)=z_2$. We shall call this the
  781. {\sl ^{vector subtraction principle}}. ^^{subtraction of vectors}
  782. It is used frequently in \MF\ programs when the designer wants to specify the
  783. direction and/or distance of one point from another.
  784. \MF\ programs often use another idea to express relations between points.
  785. Suppose we start at point~$z_1$ and travel in a straight line from there
  786. in the direction of point~$z_2$, but we don't go all the way. There's a
  787. special notation for this, using square brackets: ^^{bracket notation}
  788. \begindisplay \advance\baselineskip by 3pt
  789. ${1\over3}[z_1,z_2]$ is the point one-third of the way from $z_1$ to $z_2$,\cr
  790. ${1\over2}[z_1,z_2]$ is the point midway between $z_1$ and $z_2$,\cr
  791. $.8[z_1,z_2]$ is the point eight-tenths of the way from $z_1$ to $z_2$,\cr
  792. \enddisplay
  793. and, in general, $t[z_1,z_2]$ stands for the point that lies a fraction
  794. $t$ of the way from $z_1$ to~$z_2$. We call this the operation of {\sl
  795. ^{mediation}\/} between points, or (informally) the ``^{of-the-way
  796. function}.'' If the fraction~$t$ increases from 0 to~1, the expression
  797. $t[z_1,z_2]$ traces out a straight line from $z_1$ to~$z_2$. According to
  798. the vector subtraction principle, we must move $z_2-z_1$ in order to go all
  799. the way from $z_1$ to~$z_2$, hence the point $t$~of~the~way between them is
  800. \begindisplay
  801. $t[z_1,z_2]\;=\;z_1+t(z_2-z_1)$.
  802. \enddisplay
  803. This is a general formula by which we can calculate $t[z_1,z_2]$ for any
  804. given values of $t$, $z_1$, and~$z_2$.  But \MF\ has this formula built~in,
  805. so we can use the bracket notation explicitly.
  806. For example, let's go back to our first six example points, and suppose
  807. that we want to refer to the point that's 2/5 of the way from
  808. $z_2=(100,100)$ to $z_6=(200,0)$. In \MF\ we can write this simply as
  809. $.4[z_2,z_6]$. And if we need to compute the exact coordinates for some
  810. reason, we can always work them out from the general formula, getting
  811. $z_2+.4(z_6-z_2)=(100,100)+.4\bigl((200,0)-(100,100)\bigr)=(100,100)
  812. +.4(100,-100)=(100,100)+(40,-40)=(140,60)$.
  813. \exercise True or false: The direction vector from $(5,-2)$ to $(2,3)$
  814. is $(-3,5)$.
  815. \answer True; this is $(2,3)-(5,-2)$.
  816. \exercise Explain what the notation `$0[z_1,z_2]$' means, if anything.
  817. What about `$1[z_1,z_2]$'? And `$2[z_1,z_2]$'? And `$(-.5)[z_1,z_2]$'?
  818. \answer $0[z_1,z_2]=z_1$, because we move none of the way towards~$z_2$;
  819. similarly $1[z_1,z_2]$ simplifies to~$z_2$, because we move all of the
  820. way.  If we keep going in the same direction until we've gone twice as far
  821. as the distance from $z_1$ to~$z_2$, we get to $2[z_1,z_2]$. But if we
  822. start at point~$z_1$ and face~$z_2$, then back up exactly half the distance
  823. between them, we wind up at $(-.5)[z_1,z_2]$.
  824. \exercise True or false, for mathematicians: (a)~${1\over2}[z_1,z_2]=
  825. {1\over2}(z_1+z_2)$; \ (b)~${1\over3}[z_1,z_2]={1\over3}z_1+{2\over3}z_2$;
  826. \ (c)~$t[z_1,z_2]=(1-t)[z_2,z_1]$.
  827. \answer (a)~True; both are equal to $z_1+{1\over2}(z_2-z_1)$.
  828. (b)~False, but close; the right-hand side should be
  829. ${2\over3}z_1+{1\over3}z_2$.  (c)~True; both are equal to $(1-t)z_1+tz_2$.
  830. \setbox0=\vtop{\kern -6pt
  831.   \rightline{\rlap{\vbox to 250\apspix{
  832.         \setbox2=\vbox{\kern-1pt
  833.           \hbox{\tenex\char'77} % vertical arrow extension module
  834.           \kern-1pt}
  835.   \offinterlineskip
  836.         \vbox{\hbox{\tenex\char'170}\kern0pt} % arrowhead at top
  837.         \cleaders\copy2\vfill
  838.   \kern3pt
  839.         \hbox to\wd2{\hss$b$\hss}
  840.   \kern3pt
  841.         \cleaders\copy2\vfill
  842.         \vbox{\hbox{\tenex\char'171}\kern0pt} % arrowhead at bottom
  843.         }}\kern 30\apspix
  844.     \vbox{\kern-.2pt \hrule \kern-.2pt
  845.       \hbox{\kern-.2pt \vrule \kern-.2pt
  846.         \kern30\apspix\figbox{2e}{150\apspix}{250\apspix}\vbox
  847.         \kern30\apspix\kern-.2pt\vrule \kern-.2pt}
  848.       \kern-.2pt \hrule \kern-.2pt}\quad}
  849.   \kern2pt
  850.   \rightline{\hbox to 30\apspix{\kern-.2pt\vrule height 7pt depth 2pt
  851.       \hfil$s$\hfil\vrule\kern-.2pt}%
  852.     \hbox to 150\apspix{\leftarrowfill$\,a\,$\rightarrowfill}%
  853.     \hbox to 30\apspix{\kern-.2pt\vrule height 7pt depth 2pt
  854.       \hfil$s$\hfil\vrule\kern-.2pt}\quad}}
  855. \dp0=0pt
  856. \hangindent-300\apspix \hangafter-13
  857. Let's conclude \strut\vadjust{\box0}%
  858. this chapter by using mediation
  859. to help specify the five points in the stick-figure `{\manual\Aa}'
  860. shown enlarged at the right. The distance between points 1 and~5
  861. should be~$a$, and point~3 should be $b$ pixels above the baseline;
  862. these values $a$ and~$b$ have been predetermined by some method
  863. that doesn't concern us here, and so has a ``^{sidebar}'' parameter~$s$
  864. that specifies the horizontal distance of points 1 and~5 from the
  865. edges of the type. We shall assume that we don't know for sure what
  866. the height of the bar line should be; point~2 should be somewhere on the
  867. straight line from point~1 to point~3, and point~4 should be in the
  868. corresponding place between 5 and~3, but we want to try several
  869. possibilities before we make a decision.
  870. The width of the character will be $s+a+s$, and we can specify points
  871. $z_1$ and $z_5$ by the equations
  872. \begindisplay
  873. $"bot"\,z_1=(s,0)$;\qquad $z_5=z_1+(a,0)$.
  874. \enddisplay
  875. There are other ways to do the job, but these formulas clearly express
  876. our intention to have the bottom of the pen at the baseline, $s$ pixels
  877. to the right of the reference point, when the pen is at~$z_1$,
  878. and to have $z_5$ exactly $a$~pixels to the right of~$z_1$.
  879. Next, we can say
  880. \begindisplay
  881. $z_3=\bigl({1\over2}[x_1,x_5],b\bigr)$;
  882. \enddisplay
  883. this means that the $x$ coordinate of point 3 should be halfway between
  884. the $x$~coordinates of points 1 and~5, and that $y_3=b$.  Finally, let's say
  885. \begindisplay
  886. $z_2="alpha"[z_1,z_3]$;\qquad $z_4="alpha"[z_5,z_3]$;
  887. \enddisplay
  888. the parameter "alpha" is a number between 0 and~1 that governs the
  889. position of the bar line, and it will be supplied later. When "alpha"
  890. has indeed received a value, we can say
  891. \begindisplay
  892. @draw@ $z_1\to z_3$;\qquad @draw@ $z_3\to z_5$;\qquad @draw@ $z_2\to z_4$.
  893. \enddisplay
  894. \MF\ will draw the characters `{\manual\sevenAs}' when "alpha" varies
  895. from 0.2 to 0.5 in steps of 0.05 and when $a=150$, $b=250$, $s=30$.
  896. The illustration on the previous page has $"alpha"=(3-\sqrt5\,)/2\approx
  897. 0.38197$; this value makes the ratio of the area above the bar to the area
  898. below it equal to $(\sqrt5-1)/2\approx0.61803$, the so-called ``^{golden
  899. ratio}'' of classical Greek mathematics.
  900. \danger (Are you sure you should be reading this paragraph? The
  901. ``^{dangerous bend}'' sign here is meant to warn you about material that
  902. ought to be skipped on first reading. And maybe also on second reading.
  903. The reader-beware paragraphs sometimes refer to concepts that aren't
  904. explained until later chapters.)
  905. \dangerexercise Why is it better to define $z_3$ as $\bigl({1\over2}[x_1,
  906. x_5],b\bigr)$, rather than to work out the explicit coordinates
  907. $z_3=(s+{1\over2}a,\,b)$ that are implied by the other equations?
  908. \answer There are several reasons. (1)~The equations in a \MF\ program
  909. should represent the programmer's intentions as directly as possible;
  910. it's hard to understand those intentions if you are shown only
  911. their ultimate consequences, since it's not easy to reconstruct algebraic
  912. manipulations that have gone on behind the scenes. (2)~It's easier and
  913. safer to let the computer do algebraic calculations, rather than
  914. to do them by hand. (3)~If the specifications for $z_1$ and $z_5$ change,
  915. the formula $\bigl({1\over2}[x_1,x_5],b\bigr)$
  916. still gives a reasonable value for~$z_3$. It's
  917. almost always good to anticipate the need for subsequent modifications.\par
  918. However, the stated formula for $z_3$ isn't the only reasonable way to
  919. proceed. We could, for example, give two equations
  920. \begindisplay
  921. $x_3-x_1=x_5-x_3$;\qquad $y_3=b$;
  922. \enddisplay
  923. the first of these states that the horizontal distance from 1 to 3 is
  924. the same as the horizontal distance from 3 to~5. We'll see later that
  925. \MF\ is able to solve a wide variety of equations.
  926. \ninepoint  % all dangerous from here
  927. \ddangerexercise Given $z_1$, $z_3$, and $z_5$ as above, explain how
  928. to define $z_2$ and~$z_4$ so that all of the following conditions hold
  929. simultaneously:
  930. \enddanger
  931. \smallskip
  932. \item\bull the line from $z_2$ to $z_4$ slopes upward at a $20^\circ$ angle;
  933. \item\bull the $y$ coordinate of that line's midpoint is 2/3 of the
  934. way from $y_3$ to $y_1$;
  935. \item\bull $z_2$ and $z_4$ are on the respective lines $z_1\to z_3$ and
  936. $z_3\to z_5$.
  937. \smallskip\noindent
  938. (If you solve this exercise, you deserve an `{\manual\Az}'.)
  939. \answer The following four equations suffice to define the four
  940. unknown quantities $x_2$, $y_2$, $x_4$, and $y_4$:
  941. $z_4-z_2="whatever"\ast{\rm dir}\,20$;
  942. ${1\over2}[y_2,y_4]={2\over3}[y_3,y_1]$;
  943. $z_2="whatever"[z_1,z_3]$;
  944. $z_4="whatever"[z_3,z_5]$. ^^"whatever" ^^{dir}
  945. \endchapter
  946. Here, where we reach the sphere of mathematics,
  947. we are among processes which seem to some
  948. the most inhuman of all human activities
  949. and the most remote from poetry.
  950. Yet it is here that the artist has the fullest scope for his imagination.
  951. \author HAVELOCK ^{ELLIS}, {\sl The Dance of Life\/} (1923) % pp 138--139
  952. \bigskip
  953. To anyone who has lived in a modern American city (except Boston)
  954. at least one of the underlying ideas of ^{Descartes}' analytic geometry
  955. will seem ridiculously evident. Yet, as remarked,
  956. it took mathematicians all of two thousand years
  957. to arrive at this simple thing.
  958. \author ERIC TEMPLE ^{BELL}, {\sl Mathematics: Queen and Servant of %
  959.  Science\/} (1951) % p123
  960. \eject
  961. \beginchapter Chapter 3. Curves
  962. Albrecht ^{D\"urer} and other Renaissance men attempted to establish
  963. mathematical principles of type design, but the letters they came up with
  964. were not especially beautiful. Their methods failed because they
  965. restricted themselves to ``ruler and compass'' constructions, which cannot
  966. adequately express the nuances of good calligraphy. \MF\ gets around this
  967. problem by using more powerful mathematical techniques, which provide the
  968. necessary flexibility without really being too complicated. The purpose of
  969. the present chapter is to explain the simple principles by which a
  970. computer is able to draw ``pleasing'' ^{curves}.
  971. The basic idea is to start with four points $(z_1,z_2,z_3,z_4)$ and to
  972. ^^{four-point method for curves}
  973. construct the three ^{midpoints} $z_{12}={1\over2}[z_1,z_2]$,
  974. $z_{23}={1\over2}[z_2,z_3]$, $z_{34}={1\over2}[z_3,z_4]$:
  975. \displayfig 3a (5pc)
  976. Then take those three midpoints $(z_{12},z_{23},z_{34})$ and construct
  977. two second-order midpoints $z_{123}={1\over2}[z_{12},z_{23}]$ and
  978. $z_{234}={1\over2}[z_{23},z_{34}]$; finally, construct the third-order
  979. midpoint $z_{1234}={1\over2}[z_{123},z_{234}]$:
  980. \displayfig 3b (5pc)
  981. This point $z_{1234}$ is one of the points of the curve determined by
  982. $(z_1,z_2,z_3,z_4)$. To get the remaining points of that curve,
  983. repeat the same construction on $(z_1,z_{12},z_{123},z_{1234})$ and
  984. on $(z_{1234},z_{234},z_{34},z_4)$, ad infinitum:
  985. \displayfig 3c (4.5pc)
  986. The process converges quickly, and the preliminary scaffolding
  987. (which appears above the limiting curve in our example) is ultimately discarded.
  988. The limiting curve has the following important properties:
  989. \smallskip
  990. \item\bull It begins at $z_1$, heading in the direction from $z_1$ to $z_2$.
  991. \item\bull It ends at $z_4$, heading in the direction from $z_3$ to $z_4$.
  992. \item\bull It stays entirely within the so-called convex hull of $z_1$,
  993. $z_2$, $z_3$, and $z_4$; i.e., all points of the curve lie ``between'' the
  994. defining points.
  995. \danger The recursive midpoint rule for curve-drawing was discovered in 1959
  996. by Paul ^{de Casteljau}, who showed that the curve could be described
  997. algebraically by the remarkably simple formula
  998. \begindisplay
  999. $z(t)\;=\;(1-t)^3z_1+3(1-t)^2t\,z_2+3(1-t)t^2z_3+t^3z_4$,
  1000. \enddisplay
  1001. as the parameter $t$ varies from 0 to 1. This polynomial of degree~3 in~$t$
  1002. is called a {\sl ^{Bernshte{\u\i}n polynomial}}, because Serge\u\i~N.
  1003. ^{Bernshte{\u\i}n} introduced such functions in 1912 as part of his
  1004. pioneering work on approximation theory. Curves traced out by Bernshte{\u\i}n
  1005. polynomials of degree~3 are often called {\sl B\'ezier cubics}, after
  1006. Pierre ^{B\'ezier} who realized their importance for computer-aided design
  1007. during the 1960s.
  1008. \danger It is interesting to observe that the Bernshte\u\i n polynomial
  1009. of degree~1, i.e., the function $z(t)=(1-t)\,z_1+t\,z_2$, is precisely the
  1010. ^{mediation} operator $t[z_1,z_2]$ that we discussed in the previous chapter.
  1011. Indeed, if the geometric construction we have just seen is changed to
  1012. use $t$-of-the-way points instead of midpoints (i.e., if $z_{12}=
  1013. t[z_1,z_2]$ and $z_{23}=t[z_2,z_3]$, etc.), then $z_{1234}$ turns out
  1014. to be precisely $z(t)$ in the formula above.
  1015. No matter what four points $(z_1,z_2,z_3,z_4)$ are given, the construction
  1016. on the previous page defines a curved line that runs from $z_1$ to~$z_4$.
  1017. This curve is not always interesting or beautiful; for example, if all
  1018. four of the given points lie on a straight line, the entire ``curve''
  1019. that they define will also be contained in that same line. We obtain
  1020. rather different curves from the same four starting points if we
  1021. number the points differently:
  1022. \displayfig 3d (7.05pc)
  1023. Some discretion is evidently advisable when the $z$'s are chosen. But the
  1024. four-point method is good enough to obtain satisfactory approximations to
  1025. any curve we want, provided that we break the desired curve into short
  1026. enough segments and give four suitable control points for each segment.
  1027. It turns out, in fact, that we can usually get by with only a few segments.
  1028. For example, the four-point method can produce an approximate
  1029. quarter-circle with less than 0.06\% error; it never yields an exact
  1030. circle, but the differences between four such quarter-circles and a true
  1031. circle are imperceptible.
  1032. All of the curves that \MF\ draws are based on four points, as just
  1033. described. But it isn't necessary for a user to specify all of those
  1034. points, because the computer is usually able to figure out good values of
  1035. $z_2$ and $z_3$ by itself. Only the endpoints $z_1$ and~$z_4$, through
  1036. which the curve is actually supposed to pass, are usually mentioned
  1037. explicitly in a \MF\ program.
  1038. For example, let's return to the six points that were used to introduce the
  1039. ideas of coordinates in Chapter~2. We said `@draw@ $z_1\to z_6$' in that
  1040. chapter, in order to draw a straight line from point~$z_1$ to point~$z_6$.
  1041. In general, if three or more points are listed instead of two, \MF\ will draw a
  1042. ^^{..} smooth curve through all the points. For example, the commands
  1043. `@draw@ $z_4\to z_1\to z_2\to z_6$' and `@draw@ $z_5\to z_4\to z_1
  1044. \to z_3\to z_6\to z_5$' will produce the respective results
  1045. \displayfig 3e (7.75pc)
  1046. (Unlabeled points in these diagrams are ^{control points} that \MF\ has
  1047. supplied automatically so that it can use the four-point scheme to draw
  1048. curves between each pair of adjacent points on the specified paths.)
  1049. Notice that the curve is not smooth at $z_5$ in the right-hand example,
  1050. because $z_5$~appears at both ends of that particular path. In order to
  1051. get a completely smooth curve that returns to its starting point, you can
  1052. say `@draw@ $z_5\to z_4\to z_1\to z_3\to z_6\to \cycle$' instead:
  1053. \displayfig 3f (7.25pc)
  1054. The word `^{cycle}' at the end of a path refers to the starting point
  1055. of that path.
  1056. \MF\ believes that this ^{bean-like shape}
  1057. is the nicest way to connect the given points in the given cyclic order;
  1058. but of course there are many decent curves that satisfy the specifications,
  1059. and you may have another one in mind. You can obtain finer control
  1060. by giving hints to the machine in various ways. For example, the
  1061. bean curve can be ``pulled tighter'' between $z_1$ and~$z_3$ if you say
  1062. \begindisplay
  1063. @draw@ $z_5\to z_4\to z_1\to\tension1.2\to z_3\to z_6\to \cycle$;
  1064. \enddisplay
  1065. the so-called ^{tension} between points is normally 1, and an increase
  1066. to 1.2 yields
  1067. \displayfig 3g (5.75pc)
  1068. \danger An asymmetric effect can be obtained by increasing the tension
  1069. only at point~1 but not at points 3~or~4; the shape
  1070. \displayfig 3h (6.5pc)
  1071. comes from
  1072. %\begindisplay
  1073. %@draw@ $z_5\to z_4\to\tension1\and1.5\to z_1\to
  1074. %  \tension1.5\and1\to z_3$\cr
  1075. %\hskip6em$\to z_6\to \cycle$.
  1076. %\enddisplay
  1077. `@draw@ $z_5\to z_4\to\tension1\and1.5\to z_1\to
  1078.  \tension1.5\and1\to z_3\to z_6\to \cycle$'.
  1079. The effect of tension has been achieved in this example by moving two of
  1080. the anonymous control points closer to point~1.
  1081. It's possible to control a curve in another way, by telling \MF\ what
  1082. direction to travel at some or all of the points. Such directions are
  1083. given inside curly braces; for example,
  1084. \begindisplay
  1085. @draw@ $z_5\to z_4\{"left"\}\to z_1\to z_3\to z_6\{"left"\}\to\cycle$
  1086. \enddisplay
  1087. says that the curve should be traveling leftward at points 4 and 6. The
  1088. resulting curve is perfectly straight from $z_6$ to~$z_5$ to~$z_4$:
  1089. \displayfig 3i (5.8pc)
  1090. We will see later that `"left"' is an abbreviation for the vector $(-1,0)$,
  1091. which stands for one unit of travel in a leftward direction. Any desired
  1092. direction can be specified by enclosing a vector in $\{\ldots\}$'s; for
  1093. example, the command `@draw@ $z_4\to z_2\{z_3-z_4\}\to z_3$' will draw a
  1094. curve from $z_4$ to~$z_2$ to~$z_3$ such that the tangent direction at
  1095. $z_2$ is parallel to the line $z_4\to z_3$, because $z_3-z_4$ is the
  1096. vector that represents travel from $z_4$ to~$z_3$:
  1097. \displayfig 3j (4.7pc)
  1098. The same result would have been obtained from a command such as `@draw@
  1099. $z_4\to z_2 \{10(z_3-z_4)\}\to z_3$', because the vector $10(z_3-z_4)$ has
  1100. the same direction as $z_3-z_4$. \MF\ ignores the magnitudes of vectors
  1101. when they are simply being used to specify directions.
  1102. \exercise What do you think will be the result of
  1103. `@draw@ $z_4\to z_2\{z_4-z_3\}\to z_3$', when points $z_2$, $z_3$,~$z_4$
  1104. are the same as they have been in the last several examples?
  1105. \answer The direction at $z_2$ is parallel to the line $z_4\to z_3$, but
  1106. the vector $z_4-z_3$ specifies a direction towards $z_4$, which is
  1107. $180^\circ$ different from the direction $z_3-z_4$ that was discussed in
  1108. the text. Thus, we have a difficult specification to meet, and \MF\ draws
  1109. a pretzel-shaped curve that loops around in a way that's too ugly to show
  1110. here. The first part of the path, from $z_4$ to $z_2$, is mirror symmetric
  1111. about the line~$z1\to z5$ that bisects $z_4\to z_2$, so it starts out in a
  1112. south-by-southwesterly direction; the second part is mirror symmetric about
  1113. the vertical line that bisects $z_2\to z_3$, so when the curve ends at~$z_3$
  1114. it's traveling roughly northwest. The moral is: Don't specify a direction
  1115. that runs opposite to (i.e., is the negative of) the one you really want.
  1116. \exercise Explain how to get \MF\ to draw the wiggly shape
  1117. \displayfig 3k (5pc)
  1118. in which the curve aims directly at point 2 when it's at point~6, but
  1119. directly away from point~2 when it's at point~4. [{\sl Hint:\/} No
  1120. tension changes are needed; it's merely necessary to specify directions
  1121. at $z_4$ and~$z_6$.]
  1122. \answer @draw@ $z_5\to z_4\{z_4-z_2\}\to z_1\to z_3\to z_6\{z_2-z_6\}
  1123. \to\cycle$.
  1124. \MF\ allows you to change the shape of a curve at its endpoints by
  1125. specifying different amounts of ``^{curl}.'' For example, the two commands
  1126. \begindisplay
  1127. @draw@ $z_4\{\curl0\}\to z_2\{z3-z4\}\to\{\curl0\}\,z_3$;\cr
  1128. @draw@ $z_4\{\curl2\}\to z_2\{z3-z4\}\to\{\curl2\}\,z_3$\cr
  1129. \enddisplay
  1130. give the respective curves
  1131. \displayfig 3l (5pc)
  1132. which can be compared with the one shown earlier when no special curl was
  1133. requested. \ (The specification `$\curl1$' is assumed at an endpoint
  1134. if no explicit curl or direction has been mentioned, just as
  1135. `$\tension1$' is implied between points when no tension has
  1136. been explicitly given.) \ Chapter 14 explains more about~this.
  1137. It's possible to get curved lines instead of straight lines even when
  1138. only two points are named, if a direction has been prescribed at one or
  1139. both of the points. For example,
  1140. \begindisplay
  1141. @draw@ $z_4\{z_2-z_4\}\to\{"down"\}\,z_6$\cr
  1142. \enddisplay
  1143. asks \MF\ for a curve that starts traveling towards $z_2$ but finishes
  1144. in a downward direction:
  1145. \displayfig 3m (4pc)
  1146. \danger Here are some of the curves that \MF\ draws between two points, when
  1147. it is asked to move outward from the left-hand point at an angle of
  1148. $60^\circ$, and to approach the right-hand point at various angles:
  1149. \displayfig 3aa (2.6cm)
  1150. This diagram was produced by the \MF\ program ^^@for@ ^^@step@ ^^@until@ ^^"cm"
  1151. \begindisplay
  1152. @for@ $d=0$ @step@ 10 @until@ 120:\cr
  1153. \indent @draw@ $(0,0)\{{\rm dir}\,60\}\to\{{\rm dir}\,{-d}\}(6"cm",0)$;
  1154.  @endfor@;\cr
  1155. \enddisplay
  1156. the `^{dir}' function specifies a direction measured in degrees
  1157. counterclockwise from a horizontal rightward line, hence `${\rm dir}\,{-d}$'
  1158. gives a direction that is $d^\circ$ below the horizon.  The lowest curves
  1159. in the illustration correspond to small values of $d$, and the highest
  1160. curves correspond to values near $120^\circ$.
  1161. \danger A car that drives along the upper paths in the diagram above
  1162. is always turning to the right, but in the lower paths it comes to a
  1163. point where it needs to turn to the left in order to reach its destination
  1164. from the specified direction.
  1165. The place where a path changes its curvature from right to left or
  1166. vice versa is called an ``^{inflection point}.'' \MF\ introduces
  1167. inflection points when it seems better to change the curvature than
  1168. to make a sharp turn; indeed, when $d$ is negative there is no way to
  1169. avoid points of inflection, and the curves for small positive~$d$ ought to
  1170. be similar to those obtained when $d$~has small negative values. The program
  1171. \begindisplay
  1172. @for@ $d=0$ @step@ $-10$ @until@ $-90$:\cr
  1173. \indent @draw@ $(0,0)\{{\rm dir}\,60\}\to\{{\rm dir}\,{-d}\}(6"cm",0)$;
  1174.  @endfor@\cr
  1175. \enddisplay
  1176. shows what \MF\ does when $d$ is negative:
  1177. \displayfig 3bb (2.8cm)
  1178. \danger It is sometimes desirable to avoid points of inflection, when $d$ is
  1179. positive, and to require the curve to remain inside the triangle
  1180. determined by its initial and final directions. This can be achieved
  1181. ^^{...}
  1182. by using three dots instead of two when you specify a curve: The program
  1183. \begindisplay
  1184. @for@ $d=0$ @step@ 10 @until@ 120:\cr
  1185. \indent @draw@ $(0,0)\{{\rm dir}\,60\}\ldots\{{\rm dir}\,{-d}\}(6"cm",0)$;
  1186.  @endfor@\cr
  1187. \enddisplay
  1188. generates the curves
  1189. \displayfig 3cc (2.6cm)
  1190. which are the same as before except that inflection points do not occur
  1191. for the small values of~$d$. The `$\ldots$' specification keeps the
  1192. curve ``^{bounded}'' inside the triangle that is defined by the endpoints
  1193. and directions; but it has no effect when there is
  1194. no such triangle.  More precisely, suppose that the curve goes from $z_0$
  1195. to~$z_1$; if there's a point~$z$ such that the initial direction is from
  1196. $z_0$ to~$z$ and the final direction is from $z$ to~$z_1$, then the curve
  1197. specified by `$\ldots$' will stay entirely within the triangle whose
  1198. corners are $z_0$, $z_1$, and~$z$. But if there's no such triangle
  1199. (e.g., if $d<0$ or $d>120$ in our example program), both `$\ldots$'
  1200. and~`$\to$' will produce the same curves.
  1201. In this chapter we have seen lots of different ways to get \MF\ to draw
  1202. curves.  And there's one more way, which subsumes all of the others.
  1203. If changes to tensions, curls, directions, and/or boundedness
  1204. aren't enough to produce the sort of curve that a person wants, it's
  1205. always possible as a last resort to specify all four of the points in the
  1206. four-point method.  For example, the command
  1207. \begindisplay
  1208. @draw@ $z_4\to\controls z_1\and z_2\to z_6$
  1209. \enddisplay
  1210. will draw the following curve from $z_4$ to $z_6$:^^{controls}
  1211. \displayfig 3n (5pc)
  1212. \endchapter
  1213. And so I think I have omitted nothing
  1214. % Et ainsi ie pense n'auoir rien omis des elemens,
  1215. that is necessary to an understanding of curved lines.
  1216. % qui sont necessaires pour la connoissance des lignes courbes.
  1217. \author REN\'E ^{DESCARTES}, {\sl La G\'eom\'etrie\/} (1637) % p369
  1218. \bigskip
  1219. Rules or substitutes for the artist's hand must necessarily be inadequate,
  1220. although, when set down by such men as
  1221. ^{D\"urer}, ^{Tory}, ^{Da Vinci}, ^{Serlio}, and others,
  1222. they probably do establish canons of proportion and construction
  1223. which afford a sound basis upon which to present new expressions.
  1224. \author FREDERIC W. ^{GOUDY}, {\sl Typologia\/} (1940) % p 138f
  1225. \eject
  1226. \beginchapter Chapter 4. Pens
  1227. Our examples so far have involved straight lines or curved lines that look
  1228. as if they were drawn by a felt-tip ^{pen}, where the ^{nib} of that pen
  1229. was perfectly round.  A mathematical ``line'' has no thickness, so it's
  1230. invisible; but when we plot circular dots at each point of an infinitely
  1231. thin line, we get a visible line that has constant thickness.
  1232. Lines of constant thickness have their uses, but \MF\ also provides
  1233. several other kinds of scrivener's tools, and we shall take a look at some
  1234. of them in this chapter. We'll see not only that the sizes and shapes of
  1235. pen nibs can be varied, but also that characters can be built up in such a
  1236. way that the outlines of each stroke are precisely controlled.
  1237. \def\kk{\kern2pt } % kidney-bean kern
  1238. First let's consider the simplest extensions of what we have seen before.
  1239. The letter `{\manual\Aa}' of Chapter~2 and the kidney-^{bean}
  1240. `\kk{\manual\beana}\kk' of Chapter~3 were drawn with circular pen nibs of
  1241. diameter $0.4\pt$, where `pt' stands for a printer's point;\footnote*{$
  1242. 1\,{\rm in}=2.54\,{\rm cm}=72.27\pt$ exactly, as explained in
  1243. {\sl The \TeX book}.} $0.4\pt$ is the standard thickness of a ruled line
  1244. `$\,\vcenter{\hrule width 2em}\,$' drawn by \TeX. Such a penpoint can be
  1245. specified by telling \MF\ to
  1246. \begindisplay
  1247. \pickup @pencircle@ ^{scaled} $0.4"pt"$;
  1248. \enddisplay
  1249. \MF\ will use the pen it has most recently picked up ^^@pickup@
  1250. whenever it is asked to `^@draw@' anything. A ^@pencircle@ is a
  1251. circular pen whose diameter is the width of one pixel. Scaling it
  1252. by $0.4"pt"$ will change it to the size that corresponds
  1253. to $0.4\pt$ in the output, because ^"pt" is the number of pixels
  1254. in $1\pt$. If the key points $(z_1,z_2,z_3,z_4,z_5,z_6)$ of Chapters 2 and~3
  1255. have already been defined, the \MF\ commands
  1256. \begindisplay
  1257. \pickup @pencircle@ scaled $0.8"pt"$;\cr
  1258. @draw@ $z_5\to z_4\to z_1\to z_3\to z_6\to \cycle$\cr
  1259. \enddisplay
  1260. will produce a bean shape twice as thick as before: `\kk{\manual\beanb}\kk'
  1261. instead of `\kk{\manual\beana}\kk'.
  1262. More interesting effects arise when we use non-circular pen nibs. For example,
  1263. the command
  1264. \begindisplay
  1265. \pickup @pencircle@ ^{xscaled} $0.8"pt"$ ^{yscaled} $0.2"pt"$
  1266. \enddisplay
  1267. picks up a pen whose tip has the shape of an ellipse, $0.8\pt$ wide and
  1268. $0.2\pt$ tall; magnified 10 times, it looks like this:
  1269. `$\,\vcenter{\hbox{\manual\niba}}\,$'.
  1270. \ (The operation of ``xscaling'' multiplies $x$~coordinates by a specified
  1271. amount but leaves $y$~coordinates unchanged, and the operation of
  1272. ``yscaling'' is similar.) \ Using such a pen, the `\kk{\manual\beana}\kk'
  1273. becomes `\kk{\manual\beanc}\kk', and `{\manual\Aa}' becomes `{\manual\Ab}'.
  1274. Furthermore,
  1275. \begindisplay
  1276. \pickup @pencircle@ xscaled $0.8"pt"$ yscaled $0.2"pt"$ ^{rotated} 30
  1277. \enddisplay
  1278. takes that ellipse and rotates it $30^\circ$ counterclockwise, obtaining the nib
  1279. `$\vcenter{\hbox{\manual\nibb}}$'; this changes `\kk{\manual\beanc}\kk' into
  1280. `\kk{\manual\beand}\kk' and `{\manual\Ab}' into `{\manual\Ac}'. An
  1281. enlarged view of the bean shape shows more clearly what is going on:
  1282. \displayfig 4a (7pc)
  1283. The right-hand example was obtained by eliminating the clause
  1284. `yscaled~$0.2"pt"$'; this makes the pen almost razor thin, only
  1285. one pixel tall before rotation.
  1286. \exercise Describe the pen shapes defined by
  1287. (a)~@pencircle@ xscaled~$0.2"pt"$ yscaled~$0.8"pt"$;
  1288. \ (b)~@pencircle@ scaled~$0.8"pt"$ rotated~30;
  1289. \ (c)~@pencircle@ xscaled~.25 scaled~$0.8"pt"$.
  1290. \answer (a)~An ellipse $0.8\pt$ tall and $0.2\pt$ wide
  1291. (`$\,\vcenter{\hbox{\manual\nibc}}\,$');
  1292. \ (b)~a~circle of diameter $0.8\pt$ (rotation doesn't change a circle!);
  1293. \ (c)~same as~(a).
  1294. \exercise We've seen many examples of `^@draw@'
  1295. used with two or more points. What do you think \MF\ will do
  1296. if you ask it to perform the following commands?
  1297. \begindisplay
  1298. @draw@ $z_1$;\ @draw@ $z_2$; \ @draw@ $z_3$; \ @draw@ $z_4$;
  1299.  \ @draw@ $z_5$; \ @draw@ $z_6$.
  1300. \enddisplay
  1301. \answer Six individual points will be drawn, instead of lines or curves.
  1302. These points will be drawn with the current pen. However, for technical
  1303. reasons explained in Chapter~24, the @draw@ command does its best work when it
  1304. is moving the pen; the pixels you get at the endpoints of curves are
  1305. not always what you would expect, especially at low resolutions. It is
  1306. usually best to say `^@drawdot@' instead of `@draw@' when you are drawing
  1307. only ^{one point}.
  1308. \def\hidecoords(#1,#2){\hbox to 0pt{\hss$\scriptstyle(#1,#2)$\hss}}
  1309. \setbox0=\vtop{\kern 42pt
  1310.   \rightline{\vbox{\hbox to 208\apspix{\hidecoords(0,h)\hfil
  1311.         \hidecoords(w\mkern-2mu,h)}
  1312.       \kern3pt
  1313.       \figbox{4b}{208\apspix}{216\apspix}\vbox
  1314.       \kern-3pt
  1315.       \hbox to 208\apspix{\hidecoords(0,0)\hfil
  1316.         \hidecoords(w\mkern-2mu,0)}}\quad}}
  1317. \dp0=0pt
  1318. \hangindent-125pt \hangafter4
  1319. \indent\strut\vadjust{\box0}%
  1320. Let's turn now to the design of a real letter that has already appeared
  1321. many times in this manual, namely the `\thinspace{\manual ^{T}}\thinspace' of
  1322. `\MF'. All seven of ^^{METAFONT logo} the distinct letters in `\MF' will
  1323. be used to illustrate various ideas as we get into the details of the
  1324. language; we might as well start with~`\thinspace{\manual T}\thinspace',
  1325. because it occurs twice, and (especially) because it's the simplest. An
  1326. enlarged version of this letter is shown at the right of this paragraph,
  1327. including the locations of its four key points $(z_1,z_2,z_3,z_4)$ and its
  1328. ^{bounding box}. Typesetting systems like \TeX\ are based on the
  1329. assumption that each character fits in a rectangular ^{box}; we shall
  1330. discuss boxes in detail later, but for now we will be content simply to
  1331. know that such boundaries do exist.\footnote*{Strictly speaking, the
  1332. bounding box doesn't actually have to ``bound'' the black pixels of a
  1333. character; for example, the `\thinspace{\manual q}\thinspace' protrudes
  1334. slightly below the baseline at point~4, and italic letters frequently
  1335. extend rather far to the right of their boxes. However, \TeX\ positions
  1336. all characters by lumping boxes together as if they were pieces of metal
  1337. type that contain all of the ink.} Numbers $h$ and~$w$ ^^"h" ^^"w" will
  1338. have been computed so that the corners of the box are at positions
  1339. $(0,0)$, $(0,h)$, $(w,0)$, and~$(w,h)$ as shown.
  1340. \hangindent-125pt
  1341. \hangafter\prevgraf \advance\hangafter by -16 % 4+12 (12 lines for the figure)
  1342. Each of the letters in `\MF' is drawn with a pen whose nib is an unrotated
  1343. ellipse, 90\% as tall as it is wide. In the 10-point size, which is used
  1344. for the main text of this book, the pen is $2/3\pt$ wide, so it has
  1345. been specified by the command
  1346. \begindisplay
  1347. \pickup @pencircle@ scaled $2\over3$"pt" yscaled $9\over10$
  1348. \enddisplay
  1349. or something equivalent to this.
  1350. We shall assume that a special value `$o$' has been computed so that the
  1351. bottom of the vertical stroke in `\thinspace{\manual T}\thinspace' should
  1352. descend exactly $o$~pixels below the baseline; ^^"o" this is called the
  1353. amount of ``^{overshoot}.'' Given $h$, $w$, and~$o$, it is a simple matter
  1354. to define the four key points and to draw the
  1355. `\thinspace{\manual T}\thinspace':  ^^"top" ^^"lft" ^^"rt" ^^"bot"
  1356. \begindisplay
  1357. $"top"\,"lft"\,z_1=(0,h)$; \quad $"top"\,"rt"\,z_2=(w,h)$;\cr
  1358. $"top"\,z_3=(.5w,h)$; \quad $"bot"\,z_4=(.5w,-o)$;\cr
  1359. @draw@ $z_1\to z_2$; \quad @draw@ $z_3\to z_4$.\cr
  1360. \enddisplay
  1361. \danger Sometimes it is easier and/or clearer to define the $x$ and~$y$
  1362. ^{coordinates} separately. For example, the key points of
  1363. the~`\thinspace{\manual j}\thinspace'
  1364. could also be specified thus:
  1365. \begindisplay
  1366. $"lft"\,x_1=0$;&$w-x_2=x_1$;&$x_3=x_4=.5w$;\cr
  1367. $"top"\,y_1=h$;&$"bot"\,y_4=-o$;&$y_1=y_2=y_3$.\cr
  1368. \enddisplay
  1369. The equation $w-x_2=x_1$ expresses the fact that $x_2$ is just as far from
  1370. the right edge of the bounding box as $x_1$ is from the left edge.
  1371. \danger What exactly does `"top"\!' mean in a \MF\ equation? If the
  1372. currently-picked-up pen extends $l$~pixels to the left of its center,
  1373. $r$~pixels to the right, $t$~pixels upward and $b$~downward, then
  1374. \begindisplay
  1375. $"top"\,z=z+(0,t)$,\kern-1em&$"bot"\,z=z-(0,b)$,\kern-1em&
  1376. $"lft"\,z=z-(l,0)$,\kern-1em&$"rt"\,z=z+(r,0)$,\cr
  1377. \noalign{\vskip\belowdisplayskip
  1378. \vbox{\noindent\strut
  1379. when $z$ is a pair of coordinates. But---as the previous paragraph
  1380. shows, if you study it carefully---we also have
  1381. \strut}\vskip\abovedisplayskip}
  1382. $"top"\,y=y+t$,&$"bot"\,y=y-b$,&
  1383. $"lft"\,x=x-l$,&$"rt"\,x=x+r$,\cr
  1384. \enddisplay
  1385. when $x$ and $y$ are single values instead of coordinate pairs.
  1386. You shouldn't apply `"top"\!' or `"bot"\!' to $x$~coordinates,
  1387. nor `"lft"\!' or `"rt"\!' to $y$~coordinates.
  1388. \dangerexercise True or false: $"top"\,"bot"\,z=z$, whenever $z$
  1389. is a pair of coordinates.
  1390. \answer True, for all of the pens discussed so far. But false in general,
  1391. since we will see later that pens might extend further upward than
  1392. downward; i.e., $t$~might be unequal to~$b$ in the equations for
  1393. "top" and "bot".
  1394. \setbox0=\vtop{\kern -12pt
  1395.   \rightline{\vbox{\hbox to 288\apspix{\hidecoords(0,h)\hfil
  1396.         \hidecoords(w\mkern-2mu,h)}
  1397.       \kern3pt
  1398.       \figbox{4c}{288\apspix}{216\apspix}\vbox
  1399.       \kern-3pt
  1400.       \hbox to 288\apspix{\hidecoords(0,0)\hfil
  1401.         \hidecoords(w\mkern-2mu,0)}}\quad}}
  1402. \dp0=0pt
  1403. \begingroup\decreasehsize 165pt
  1404. \dangerexercise An enlarged \strut\vadjust{\box0}%
  1405. picture of \MF's `{\manual h}' shows that it has five key points. Assuming ^^{M}
  1406. that special values $ss$ and~"ygap" have been precomputed and that the equations
  1407. \begindisplay
  1408. $x_1=ss=w-x5$;\quad$y_3-y_1="ygap"$\cr
  1409. \enddisplay
  1410. have already been given, what further equations and `@draw@' ^^{METAFONT
  1411. logo} commands will complete the specification of this letter? \ (The
  1412. value of~$w$ will be greater for~`\thinspace{\manual h}\thinspace' than it was
  1413. for~`\thinspace{\manual j}\thinspace'; it
  1414. stands for the pixel width of whatever character is currently being drawn.)
  1415. \answer $x_2=x_1$; $x_3={1\over2}[x_2,x_4]$; $x_4=x_5$; $"bot"\,y_1=-o$;
  1416. $"top"\,y_2=h+o$; $y_4=y_2$; $y_5=y_1$; @draw@ $z_1\to z_2$;
  1417. @draw@ $z_2\to z_3$; @draw@ $z_3\to z_4$; @draw@ $z_4\to z_5$.
  1418. We will learn later that the four @draw@ commands can be replaced by
  1419. \begindisplay
  1420. @draw@ $z_1\dashto z_2\dashto z_3\dashto z_4\dashto z_5$;
  1421. \enddisplay
  1422. in fact, this will make \MF\ run slightly faster. ^^{--}
  1423. \endgroup % end of the diminished \hsize
  1424. \MF's ability to `@draw@' allows it to produce character shapes that are
  1425. satisfactory for many applications, but the shapes are inherently limited
  1426. by the fact that the simulated pen nib must stay the same through an
  1427. entire stroke. Human penpushers are able to get richer effects by
  1428. using different amounts of pressure and/or by rotating the pen as they draw.
  1429. We can obtain finer control over the characters we produce if we specify
  1430. their outlines, instead of working only with key points that lie somewhere
  1431. in the middle.  In fact, \MF\ works internally with outlines, and the
  1432. computer finds it much easier to fill a region with solid black than to
  1433. figure out what pixels are blackened by a moving pen. There's a `^@fill@'
  1434. command that does region filling; for example, the solid ^{bean} shape
  1435. \displayfig 4d (6.5pc)
  1436. can be obtained from our six famous example points by giving the command
  1437. \begindisplay
  1438. @fill@ $z_5\to z_4\to z_1\to z_3\to z_6\to \cycle$.
  1439. \enddisplay
  1440. The filled region is essentially what would be cut out by an
  1441. infinitely sharp ^{knife} blade if it traced over the given curve while
  1442. cutting a piece of thin film. A @draw@ command needs to add thickness to
  1443. its curve, because the result would otherwise be invisible; but a @fill@
  1444. command adds no thickness.
  1445. The curve in a @fill@ command must end with `^{cycle}', because an
  1446. entire region must be filled. It wouldn't make sense to say, e.g.,
  1447. `@fill@ $z_1\to z_2$'. The cycle being filled shouldn't cross itself,
  1448. either; \MF\ would have lots of trouble trying to figure out how to
  1449. obey a command like `@fill@ $z_1\to z_6\to z_3\to z_4\to\cycle$'.
  1450. \dangerexercise Chapter 3 discusses the curve $z_5\to z_4\to z_1\to
  1451. z_3\to z_6\to z_5$, which isn't smooth at~$z_5$. Since this curve
  1452. doesn't end with `cycle', you can't use it in a @fill@ command.
  1453. But it does define a closed region. How can \MF\ be instructed
  1454. to fill that region?
  1455. \answer Either say `@fill@ $z_5\to z_4\to z_1\to z_3\to z_6\to z_5\to
  1456. \cycle$', which doubles point~$z_5$ and abandons smoothness there,
  1457. or `@fill@ $z_5\{\curl1\}\to z_4\to z_1\to z_3\to z_6\to
  1458. \{\curl1\}\cycle$'. In the latter case you can omit either one of
  1459. the ^{curl} specifications, but not both.
  1460. The black ^{triangle} `{\manual\char'170}' that appears in the statement of
  1461. exercises in this book was drawn with the command
  1462. \begindisplay
  1463. @fill@ $z_1\dashto z_2\dashto z_3\dashto\cycle$
  1464. \enddisplay
  1465. after appropriate corner points $z_1$, $z_2$, and $z_3$ had been specified.
  1466. In this case the outline of the region to be filled was specified in terms
  1467. of the symbol `$\dashto$' instead of `$\to$'; ^^{--}^^{..}
  1468. this is a convention we haven't discussed before. Each `$\dashto$'
  1469. introduces a straight line segment, which is independent of the rest of
  1470. ^^{polygonal path}
  1471. the path that it belongs to; thus it is quite different from `$\to$', which
  1472. specifies a possibly curved line segment that connects smoothly with neighboring
  1473. points and lines of a path. In this case `$\dashto$' was used so that the
  1474. triangular region would have straight edges and sharp corners. We might say
  1475. informally that `$\to$' means ``Connect the points with a nice curve,''
  1476. while `$\dashto$' means ``Connect the points with a straight line.''
  1477. \setbox0=\vtop{\kern -9pt
  1478.   \rightline{\vbox{\hbox to 180\apspix{\hidecoords(0,h)\hfil
  1479.         \hidecoords(w\mkern-2mu,h)}
  1480.       \kern3pt
  1481.       \figbox{4e}{180\apspix}{225\apspix}\vbox
  1482.       \kern-3pt
  1483.       \hbox to 180\apspix{\hidecoords(0,0)\hfil
  1484.         \hidecoords(w\mkern-2mu,0)}}\quad}}
  1485. \dp0=0pt
  1486. \begingroup\decreasehsize 111pt
  1487. \danger \strut\vadjust{\box0}%
  1488. The corner points $z_1$, $z_2$, and $z_3$ were defined carefully
  1489. so that the triangle would be {\sl^{equilateral}}, i.e., so that all three
  1490. of its sides would have the same length. Since an equilateral triangle
  1491. has $60^\circ$ angles, the following equations did the job:
  1492. \begindisplay
  1493. $x_1=x_2=w-x_3=s$;\cr
  1494. $y_3=.5h$;\cr
  1495. $z_1-z_2=(z_3-z_2)$ ^{rotated} 60.\cr
  1496. \enddisplay
  1497. Here $w$ and $h$ represent the character's width and height, and $s$~is
  1498. the distance of the triangle from the left and right edges of the type.
  1499. \endgroup % end of the diminished \hsize
  1500. \danger The @fill@ command has a companion called ^@unfill@, which changes
  1501. pixels from black to white inside a given region. For example, the solid
  1502. bean shape on the previous page can be changed to
  1503. \displayfig 4f (6.5pc)
  1504. if we say also `@unfill@ ${1\over4}[z_4,z_2]\to{3\over4}[z_4,z_2]\to\cycle$;
  1505. \ @unfill@ ${1\over4}[z_6,z_2]\to{3\over4}[z_6,z_2]\to\cycle$'.
  1506. This example shows, incidentally, that \MF\ converts a two-point specification
  1507. like `$z_1\to z_2\to\cycle$' into a more-or-less circular path, even though
  1508. two points by themselves define only a straight line.
  1509. \dangerexercise Let $z_0$ be the point $(.8[x_1,x_2],.5[y_1,y_4])$,
  1510. and introduce six new points by letting $z'_k=.2[z_k,z_0]$ for $k=1,$ 2,
  1511. \dots,~6. Explain how to obtain the shape
  1512. \displayfig 4g (7.0pc)
  1513. in which the interior region is defined by $z'_1\ldots z'_6$ instead of
  1514. by $z_1\ldots z_6$.
  1515. \answer After the six original points have been defined, say
  1516. \begindisplay
  1517. @fill@ $z_5\to z_4\to z_1\to z_3\to z_6\to\cycle$;\cr
  1518. $z_0=(.8[x_1,x_2],.5[y_1,y_4])$;\cr
  1519. @for@ $k=1$ @upto@ 6: $z_k'=.2[z_k,z_0]$; @endfor@\cr
  1520. @unfill@ $z_5'\to z_4'\to z_1'\to z_3'\to z_6'\to\cycle$.\cr
  1521. \enddisplay
  1522. The ability to fill between outlines makes it possible to pretend that we
  1523. have ^{broad-edge pens} that change in direction and pressure as they
  1524. glide over the paper, if we consider the separate paths traced out by the
  1525. pen's left edge and right edge.  For example, the stroke
  1526. \displayfig 4h (3.5pc)
  1527. can be regarded as drawn by a pen that starts at the left, inclined
  1528. at a $30^\circ$ angle; as the pen moves, it turns gradually until its
  1529. ^^{angle of pen} edge is strictly vertical by the time it reaches the
  1530. right end. The pen motion was horizontal at positions 2 and~3. This stroke
  1531. was actually obtained by the command
  1532. \begindisplay
  1533. @fill@ $z_{1l}\to z_{2l}\{"right"\}\to\{"right"\}\,z_{3l}$\cr
  1534. $\hskip4em\dashto z_{3r}\{"left"\}\to\{"left"\}\,z_{2r}\to z_{1r}$\cr
  1535. $\hskip4em\dashto\cycle$;
  1536. \enddisplay
  1537. i.e., \MF\ was asked to fill a region bounded by a ``left path'' from
  1538. $z_{1l}$ to $z_{2l}$ to $z_{3l}$, followed by a straight line ^^{--}
  1539. to~$z_{3r}$, then a reversed ``right path'' from $z_{3r}$ to $z_{2r}$ to
  1540. $z_{1r}$, and finally a straight line back to the starting point~$z_{1l}$.
  1541. Key positions of the ``pen'' are represented in this example by sets of
  1542. three points, like $(z_{1l},z_1,z_{1r})$, which stand for the pen's left edge,
  1543. its midpoint, and its right edge. The midpoint doesn't actually occur in the
  1544. specification of the outline, but we'll see examples of its usefulness.
  1545. The relationships between such triples of points are established by a
  1546. `^"penpos"' command, which states the breadth of the pen and its angle of
  1547. inclination at a particular position.  For example, positions 1, 2, and~3
  1548. in the stroke above were established by saying
  1549. \begindisplay
  1550. $\penpos1(1.2"pt",30)$;&
  1551. $\penpos2(1.0"pt",45)$;&
  1552. $\penpos3(0.8"pt",90)$;\cr
  1553. \enddisplay
  1554. this made the pen $1.2\pt$ broad and tipped $30^\circ$ with respect to
  1555. the horizontal at position~1, etc. In general the idea is to specify
  1556. `$\penpos k(b,d)$',
  1557. where $k$ is the position number or position name, $b$ is the breadth (in
  1558. pixels), and $d$~is the angle (in degrees). Pen angles are measured
  1559. counterclockwise from the horizontal. Thus, an angle of~0 makes the right
  1560. edge of the pen exactly $b$~pixels to the right of the left edge; an angle
  1561. of~90 makes the right pen edge exactly $b$~pixels above the left; an angle
  1562. of~$-90$ makes it exactly $b$~pixels below. An angle of 45 makes the right
  1563. edge $b/{\sqrt2}$ pixels above and $b/{\sqrt2}$ pixels to the right of the
  1564. left edge; an angle of~$-45$ makes it $b/{\sqrt2}$ pixels below and
  1565. $b/{\sqrt2}$ to the right. When the pen angle is between $90^\circ$ and
  1566. $180^\circ$, the ``right'' edge actually lies to the left of the ``left''
  1567. edge. In terms of ^{compass directions} on a conventional map, an angle
  1568. of~$0^\circ$ points due East, while $90^\circ$ points North and $-90^\circ$
  1569. points South. The angle corresponding to Southwest is $-135^\circ$,
  1570. also known as $+225^\circ$.
  1571. \exercise What angle corresponds to the direction North-Northwest?
  1572. \answer ${1\over2}\bigl["North",{1\over2}["North","West"]\bigr]=
  1573. {1\over2}\bigl[90,{1\over2}[90,180]\bigr]={1\over2}[90,135]=112.5$.
  1574. \begingroup \decreasehsize 9pc
  1575. \exercise \xdef\circlex{4.\number\exno}%
  1576. \rightfig 4i (7pc x 7pc) ^20pt
  1577. What are the pen angles at positions 1, 2, 3, and~4 in
  1578. the circular shape shown here? [{\sl Hint:\/} Each angle is a multiple
  1579. of $30^\circ$. Note that $z_{3r}$ lies to the left of $z_{3l}$.]
  1580. \answer $30^\circ$, $60^\circ$, $210^\circ$, and $240^\circ$. Since it's
  1581. possible to add or subtract $360^\circ$ without changing the meaning,
  1582. the answers $-330^\circ$, $-300^\circ$, $-150^\circ$, and $-120^\circ$
  1583. are also correct.
  1584. \exercise What are the coordinates of $z_{1l}$ and $z_{1r}$ after the
  1585. command `$\penpos1(10,-90)$', if $z_1=(25,25)$?
  1586. \answer $z_{1l}=(25,30)$, $z_{1r}=(25,20)$.
  1587. \endgroup % end of the diminished \hsize
  1588. \danger The statement `$\penpos k(b,d)$' is simply an abbreviation for
  1589. two equations, `$z_k={1\over2}[z_{kl},z_{kr}]$' and
  1590. `$z_{kr}=z_{kl}+(b,0)$ ^{rotated}~$d\,$'. You might want to use other
  1591. equations to define the relationship between $z_{kl}$, $z_k$, and
  1592. $z_{kr}$, instead of giving a "penpos" command, if an alternative
  1593. formulation turns out to be more convenient.
  1594. After `"penpos"' has specified the relations between three points, we still
  1595. don't know exactly where they are; we only know their positions relative
  1596. to each other. Another equation or two is needed in order to fix the
  1597. horizontal and vertical locations of each triple. For example, the three
  1598. "penpos" commands that led to the pen stroke on the previous page were
  1599. accompanied by the equations
  1600. \begindisplay
  1601. $z_1=(0,2"pt")$;&$z_2=(4"pt",0)$;&$x_3=9"pt"$;&$y_{3l}=y_{2r}$;
  1602. \enddisplay
  1603. these made the information complete. There should be one $x$~equation and
  1604. one $y$~equation for each position; or you can use a $z$~equation, which
  1605. defines both $x$ and~$y$ simultaneously.
  1606. It's a nuisance to write long-winded @fill@ commands when broad-edge
  1607. pens are being simulated in this way, so \MF\ provides a convenient
  1608. abbreviation: You can write simply
  1609. \begindisplay
  1610. ^@penstroke@ $z_{1e}\to z_{2e}\{"right"\}\to\{"right"\}z_{3e}$
  1611. \enddisplay
  1612. instead of the command `\thinspace@fill@ $z_{1l}\to
  1613. z_{2l}\{"right"\}\to\{"right"\}\,z_{3l} \dashto
  1614. z_{3r}\{"left"\}\to\{"left"\}\,z_{2r}\to z_{1r}\dashto\cycle$' that was
  1615. stated earlier. The letter `$e$' ^^"e" stands for the pen's edge. A @penstroke@
  1616. command fills the region `$p.l\dashto \reverse p.r\dashto\cycle$', where
  1617. $p.l$ and~$p.r$ are the left and right paths formed by changing each~`$e$'
  1618. into `$l$' or~`$r$', respectively.
  1619. \danger The @penstroke@ abbreviation can be used to draw cyclic paths
  1620. as well as ordinary ones. For example, the circle in exercise \circlex\
  1621. was created by saying simply `@penstroke@ $z_{1e}\to z_{2e}\to z_{3e}\to
  1622. z_{4e}\to\cycle$'. This type of penstroke essentially expands into
  1623. \begindisplay
  1624. @fill@ $z_{1r}\to z_{2r}\to z_{3r}\to z_{4r}\to\cycle$;\cr
  1625. @unfill@ $z_{1l}\to z_{2l}\to z_{3l}\to z_{4l}\to\cycle$;\cr
  1626. \enddisplay
  1627. or the operations `@fill@' and `@unfill@' are reversed, if points
  1628. $(z_{1r},z_{2r}, z_{3r},z_{4r})$ are on the inside and
  1629. $(z_{1l},z_{2l},z_{3l},z_{4l})$ are on the outside.
  1630. \dangerexercise The circle of exercise \circlex\ was actually drawn with
  1631. a slightly more complicated @penstroke@ command than just claimed: The
  1632. edges of the curve were forced to be vertical at
  1633. positions 1 and~3, horizontal at 2 and~4. How did the author do this?
  1634. \answer He said `@penstroke@
  1635. $z_{1e}\{"up"\}\to z_{2e}\{"left"\}\to z_{3e}\{"down"\}
  1636.  \to z_{4e}\{"right"\}\to\cycle$'.
  1637. \setbox0=\vtop{\kern 21pt
  1638.   \rightline{\vbox{\hbox to 126\apspix{\hidecoords(0,h)\hfil
  1639.         \hidecoords(w\mkern-2mu,h)}
  1640.       \kern6pt
  1641.       \figbox{4j}{126\apspix}{252\apspix}\vbox
  1642.       \kern-3pt
  1643.       \hbox to 126\apspix{\hidecoords(0,0)\hfil
  1644.         \hidecoords(w\mkern-2mu,0)}}\qquad}}
  1645. \dp0=0pt
  1646. \hangindent-100pt \hangafter2
  1647. \indent\strut\vadjust{\box0}%
  1648. Here's an example of how this new sort of pen can be used to draw a
  1649. sans-serif letter `{\manual\IOI}'. As usual, we assume ^^{I}
  1650. that two variables, $h$ and~$w$, have been set up to give the height and
  1651. width of the character in pixels. We shall also assume that there's a
  1652. "stem" parameter, which specifies the nominal pen breadth. The breadth
  1653. decreases to .9"stem" in the middle of the stroke, and the
  1654. pen angle changes from $15^\circ$ to~$10^\circ$:
  1655. \begindisplay
  1656. $\penpos1("stem",15)$; \ $\penpos2(.9"stem",12)$;\cr
  1657. $\penpos3("stem",10)$; \ $x_1=x_2=x_3=.5w$;\cr
  1658. $y_1=h$; \ $y_2=.55h$; \ $y_3=0$;\cr
  1659. $x_{2l}:={1\over6}[x_{2l},x_2]$;\cr
  1660. @penstroke@ $z_{1e}\to z_{2e}\{down\}\to z_{3e}$.\cr
  1661. \enddisplay
  1662. Setting $x_1=x_2=x_3=.5w$ centers the stroke; setting $y_1=h$ and $y_3=0$
  1663. makes it sit in the type box, protruding just slightly at the top and bottom.
  1664. The second-last line of this program is something that we haven't seen
  1665. before: It resets $x_{2l}$ to a value 1/6 of the way towards the center
  1666. of the pen, thereby making the stroke ^{taper} a bit at the left.
  1667. The `$:=$' operation is called an {\sl^{assignment}\/}; we shall
  1668. ^^{:=} study the differences between `$:=$' and~`$=$' in Chapter~10.
  1669. \danger It is important to note that these simulated pens
  1670. have a serious limitation compared to the way a real calligrapher's pen
  1671. works: The left and right edges of a "penpos"-made pen must never cross,
  1672. hence it is necessary to turn the pen when going around a curve.
  1673. Consider, for example, the following two curves:
  1674. \displayfig 4k (6pc)
  1675. The left-hand circle was drawn with a broad-edge pen of fixed breadth,
  1676. held at a fixed angle; consequently the left edge of the pen was responsible
  1677. for the outer boundary on the left, but the inner boundary on the right.
  1678. \ (This curve was produced by saying `\pickup @pencircle@ xscaled~0.8"pt"
  1679. rotated~25; @draw@ $z_1\to z_2\to\cycle$'.) \ The right-hand shape
  1680. was produced by `$\penpos1(0.8"pt",25)$; $\penpos2(0.8"pt",25)$;
  1681. @penstroke@ $z_{1e}\to z_{2e}\to\cycle$'; important chunks of the shape
  1682. are missing at the crossover points, because they don't lie on either of
  1683. the circles $z_{1l}\to z_{2l}\to\cycle$ or $z_{1r}\to z_{2r}\to\cycle$.
  1684. \danger To conclude this chapter we shall improve the ^{hex} character
  1685. {\manual\hexb} of Chapter~2, which is too dark in the middle because it has
  1686. been drawn with a pen of uniform thickness. The main trouble with unvarying
  1687. pens is that they tend to produce black blotches where two strokes meet,
  1688. unless the pens are comparatively thin or unless the strokes are nearly
  1689. perpendicular. We want to thin out the lines at the center just enough
  1690. to cure the darkness problem, without destroying the illusion that the lines
  1691. still seem (at first glance) to have uniform thickness.
  1692. \setbox0=\vtop{\kern 69pt
  1693.   \rightline{\vbox{\hbox to 200\apspix{\hidecoords(0,h)\hfil
  1694.         \hidecoords(w\mkern-2mu,h)}
  1695.       \kern3pt
  1696.       \figbox{4l}{200\apspix}{100\apspix}\vbox
  1697.       \kern-3pt
  1698.       \hbox to 200\apspix{\hidecoords(0,0)\hfil
  1699.         \hidecoords(w\mkern-2mu,0)}}\quad}}
  1700. \dp0=0pt
  1701. \danger \strut\vadjust{\box0}%
  1702. It isn't difficult to produce `\thinspace
  1703. {\manual\hexe\hexe\hexe\hexe\hexe\hexe\hexe\hexe\hexe\hexe}\thinspace'
  1704. instead of `\thinspace
  1705. {\manual\hexb\hexb\hexb\hexb\hexb\hexb\hexb\hexb\hexb\hexb}\thinspace'
  1706. when we work with dynamic pens:
  1707. \begindisplay
  1708. \pickup @pencircle@ scaled $b$;\cr
  1709. $"top"\,z_1=(0,h)$; \ $"top"\,z_2=(.5w,h)$; \ $"top"\,z_3=(w,h)$;\cr
  1710. $"bot"\,z_4=(0,0)$; \ $"bot"\,z_5=(.5w,0)$; \ $"bot"\,z_6=(w,0)$; \
  1711.  @draw@ $z_2\to z_5$;\cr
  1712. $z_{1'}=.25[z_1,z_6]$; \ $z_{6'}=.75[z_1,z_6]$; \
  1713. $z_{3'}=.25[z_3,z_4]$; \ $z_{4'}=.75[z_3,z_4]$;\cr
  1714. $"theta"_1:=\angle(z_6-z_1)+90$;\cr
  1715. $"theta"_3:=\angle(z_4-z_3)+90$;\cr
  1716. $\penpos{1'}(b,"theta"_1)$; \ $\penpos{6'}(b,"theta"_1)$;\cr
  1717. $\penpos{3'}(b,"theta"_3)$; \ $\penpos{4'}(b,"theta"_3)$;\cr
  1718. $\penpos7(.6b,"theta"_1)$; \ $\penpos8(.6b,"theta"_3)$;\cr
  1719. $z_7=z_8=.5[z_1,z_6]$;\cr
  1720. @draw@ $z_1\to z_{1'}$; \ @draw@ $z_{6'}\to z_6$;\cr
  1721. @draw@ $z_3\to z_{3'}$; \ @draw@ $z_{4'}\to z_4$;\cr
  1722. @penstroke@ $z_{1'e}\{z_{6'}-z_{1'}\}\to z_{7e}\to\{z_{6'}-z_{1'}\}z_{6'e}$;\cr
  1723. @penstroke@ $z_{3'e}\{z_{4'}-z_{3'}\}\to z_{8e}\to\{z_{4'}-z_{3'}\}z_{4'e}$.\cr
  1724. \enddisplay
  1725. Here $b$ is the diameter of the pen at the terminal points;
  1726. `^{angle}' computes the direction angle of a given vector.
  1727. Adding $90^\circ$ to a direction angle gives a ^{perpendicular}
  1728. direction (see the definitions of $"theta"_1$ and~$"theta"_3$).
  1729. It isn't necessary to take anything off of the vertical stroke $z_2\to z_5$,
  1730. because the two diagonal strokes fill more than the width of the vertical
  1731. stroke at the point where they intersect.
  1732. \setbox0=\vtop{\kern -30pt
  1733.   \rightline{\vbox{\hbox to 200\apspix{\hidecoords(0,h)\hfil
  1734.         \hidecoords(w\mkern-2mu,h)}
  1735.       \kern6pt
  1736.       \figbox{4m}{200\apspix}{100\apspix}\vbox
  1737.       \kern0pt
  1738.       \hbox to 200\apspix{\hidecoords(0,0)\hfil
  1739.         \hidecoords(w\mkern-2mu,0)}}\quad}}
  1740. \dp0=0pt
  1741. \begingroup \decreasehsize 125pt
  1742. \dangerexercise \strut\vadjust{\box0}%
  1743. Modify the hex character so that its ends are cut
  1744. sharply and confined to the bounding box, as shown.
  1745. \answer We use angles ^{perpendicular} to $(w,h)$ and $(w,-h)$ at the
  1746. diagonal endpoints:
  1747. \begindisplay
  1748. $x_{1l}=x_{4l}=0$;\cr
  1749. $x_2=x_5=.5w$;\cr
  1750. $x_{3r}=x_{6r}=w$;\cr
  1751. $y_{1r}=y_2=y_{3l}=h$;\cr
  1752. $y_{4r}=y_5=y_{6l}=0$;\cr
  1753. $z_{1'}=.25[z_1,z_6]$; \ $z_{6'}=.75[z_1,z_6]$;\cr
  1754. $theta_1:=\angle(w,-h)+90$;\cr
  1755. $\penpos1(b,theta_1)$; \ $\penpos6(b,theta_1)$;\cr
  1756. $z_7=.5[z_1,z_6]$; \ $\penpos7(.6b,theta_1)$;\cr
  1757. $\penpos{1'}(b,theta_1)$; \ $\penpos{6'}(b,theta_1)$;\cr
  1758. @penstroke@ $z_{1e}\to z_{1'e}\{z_{6'}-z_{1'}\}\to z_{7e}\to
  1759. \{z_{6'}-z_{1'}\}z_{6'e}\to z_{6e}$;\cr
  1760. $z_{3'}=.25[z_3,z_4]$; \ $z_{4'}=.75[z_3,z_4]$;\cr
  1761. $theta_3:=\angle(-w,-h)+90$;\cr
  1762. $\penpos3(b,theta_3)$; \ $\penpos4(b,theta_3)$;\cr
  1763. $z_8=.5[z_1,z_6]$; \ $\penpos8(.6b,theta_3)$;\cr
  1764. $\penpos{3'}(b,theta_3)$; \ $\penpos{4'}(b,theta_3)$;\cr
  1765. @penstroke@ $z_{3e}\to z_{3'e}\{z_{4'}-z_{3'}\}\to z_{8e}\to
  1766. \{z_{4'}-z_{3'}\}z_{4'e}\to z_{4e}$;\cr
  1767. $\penpos2(b,0)$; \ $\penpos5(b,0)$; \ @penstroke@ $z_{2e}\to z_{5e}$.\cr
  1768. \enddisplay
  1769. \endgroup % end of the diminished \hsize
  1770. \endchapter
  1771. It is very important that the nib be cut ``sharp,''
  1772. and as often as its edge wears blunt it must be resharpened.
  1773. It is impossible to make ``clean cut'' strokes with a blunt pen.
  1774. \author EDWARD ^{JOHNSTON}, {\sl Writing \& Illuminating, %
  1775.  \& Lettering\/} (1906)
  1776. \bigskip
  1777. I might compare the high-speed computing machine
  1778. to a remarkably large and awkward pencil
  1779. which takes a long time to sharpen and
  1780. cannot be held in the fingers in the usual manner so that it
  1781. gives the illusion of responding to my thoughts,
  1782. but is fitted with a rather delicate engine
  1783. and will write like a mad thing
  1784. provided I am willing to let it dictate pretty much
  1785. the subjects on which it writes.
  1786. \author R. H. ^{BRUCK}, {\sl Computational Aspects of Certain
  1787.   Combinatorial Problems\/} (1956) % AMS Symp Appl Math 6, p31
  1788. \eject
  1789. \beginchapter Chapter 5. Running\\\MF
  1790. It's high time now for you to stop reading and to start playing with the
  1791. computer, since \MF\ is an interactive system that is best learned by
  1792. trial and error. \ (In fact, one of the nicest things about computer graphics
  1793. is that errors are often more interesting and more fun than ``successes.'')
  1794. You probably will have to ask somebody how to deal with the idiosyncrasies
  1795. of your particular version of the system, even though \MF\ itself works in
  1796. essentially the same way on all machines; different computer terminals and
  1797. different hardcopy devices make it necessary to have somewhat different
  1798. interfaces. In~this chapter we shall assume that you have a computer
  1799. terminal with a reasonably high-resolution graphics display; that you have
  1800. access to a (possibly low-resolution) output device; and that you can
  1801. rather easily get that device to work with newly created fonts.
  1802. OK, are you ready to run the program? First you need to log in, of course;
  1803. then start \MF\!, which is usually called ^|mf| for short. Once you've figured
  1804. out how to do it, you'll be welcomed by a message something like
  1805. $$\def\\{{\rm\ }} % take a wee bit off of the \tt spaces
  1806. \vtop{\line{\indent \tt
  1807. This\\is\\METAFONT,\\Version\\2.0\\(preloaded\\base=plain 89.11.8)}
  1808. \leftline{\indent \tt **}}$$
  1809. The `^|**|' is \MF's way of asking you for an input file name.
  1810. % Incidentally, 89.11.8 was Hermann's 71st birthday.
  1811. Now type `|\relax|'---that's ^{backslash}, |r|, |e|, |l|, |a|, |x|---and
  1812. hit ^\<return> (or~whatever stands for ``end-of-line'' on your keyboard).
  1813. \MF\ is all geared up for action, ready to make a big font; but you're
  1814. saying that it's all right to take things easy, since this is going to
  1815. be a real simple run. The backslash means that \MF\ should not read a file,
  1816. it should get instructions from the keyboard; the `^|relax|' means
  1817. ``do nothing.''
  1818. The machine will respond by typing a single asterisk: `^|*|'. This means
  1819. it's ready to accept instructions (not the name of a file). Type the
  1820. following, just for fun:
  1821. \begintt
  1822. drawdot (35,70); showit;
  1823. \endtt
  1824. and \<return>---don't forget to type the semicolons along with the other
  1825. stuff. A more-or-less circular dot should now appear on your screen! And
  1826. you should also be prompted with another asterisk.
  1827. \begintt
  1828. drawdot (65,70); showit;
  1829. \endtt
  1830. and \<return>, to get another dot. \ (Henceforth we won't keep mentioning
  1831. the necessity of \<return>ing after each line of keyboard input.) \ Finally,
  1832. \begintt
  1833. draw (20,40)..(50,25)..(80,40); showit; shipit; end.
  1834. \endtt
  1835. This draws a curve through three given points, displays the result,
  1836. ^^|showit| ^^|shipit| ^^|end|
  1837. ships it to an output file, and stops. \MF\ should respond with `|[0]|',
  1838. meaning that it has shipped out a character whose number is zero, in the
  1839. ``font'' just made; and it should also tell you that it has created
  1840. an output file called `|mfput.2602gf|'. \ (The name ^|mfput| is used when
  1841. you haven't specified any better name in response to the ^|**| at the
  1842. beginning. The suffix |2602|^|gf| stands for ``^{generic font} at
  1843. 2602 pixels per inch.'' The data in |mfput.2602gf| can be converted into
  1844. fonts suitable for a wide assortment of typographical output devices;
  1845. since it doesn't match the font file conventions of any name-brand
  1846. manufacturer, we call it generic.)
  1847. This particular file won't make a very interesting font,
  1848. because it contains only one character, and because it probably doesn't
  1849. have the correct resolution for your output device. However, it does
  1850. have the right resolution for hardcopy proofs of characters; your next
  1851. step should therefore be to convert the data of |mfput.2602gf| into a
  1852. picture, suitable for framing. There should be a program called
  1853. ^|GFtoDVI| on your computer. Apply it to |mfput.2602gf|, thereby
  1854. obtaining a file called |mfput.dvi| ^^|dvi| that can be printed.
  1855. Your friendly local computer hackers will tell you how to run
  1856. |GFtoDVI| and how to print |mfput.dvi|; then you'll have a marvelous
  1857. souvenir of your very first encounter with \MF\!. \looseness=-1
  1858. \smallskip
  1859. Once you have made a complete test run as just described, you will
  1860. know how to get through the whole cycle, so you'll be ready to tackle
  1861. a more complex project. Our next experiment will therefore be
  1862. to work from a file, instead of typing the input online.
  1863. Use your favorite text editor to create a file called |io.mf| that
  1864. contains the following 23 lines of text (no more, no less):
  1865. $$\halign{\hbox to\parindent{\hfil\sevenrm#\ \ }&#\hfil\cr
  1866. 1&|mode_setup;|\cr\noalign{^^@mode\_setup@}
  1867. 2&| em#:=10pt#; cap#:=7pt#;|\cr
  1868. 3&| thin#:=1/3pt#; thick#:=5/6pt#;|\cr
  1869. 4&| o#:=1/5pt#;|\cr
  1870. 5&|define_pixels(em,cap);|\cr
  1871. 6&|define_blacker_pixels(thin,thick);|\cr
  1872. 7&|define_corrected_pixels(o);|\cr
  1873. 8&| curve_sidebar=round 1/18em;|\cr
  1874. 9&|beginchar("O",0.8em#,cap#,0); "The letter O";|\cr
  1875. 10&| penpos1(thick,10); penpos2(.1[thin,thick],90-10);|\cr
  1876. 11&| penpos3(thick,180+10); penpos4(thin,270-10);|\cr
  1877. 12&| x1l=w-x3l=curve_sidebar; x2=x4=.5w;|\cr
  1878. 13&| y1=.49h; y2l=-o; y3=.51h; y4l=h+o;|\cr
  1879. 14&| penstroke z1e{down}..z2e{right}|\cr
  1880. 15&|            ..z3e{up}..z4e{left}..cycle;|\cr
  1881. 16&| penlabels(1,2,3,4); endchar;|\cr
  1882. 17&|def test_I(expr code,trial_stem,trial_width) =|\cr
  1883. 18&| stem#:=trial_stem*pt#; define_blacker_pixels(stem);|\cr
  1884. 19&| beginchar(code,trial_width*em#,cap#,0); "The letter I";|\cr
  1885. 20&|  penpos1(stem,15); penpos2(stem,12); penpos3(stem,10);|\cr
  1886. 21&|  x1=x2=x3=.5w; y1=h; y2=.55h; y3=0; x2l:=1/6[x2l,x2];|\cr
  1887. 22&|  penstroke z1e..z2e{down}..z3e;|\cr
  1888. 23&|  penlabels(1,2,3); endchar; enddef;|\cr}$$
  1889. (But don't type the numbers at the left of these lines; they're
  1890. only for reference.)
  1891. This example file is dedicated to ^{Io}, the Greek goddess of input
  1892. and output. It's a trifle long, but you'll be able to get worthwhile
  1893. experience by typing it; so go ahead and type it now. For your own
  1894. good. And think about what you're typing, as you go; the example
  1895. introduces several important features of \MF\ that you can learn
  1896. as you're creating the file.
  1897. Here's a brief explanation of what you've just typed: Line~1 contains a
  1898. command that usually appears near the beginning of every \MF\ file;
  1899. it tells the computer to get ready to work in whatever ``mode'' is
  1900. currently desired. \ (A file like |io.mf| can be used to generate
  1901. proofsheets as well as to make fonts for a variety of devices at a
  1902. variety of magnifications, and `@mode\_setup@' is what adapts \MF\
  1903. to the task at hand.) \ Lines 2--8 define parameters that will be used
  1904. to draw the letters in the font. Lines 9--16 give a complete program
  1905. for the letter `O'; and lines 17--23 give a program that will draw
  1906. the letter~`I' in a number of related ways.
  1907. It all looks pretty frightening at first glance, but a closer look
  1908. shows that Io is not so mysterious once we penetrate her disguise.
  1909. Let's spend a few minutes studying the file in more detail.
  1910. Lines 2--4 define dimensions that are independent of the mode; the `|#|'
  1911. ^^{sharpsign} signs are meant to imply ``sharp'' or ``true'' ^{units of
  1912. measure}, which remain the same whether we are making a font at high or
  1913. low resolution. For example, one `|pt#|' is a true printer's point, one
  1914. 72.27th of an inch. This is quite different from the `^"pt"' we have
  1915. discussed in previous chapters, because `"pt"' is the number of pixels
  1916. that happen to correspond to a printer's point when the current resolution
  1917. is taken into account. The value of `|pt#|' never changes, but
  1918. @mode\_setup@ establishes the appropriate value of `"pt"'.
  1919. The ^{assignments} `|em#:=10pt#|' and `|cap#:=7pt#|' in line~2 mean that
  1920. the Io font has two parameters, called "em" and "cap", whose mode-independent
  1921. values are 10 and~7 points, respectively. The statement ^^@define\_pixels@
  1922. `|define_pixels(em,cap)|' on line~5 converts these values into pixel
  1923. units. For example, if we are working at the comparatively low resolution
  1924. of 3~pixels per~pt, the values of "em" and "cap" after the computer has
  1925. performed the instructions on line~5 will be $"em"=30$ and $"cap"=21$.
  1926. \ (We will see later that the widths of characters in this font are
  1927. expressed in terms of ems, and that "cap" is the height of the capital
  1928. letters. A change to line~2 will therefore affect the widths and/or heights
  1929. of all the letters.)
  1930. Similarly, the Io font has parameters called "thin" and "thick", defined
  1931. on line~3 and converted to pixel units in line~6. These are used to control
  1932. the breadth of a simulated pen when it draws the letter~O. Experience has
  1933. shown that \MF\ produces better results on certain output devices if
  1934. pixel-oriented pens are made slightly broader than the true dimensions would
  1935. imply, because black pixels sometimes tend to ``burn off'' in the process
  1936. of printing. The command on line~6, `|define_blacker_pixels|',
  1937. ^^@define\_blacker\_pixels@ adds a correction based on the device for which
  1938. the font is being prepared. For example, if the resolution is 3~pixels
  1939. per point, the value of "thin" when converted from true units to pixels
  1940. by @define\_pixels@ would be~1, but @define\_blacker\_pixels@ might set
  1941. "thin" to a value closer to~2.
  1942. The `|o|' parameter ^^"o" on line 4 represents the amount by which curves will
  1943. ^{overshoot} their boundaries. This is converted to pixels in yet another
  1944. way on line~7, so as to avoid yet another problem that arises in low-resolution
  1945. printing. The author apologizes for letting such real-world considerations
  1946. intrude into a textbook example; let's not get bogged down in fussy details
  1947. now, since these refinements will be explained in Chapter~11 after we have
  1948. mastered the basics.
  1949. For now, the important point is simply that a typeface
  1950. design usually involves parameters that represent physical lengths. The
  1951. true, ``sharped'' forms of these parameters need to be converted to
  1952. ``unsharped'' pixel-oriented quantities, and best results are obtained when
  1953. such conversions are done carefully. After \MF\ has obeyed line~7 of the
  1954. example, the pixel-oriented parameters "em", "cap", "thin", "thick",
  1955. and~"o" are ready to be used as we draw letters of the font.
  1956. Line 8 defines a quantity called "curve\_sidebar" ^^{sidebar} that will
  1957. measure the distance of the left and right edges of the `O' from the
  1958. bounding box. It is computed by ^{rounding} ${1\over18}"em"$ to the nearest
  1959. integer number of pixels. For example, if $"em"=30$ then ${30\over18}=
  1960. {5\over3}$ yields the rounded value $"curve\_sidebar"=2$; there will be
  1961. two all-white columns of pixels at the left and right of the `O',
  1962. when we work at this particular resolution.
  1963. Before we go any further, we ought to discuss the strange collection
  1964. of words and pseudo-words in the file |io.mf|. Which of the terms
  1965. `|mode_setup|', `|em|', `|curve_sidebar|' and so forth are part of
  1966. the \MF\ language, and which of them are made up specifically for
  1967. the Io example? Well, it turns out that almost {\sl nothing\/} in this
  1968. example is written in the pure \MF\ language that the computer understands!
  1969. \MF\ is really a low-level language that has been designed to allow easy
  1970. adaptation to many different styles of programming, and |io.mf|
  1971. illustrates just one of countless ways to use it. Most of the terms
  1972. in |io.mf| are conventions of ``^{plain} \MF\!,'' which is a collection
  1973. of subroutines found in Appendix~B\null. \MF's primitive capabilities are
  1974. not meant to be used directly, because that would force a particular style
  1975. on all users. A ``base file'' is generally loaded into the computer
  1976. at the beginning of a run, so that a standard set of conventions is
  1977. readily available. \MF's welcoming message, quoted at the
  1978. beginning of this chapter, says `|preloaded| |base=plain|'; it
  1979. means that the primitive \MF\ language has been extended to include the
  1980. features of the plain base file.  This book is not only about \MF; it also
  1981. explains how to use the conventions of \MF's plain base. Similarly, {\sl
  1982. The \TeX book\/} describes a standard extension of \TeX\ called ``plain
  1983. \TeX\ format''; ^^{TeX} the ``plain'' extensions of \TeX\ and \MF\ are
  1984. completely analogous to each other.
  1985. The notions of @mode\_setup@, @define\_pixels@, @beginchar@, "penpos",
  1986. and many other things found in |io.mf| are aspects
  1987. of plain \MF\ but they are not hardwired into \MF\ itself. Appendix~B
  1988. defines all of these things, as well as the relations between ``sharped''
  1989. and ``unsharped'' variables. Even the fact that $z_1$ stands for
  1990. $(x_1,y_1)$ is defined in Appendix~B\null; \MF\ does not have this built~in.
  1991. You are free to define even fancier bases as you gain more experience,
  1992. but the plain base is a suitable starting point for a novice.
  1993. \danger If you have important applications that make use of a different
  1994. base file, it's possible to create a version of \MF\ that has any desired
  1995. base preloaded. Such a program is generally called by a special name,
  1996. since the nickname `^|mf|' is reserved for the version that includes the
  1997. standard plain base assumed in this book. For example, the author has made
  1998. a special version called `^|cmmf|' just for the ^{Computer Modern} typefaces
  1999. he has been developing, so that the Computer Modern base file does not
  2000. have to be loaded each time he makes a new experiment.
  2001. \danger There's a simple way to change the base file from the one that has
  2002. been preloaded: If the first character you type in response to `^|**|' is
  2003. an ^{ampersand} (\thinspace`|&|'\thinspace), \MF\ will replace its memory
  2004. with a specified base file before proceeding. If, for example, there is a
  2005. base file called `|cm.base|' but not a special program called `|cmmf|',
  2006. you can substitute the Computer Modern base for the plain base in |mf| by
  2007. typing `|&cm|' at the very beginning of a run.  If you are working with a
  2008. program that doesn't have the plain base preloaded, the first experiment
  2009. in this chapter won't work as described, but you can do it by starting
  2010. with `|&plain \relax|' instead of just `|\relax|'.  These conventions are
  2011. exactly the same as those of \TeX.
  2012. Our Ionian example uses the following words that are not part of plain
  2013. \MF: "em", "cap", "thin", "thick", "o", "curve\_sidebar", "test\_I", "code",
  2014. "trial\_stem", "trial\_width", and "stem". If you change these to some other
  2015. words or symbols---for example, if you replace `|thin|' and `|thick|' by
  2016. `|t|' and `|T|' respectively, in lines 3, 6, 10, and~11---the results will
  2017. be unchanged, unless your substitutions just happen to clash with something
  2018. that plain \MF\ has already pre\"empted. In general, the best policy is to
  2019. choose descriptive terms for the quantities in your programs, since they
  2020. are not likely to conflict with reserved pseudo-words like "penpos" and
  2021. @endchar@.
  2022. We have already noted that lines 9--16 of the file represent a program
  2023. for the letter `O'. The main part of this program, in lines 10--15,
  2024. uses the ideas of Chapter~4, but we haven't seen the stuff in lines 9
  2025. and~16 before. Plain \MF\ makes it convenient to define letters by starting
  2026. each one with
  2027. \begindisplay
  2028. $@beginchar@\kern1pt($\<code>, \<width>, \<height>, \<depth>);^^@beginchar@
  2029. \enddisplay
  2030. here \<code> is either a quoted single character like |"O"| or a number that
  2031. represents the character's position in the final font. The other three
  2032. quantities \<width>, \<height>, and \<depth> say how big the ^{bounding box}
  2033. is, so that typesetting systems like \TeX\ will be able to use the character.
  2034. These three dimensions must be given in device-independent units, i.e.,
  2035. in ``^{sharped}'' form.
  2036. \exercise What are the height and width of the bounding box described
  2037. in the @beginchar@ command on line~9 of |io.mf|, given the parameter
  2038. values defined on line~2? Give your answer in terms of printer's points.
  2039. \answer The width is |0.8em#|, and an |em#| is 10 true points, so the
  2040. box will be exactly $8\pt$ wide in device-independent units. The
  2041. height will be $7\pt$. \ (And the depth below the baseline will be $0\pt$.)
  2042. Each @beginchar@ operation assigns values to special variables called
  2043. $w$, $h$, and~$d$, ^^"w" ^^"h" ^^"d" which represent the respective
  2044. width, height, and depth of the current character's bounding box,
  2045. ^{rounded} to the nearest integer number of pixels. Our example file
  2046. uses $w$ and~$h$ to help establish the locations of several pen positions
  2047. (see lines 12, 13, and~21 of |io.mf|).
  2048. \exercise Continuing the previous exercise, what will be the values of
  2049. $w$ and~$h$ if there are exactly 3.6 pixels per point?
  2050. \answer $8\times3.6=28.8$ rounds to the value $w=29$; similarly, $h=25$.
  2051. \ (And $d=0$.)
  2052. There's a quoted phrase |"The| |letter| |O"| at the end of line~9; this is
  2053. simply a title that will be used in printouts.
  2054. The `|endchar|' ^^@endchar@ on line 16 finishes the character that was
  2055. begun on line~9, by writing it to an output file and possibly displaying
  2056. it on your screen. We will want
  2057. to see the positions of the control points $z_1$, $z_2$,
  2058. $z_3$, and~$z_4$ that are used in its design, together with the auxiliary
  2059. points $(z_{1l},z_{2l},z_{3l},z_{4l})$ and $(z_{1r},z_{2r},z_{3r},z_{4r})$
  2060. that come with the "penpos" conventions; the statement `|penlabels(1,2,3,4)|'
  2061. ^^"penlabels" takes care of labeling these points on the proofsheets.
  2062. So much for the letter O. Lines 17--23 are analogous to what we've seen
  2063. before, except that there's a new wrinkle: They contain a little program
  2064. ^^@def@ enclosed by `|def...enddef|', which means that a
  2065. {\sl^{subroutine}\/} is being defined.  In other words, those lines set up
  2066. a whole bunch of \MF\ commands that we will want to execute several times
  2067. with minor variations. The subroutine is called "test\_I" and it has three
  2068. parameters called "code", "trial\_stem", and "trial\_width" (see line~17).
  2069. The idea is that we'll want to draw several different versions of an `I',
  2070. having different stem widths and character widths; but we want to type the
  2071. program only once. Line~18 defines "stem"\0 and "stem", given a value of
  2072. "trial\_stem"; and lines 19--23 complete the program for the letter~I
  2073. (copying it from Chapter~4).
  2074. \smallskip
  2075. Oops---we've been talking much too long about |io.mf|. It's time to stop
  2076. rambling and to begin Experiment~2 in earnest, because it will be much
  2077. more fun to see what the computer actually does with that file.
  2078. Are you brave enough to try Experiment 2? Sure.
  2079. Get \MF\ going again, but this time when the machine says `^|**|' you should
  2080. say `|io|', since that's the name of the file you have prepared so
  2081. laboriously. \ (The file could also be specified by giving its full name
  2082. `|io.mf|', but \MF\ automatically adds `|.mf|' ^^|mf| ^^{file names} when
  2083. no suffix has been given explicitly.)
  2084. If all goes well, the computer should now flash its lights a bit
  2085. and---presto---a big `{\manual\IOO}' should be drawn on your screen.
  2086. But if your luck is as good as the author's, something will probably go wrong
  2087. the first time, most likely because of a typographic error in the file.
  2088. A \MF\ program contains lots of data with comparatively little redundancy,
  2089. so a single error can make a drastic change in the meaning. Check that
  2090. you've typed everything perfectly: Be sure to notice the difference between
  2091. the letter~`|l|' and the numeral~`|1|' (especially in line~12, where it
  2092. says `|x1l|', not `|x11| or~`|xll|'); be sure to distinguish between
  2093. the letter~`|O|' and the numeral~`|0|' (especially in line~9); be sure to
  2094. type the ``underline'' characters in words like `|mode_setup|'. We'll see
  2095. later that \MF\ can recover gracefully from most errors, but your job for
  2096. now is to make sure that you've got |io.mf| correct.
  2097. Once you have a working file, the computer will draw you an `{\manual\IOO}'
  2098. and it will also say something like this:
  2099. \begintt
  2100. (io.mf
  2101. The letter O [79])
  2102. \endtt
  2103. What does this mean? Well, `|(io.mf|' means that it has started to read your
  2104. file, and `|The| |letter|~|O|' was printed when the title was found in
  2105. line~9. Then when \MF\ got to the |endchar| on line~16, it said
  2106. `|[79]|' to tell you that it had just output character number~79.
  2107. \ (This is the ^{ASCII} code for the letter~|O|; Appendix~C lists all
  2108. of these codes, if you need to know them.) The `|)|' after `|[79]|'
  2109. means that \MF\ subsequently finished reading the file, and the `^|*|'
  2110. means that it wants another instruction.
  2111. Hmmm. The file contains programs for both I and O; why did we get only
  2112. an~O? Answer: Because lines 17--23 simply define the subroutine "test\_I";
  2113. they don't actually {\sl do\/} anything with that subroutine. We need to
  2114. activate "test\_I" if we're going to see what it does. So let's type
  2115. \begintt
  2116. test_I("I",5/6,1/3);
  2117. \endtt
  2118. this invokes the subroutine, with $"code"=\null$|"I"|,
  2119. $"trial\_stem"={5\over6}$, and $"trial\_width"={1\over3}$. The computer will
  2120. now draw an~I corresponding to these values,\footnote*{Unless, of course,
  2121. there was a typing error in lines 17--23, where "test\_I" is defined.} and
  2122. it will prompt us for another command.
  2123. It's time to type `^|end|' now, after which \MF\ should tell us that it has
  2124. completed this run and made an output file called `|io.2602gf|'. Running this
  2125. file through ^|GFtoDVI| as in Experiment~1 will produce two proofsheets,
  2126. showing the `{\manual\IOO}' and the `{\manual\IOI}' we have created.
  2127. The output won't be shown here, but you can see the results by doing
  2128. the experiment personally.
  2129. Look at those proofsheets now, because they provide instructive examples
  2130. of the simulated broad-edge pen constructions introduced in Chapter~4.
  2131. Compare the `{\manual\IOO}' with the program that drew it: Notice that
  2132. the $\penpos2$ in line~10 makes the curve slightly thicker at the ^^"penpos"
  2133. bottom than at the top; that the equation `$x_{1l}=w-x_{3l}="curve\_sidebar"$'
  2134. in line~12 makes the right edge of the curve as far from the right of the
  2135. bounding box as the left edge is from the left; that line~13 places point~1
  2136. slightly lower than point~3. The proofsheet for `{\manual\IOI}' should look
  2137. very much like the corresponding illustration near the end of Chapter~4,
  2138. but it will be somewhat larger.
  2139. \danger Your proof copy of the `{\manual\IOO}' should show twelve dots
  2140. for key points; but only ten of them will be labeled, because there isn't
  2141. room enough to put labels on points 2 and~4. The missing ^{labels} usually
  2142. ^^{overflow labels} appear in the upper right corner, where it might say, e.g.,
  2143. `|4|~|=|~|4l|~|+|~|(-1,-5.9)|'; this
  2144. means that point $z_4$ is one pixel to the left and 5.9 pixels down
  2145. from point~$z_{4l}$, which is labeled. \ (Some implementations omit this
  2146. information, because there isn't always room for it.)
  2147. The proofsheets obtained in Experiment~2 show the key points and the
  2148. bounding boxes, but this extra information can interfere with our
  2149. perception of the character shape itself. There's a simple way to
  2150. get proofs that allow a viewer to criticize the results from an aesthetic
  2151. rather than a logical standpoint; the creation of such proofs will be the
  2152. goal of our next experiment.
  2153. Here's how to do Experiment~3: Start \MF\ as usual, then type
  2154. \begintt
  2155. \mode=smoke; input io
  2156. \endtt
  2157. in response to the `^|**|'. This will input file |io.mf| again,
  2158. after establishing ``smoke'' mode. \ (As in Experiment~1, the command line
  2159. begins with `|\|' so that the computer knows you aren't starting with
  2160. the name of a file.) \ Then complete the run exactly ^^{backslash}
  2161. as in Experiment~2, by typing `|test_I("I",5/6,1/3);| |end|';
  2162. and apply |GFtoDVI| to the resulting file |io.2602gf|.
  2163. This time the proofsheets will contain the same characters as before, but
  2164. they will be darker and without labeled points. The bounding boxes will
  2165. be indicated only by small markings at the corners; you can put these
  2166. boxes next to each other and tack the results up on the wall, then stand
  2167. back to see how the characters will look when set by a high-resolution
  2168. typesetter. \ (This way of working is called ^"smoke" mode because it's
  2169. analogous to the ``smoke proofs'' that punch-cutters traditionally used to
  2170. test their handiwork. They held the newly cut type over a candle flame so
  2171. that it would be covered with carbon; then they pressed it on paper to
  2172. make a clean impression of the character, in order to see whether changes
  2173. were needed.)
  2174. \danger Incidentally, many systems allow you to invoke \MF\ by typing
  2175. a one-line command like `|mf|~|io|' in the case of Experiment~2; you
  2176. don't have to wait for the `|**|' before giving a file name. Similarly,
  2177. the one-liners `|mf|~|\relax|' and `|mf|~|\mode=smoke;| |input|~|io|' can be
  2178. used on many systems at the beginning of Experiments 1 and~3. You might want
  2179. to try this, to see if it works on your computer; or you might ask
  2180. somebody if there's a similar shortcut.
  2181. Experiments 1, 2, and 3 have demonstrated how to make proof drawings of
  2182. test characters, but they don't actually produce new fonts that can be
  2183. used in typesetting. For this, we move onward to Experiment~4, in which
  2184. we put ourselves in the position of a person who is just starting to
  2185. design a new typeface. Let's imagine that we're happy with the~O of
  2186. |io.mf|, and that we want a ``sans serif'' I in the general style produced
  2187. by "test\_I", but we aren't sure about how thick the stem of the~I
  2188. should be in order to make it blend properly with the~O. Moreover, we aren't
  2189. sure how much white space to leave at the sides of the~I. So~we want to do
  2190. some typesetting experiments, using a sequence of different I's.
  2191. The ideal way to do this would be to produce a high-resolution test font and to
  2192. view the output at its true size. But this may be too expensive, because fine
  2193. printing equipment is usually available only for large production runs.
  2194. The next-best alternative is to use a low-resolution printer but to magnify
  2195. the output, so that the resolution is effectively increased. We shall adopt
  2196. the latter strategy, because it gives us a chance to learn about
  2197. ^{magnification} as well as fontmaking.
  2198. After starting \MF\ again, you can begin Experiment 4 by typing
  2199. \begintt
  2200. \mode=localfont; mag=4; input io
  2201. \endtt
  2202. in response to the `|**|'. The ^{plain base} at your installation is supposed
  2203. to recognize ^|localfont| as the name of the mode that makes fonts for your
  2204. ``standard'' output device. The equation `|mag=4|' means that this run will
  2205. produce a font that is magnified fourfold; i.e., the results will be
  2206. 4~times bigger than usual.
  2207. The computer will read |io.mf| as before, but this time it won't display an~`O';
  2208. characters are normally not displayed in fontmaking modes, because we usually
  2209. want the computer to run as fast as possible when it's generating a font
  2210. that has already been designed. All you'll see is `|(io.mf| |[79])|',
  2211. followed by~`^|*|'. Now the fun starts: You should type
  2212. \begintt
  2213. code=100;
  2214. for s=7 upto 10:
  2215.  for w=5 upto 8:
  2216.   test_I(incr code,s/10,w/20);
  2217. endfor endfor end.
  2218. \endtt
  2219. (Here `^|upto|' must be typed as a single word.) \ We'll learn about
  2220. repeating things with `^|for||...|^|endfor|' in Chapter~19. This little
  2221. program produces 16 versions of the letter~I, with stem widths of
  2222. $7\over10$, $8\over10$, $9\over10$, and~${10\over10}\pt$, and with
  2223. character widths of $5\over20$, $6\over20$, $7\over20$, and~${8\over20}\,
  2224. \rm em$. The sixteen trial characters will appear in positions 101 through~116
  2225. of the font; it turns out that these are the ^{ASCII} codes for lower case
  2226. letters |e| through~|t| inclusive. \ (Other codes would have been used if
  2227. `|code|' had been started at a value different from~100. The construction
  2228. `|incr|~|code|' increases the value of |code| by~1 and produces the new value;
  2229. thus, each use of |test_I| has a different code number.) ^^"incr"
  2230. This run of \MF\ will not only produce a generic font |io.nnngf|, it will also
  2231. create a file called |io.tfm|, the ``^{font metric file}'' that tells
  2232. ^^{output of METAFONT} ^^|tfm|
  2233. typesetting systems like \TeX\ how to make use of the new font. The remaining
  2234. part of Experiment~4 will be to put \TeX\ to work: We shall make some test
  2235. patterns from the new font, in order to determine which `I' is best.
  2236. You may need to ask a local system wizard for help at this point, because
  2237. it may be necessary to move the file |io.tfm| to some special place where
  2238. \TeX\ and the other typesetting software can find it. Furthermore, you'll
  2239. need to run a program that converts |io.nnngf| to the font format used by your
  2240. local output device. But with luck, these will both be fairly simple
  2241. operations, and a new font called `|io|' will effectively be installed
  2242. on your system. This font will contain seventeen letters, namely an |O| and
  2243. sixteen |I|'s, where the |I|'s happen to be in the positions normally occupied
  2244. by |e|, |f|, \dots,~|t|. Furthermore, the font will be magnified fourfold.
  2245. \danger The magnification of the font will be reflected in its file name.
  2246. For example, if "localfont" mode is for a device with 200 pixels per inch,
  2247. the |io| font at 4$\times$ magnification will be called `|io.800gf|'.
  2248. You can use \TeX\ to typeset from this font like any other, but for the
  2249. purposes of Experiment~4 it's best to use a special \TeX\ package that has
  2250. been specifically designed for font testing. All you need to do is to
  2251. run \TeX---which is just like running \MF\!, except that you call it `|tex|'
  2252. instead of `|mf|'; and you simply type `^|testfont|' in reply to \TeX's
  2253. `|**|'.  \ (The |testfont| routine should be available on your system; if
  2254. not, you or somebody else can type it in, by copying the relevant material
  2255. from Appendix~H\null.) \ You will then be asked for the name of the font
  2256. you wish to test. Type
  2257. \begintt
  2258. io scaled 4000
  2259. \endtt
  2260. (which means the |io| font magnified by 4, in \TeX's jargon),
  2261. since this is what \MF\ just created. The machine will now ask you for
  2262. a test command, and you should reply
  2263. \begintt
  2264. \mixture
  2265. \endtt
  2266. to get the ``^{mixture}'' test. \ (Don't forget the ^{backslash}.) \
  2267. You'll be asked for a ^{background letter}, a starting letter, and an
  2268. ending letter; type `|O|', `|e|', and `|t|', respectively. This will
  2269. produce sixteen lines of typeset output, in which the first line contains
  2270. a mixture of |O| with~|e|, the second contains a mixture of |O|~with~|f|,
  2271. and so on.  To complete Experiment~4, type `|\end|' to \TeX, and print the
  2272. file |testfont.dvi| ^^|dvi| that \TeX\ gives you.
  2273. \setbox0=\hbox{\kern.5pt I\kern.5pt} \def\\{\copy0}
  2274. If all goes well, you'll have sixteen lines that say `O\\OO\\\\OOO\\\\\\O\\',
  2275. but with a different I on each line. In order to choose the line that looks
  2276. best, without being influenced by neighboring lines, it's convenient to take
  2277. two sheets of blank paper and use them to mask out all of the lines
  2278. except the one you're studying. Caution: These letters are four times
  2279. larger than the size at which the final font is meant to be viewed,
  2280. so you should look at the samples from afar. Xerographic reductions may
  2281. introduce distortions that will give misleading results. Sometimes when
  2282. you stare at things like this too closely, they all look wrong, or
  2283. they all look right; first impressions are usually more significant
  2284. than the results of logical reflection. At any rate, you should be able
  2285. to come up with an informed judgment about what values to use for the
  2286. stem width and the character width of a decent `I'; these can then be
  2287. incorporated into the program, the `|def|' and `|enddef|' parts of
  2288. |io.mf| can be removed, and you can go on to design other characters
  2289. that go with your I and~O. Furthermore you can always go back and make
  2290. editorial changes after you see your letters in more contexts.
  2291. \ddangerexercise The goddess Io was known in Egypt as ^{Isis}.
  2292. Design an `{\manual\IOS}' for her.
  2293. \answer Here's one way, using a variable "slab" to control the
  2294. \rightfig A5a ({200\apspix} x 252\apspix) ^-71pt
  2295. ^^{S} pen breadth at the ends of the stroke:
  2296. \begintt
  2297. slab#:=.8pt#; define_blacker_pixels(slab);
  2298. beginchar("S",5/9em#,cap#,0); "The letter S";
  2299. penpos1(slab,70); penpos2(.5slab,80);
  2300. penpos3(.5[slab,thick],200); penpos5(.5[slab,thick],210);
  2301. penpos6(.7slab,80);
  2302. penpos7(.25[slab,thick],72);
  2303. x1=x5; y1r=.94h+o;
  2304. x2=x4=x6=.5w; y2r=h+o; y4=.54h; y6l=-o;
  2305. x3r=.04em; y3=.5[y4,y2];
  2306. x5l=w-.03em; y5=.5[y4,y6];
  2307. .5[x7l,x7]=.04em; y7l=.12h-o;
  2308. path trial; trial=z3{down}..z4..{down}z5;
  2309. pair dz; dz=direction 1 of trial;
  2310. penpos4(thick,angle dz-90);
  2311. penstroke z1e..z2e{left}..z3e{down}
  2312.     ..z4e{dz}..z5e{down}..z6e{left}..z7e;
  2313. penlabels(1,2,3,4,5,6,7); endchar;
  2314. \endtt
  2315. Notice that the pen angle at point 4 has been found by letting \MF\
  2316. ^^{direction} construct a ^{trial path} through the center points,
  2317. then using the ^{perpendicular} direction. The letters work reasonably
  2318. well at their true size: `{\manual\IOS\IOO} {\manual\IOI\IOO}
  2319. {\manual\IOI\IOS} {\manual\IOI\IOS\IOI\IOS}.'
  2320. Well, this isn't a book about type design; the example of |io.mf| is
  2321. simply intended to illustrate how a type designer might want to operate,
  2322. and to provide a run-through of the complete process from design of
  2323. type to its use in a document. We must go back now to the world of
  2324. computerese, and study a few more practical details about the use of \MF\!.
  2325. This has been a long chapter, but take heart: There's only one more
  2326. experiment to do, and then you will know enough about \MF\ to run it
  2327. fearlessly by yourself forever after. The only thing you are still missing
  2328. is some information about how to cope with error messages. Sometimes
  2329. \MF\ stops and asks you what to do next. Indeed, this may have already
  2330. happened, and you may have panicked.
  2331. Error messages can be terrifying when you aren't prepared for them;
  2332. but they can be fun when you have the right attitude. Just remember that
  2333. you really haven't hurt the computer's feelings, and that nobody will
  2334. hold the errors against you. Then you'll find that running \MF\ might
  2335. actually be a creative experience instead of something to dread.
  2336. The first step in Experiment 5 is to plant some intentional mistakes
  2337. in the input file. Make a copy of |io.mf| and call it |badio.mf|; then
  2338. change line~1 of |badio.mf| to
  2339. \begintt
  2340. mode setup; % an intentional error!
  2341. \endtt
  2342. (thereby omitting the underline character in |mode_setup|).
  2343. Also change the first semicolon (\thinspace`|;|'\thinspace) on line~2
  2344. to a colon (\thinspace`|:|'\thinspace);
  2345. change `|thick,10|' to `|thick,l0|' on line~10 (i.e., replace the numeral~`|1|'
  2346. by the letter~`|l|'\thinspace); and change `|thin|' to `|thinn|' on line~11.
  2347. These four changes introduce typical typographic errors, and it will be
  2348. instructive to see if they lead to any disastrous consequences.
  2349. Now start \MF\ up again; but instead of cooperating with the computer, type
  2350. `|mumble|' in reply to the~`|**|'. \ (As long as you're going to make
  2351. intentional mistakes, you might as well make some dillies.) \
  2352. \MF\ will say that it can't find any file called |mumble.mf|,
  2353. and it will ask you for another name. Just hit \<return> this time;
  2354. you'll see that you had better give the name of a real file.
  2355. So type `|badio|' and wait for \MF\ to find one of the {\sl faux pas\/}
  2356. in that messed-up travesty.
  2357. Ah yes, the machine will soon stop, after typing something like this:
  2358. \begintt
  2359. >> mode.setup
  2360. ! Isolated expression.
  2361. <to be read again>
  2362.                    ;
  2363. l.1 mode setup;
  2364.                 % an intentional error!
  2365. \endtt
  2366. \MF\ begins its error messages with `|!|', and it sometimes precedes them
  2367. with one or two related mathematical expressions that are displayed on
  2368. lines starting with `^|>>|'.  Each error message is also followed by lines
  2369. of context that show what the computer was reading at the time of the
  2370. error. Such context lines occur in pairs; the top line of the pair (e.g.,
  2371. `|mode| |setup;|'\thinspace) shows what \MF\ has looked at so far, and
  2372. where it came from (`|l.1|', i.e., line number~1); the bottom line (here
  2373. `|%|~|an| |intentional| |error!|'\thinspace) shows what \MF\ has yet to
  2374. read. In this case there are two pairs of context lines; the top pair
  2375. refers to a semicolon that \MF\ has read once but will be reading again,
  2376. because it didn't belong with the preceding material.
  2377. You don't have to take out pencil and paper in order to write down the
  2378. error messages that you get before they disappear from view, since \MF\
  2379. always writes a ``^{transcript}'' or ``^{log file}'' that records what
  2380. happened during each session. For example, you should now have a file
  2381. called |io.log| containing the transcript of Experiment~4, as well as a file
  2382. |mfput.log| that contains the transcript of Experiment~1. \ (The old
  2383. transcript of Experiment~2 was probably overwritten when you did
  2384. Experiment~3, and again when you did Experiment~4, because all three
  2385. transcripts were called |io.log|.) \ At the end of Experiment~5 you'll
  2386. have a file |badio.log| that will serve as a helpful reminder of
  2387. what errors need to be fixed up.
  2388. The `^|?|' that appears after the context display means that \MF\ wants
  2389. advice about what to do next. If you've never seen an error message before,
  2390. or if you've forgotten what sort of response is expected, you can type
  2391. `|?|' now (go ahead and try it!); \MF\ will respond as follows:
  2392. \begintt
  2393. Type <return> to proceed, S to scroll future error messages,
  2394. R to run without stopping, Q to run quietly,
  2395. I to insert something, E to edit your file,
  2396. 1 or ... or 9 to ignore the next 1 to 9 tokens of input,
  2397. H for help, X to quit.
  2398. \endtt
  2399. This is your menu of options. You may choose to continue in various ways:
  2400. \smallskip\item{1.}
  2401. Simply type \<return>. \MF\ will resume its processing, after
  2402. attempting to recover from the error as best it can.
  2403. \smallbreak\item{2.} Type `|S|'. \MF\ will proceed without
  2404. pausing for instructions if further errors arise. Subsequent error messages
  2405. will flash by on your terminal, possibly faster than you can read them, and
  2406. they will appear in your log file where you can scrutinize them at your
  2407. leisure. Thus, `|S|'~is sort of like typing \<return> to every message.
  2408. \smallbreak\item{3.} Type `|R|'. This is like `|S|' but even stronger,
  2409. since it tells \MF\ not to stop for any reason, not even if a file name
  2410. can't be found.
  2411. \smallbreak\item{4.} Type `|Q|'. This is like `|R|' but even more so,
  2412. since it tells \MF\ not only to proceed without stopping but also to
  2413. suppress all further output to your terminal. It is a fast, but somewhat
  2414. reckless, way to proceed (intended for running \MF\ with no operator in
  2415. attendance).
  2416. \smallbreak\item{5.} Type `|I|', followed by some text that you want to
  2417. insert. \MF\ will read this text before encountering what it
  2418. would ordinarily see ^^{inserting text online}
  2419. ^^{online interaction, see interaction} ^^{interacting with MF}
  2420. next.
  2421. \smallbreak\item{6.} Type a small number (less than 100). \MF\ will
  2422. delete this many ^{tokens} from whatever it is
  2423. about to read next, and it will pause again to give you another chance to
  2424. look things over.  ^^{deleting tokens}
  2425. \ (A~``token'' is a name, number, or symbol that \MF\ reads as a unit;
  2426. e.g., `|mode|' and `|setup|' and `|;|' are the first three tokens
  2427. of |badio.mf|, but `|mode_setup|' is the first token of |io.mf|.
  2428. Chapter~6 explains this concept precisely.)
  2429. \smallbreak\item{7.} Type `|H|'. This is what you should do now and whenever
  2430. you are faced with an error message that you haven't seen for a~while. \MF\
  2431. has two messages built in for each perceived error: a formal one and an
  2432. informal one. The formal message is printed first (e.g., `|!|~|Isolated|
  2433. |expression.|'\thinspace); the informal one is printed if you request
  2434. more help by typing `|H|', and it also appears in your log file if you
  2435. are scrolling error messages. The informal message tries to complement the
  2436. formal one by explaining what \MF\ thinks the trouble is, and often
  2437. by suggesting a strategy for recouping your losses.^^{help messages}
  2438. \smallbreak\item{8.} Type `|X|'. This stands for ``exit.'' It causes \MF\
  2439. to stop working on your job, after putting the finishing touches on your
  2440. |log| file and on any characters that have already been output to your |gf|
  2441. and/or |tfm| files.  The current (incomplete) character will not be output.
  2442. \smallbreak\item{9.} Type `|E|'. This is like `|X|', but it also prepares
  2443. the computer to edit the file that \MF\ is currently reading, at the
  2444. current position, so that you can conveniently make a change before
  2445. trying again.
  2446. \smallbreak\noindent
  2447. After you type `|H|' (or `|h|', which also works), you'll get a message
  2448. that tries to explain the current problem: The mathematical quantity just
  2449. read by \MF\ (i.e., |mode.setup|) was not followed by `|=|' or `|:=|', so
  2450. there was nothing for the computer to do with it. Chapter~6 explains that
  2451. a ^{space} between tokens (e.g., `|mode|~|setup|'\thinspace) is equivalent to
  2452. a ^{period} between tokens (e.g., `|mode.setup|'\thinspace).  The correct
  2453. spelling `|mode_setup|' would be recognized as a preloaded subroutine of
  2454. plain \MF\!, but plain \MF\ doesn't have any built-in meaning for
  2455. |mode.setup|. Hence |mode.setup| appears as a sort of orphan, and \MF\
  2456. realizes that something is amiss.
  2457. In this case, it's OK to go ahead and type \<return>, because we really
  2458. don't need to do the operations of @mode\_setup@ when no special mode
  2459. has been selected. \MF\ will continue by forgetting the isolated expression,
  2460. and it will ignore the rest of line~1 because everything after a
  2461. ^^{percent} `|%|'~sign is always ignored. \ (This is another thing that
  2462. will be explained in Chapter~6; it's a handy way to put ^{comments}
  2463. into your \MF\ programs.) \ The changes that were made to line~1 of |badio.mf|
  2464. therefore have turned out to be relatively harmless. But \MF\ will
  2465. almost immediately encounter the mutilated semicolon in line~2:
  2466. \begintt
  2467. ! Extra tokens will be flushed.
  2468. <to be read again>
  2469.                    :
  2470. l.2  em#:=10pt#:
  2471.                  cap#:=7pt#;
  2472. \endtt
  2473. What does this mean? Type `|H|' to find out. \MF\ has no idea what to
  2474. do with a `|:|' at this place in the file, so it plans to recover by
  2475. ``^{flushing}'' or getting rid of everything it sees, until coming to a
  2476. semicolon.  It would be a bad idea to type \<return> now, since you'd lose
  2477. the important assignment `|cap#:=7pt#|', and that would lead to worse errors.
  2478. You might type `|X|' or `|E|' at this point, to exit from \MF\ and to fix
  2479. the errors in lines 1 and~2 before trying again. But it's usually best
  2480. to keep going, trying to detect and correct as many mistakes as possible
  2481. in each run, since that increases your productivity while
  2482. decreasing your computer bills. An experienced \MF\ user will quit
  2483. after an error only if the error is unfixable, or if there's almost no
  2484. chance that additional errors are present.
  2485. The solution in this case is to proceed in two steps: First type `|1|',
  2486. which tells \MF\ to delete the next token (the unwanted `|:|'); then type
  2487. `|I;|', which inserts a semicolon. This semicolon protects the rest of line~2
  2488. from being flushed away,
  2489. so all will go well until \MF\ reaches another garbled line.
  2490. The next error message is more elaborate, because it is detected while
  2491. \MF\ is trying to carry out a "penpos" command; "penpos" is not a
  2492. primitive operation (it is defined in plain \MF), hence a lot more
  2493. context is given:
  2494. \begintt
  2495. >> l0
  2496. ! Improper transformation argument.
  2497. <to be read again>
  2498.                    ;
  2499. penpos->...(EXPR3),0)rotated(EXPR4);
  2500.                                     x(SUFFIX2)=0.5(x(SUFF...
  2501. l.10  penpos1(thick,l0)
  2502.                        ; penpos2(.1[thin,thick],90-10);
  2503. \endtt
  2504. At first, such error messages will appear to be complete nonsense to you,
  2505. because much of what you see is low-level \MF\ code that you never wrote. But
  2506. you can overcome this hangup by getting a feeling for the way \MF\ operates.
  2507. The bottom line shows how much progress \MF\ has made so far in the |badio|
  2508. file:  It has read `|penpos1(thick,l0)|' but not yet the semicolon, on line~10.
  2509. The "penpos" routine expands into a long list of tokens; indeed, this list
  2510. is so long that it can't all be shown on two lines, and the appearances of
  2511. `^|...|' indicate that the definition of "penpos" has been truncated here.
  2512. Parameter values are often inserted into the expansion of a high-level
  2513. routine; in this case, for example, `|(EXPR3)|' and `|(EXPR4)|' correspond
  2514. to the respective parameters `|thick|' and `|l0|', and `|(SUFFIX2)|'
  2515. corresponds to~`|1|'. ^^|EXPR| ^^|SUFFIX|
  2516. \MF\ detected an error just after encountering the phrase `|rotated(EXPR4)|';
  2517. the value of |(EXPR4)| was an undefined quantity (namely `|l0|',
  2518. which \MF\ treats as the subscripted variable~`$l_0$'\thinspace), and
  2519. ^{rotation} is permitted only when a known numeric value has been supplied.
  2520. Rotations are particular instances of what \MF\ calls {\sl^{transformations}\/};
  2521. hence \MF\ describes this particular error by saying that an ``improper
  2522. transformation argument'' was present.
  2523. When you get a multiline error message like this, the best clues about the
  2524. source of the trouble are usually on the bottom line (since that is what
  2525. you typed) and on the top line (since that is what triggered the error
  2526. message). Somewhere in there you can usually spot the problem.
  2527. If you type `|H|' now, you'll find that
  2528. \MF\ has simply decided to continue without doing the requested rotation.
  2529. Thus, if you respond by typing \<return>, \MF\ will go on as if the program
  2530. had said `|penpos1(thick,0)|'. Comparatively little harm has been done;
  2531. but there's actually a way to fix the error perfectly before proceeding:
  2532. Insert the correct rotation by typing
  2533. \begintt
  2534. I rotated 10
  2535. \endtt
  2536. and \MF\ will rotate by 10 degrees as if `|l0|' had been `|10|'.
  2537. What happens next in Experiment 5? \MF\ will hiccup on the remaining
  2538. bug that we planted in the file. This time, however, the typo will
  2539. not be discovered until much later, because there's nothing wrong
  2540. with line~11 as it stands. \ (The variable |thinn| is not defined,
  2541. but undefined quantities are no problem unless you're doing something
  2542. complicated like rotation. Indeed, \MF\ programs typically
  2543. consist of equations in which there are lots of unknowns;
  2544. variables get more and more defined as time goes on. Hence spelling
  2545. errors cannot possibly be detected until the last minute.) \
  2546. Finally comes the moment of truth, when |badio| tries to draw a
  2547. path through an unknown point; and you will get an error message
  2548. that's even scarier than the previous one:
  2549. \begintt
  2550. >> 0.08682thinn+144
  2551. ! Undefined x coordinate has been replaced by 0.
  2552. <to be read again>
  2553.                    {
  2554. <for(l)> ...FFIX0){up}..z4(SUFFIX0){
  2555.                                     left}..cycle; ENDFOR
  2556. penstroke->...ath_.e:=(TEXT0);endfor
  2557.                                     .if.cycle.path_.l:cyc...
  2558. <to be read again>
  2559.                    ;
  2560. l.15 ...      ..z3e{up}..z4e{left}..cycle;
  2561. |quad
  2562. \endtt
  2563. Wow; what's this?  The expansion of @penstroke@ involves a ``@for@ loop,''
  2564. and the error was detected in the midst of it. The
  2565. expression `|0.08682thinn+144|' just above the error message implies that
  2566. the culprit in this case was a misspelled `|thin|'. If that hadn't been
  2567. enough information, you could have gleaned another clue from the fact that
  2568. `|z4(SUFFIX0)|' has just been read; |(SUFFIX0)| is the current loop value
  2569. and `|<for(l)>|' indicates that the value in question is `|l|', hence
  2570. $z_{4l}$ is under suspicion. \ (Sure enough, the undefined $x$~coordinate
  2571. that provoked this error can be shown to be $x_{4l}=0.08682"thinn"+144$.)
  2572. In any event the mistake on line~11 has propagated too far to be fixable,
  2573. so you're justified in typing `|X|' or~`|E|' at this point. But type~`|S|'
  2574. instead, just for fun: This tells \MF\ to plunge ahead, correcting all
  2575. remaining errors as best it can. \ (There will be a few more problems,
  2576. since several variables still depend on `|thinn|'.) \ \MF\ will draw a
  2577. very strange letter~O before it gets to the end of the file. Then you
  2578. should type `|end|' to terminate the run.
  2579. If you try to edit |badio.mf| again, you'll notice that line~2 still
  2580. contains ^^{editing} a colon instead of a semicolon. The fact that you
  2581. told \MF\ to delete the colon and to insert additional material doesn't
  2582. mean that your file has changed in any way. However, the transcript file
  2583. |badio.log| has a record of all the errors, so it's a handy reference when
  2584. you want to correct mistakes. \ (Why not look at
  2585. |badio.log| now, and |io.log| too, in order to get familiar with log files?)
  2586. \dangerexercise Suppose you were doing Experiment 3 with |badio| instead
  2587. of~|io|, so you began by saying `|\mode=smoke|; |input| |badio|'.  Then you
  2588. would want to recover from the error on line~1 by inserting a correct
  2589. @mode\_setup@ command, instead of by simply \<return>ing, because
  2590. @mode\_setup@ is what really establishes "smoke" mode. Unfortunately if you
  2591. try typing `|I|~|mode_setup|' in response to the ``isolated expression''
  2592. error, it doesn't work. What should you type instead?
  2593. \answer After an ``isolated expression,'' \MF\ thinks it is at the end of
  2594. a statement or command, so it expects to see a semicolon next. You should
  2595. type, e.g., `|I;|~|mode_setup|' to keep \MF\ happy.
  2596. By doing the five experiments in this chapter you have learned at first hand
  2597. (1)~how to produce proofsheets of various kinds, including ``smoke proofs'';
  2598. (2)~how to make a new font and test it; (3)~how to keep calm when \MF\
  2599. issues stern warnings. Congratulations! You're on the threshold of being able to
  2600. do lots more. As you read the following chapters, the best strategy
  2601. will be for you to continue making trial runs, using experiments
  2602. of your own design.
  2603. \exercise However, this has been an extremely long chapter,
  2604. so you should go outside now and get some {\sl real\/} exercise.
  2605. \answer Yes.
  2606. \endchapter
  2607. Let us learn how Io's frenzy came---
  2608. She telling her disasters manifold.
  2609. \author \AE SCHYLUS, ^^{Aeschylus} %
  2610.  {\sl Prometheus Bound\/} (c.\thinspace470 B.C.) % verse 801
  2611.  % This is the translation by Morshead
  2612. \bigskip
  2613. To the student who wishes to use graphical methods as a tool,
  2614. it can not be emphasized too strongly that practice in the use of that tool
  2615. is as essential as a knowledge of how to use it.
  2616. The oft-repeated pedagogical phrase, ``we learn by doing,'' is applicable here.
  2617. \author THEODORE ^{RUNNING}, {\sl Graphical Mathematics\/} (1927) % p viii
  2618. \eject
  2619. \beginchapter Chapter 6. How \MF\\Reads What You\\Type
  2620. So far in this book we've seen lots of things that \MF\ can do, but we haven't
  2621. discussed what \MF\ can't do. We have looked at many examples of commands that
  2622. \MF\ can understand, but we haven't dwelt on the fact that the computer will
  2623. find many phrases unintelligible. It's time now to adopt a more systematic
  2624. approach and to study the exact rules of \MF's language. Then we'll know what
  2625. makes sense to the machine, and we'll also know how to avoid ungrammatical
  2626. utterances.
  2627. A \MF\ program consists of one or more lines of text, where each line is made
  2628. up of letters, numbers, punctuation marks, and other symbols that appear on
  2629. a standard computer keyboard. A total of 95 different characters can be
  2630. employed, namely a blank space plus the 94 visible symbols of standard ^{ASCII}.
  2631. \ (Appendix~C describes the American Standard Code for Information
  2632. Interchange, popularly known as ``ASCII,'' under which code numbers 33
  2633. through~126 have been assigned to 94 specific symbols. This particular
  2634. coding scheme is not important to a \MF\ programmer; the only relevant thing
  2635. is that 94 different nonblank symbols can be used.)
  2636. \MF\ converts each line of text into a series of {\sl ^{tokens}}, and a
  2637. programmer should understand exactly how this conversion takes place.
  2638. Tokens are the individual lexical units that govern the computer's
  2639. activities. They are the basic building blocks from which meaningful
  2640. sequences of instructions can be constructed. We discussed tokens briefly
  2641. at the end of the previous chapter; now we shall consider them in detail.
  2642. Line~9 of the file |io.mf| in that chapter is a typical example of what
  2643. the machine might encounter:
  2644. \begintt
  2645. beginchar("O",0.8em#,cap#,0); "The letter O";
  2646. \endtt
  2647. When \MF\ reads these ASCII characters it finds sixteen tokens:
  2648. \begindisplay \chardef\"=`\" \openup 2pt
  2649. \ttok{beginchar}\quad\ttok{(}\quad\ttok{\"O\"}\quad
  2650.  \ttok{,}\quad\ttok{0.8}\quad\ttok{em}\quad\ttok{\#}\quad\ttok{,}\cr
  2651. \ttok{cap}\quad\ttok{\#}\quad\ttok{,}\quad\ttok{0}\quad
  2652.  \ttok{)}\quad\ttok{;}\quad\ttok{\"The letter O\"}\quad\ttok{;}\cr
  2653. \enddisplay
  2654. Two of these, |"O"| and |"The| |letter| |O"|, are called {\sl^{string tokens}\/}
  2655. because they represent strings of characters. Two of them, `|0.8|' and `|0|',
  2656. are called {\sl^{numeric tokens}\/} because they represent numbers. The
  2657. other twelve---`|beginchar|', `|(|', etc.---are called {\sl^{symbolic
  2658. tokens}\/}; such tokens can change their meaning while a \MF\ program runs,
  2659. but string tokens and numeric tokens always have a predetermined significance.
  2660. Notice that clusters of letters like `|beginchar|' are treated as a unit;
  2661. the same holds with respect to letters mixed with ^{underline} characters,
  2662. as in `|mode_setup|'. Indeed,
  2663. the rules we are about to study will explain that clusters of other
  2664. characters like `|0.8|' and `|:=|' are also considered to be
  2665. indecomposable tokens. \MF\ has a definite way of deciding where one
  2666. token stops and another one begins.
  2667. It's often convenient to discuss ^{grammatical rules} by formulating them in
  2668. a special notation that was introduced about 1960 by John ^{Backus} and
  2669. Peter ^{Naur}. Parts of speech are represented by named quantities in
  2670. ^{angle brackets}, and {\sl^{syntax rules}\/} are used to express the ways
  2671. in which those quantities can be built~up from simpler units. For example,
  2672. here are three syntax rules that completely describe the possible forms of
  2673. numeric tokens:
  2674. \def\\#1{\thinspace{\tt#1}\thinspace}
  2675. \beginsyntax
  2676. <decimal digit>\is\\0\alt\\1\alt\\2\alt\\3\alt\\4\alt\\5\alt\\6%
  2677.   \alt\\7\alt\\8\alt\\9
  2678. <digit string>\is<decimal digit>\alt<digit string><decimal digit>
  2679. <numeric token>\is<digit string>\alt[.]<digit string>
  2680.   \alt<digit string>\\.<digit string>
  2681. \endsyntax
  2682. The first rule says that a \<decimal digit> is either `|0|' or `|1|' or
  2683. $\cdots$ or `|9|'; thus it must be one of the ten numerals. The next
  2684. rule says that a \<digit string> is either a \<decimal digit> or a
  2685. \<digit string> followed by a \<decimal digit>; thus it must be a sequence
  2686. of one or more digits. Finally, a \<numeric token> has one of three forms,
  2687. exemplified respectively by `|15|', `|.05|', and `|3.14159|'.
  2688. Syntax rules explain only the surface structure of a language, not the
  2689. underlying meanings of things. For example, the rules above tell us that
  2690. `|15|' is a \<numeric token>, but they don't imply that `|15|' has
  2691. any connection with the number fifteen. Therefore syntax rules are
  2692. generally accompanied by rules of {\sl^{semantics}}, which ascribe
  2693. meanings to the strings of symbols that meet the conditions of the syntax.
  2694. In the case of numeric tokens, the principles of ordinary decimal notation
  2695. define the semantics, except that \MF\ deals only with numbers in a
  2696. limited range: A numeric token must be less than 4096, and its value is
  2697. always rounded to the nearest multiple of $1\over65536$. Thus, for example,
  2698. `|.1|'~does not mean $1\over10$, it means $6554\over65536$ (which is
  2699. slightly greater than $1\over10$). It turns out that the tokens
  2700. `|.099999|' and `|0.10001|' both have exactly the same meaning as
  2701. ^^{numeric tokens, rounded values} ^^{numeric tokens, maximum value}
  2702. `|.1|', because all three tokens represent the value $6554\over65536$.
  2703. \dangerexercise Are the following pairs of numeric tokens equivalent
  2704. to each other, when they appear in \MF\ programs?
  2705. \ (a)~|0| and |0.00001|; \ (b)~|0.00001| and |0.00002|;
  2706. \ (c)~|0.00002| and |0.00003|; \ (d)~|04095.999999| and |10000|?
  2707. \answer (a) No, the second token represents $1\over65536$. \ (A token has
  2708. the same meaning as~`|0|' ^^{zero} if and only if its decimal value
  2709. is strictly less than $2^{-17}=.00000\,76293\,94531\,25$.) \ (b)~Yes; both
  2710. tokens represent $1\over65536$, because 1~is the nearest integer to both
  2711. $.00001\times65536=.65536$ and $0.00002\times65536=1.31072$. \ (c)~No,
  2712. |0.00003| represents $2\over65536$. \ (d)~Yes, they both mean ``^{enormous
  2713. number} that needs to be reduced''; \MF\ complains in both
  2714. cases and substitutes the largest legal numeric token.  \ (Rounding
  2715. 4095.999999 to the nearest multiple of $1\over65536$ yields 4096,
  2716. which is too big.)
  2717. \MF\ converts each line of text into a sequence of tokens by repeating
  2718. the following rules until no more characters remain on the line:
  2719. \smallskip
  2720. \hang\textindent{1)}If the next character is a ^{space}, or if it's a ^{period}
  2721. (\thinspace`|.|'\thinspace) that isn't ^^{decimal point} followed by a
  2722. decimal digit or a period, ignore it and move on.
  2723. \hang\textindent{2)}If the next character is a ^{percent sign}
  2724. (\thinspace`|%|'\thinspace), ignore it and also ignore everything else
  2725. that remains on the current line. \ (Percent signs therefore allow you to
  2726. write ^{comments} that are unseen by \MF\!.)
  2727. \hang\textindent{3)}If the next character is a ^{decimal digit} or a period
  2728. that's followed by a decimal digit, the next token is a numeric token,
  2729. consisting of the longest sequence of contiguous characters starting at
  2730. the current place that satisfies the syntax for \<numeric token> above.
  2731. \hang\textindent{4)}If the next character is a ^{double-quote mark} (\thinspace
  2732. `|"|'\thinspace), the next token is a string token, consisting of all
  2733. characters from the current place to the next double-quote, inclusive.
  2734. \ (There must be at least one more double-quote remaining on the line,
  2735. otherwise \MF\ will complain about an ``^{incomplete string}.'') \ A string
  2736. token represents the sequence of characters between the double-quotes.
  2737. \hang\textindent{5)}If the next character is a ^{parenthesis} (\thinspace
  2738. `|(|' or `|)|'\thinspace), a comma (\thinspace`|,|'\thinspace), or a
  2739. semicolon (\thinspace`|;|'\thinspace), the next token is a symbolic token
  2740. consisting of that single character.
  2741. \hang\textindent{6)}Otherwise the next token is a symbolic token consisting
  2742. of the next character together with all immediately following characters
  2743. that appear in the same row of the following
  2744. ^^{table of character classes} table:
  2745. \begindisplay \displayindent=0pt
  2746. |ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz|\hidewidth\cr
  2747. |<=>:|\|\cr
  2748. |`'|\cr
  2749. |+-|\cr
  2750. |/*\|\cr
  2751. |!?|\cr
  2752. |#&@$|\cr
  2753. |^~|\cr
  2754. |[|\cr
  2755. |]|\cr
  2756. |{}|\cr
  2757. |.|&(see rules 1, 3, 6)\cr
  2758. |,  ;  (  )|&(see rule 5; these characters are ``loners'')\cr
  2759. |"|&(see rule 4 for details about string tokens)\cr
  2760. |0123456789|&(see rule 3 for details about numeric tokens)\cr
  2761. |%|&(see rule 2 for details about comments)\cr
  2762. \enddisplay
  2763. \noindent
  2764. The best way to learn the six rules about tokens is to work the following
  2765. exercise, after which you'll be able to read any input file just as the
  2766. computer does.
  2767. \exercise What tokens does \MF\ find in the (ridiculous) line
  2768. \begindisplay
  2769. |xx3.1.6..[[a+-bc_d.e] ]"a %" <|\||>(($1. 5"+-""" % weird?|
  2770. \enddisplay
  2771. \answer \cstok{xx}, \cstok{3.1} (a numeric token), \cstok{.6} (another
  2772. numeric token), \cstok{..}, \cstok{[[}, \cstok{a}, \cstok{+-},
  2773. \cstok{bc\_d}, \cstok{e}, \cstok{]}, \cstok{]}, {\chardef\"=`\"\cstok{\"a
  2774. \%\"} (a string token), \cstok{<\|>}, \cstok{(} (see rule~5), \cstok{(},
  2775. \cstok{\$}, \cstok{1} (a numeric token), \cstok{5} (likewise numeric),
  2776. \cstok{\"+-\"} (a string token), and \cstok{\"\"}} (a string token that
  2777. denotes an empty sequence of characters).
  2778. All of these tokens are symbolic unless otherwise mentioned. \ (Notice that
  2779. four of the spaces and two of the periods were deleted by rule~1.
  2780. One way to verify that \MF\ finds precisely these tokens is to prepare a
  2781. test file that says `|isolated| |expression;|' on its first line and that
  2782. contains the stated text on its second line. Then respond to \MF's
  2783. error message by repeatedly typing `|1|', so that one token is deleted
  2784. at a time.)
  2785. \exercise Criticize the following statement: \MF\ ignores all spaces in the
  2786. input.
  2787. \answer The statement is basically true but potentially misleading. You can
  2788. insert any number of spaces {\sl between\/} tokens without changing the
  2789. meaning of a program, but you cannot insert a space in the {\sl middle\/}
  2790. of any token without changing something. You can delete spaces between
  2791. tokens {\sl unless\/} that would ``glue'' two adjacent tokens together.
  2792. \dangerexercise True or false: If the syntax for \<numeric token> were
  2793. changed to include a fourth alternative, `\<digit string>|.|', the meaning
  2794. of \MF\ programs would not change in any way.
  2795. \answer False. It may seem that this new sort of numeric token would be
  2796. recognized only in cases where the period is not followed by a digit,
  2797. hence the period would be dropped anyway by rule~1. However, the new rule
  2798. would have disastrous consequences in a line like `|draw| |z1..z2|'!
  2799. \endchapter
  2800. Yet wee with all our seeking could see no tokens.
  2801.  % of any such Wall.
  2802. \author PHILEMON ^{HOLLAND},  {\sl ^{Camden}'s Brittania\/} (1610)
  2803. % OED says page 518, but I couldn't find it there in the 1637 edition
  2804. \bigskip
  2805. Unpropitious tokens interfered.
  2806. \author WILLIAM ^{COWPER},  {\sl ^{Homer}'s Iliad\/} (1791) % Book 4 verse 455
  2807. \eject
  2808. \beginchapter Chapter 7. Variables
  2809. One of \MF's most important concepts is the notion of a
  2810. {\sl^{variable}\/}---something that can take on a variety of different
  2811. values. Indeed, this is one of the most important concepts in all of
  2812. mathematics, and variables play a prominent r\^ole in almost all
  2813. computer languages. The basic idea is that a program manipulates data,
  2814. and the data values are stored in little compartments of a computer's
  2815. memory. Each little compartment is a variable, and we refer to an item
  2816. of data by giving its compartment a name.
  2817. For example, the |io.mf| program for the letter {\manual\IOO} in Chapter~5
  2818. contains lots of variables. Some of these, like `|x1l|' and `|y1|', represent
  2819. coordinates. Others, like `|up|', represent
  2820. directions. The variables `|em#|' and `|thin#|' stand for physical,
  2821. machine-independent distances; the analogous variables `|em|' and `|thin|'
  2822. stand for the corresponding machine-dependent distances in units of pixels.
  2823. These examples indicate that different variables are often related to each
  2824. other. There's an implicit connection between `|em#|' and `|em|',
  2825. between `|x1|' and `|y1|'; the `"penpos"' convention
  2826. sets up relationships between `|x1l|', `|x1|', and `|x1r|'. By choosing
  2827. the names of variables carefully, programmers can make their programs
  2828. much easier to understand, because the relationships between variables
  2829. can be made to correspond to the ^^{data structure} structure
  2830. of their names.
  2831. In the previous chapter we discussed tokens, the atomic elements from which
  2832. all \MF\ programs are made. We learned that there are three kinds of
  2833. tokens: numeric (representing numbers), string (representing text), and
  2834. symbolic (representing everything else).  Symbolic tokens have no
  2835. intrinsic meaning; any symbolic token can stand for whatever a programmer
  2836. wants it to represent.
  2837. Some symbolic tokens do, however, have predefined {\sl^{primitive}\/}
  2838. meanings, when \MF\ begins its operations. For example, `|+|' stands
  2839. initially for ``plus,'' and `|;|' stands for ``finish the current
  2840. statement and move on to the next part of the program.''  It is customary
  2841. to let such tokens retain their primitive meanings, but any symbolic token
  2842. can actually be assigned a new meaning as a program is performed. For
  2843. example, the definition of `|test_I|' in |io.mf| makes that token stand
  2844. for a {\sl^{macro}}, i.e., a subroutine. We'll see later that you can
  2845. instruct \MF\ to `|let| |plus=+|', after which `|plus|' will act just
  2846. like `|+|' did.
  2847. \MF\ divides symbolic tokens into two categories, depending on their
  2848. current meaning. If the symbolic token currently stands for one of \MF's
  2849. primitive operations, or if it has been defined to be a macro, it is
  2850. called a {\sl^{spark}\/}; otherwise it is called a {\sl^{tag}}. Almost
  2851. all symbolic tokens are tags, because only a few are defined to be sparks;
  2852. however, \MF\ programs typically involve lots of sparks, because sparks
  2853. are what make things happen. The symbolic tokens on the first five lines
  2854. of |io.mf| include the following sparks:
  2855. \begintt
  2856. mode_setup  ;  :=  /  define_pixels  (  ,  )
  2857. \endtt
  2858. and the following tags:
  2859. \begintt
  2860. em  #  pt  cap  thin  thick  o
  2861. \endtt
  2862. (some of which appear several times). Tags are used to designate variables,
  2863. but sparks cannot be used within a variable's name.
  2864. Some variables, like `|em#|', have names that are made from more than one token;
  2865. in fact, the variable `|x1l|' is named by three tokens, one of which is
  2866. numeric. \MF\ has been designed so that it is easy to make compound names
  2867. that correspond to the relations between variables. Conventional programming
  2868. languages like ^{Pascal} would refer to `|x1l|' by the more
  2869. cumbersome notation `|x[1].l|'; it turns out that `|x[1].l|' is an
  2870. acceptable way to designate the variable |x1l| in a \MF\ program, but the
  2871. shorthand form `|x1l|' is a great convenience because such variables
  2872. are used frequently.
  2873. Here are the formal rules of syntax by which \MF\ understands the names of
  2874. variables:
  2875. \def\\#1{\thinspace{\tt#1}\thinspace}
  2876. \beginsyntax
  2877. <variable>\is<tag><suffix>
  2878. <suffix>\is<empty>\alt<suffix><subscript>\alt<suffix><tag>
  2879. <subscript>\is<numeric token>\alt\\{\char`\[}<numeric expression>\\]
  2880. \endsyntax
  2881. First comes a tag, like `|x|'; then comes a {\sl^{suffix}\/} to the tag,
  2882. like `|1l|'.
  2883. The suffix might be empty, or it might consist of one or more subscripts
  2884. or tags that are tacked on to the original tag. A {\sl^{subscript}\/} is
  2885. a numeric index that permits you to construct ^{arrays} of related
  2886. variables. The subscript is either a single numeric token, or it is a formula
  2887. enclosed in square ^{brackets}; in the latter case the formula should produce a
  2888. ^^|[| numeric value. For example, `|x[1]|' and `|x[k]|' and `|x[3-2k]|' all mean
  2889. ^^|]| the same thing as `|x1|', if\/ |k|~is a variable whose value is~1. But
  2890. `|x.k|' is not the same; it is the tag~`|x|' suffixed by the tag~`|k|',
  2891. not the tag~`|x|' subscripted by the value of variable~|k|.
  2892. \danger The variables `|x1|' and `|x01|' and `|x1.00|' are identical.
  2893. Since any numeric token can be used as a subscript, fractional indices
  2894. are possible; for example, `|x1.5|' is the same as `|x[3/2]|'. Notice,
  2895. however, that `|B007|' and `|B.007|' are {\sl not\/} the same variable,
  2896. because the latter has a fractional subscript.
  2897. \danger \MF\ makes each \<suffix> as long as possible. In other words,
  2898. a \<suffix> is always extended if it is followed by a \<subscript>
  2899. or a~\<tag>.
  2900. \dangerexercise Explain how to type a reference to the doubly subscripted
  2901. variable `|a[1][5]|' without using square brackets.
  2902. \answer You can put a space between the subscripts, as in `|a1|~|5|'. \
  2903. (We'll see later that a ^{backslash} acts as a null symbol,
  2904. hence `|a1\5|' is another solution.)
  2905. \dangerexercise Is it possible to refer to {\sl any\/} variable without
  2906. using square brackets?
  2907. \answer No; |a[-1]| can't be accessed without using |[| and |]|. The
  2908. only other form of \<subscript> is \<numeric token>, which can't be
  2909. negative. \ (Well, strictly speaking, you could say `|let|~|?=[;|
  2910. |let|~|??=]|' and then refer to `|a?-1??|'; but that's cheating.)
  2911. \ddangerexercise Jonathan H. ^{Quick} (a student) used `|a.plus1|' as the name
  2912. of a variable at the beginning of his program; later he said `|let|
  2913. |plus=+|'. How could he refer to the variable `|a.plus1|' after that?
  2914. \answer Assuming that `|+|' was still a spark when he said `|let|~|plus=+|',
  2915. he can't refer to the variable `|a.plus1|' unless he changes the meaning of
  2916. |plus| again to make it a~tag. \ (We will eventually learn a way to do this
  2917. without permanently clobbering |plus|, as follows: `^|begingroup| ^|save|
  2918. |plus;| |a.plus1| ^|endgroup|'.)
  2919. \danger \MF\ has several special variables called {\sl^{internal
  2920. quantities}\/} that are intimately wired-in to the computer's behavior.
  2921. For example, there's an internal quantity called `^|fontmaking|' that controls
  2922. whether or not a |tfm| file is produced; another one called `^|tracingtitles|'
  2923. governs whether or not titles like |"The| |letter|~|O"| appear on your
  2924. terminal; still another one called `^|smoothing|' affects the digitization of
  2925. curves. \ (A complete list of \MF's internal quantities appears in
  2926. Chapter~25.) \ The name of an internal quantity acts like a tag, but
  2927. internal quantities cannot be suffixed. Thus, the syntax rule for \<variable>
  2928. should actually be replaced by a slightly more complicated pair of rules:
  2929. \beginsyntax
  2930. <variable>\is<external tag><suffix>\alt<internal quantity>
  2931. <tag>\is<external tag>\alt<internal quantity>
  2932. \endsyntax
  2933. \dangerexercise True or false: Every \<variable> is a legal \<suffix>.
  2934. \answer True. \ (But a \<suffix> is not always a \<variable>.)
  2935. \ddanger The `|[|' and `|]|' that appear in the syntax for \<subscript>
  2936. stand for any symbolic tokens whose current meanings are the same as
  2937. \MF's primitive meanings of left and right bracket, respectively;
  2938. those tokens don't necessarily have to be brackets. Conversely, if the
  2939. meanings of the tokens `|[|' and `|]|' have been changed, brackets cannot
  2940. be used to delimit subscripts. Similar remarks apply to all of the
  2941. symbolic tokens in all of the syntax rules from now on. \MF\ doesn't look
  2942. at the form of a token; it considers only a token's current meaning.
  2943. The examples of \MF\ programs in this book have used two different
  2944. typographic conventions. Sometimes we refer to variables by using
  2945. ^{italic type} and/or genuine subscripts, e.g., `"em"' and `$x_{2r}$';
  2946. but sometimes we refer to those same variables by using a ^{typewriter}-like
  2947. style of type, e.g., `|em|' and~`|x2r|'. In general, the typewriter style
  2948. is used when we are mainly concerned with the way a programmer is supposed
  2949. to type something that will appear on the terminal or in a file; but fancier
  2950. typography is used when we are focusing on the meaning of a program rather
  2951. than its ASCII representation. It should be clear how to convert the fancier
  2952. form into tokens that \MF\ can actually understand.
  2953. \danger In general, we shall use italic type only for tags (e.g., "em",
  2954. "x", "r"), while boldface and roman type will be used for sparks
  2955. (e.g., @draw@, @fill@, cycle, rotated, sqrt). Tags that consist of special
  2956. characters instead of letters will sometimes get special treatment;
  2957. for example, |em#| and |z2'| might be rendered $"em"\0$ and $z'_2$,
  2958. respectively.
  2959. The variables we've discussed so far have almost always had numbers as their
  2960. values, but in fact \MF's variables are allowed to assume values of eight
  2961. different ^{types}. A variable can be of type
  2962. \nobreak\smallskip
  2963. \item\bull^{boolean}, representing the values `^{true}' or `^{false}';
  2964. \item\bull^{string}, representing sequences of ASCII characters;
  2965. \item\bull^{path}, representing a (possibly curved) line;
  2966. \item\bull^{pen}, representing the shape of a pen nib;
  2967. \item\bull^{picture}, representing an entire pattern of pixels;
  2968. \item\bull^{transform}, representing the operations of scaling, rotating,
  2969.   shifting, reflecting, and/or slanting;
  2970. \item\bull^{pair}, representing two numbers (e.g., a point or a vector);
  2971. \item\bull^{numeric}, representing a single number.
  2972. \smallskip\noindent
  2973. If you want a variable to represent something besides a number, you must
  2974. first give a {\sl^{type declaration}\/} ^^{declarations} that states
  2975. what the type will be. But if you refer to a variable whose type has not
  2976. been declared, \MF\ won't complain, unless you try to use it in a way that
  2977. demands a value that isn't numeric.
  2978. Type declarations are easy. You simply name one of the eight types,
  2979. then you list the variables that you wish to declare for that type.
  2980. For example, the declaration
  2981. \begindisplay
  2982. @pair@ "right", "left", $a.p$
  2983. \enddisplay
  2984. says that "right" and "left" and $a.p$ will be variables of type @pair@,
  2985. so that equations like
  2986. \begindisplay
  2987. $"right"=-"left"=2a.p=(1,0)$
  2988. \enddisplay
  2989. can be given later. These equations, incidentally, define the values
  2990. $"right"=(1,0)$, $"left"=(-1,0)$, and $a.p=(.5,0)$. \ (Plain \MF\
  2991. has the stated values of "right" and "left" already built~in.)
  2992. The rules for declarations are slightly trickier when subscripts are
  2993. involved, because \MF\ insists that all variables whose names are identical
  2994. except for subscript values must have the same type. It's possible to
  2995. set things up so that, for example, $a$~is numeric, $a.p$ is a pair,
  2996. $a.q$ is a pen, $a.r$ is a path, and $a_1$ is a string; but if $a_1$
  2997. is a string, then all other variables $a_2$, $a_3$, etc., must also be
  2998. strings. In order to enforce this restriction, \MF\ allows only
  2999. ``collective'' subscripts, represented by empty brackets `^|[]|',
  3000. to appear in type declarations. ^^{collective subscripts} For example,
  3001. \begintt
  3002. path r, r[], x[]arc, f[][]
  3003. \endtt
  3004. declares $r$ and all variables of the forms $r[i]$, $x[i]"arc"$,
  3005. and $f[i][j]$ to be path variables. This declaration doesn't affect
  3006. the types or values of other variables like $r[\,]"arc"$; it affects
  3007. only the variables that are specifically mentioned.
  3008. Declarations destroy all previous values of the variables being defined.
  3009. For example, the path declaration above makes $r$ and $r[i]$ and $x[i]"arc"$
  3010. and $f[i][j]$ undefined, even if those variables previously had paths
  3011. as their values. The idea is that all such variables will start out with a
  3012. clean slate so that they can receive appropriate new values based on
  3013. subsequent equations. ^^{value, disappearance of}
  3014. \exercise Numeric variables don't need to be declared. Therefore is there
  3015. ever any reason for saying `|numeric| |x|'\thinspace?
  3016. \answer Yes, because it removes any existing value that $x$ may have
  3017. had, of whatever type; otherwise you couldn't safely use $x$ in a
  3018. numeric equation. It's wise to declare numeric variables when you're
  3019. not sure about their former status, and when you're sure that you don't
  3020. care what their previous value was. A numeric declaration together with a
  3021. comment also provides useful documentation. \ (Incidentally, `|numeric|~|x|'
  3022. doesn't affect other variables like `|x2|' or `|x.x|' that might be present.)
  3023. \danger The formal syntax rules for type declarations explain these
  3024. grammatical conventions precisely. If the symbolic token that begins a
  3025. declared variable was previously a spark, it loses its former meaning and
  3026. immediately becomes a tag.
  3027. \beginsyntax
  3028. <declaration>\is<type><declaration list>
  3029. <type>\is[boolean]\alt[string]\alt[path]\alt[pen]
  3030.   \alt[picture]\alt[transform]\alt[pair]\alt[numeric]
  3031. <declaration list>\is<declared variable>
  3032.   \alt<declaration list>[,]<declared variable>
  3033. <declared variable>\is<symbolic token><declared suffix>
  3034. <declared suffix>\is<empty>\alt<declared suffix><tag>
  3035.   \alt<declared suffix>\\{\char`\[}\\]
  3036. \endsyntax
  3037. \dangerexercise Find three errors in the supposed declaration
  3038. `|transform| |t42,24t,,t,path|'.
  3039. \answer (a)~The `|42|' is illegal because subscripts must be collective.
  3040. \ (b)~The `|24|' is illegal because a \<declared variable> must start with
  3041. a \<symbolic token>, not a numeric token. \ (c)~There's nothing wrong with
  3042. the consecutive commas; the second comma begins a \<declared variable>, so
  3043. it loses its former meaning and becomes a tag. Thus \MF\ tries to declare
  3044. the variable `|,t,path|'. However, `|path|' cannot appear in a suffix,
  3045. since it's a spark. \ (Yes, this is admittedly tricky. Computers follow rules.)
  3046. \endchapter
  3047. Beings low in the scale of nature are
  3048. more variable than those which are higher.
  3049. \author CHARLES ^{DARWIN}, {\sl On the Origin of Species\/} (1859) % p149
  3050. \bigskip
  3051. Among the variables, {\rm Beta ({\cmman\char'14\/}) Persei}, or\/ {\rm^{Algol}},
  3052. is perhaps the most interesting, as its period is short.
  3053. \author J. NORMAN ^{LOCKYER},  {\sl Elements of Astronomy\/} (1870)
  3054.  % American edition, p40
  3055. \eject
  3056. \beginchapter Chapter 8. Algebraic\\Expressions
  3057. \MF\ programmers express themselves algebraically by writing algebraic
  3058. formulas called {\sl^{expressions}}. The formulas are algebraic in the
  3059. sense that they involve variables as well as constants. By combining
  3060. variables and constants with appropriate mathematical operations, a
  3061. programmer can specify an amazing variety of things with comparative ease.
  3062. We have already seen many examples of expressions; our goal now is to make
  3063. a more systematic study of what is possible. The general idea is that an
  3064. expression is either a ^{variable} (e.g., `$x_1$'\thinspace) or a
  3065. ^{constant} (e.g., `20'\thinspace), or it consists of an ^{operator}
  3066. (e.g., `$+$'\thinspace) together with its ^{operands} (e.g.,
  3067. `$x_1+20$'\thinspace). The operands are, in turn, expressions built~up in
  3068. the same way, perhaps enclosed in ^{parentheses}. For example,
  3069. `$(x_1+20)/(x_2-20)$' is an expression that stands for the quotient of two
  3070. subexpressions.  It is possible to concoct extremely complicated algebraic
  3071. expressions, but even the most intricate constructions are built from
  3072. simple parts in simple ways.
  3073. Mathematicians spent hundreds of years developing good ways to write formulas;
  3074. then computer scientists came along and upset all the time-honored traditions.
  3075. The main reason for making a change was the fact that computers find it
  3076. difficult to deal with two-dimensional constructions like
  3077. \begindisplay
  3078. $\displaystyle{x_1+20\over x_2-20}+\sqrt{a^2-{2\over3}\sqrt b}.$
  3079. \enddisplay
  3080. One-dimensional sequences of tokens are much easier to input and to decode;
  3081. hence programming languages generally put such formulas all on one line,
  3082. ^^{sqrt} by inserting parentheses, brackets, and asterisks as follows:
  3083. \begintt
  3084. (x[1]+20)/(x[2]-20)+sqrt(a**2-(2/3)*sqrt(b)).
  3085. \endtt
  3086. \MF\ will understand this formula, but it also accepts a notation that
  3087. is shorter and closer to the standard conventions of mathematics:
  3088. \begintt
  3089. (x1+20)/(x2-20)+sqrt(a**2-2/3sqrt b).
  3090. \endtt
  3091. We observed in the previous chapter that \MF\ allows you to write `|x2|'
  3092. instead of `|x[2]|'; similarly, you can write `|2x|' instead of `|2*x|'
  3093. and `|2/3x|' instead of `|(2/3)*x|'. Such operations are extremely common
  3094. in \MF\ programs, hence the language has been set up to facilitate them.
  3095. On the other hand, \MF\ doesn't free you from all the inconveniences of
  3096. computer languages; you must still write `|x*k|' for the ^{product} of
  3097. $x$ times~$k$, and `|x[k]|' for the variable $x$~subscripted by~$k$,
  3098. in order to avoid confusion with the suffixed variable `|x.k|'.
  3099. We learned in the previous chapter that there are eight types of
  3100. variables: numeric, boolean, string, and so~on. The same types apply
  3101. to expressions; \MF\ deals not only with numeric expressions but also
  3102. with boolean expressions, string expressions, and the others. For example,
  3103. `$(0,0)\to(x_1,y_1)$'
  3104. is a path-valued expression, formed by applying the operator `$\to$' to the
  3105. subexpressions `$(0,0)$' and `$(x_1,y_1)$'; these subexpressions, in turn,
  3106. have values of type ``pair,'' and they have been built up from values of
  3107. type ``numeric.'' Each operation produces a result whose type can be
  3108. determined from the types of the operands; furthermore, the simplest
  3109. expressions (variables and constants) always have a definite type.
  3110. Therefore the machine always knows what type of quantity it is dealing
  3111. with, after it has evaluated an expression.
  3112. If an expression contains several operators, \MF\ has to decide which
  3113. ^^{order of operations}
  3114. operation should be done first. For example, in the expression `$a-b+c$'
  3115. it is important to compute `$a-b$' first, then to add~$c$; if `$b+c$' were
  3116. computed first, the result `$a-(b+c)$' would be quite different from the
  3117. usual conventions of mathematics. On the other hand, mathematicians
  3118. usually expect `$b/c$' to be computed first in an expression like
  3119. `$a-b/c$'; multiplications and divisions are usually performed before
  3120. additions and subtractions, unless the contrary is specifically indicated
  3121. by parentheses as in `$(a-b)/c$'. The general rule is to evaluate
  3122. subexpressions in parentheses first, then to do operations in order of
  3123. their ``^{precedence}''; if two operations have the same precedence, the
  3124. left one is done first. For example, `$a-b/c$' is equivalent to
  3125. `$a-(b/c)$' because division takes precedence over subtraction; but
  3126. `$a-b+c$' is equivalent to `$(a-b)+c$' because left-to-right order is
  3127. used on operators of equal precedence.
  3128. It's convenient to think of operators as if they are tiny ^{magnets} that
  3129. attract their operands; the magnets for `$\ast$' and `/' are stronger
  3130. than the magnets for `$+$' and `$-$', so they stick to their operands more
  3131. tightly and we want to perform them first.
  3132. \MF\ distinguishes four (and only four) levels of precedence. The
  3133. strongest magnets are those that join `2' to~`$x$' and `sqrt' to `$b$'
  3134. in expressions like `$2x$' and `sqrt$\,b$'. The next strongest are
  3135. multiplicative operators like `$\ast$' and~`/'; then come the additive
  3136. operators like `$+$' and~`$-$'. The weakest magnets are operators like
  3137. `$\to$' or `$<$'. For example, the expression
  3138. \begindisplay
  3139. $a+{\rm sqrt}\,b/2x<c$
  3140. \enddisplay
  3141. is equivalent to the fully parenthesized formula
  3142. \begindisplay
  3143. $\bigl(a+\bigl(({\rm sqrt}\,b)/(2x)\bigr)\bigr)<c$.
  3144. \enddisplay
  3145. \exercise Insert parentheses into the formula `|z1+z2..z3/4*5..z6-7*8z9|',
  3146. to show explicitly in what order \MF\ will do the operations.
  3147. \answer |((z1+z2)..((z3/4)*5))..(z6-(7*(8z9)))|.
  3148. \danger High-school algebra texts often avoid parentheses inside of
  3149. parentheses by using ^{braces} and ^{brackets}. Therefore many people
  3150. have been trained to write
  3151. \begindisplay
  3152. $\{a+[({\rm sqrt}\,b)/(2x)]\}<c$
  3153. \enddisplay
  3154. instead of the fully parenthesized formula above. However, professional
  3155. mathematicians usually stick to only one kind of parentheses, because
  3156. braces and brackets have other meanings that are more important. In this
  3157. respect \MF\ is like the professionals: It reserves curly braces `|{}|'
  3158. and square brackets `|[]|' for special purposes, so you should not
  3159. try to substitute them for parentheses.
  3160. \ddanger If you really want alternatives to parentheses, there is actually
  3161. a way to get them. You can say, for example,
  3162. \begintt
  3163. delimiters [[ ]];  delimiters {{  }}
  3164. \endtt
  3165. after which double brackets and braces can be used in formulas like
  3166. \begintt
  3167. {{a+[[(sqrt b)/(2x)]]}}<c.
  3168. \endtt
  3169. The symbolic token `|{{|' has no relation to `|{|', and it
  3170. has no primitive meaning, hence you are free to define it in any way you
  3171. like; the ^@delimiters@ command defines a new pair of delimiters. In formulas
  3172. with mixed delimiters as defined here, \MF\ will check that `|[[|' matches only
  3173. with~`|]]|', `|{{|'~only with~`|}}|', and `|(|'~only with~`|)|'; thus you
  3174. can more easily detect errors in large expressions. However, it's usually
  3175. unnecessary to have any delimiters other than parentheses, because large
  3176. expressions are rare, and because the rules of operator precedence make
  3177. most parentheses superfluous.
  3178. If you're reading this chapter carefully, you may be thinking, ``Hey wait!
  3179. Isn't there a contradiction? A minute ago I was told that `|2/3x|' stands
  3180. for `|(2/3)*x|', but now the rules of precedence appear to state that
  3181. `|2/3x|' really stands for `|2/(3x)|'. What gives?'' Indeed, you have an
  3182. excellent point; but there is no contradiction, because of another rule that
  3183. hasn't been mentioned yet. When two {\sl numeric tokens\/} are divided, the
  3184. ^^{division of numeric tokens} magnetism of `|/|' is stronger than usual;
  3185. in this case `|/|' has the same precedence as the implied multiplication
  3186. operator in `|3x|'. Hence the operations in `|2/3x|' are carried out from
  3187. left to right, as stated previously. \ (This is a good rule because it
  3188. is almost always what a \MF\ programmer wants. However, one should bear
  3189. in mind that `|a/3x|' means `|a/(3x)|' when |a| is {\sl not\/} a numeric token.)
  3190. Because of the rule in the previous paragraph, the \MF\ programs in this
  3191. book often say `${2\over3}x$' for what would be typed `|2/3x|' in a file.
  3192. Such built-up ^{fractions} are never used except when the numerator and
  3193. denominator are both numbers; a construction like `|a/3x|' will always be
  3194. rendered as `$a/3x$', not~`$\,{a\over3x}\,$'.
  3195. \MF\ knows how to do dozens of operations that haven't been mentioned yet
  3196. in this book. Let's take a look at some of them, so that we will know
  3197. they are available in case of need. It will be most instructive and
  3198. most fun to learn about expressions by interacting with the computer;
  3199. ^^"tracingonline" ^^@scrollmode@ ^^@forever@ ^^@scantokens@ ^^{readstring}
  3200. ^^@message@
  3201. therefore you should prepare the following short file, called ^|expr.mf|:
  3202. \begintt
  3203. string s[]; s1="abra";
  3204. path p[]; p1=(0,0)..(3,3); p2=(0,0)..(3,3)..cycle;
  3205. tracingonline:=1; scrollmode;
  3206. forever: message "gimme an expr: "; s0:=readstring;
  3207. show scantokens s0; endfor
  3208. \endtt
  3209. \danger You don't need to understand what's in |expr.mf| when you read this
  3210. chapter for the first time, because the file uses \MF\ in ways that will be
  3211. explained carefully later. But here is a translation, in case you're
  3212. curious: Line~1 declares all variables of the form $s_k$ to be strings, and
  3213. sets $s_1$ to the value |"abra"|. Line~2 declares all variables of the
  3214. form~$p_k$ to be paths, and sets $p_1$ and~$p_2$ to simple example paths.
  3215. Line~3 tells \MF\ to print diagnostic information ^{online}, i.e., on the
  3216. terminal as well as in the ^{log file}; it also establishes
  3217. `@scrollmode@', which means that the computer won't stop after error
  3218. messages. Lines 4 and~5 set up an infinite loop in which \MF\ reads an
  3219. expression from the terminal and shows the corresponding value.
  3220. \outer\def\begindemo{$$\advance\baselineskip by2pt
  3221.   \catcode`\"=\other
  3222.   \halign\bgroup\indent\hbox to 160pt{\tt##\hfil}&\tt##\hfil\cr
  3223.   \noalign{\vskip-2pt}}
  3224. \outer\def\enddemo{\egroup$$}
  3225. \def\werror{\ \rm(with error message)}
  3226. \def\werrors{\ \rm(with error messages)}
  3227. \def\demohead{\it\kern-2pt You type&\it\kern-1pt And the result is\cr
  3228.   \noalign{\nobreak\vskip2pt}}
  3229. If you start \MF\ and type `|expr|' when it asks for an input file name,
  3230. it will read the file |expr.mf| and then it will say `^|gimme|
  3231. |an|~|expr|'. Here's where the fun starts: You can type any expression,
  3232. and \MF\ will compute
  3233. and display its value. Try it; type `|2+2|' and \<return>, obtaining the
  3234. value~`|>>|~|4|'. Isn't that amazing? Here are some more things to try:
  3235. \begindemo
  3236. \demohead
  3237. 1.2-2.3&-1.1\cr
  3238. 1.3-2.4&-1.09999\cr
  3239. 1.3*1000&1300.00305\cr
  3240. 2.4*1000&2399.9939\cr
  3241. 3/8&0.375\cr
  3242. .375*1000&375\cr
  3243. 1/3&0.33333\cr
  3244. 1/3*3&0.99998\cr
  3245. 0.99999&0.99998\cr
  3246. 1-epsilon&0.99998\cr
  3247. 1/(1/3)&3.00005\cr
  3248. 1/3.00005&0.33333\cr
  3249. .1*10&1.00006\cr
  3250. 1+4epsilon&1.00006\cr
  3251. \enddemo
  3252. These examples illustrate the small errors that occur because \MF\ does
  3253. ``fixed binary'' ^{arithmetic} using integer multiples of $1\over65536$.
  3254. The result of $1.3-2.4$ is not quite the same as $-1.1$, because |1.3| is
  3255. a little bit larger than~$13\over10$ and |2.4| is a little smaller
  3256. than~$24\over10$. Small errors get magnified when they are multiplied by
  3257. 1000, but even after magnification the discrepancies are negligible because
  3258. they are just tiny fractions of a pixel. You may be surprised that
  3259. 1/3~times~3 comes out to be .99998 instead of .99999; the truth is that both
  3260. |0.99999| and |0.99998| represent the same value, namely $65535\over65536$; \MF\
  3261. displays this value as |0.99998| because it is closer to .99998 than to
  3262. .99999. Plain \MF\ defines ^"epsilon" to be $1\over65536$, the smallest
  3263. representable number that is greater than zero; therefore |1-epsilon|
  3264. is $65535\over65536$, and |1+4epsilon| is $65540\over65536$.
  3265. \begindemo
  3266. \demohead
  3267. 4096&4095.99998\werror\cr
  3268. infinity&4095.99998\cr
  3269. 1000*1000&32767.99998\werror\cr
  3270. infinity+epsilon&4096\cr
  3271. 100*100&10000\cr
  3272. .1(100*100)&1000.06104\cr
  3273. (100*100)/3&3333.33333\cr
  3274. \enddemo
  3275. \MF\ will complain that an `|Enormous| ^^{enormous number} |number| |has|
  3276. |been| |reduced|' when you try to introduce constants that are 4096 or~more.
  3277. Plain \MF\ defines ^"infinity" to be $4096-"epsilon"$, which is the largest
  3278. legal numeric token. On the other hand, it turns out that larger numbers
  3279. can actually arise when an expression is being evaluated; \MF\ doesn't
  3280. worry about this unless the resulting magnitude is at least 32768.
  3281. \dangerexercise If you try `|100*100/3|' instead of `|(100*100)/3|', you
  3282. get `|3333.33282|'. Why?
  3283. \answer The fraction |100/3| is evaluated first (because such divisions
  3284. take precedence); the rounding error in this fraction is then magnified by~100.
  3285. \ddanger Sometimes \MF\ will compute things more accurately than you would
  3286. expect from the examples above, because many of its internal calculations
  3287. are done with multiples of $2^{-28}$ instead of $2^{-16}$. For example,
  3288. if $t=3$ the result of `|1/3t|' will be exactly~1
  3289. (not 0.99998); the same thing happens if you write `|1/3(3)|'.
  3290. Now let's try some more complicated expressions, using undefined
  3291. variables as well as constants. \ (Are you actually trying these
  3292. examples, or are you just reading the book? It's far better to type
  3293. them yourself and to watch what happens; in fact, you're also allowed
  3294. to type things that {\sl aren't\/} in the book!)
  3295. \begindemo
  3296. \demohead
  3297. b+a&a+b\cr
  3298. a+b&a+b\cr
  3299. b+a-2b&a-b\cr
  3300. 2(a-b+.5)&2a-2b+1\cr
  3301. .5(b-a)&-0.5a+0.5b\cr
  3302. .5[a,b]&0.5a+0.5b\cr
  3303. 1/3[a,b]&0.66667a+0.33333b\cr
  3304. 0[a,b]&a\cr
  3305. a[2,3]&a+2\cr
  3306. t[a,a+1]&t+a\cr
  3307. a*b&b\werror\cr
  3308. 1/b&b\werror\cr
  3309. \enddemo
  3310. \MF\ has a preferred way to arrange variables in order when they are added
  3311. together; therefore `$a+b$' and `$b+a$' give the same result. Notice that
  3312. the ^{mediation} construction `$.5[a,b]$' specifies a number that's halfway
  3313. between $a$ and~$b$, as explained in Chapter~2. \MF\ does not allow you to
  3314. ^{multiply} two unknown numeric quantities together, nor can you ^{divide} by an
  3315. unknown numeric; all of the unknown expressions that \MF\ works with must be
  3316. ``^{linear forms},'' i.e., they must be sums of variables with constant
  3317. coefficients, plus an optional constant. \ (You might want to try typing
  3318. `|t[a,b]|' now, in order to see what error message is given.)
  3319. \begindemo
  3320. \demohead
  3321. sqrt 2&1.41422\cr
  3322. sqrt 100&10\cr
  3323. sqrt 100*100&1000\cr
  3324. sqrt(100*100)&100\cr
  3325. sqrt 100(100)&100\cr
  3326. sqrt sqrt 100(100)&10\cr
  3327. sqrt .01&0.09998\cr
  3328. 0.09998**2&0.01\cr
  3329. 2**1/2&1.41422\cr
  3330. sqrt 2**2&2\cr
  3331. sqrt -1&0\werror\cr
  3332. sqrt a&a\werror\cr
  3333. \enddemo
  3334. Since ^|sqrt| has more ``magnetism'' than |*|, the formula |sqrt|~|100*100|
  3335. ^^{square roots}
  3336. is evaluated as |(sqrt|~|100)*100|; but in `|sqrt|~|100(100)|' the
  3337. |100(100)| is computed first. The reason is that `|(sqrt|~|100)(100)|' isn't
  3338. a legal expression, so the operations in `|sqrt|~|100(100)|' must be carried
  3339. out from right to left. If you are unsure about the order of evaluation,
  3340. ^^|**| you can always insert parentheses; but you'll find that \MF's rules of
  3341. precedence are fairly natural as you gain experience.
  3342. \exercise Is `|sqrt|~|2**2|' computed as `|(sqrt|~|2)**2|' or as
  3343. `|sqrt(2**2)|'\thinspace?
  3344. \answer A |sqrt| takes precedence over any operation with two operands, hence
  3345. the machine computes `|(sqrt|~|2)**2|'; \MF\ was somewhat lucky that the
  3346. answer turned out to be exactly~2. \ (The |sqrt| operation computes the
  3347. nearest multiple of $1\over65536$, and the rounding error in this quantity
  3348. is magnified when it is squared. If you try |sqrt|~|3**2|, you'll get
  3349. |3.00002|; also |sqrt|~|2**4| turns out to be |4.00002|.) \ Incidentally,
  3350. the ^|**| operation of plain \MF\ has the same precedence as |*| and~|/|;
  3351. hence `|x*y**2|' means the same as `|(x*y)**2|', and `|-x**2|' means
  3352. `|(-x)**2|', contrary to the conventions of {\eightrm ^{FORTRAN}}.
  3353. Some \MF\ expressions have `^{true}' or `^{false}' values, instead of numbers;
  3354. we will see later that they can be used to adapt \MF\ programs to special
  3355. conditions.
  3356. \begindemo
  3357. \demohead
  3358. 0<1&true\cr
  3359. 0=1&false\cr
  3360. a+1>a&true\cr
  3361. a>=b&false\werror\cr
  3362. "abc"<="b"&true\cr
  3363. "B">"a!"&false\cr
  3364. "b">"a?"&true\cr
  3365. (1,2)<>(0,4)&true\cr
  3366. (1,2)<(0,4)&false\cr
  3367. (1,a)>(0,b)&true\cr
  3368. numeric a&true\cr
  3369. known a&false\cr
  3370. not pen a&true\cr
  3371. known "a" and numeric 1&true\cr
  3372. (0>1) or (a<a)&false\cr
  3373. 0>1 or a<a&a\werrors\cr
  3374. \enddemo
  3375. ^^{not} ^^@and@ ^^@or@ ^^{comparison}
  3376. The tokens `^|>=|', `^|<=|', and `^|<>|' stand respectively for the
  3377. ^{relations} ^{greater-than-or-equal-to}, ^{less-than-or-equal-to}, and
  3378. ^{unequal-to}. When strings are compared, \MF\ uses the order of words in
  3379. a dictionary, except that it uses ASCII code to define ordering of individual
  3380. characters; thus, all uppercase letters are considered to be less than all
  3381. lowercase letters. \ (See Appendix~C\null.) \ When pairs of numbers are
  3382. compared, \MF\ considers only the $x$~coordinates, unless the $x$~coordinates
  3383. are equal; in the latter case it compares the $y$~coordinates. The type
  3384. of an expression can be ascertained by an expression like `|pair|~|a|',
  3385. which is true if and only if |a|~is a pair. ^^{pair} ^^{numeric} ^^{pen}
  3386. The expression `|known|~|a|' ^^{known} is true if and only if the value
  3387. of~|a| is fully known.
  3388. \dangerexercise What causes the error messages in `|0>1|~|or|~|a<a|'\thinspace?
  3389. \answer Since `^@or@' has stronger precedence than `$<$' or `$>$', ^^|<| ^^|>|
  3390. \MF\thinspace\ tries to evaluate this expression by putting things in
  3391. parentheses as follows: `$(0>(1\mathbin{\bf or}a))<a$'. Now
  3392. `$1\mathbin{\bf or}a$' makes no sense, because `@or@' operates only on
  3393. booleans; in such cases \MF\ uses the right operand~`$a$' as the result. Then
  3394. `$\mkern1mu0>a$' is indeterminate because $a$~is unknown; \MF\ treats this as
  3395. false. Finally `${\rm false}<a$' is another illegal combination of types.
  3396. \danger The rest of this chapter is entirely preceded by ``dangerous bend''
  3397. signs, so you can safely omit it on first reading (unless you're hooked
  3398. and can't stop).
  3399. \danger \MF\ expressions can include many operations that are
  3400. less familiar but still useful. For example, the ^{max} and ^{min}
  3401. operations compute the ^{maximum} and ^{minimum} of numbers, strings,
  3402. or pairs:
  3403. \begindemo
  3404. \demohead
  3405. max(1,-2,4)&4\cr
  3406. min(1,-2,4)&-2\cr
  3407. max("a","b","ab")&"b"\cr
  3408. min("a","b","ab")&"a"\cr
  3409. max((1,5),(0,6),(1,4))&(1,5)\cr
  3410. min((1,5),(0,6),(1,4))&(0,6)\cr
  3411. max(.5a+1,.5a-1)&0.5a+1\cr
  3412. \enddemo
  3413. Numbers can be converted to ^{integers} in a variety of ways:
  3414. \begindemo
  3415. \demohead
  3416. floor 3.14159&3\cr
  3417. floor -3.14159&-4\cr
  3418. floor -epsilon&-1\cr
  3419. floor infinity&4095\cr
  3420. ceiling 3.14159&4\cr
  3421. ceiling -3.14159&-3\cr
  3422. round 3.14159&3\cr
  3423. round -3.14159&-3\cr
  3424. round(1.1,2.8)&(1,3)\cr
  3425. round(3.5,-3.5)&(4,-3)\cr
  3426. round a&a+0.5\werror\cr
  3427. 8 mod 3&2\cr
  3428. -8 mod 3&1\cr
  3429. .8 mod .3&0.2\cr
  3430. \enddemo
  3431. The `^{floor}' operation computes the ^{greatest integer} that is less than
  3432. or equal to its operand; this quantity is often denoted by $\lfloor x\rfloor$
  3433. in mathematics texts. Plain \MF\ also includes the analogous `^{ceiling}'
  3434. operation $\lceil x\rceil$, which is the ^{least integer} greater than or
  3435. equal to~$x$.  Furthermore, `^{round}$\,x$' is the integer nearest to~$x$;
  3436. plain \MF\ computes this by using the formula $\lfloor x+.5\rfloor$, and
  3437. applies it to both components of a pair if a pair is being rounded. The
  3438. ^{remainder} of $x$ with respect to~$y$, written `$x\bmod y$', ^^{mod} is
  3439. calculated by using the formula $x-y\lfloor x/y\rfloor$.
  3440. \begindemo
  3441. \demohead
  3442. abs -7&7\cr
  3443. abs(3,4)&5\cr
  3444. length(3,4)&5\cr
  3445. 3++4&5\cr
  3446. 300++400&500\cr
  3447. sqrt(300**2 + 400**2)&181.01933\werrors\cr
  3448. 1++1&1.4142\cr
  3449. 0 ++ -7&7\cr
  3450. 5+-+4&3\cr
  3451. \enddemo
  3452. ^^{abs} ^^{length} ^^{absolute value}
  3453. \def\stt{\vbox to7.25pt{}}
  3454. The `^|++|' operation is called {\sl^{Pythagorean addition}\/}; $a\pyth+b$
  3455. is the same thing as $\sqrt{\stt a^2+b^2}$. Most of the ^{square root}
  3456. operations in computer programs could probably be avoided if $++$ were
  3457. more widely available, because people seem to want square roots primarily
  3458. when they are computing distances. Notice that $a\pyth+b\pyth+c=
  3459. \sqrt{\stt a^2+b^2+c^2}$; we have the identity $(a\pyth+b)\pyth+c=a\pyth+(
  3460. b\pyth+c)$ as well as $a\pyth+b=b\pyth+a$. It is better to use Pythagorean
  3461. addition than to calculate $\sqrt{\stt a^2+b^2}$, because the computation
  3462. of $a^2$ and $b^2$ might produce numbers that are too large even when
  3463. $a\pyth+b$ is rather small. There's also an inverse operation,
  3464. ^{Pythagorean subtraction}, which is denoted by `^|+-+|'; the quantity
  3465. $a\mathbin{+{-}+}b$ is equal to $\sqrt{\stt a^2-b^2}$.
  3466. \dangerexercise When the author was preparing these examples he typed
  3467. `|0++-7|' and was surprised to get the answer `|0|'. Why should this not
  3468. have been a surprise?
  3469. \answer The token `|++-|' is undefined, so it is a tag; therefore
  3470. |++-7| is a subscripted variable, which was multiplied by zero.
  3471. \ddangerexercise (For mathematicians.) \ Although the Pythagorean addition
  3472. operation is associative and commutative, \MF\ says that
  3473. $5\pyth+4\pyth+2\pyth+2=7=2\pyth+2\pyth+4\pyth+5$ yet
  3474. $2\pyth+4\pyth+5\pyth+2=6.99998$. Why?
  3475. \answer The associative law is valid for exact computations, but not
  3476. for rounded computations. For example, it fails even in the case of
  3477. multiplication, since $(.1\ast.1)\ast10=0.09995$ while $.1\ast(.1\ast10)=.1$
  3478. when products are rounded to the nearest multiples of $1\over65536$.
  3479. However, this observation doesn't quite explain the stated example, which
  3480. would have yielded 7 in all cases if \MF\ had computed $2\pyth+4$ with
  3481. full accuracy!  The closest approximation to $\sqrt{20}$ is ^^{accuracy}
  3482. $4{30942\over65536}$, but $2\pyth+4$ turns out to be $4{30941\over65536}$
  3483. instead. \MF\ computes the absolutely best possible approximations to the
  3484. true answers when it does multiplications, divisions, and square roots,
  3485. but not when it does Pythagorean operations.
  3486. \danger \MF\ uses the names `^{sind}' and `^{cosd}' for the ^{trigonometric}
  3487. functions ^{sine} and ^{cosine}, because \MF's operations are designed to
  3488. deal with angles expressed in degrees. But it turns out that programmers
  3489. rarely need to refer to sines and cosines explicitly, because the `^{dir}'
  3490. and `^{angle}' functions provide most of what a font designer needs.
  3491. \begindemo
  3492. \demohead
  3493. sind 30&0.5\cr
  3494. cosd 30&0.86603\cr
  3495. sind -30&-0.5\cr
  3496. cosd 360&1\cr
  3497. sind 10 ++ cosd 10&1\cr
  3498. dir 30&(0.86603,0.5)\cr
  3499. dir -90&(0,-1)\cr
  3500. angle(1,1)&45\cr
  3501. angle(1,2)&63.43495\cr
  3502. angle(1,-2)&-63.43495\cr
  3503. sind 63.43495 / cosd 63.43495&1.99997\cr
  3504. angle up&90\cr
  3505. angle left&180\cr
  3506. angle(-1000,-epsilon)&-180\cr
  3507. angle dir 60&60.00008\cr
  3508. angle(0,0)&0\werror\cr
  3509. \enddemo
  3510. Plain \MF\ defines `dir$\,x$' to be the pair of values $(\mathop{\rm cosd}x,
  3511. \mathop{\rm sind}x)$; this is a vector, which points $x$~degrees above the
  3512. rightward horizon. Conversely, the `angle' operator determines the angle
  3513. that corresponds to a given vector.
  3514. \ddanger Logarithms and exponentials are computed with respect to an
  3515. unusual base, designed to enhance the accuracy of calculations
  3516. involving fixed-radix numbers in \MF's range. The values ^{mlog}$\,x=256\ln x$
  3517. and ^{mexp}$\,x=e^{x/256}$ produce reasonably good results when
  3518. $x\mathbin{\ast\ast}y$ is computed by the formula mexp$(y\ast\mathop{\rm
  3519. mlog} x)$.
  3520. \begindemo
  3521. \demohead
  3522. mlog 2&177.44568\cr
  3523. mexp mlog 2&2\cr
  3524. mexp 8 mlog 2&256\cr
  3525. mexp 256&2.71828\cr
  3526. mlog 2.71828&255.99954\cr
  3527. mlog 2.71829&256.00098\cr
  3528. %mlog mexp 2&1.99998\cr
  3529. 15 mlog 2&2661.68518\cr
  3530. mexp 2661.68518&32767.99998\cr
  3531. mexp 2661.68519&32767.99998\werror\cr
  3532. mexp-2661.68519&0.00003\cr
  3533. \enddemo
  3534. \danger \MF\ also generates two flavors of random numbers. It is very
  3535. unlikely that you will get the particular values shown in the following
  3536. examples, when you do the experiment yourself, because the results come
  3537. out different each time the computer is asked for a new random number
  3538. (unless you have specified a ``seed value'' as explained in Chapter~21).
  3539. \begindemo
  3540. \it\kern-2pt You type&\it\kern-1pt And the result might be\cr
  3541. \noalign{\vskip2pt}
  3542. uniformdeviate 100&47.4241\cr
  3543. uniformdeviate 100&97.28148\cr
  3544. uniformdeviate -100&-36.16279\cr
  3545. (normaldeviate,normaldeviate)&(0.46236,-1.87648)\cr
  3546. \enddemo
  3547. The value of `uniformdeviate\thinspace100' is a random number between 0 and~100;
  3548. ^^{uniformdeviate} ^^{normaldeviate}
  3549. the value of `normaldeviate' is a normally distributed random number whose
  3550. mean value is zero and whose standard deviation is unity. Chapter~21 explains
  3551. what this means and gives several applications.
  3552. \danger Besides all of these operations on numbers, \MF\ has a rich collection
  3553. ^^{scaled} ^^{xscaled} ^^{yscaled} ^^{dir}
  3554. of operations on pairs, some of which are indicated in the following examples:
  3555. \begindemo
  3556. \demohead
  3557. right&(1,0)\cr
  3558. (1,2)+(3,4)&(4,6)\cr
  3559. 1/3(3,10)&(1,3.33333)\cr
  3560. z2-z1&(-x1+x2,-y1+y2)\cr
  3561. .2[z1,z2]&(0.8x1+0.2x2,0.8y1+0.2y2)\cr
  3562. 3z&(3x,3y)\cr
  3563. z scaled 3&(3x,3y)\cr
  3564. z xscaled 2 yscaled 1/2&(2x,0.5y)\cr
  3565. z shifted (2,3)&(x+2,y+3)\cr
  3566. z shifted 3right&(x+3,y)\cr
  3567. z slanted 1/6&(x+0.16667y,y)\cr
  3568. z rotated 90&(-y,x)\cr
  3569. z rotated 30&(-0.5y+0.86603x,0.86603y+0.5x)\cr
  3570. xpart(z rotated 30)&-0.5y+0.86603x\cr
  3571. ypart(z rotated 30)&0.86603y+0.5x\cr
  3572. (1,2)*(3,4)&(3,4)\werror\cr
  3573. (1,2)zscaled(3,4)&(-5,10)\cr
  3574. (a,b)zscaled(3,4)&(3a-4b,4a+3b)\cr
  3575. (a,b)zscaled dir 30&(0.86603a-0.5b,0.5a+0.86603b)\cr
  3576. (1,2)dotprod(3,4)&11\cr
  3577. (a,b)dotprod(3,4)&3a+4b\cr
  3578. dir 21 dotprod dir 51&0.86603\cr
  3579. (3,4)dotprod((30,40)rotated 90)&0\cr
  3580. \enddemo
  3581. (Recall that plain \MF\ converts `|z$|' into `|(x$,y$)|' when |$| is any
  3582. \<suffix>.) \  ^^{xpart} ^^{ypart} ^^{shifted} ^^"right" ^^{slanted}
  3583. ^^{zscaled} ^^{dotprod} ^^"z" The operations exhibited here are almost
  3584. all self-evident. When a point or vector is ^{rotated}, it is moved
  3585. counterclockwise about $(0,0)$ through a given number
  3586. of degrees. \MF\ computes the rotated coordinates by using
  3587. ^{sines} and ^{cosines} in an appropriate way; you don't have to
  3588. remember the formulas! Although you cannot use `|*|' to multiply
  3589. a pair by a pair, you can use `^{zscaled}' to get the effect of
  3590. ^{complex number} multiplication: Since $(1+2i)$ times $(3+4i)$ is
  3591. $-5+10i$, we have $(1,2)\mathbin{\rm zscaled}(3,4)=(-5,10)$.
  3592. There's also a ^{multiplication} that converts pairs into numbers:
  3593. $(a,b)\mathbin{\rm dotprod}(c,d\mkern1mu)=ac+bd$. This is the
  3594. ``^{dot product},'' often written `$(a,b)\cdot(c,d\mkern1mu)$' in
  3595. mathematics texts; it turns out to be equal to $a\pyth+b$ times
  3596. $c\pyth+d$ times the cosine of the angle between the vectors $(a,b)$ and
  3597. $(c,d)$. Since cosd$\,90^\circ=0$, two vectors are
  3598. ^{perpendicular} to each other if and only if their dot ^{product} is zero.
  3599. \danger There are operations on strings, paths, and the other types too;
  3600. we shall study such things carefully in later chapters. For now, it will
  3601. suffice to give a few examples, keeping in mind that the file |expr.mf|
  3602. defines |s| with any subscript to be a ^{string}, while |p| with any subscript
  3603. is a path. Furthermore $s_1$ has been given the value |"abra"|, while
  3604. $p_1$ is `$(0,0)\to(3,3)$' and $p_2$ is `$(0,0)\to(3,3)\to"cycle"$'.
  3605. \begindemo
  3606. \demohead
  3607. s2&unknown string s2\cr
  3608. s1\&"cad"\&s1&"abracadabra"\cr
  3609. length s1&4\cr
  3610. length p1&1\cr
  3611. length p2&2\cr
  3612. cycle p1&false\cr
  3613. cycle p2&true\cr
  3614. substring (0,2) of s1&"ab"\cr
  3615. substring (2,infinity) of s1&"ra"\cr
  3616. point 0 of p1&(0,0)\cr
  3617. point 1 of p1&(3,3)\cr
  3618. point .5 of p1&(1.5,1.5)\cr
  3619. point infinity of p1&(3,3)\cr
  3620. point .5 of p2&(3,0)\cr
  3621. point 1.5 of p2&(0,3)\cr
  3622. point 2 of p2&(0,0)\cr
  3623. point 2+epsilon of p2&(0.00009,-0.00009)\cr
  3624. point -epsilon of p2&(-0.00009,0.00009)\cr
  3625. point -1 of p1&(0,0)\cr
  3626. direction 0 of p1&(1,1)\cr
  3627. direction 0 of p2&(4,-4)\cr
  3628. direction 1 of p2&(-4,4)\cr
  3629. \enddemo
  3630. ^^{point} ^^{direction}
  3631. The ^{length} of a path is the number of `$\to$' steps that it contains;
  3632. the construction `^|cycle|~\<path>' can be used to tell whether or not a
  3633. particular path is cyclic.  If you say just `|p1|' you get to see
  3634. path~$p_1$ with its ^{control points}:
  3635. \begintt
  3636. (0,0)..controls (1,1) and (2,2)
  3637.  ..(3,3)
  3638. \endtt
  3639. Similarly, `|p2|' is
  3640. \begintt
  3641. (0,0)..controls (2,-2) and (5,1)
  3642.  ..(3,3)..controls (1,5) and (-2,2)
  3643.  ..cycle
  3644. \endtt
  3645. and `|subpath| |(0,1)| |of| |p2|' is analogous to a ^{substring}:^^{subpath}
  3646. \begintt
  3647. (0,0)..controls (2,-2) and (5,1)
  3648.  ..(3,3)
  3649. \endtt
  3650. The expression `point $t$ of $p_2$' gives the position of a point that
  3651. moves along path~$p_2$, starting with the initial point $(0,0)$ at $t=0$,
  3652. then reaching point $(3,3)$ at $t=1$, etc.;
  3653.  the value at $t=1/2$ is the
  3654. third-order midpoint obtained by the construction of Chapter~3, using
  3655. intermediate control points $(2,-2)$ and $(5,1)$.
  3656. Since $p_2$ is a cyclic path of length~2,
  3657. point $(t+2)$ of~$p_2$ is the same as point~$t$. Path $p_1$ is not
  3658. cyclic, so its points turn out to be identical to point~0 when $t<0$,
  3659. and identical to point~1 when $t>1$. The expression `direction~$t$
  3660. of~\<path>' is similar to `point~$t$ of \<path>'; it yields a vector for the
  3661. direction of travel at time~$t$.
  3662. {\ninepoint
  3663. \medbreak
  3664. \parshape 14 3pc 12pc 3pc 12pc
  3665. 0pc 15pc 0pc 15pc 0pc 15pc 0pc 15pc 0pc 15pc 0pc 15pc
  3666. 0pc 15pc 0pc 15pc 0pc 15pc 0pc 15pc 0pc 15pc 0pc 29pc
  3667. \noindent
  3668. \hbox to0pt{\hskip-3pc\dbend\hfill}
  3669. \rightfig 8a (12pc x 12pc) ^16pt
  3670. Paths are not necessarily traversed at constant speed. For example,
  3671. the diagram at the right shows point $t$ of~$p_2$ at twenty equally
  3672. spaced values of~$t$.
  3673. \MF\ moves faster in this case at time~1.0 than at time 1.2; but the
  3674. points are spread out fairly well, so the concept of fractional
  3675. time can be useful. The diagram shows, incidentally, that
  3676. path~$p_2$ is not an especially good approximation to
  3677. a circle; there is no left-right symmetry, although the curve from point~1
  3678. to point~2 is a mirror image of the curve from point~0 to point~1.
  3679. This lack of circularity is not surprising, since
  3680. $p_2$ was defined by simply specifying two points, $(0,0)$ and~$(3,3)$;
  3681. at least four points are needed to get a path that is convincingly round.
  3682. \parfillskip=0pt\par}
  3683. \ddanger The ^{ampersand} operation `|&|' can be used to splice paths
  3684. together in much the same way as it concatenates strings. For example, if
  3685. you type `|p2|~|&|~|p1|', you get the path of length~3 that is obtained by
  3686. breaking the cyclic connection at the end of path~$p_2$ and attaching~$p_1$:
  3687. \begintt
  3688. (0,0)..controls (2,-2) and (5,1)
  3689.  ..(3,3)..controls (1,5) and (-2,2)
  3690.  ..(0,0)..controls (1,1) and (2,2)
  3691.  ..(3,3)
  3692. \endtt
  3693. Concatenated paths must have identical endpoints at the junction.
  3694. \ddanger You can even ``slow down the clock'' by concatenating subpaths
  3695. that have non-integer time specifications. For example, here's what you
  3696. get if you ask for `|subpath|~|(0,.5)| |of|~|p2| |&| |subpath| |(.5,2)|
  3697. |of|~|p2| |&| |cycle|':
  3698. \begintt
  3699. (0,0)..controls (1,-1) and (2.25,-0.75)
  3700.  ..(3,0)..controls (3.75,0.75) and (4,2)
  3701.  ..(3,3)..controls (1,5) and (-2,2)
  3702.  ..cycle
  3703. \endtt
  3704. When $t$ goes from 0 to 1 in subpath $(0,.5)$ of $p_2$, you get the same
  3705. points as when $t$ goes from 0 to~.5 in $p_2$; when $t$ goes from 0 to 1
  3706. in subpath $(.5,2)$ of~$p_2$, you get the same points as when $t$ goes
  3707. from .5 to~1 in~$p_2$; but when $t$ goes from 1 to~2 in subpath
  3708. $(.5,2)$ of~$p_2$, it's the same as the segment from 1 to~2 in~$p_2$.
  3709. \danger Let's conclude this chapter by discussing the exact rules of
  3710. ^{precedence} by which \MF\ decides what operations to do first. The
  3711. informal notion of ``magnetism'' gives a good intuitive picture of what
  3712. happens, but syntax rules express things unambiguously in borderline cases.
  3713. \danger The four levels of precedence correspond to four kinds of formulas,
  3714. which are called primaries, secondaries, tertiaries, and
  3715. expressions. A {\sl^{primary}\/} is a~variable or a constant or a
  3716. tightly bound unit like `|2x|' or `|sqrt 2|'; a {\sl^{secondary}\/}
  3717. is~a primary or a sequence of primaries connected by multiplicative
  3718. operators like `|*|' or `|scaled|'; a {\sl^{tertiary}\/} is a secondary
  3719. or a sequence of secondaries connected by additive operators like `|+|'
  3720. or `|++|'; an {\sl^{expression}\/} is a tertiary or a sequence of
  3721. tertiaries connected by external operators like `|<|' or `|..|'. For example,
  3722. the expression
  3723. \begintt
  3724. a+b/2>3c*sqrt4d
  3725. \endtt
  3726. is composed of the primaries `|a|', `|b|', `|2|', `|3c|', and `|sqrt4d|';
  3727. the last of these is a primary containing `|4d|' as a primary within itself.
  3728. The subformulas `|a|', `|b/2|', and `|3c*sqrt4d|' are secondaries; the
  3729. subformulas `|a+b/2|' and `|3c*sqrt4d|' are tertiaries.
  3730. \danger If an expression is enclosed in parentheses, it becomes a primary
  3731. that can be used to build up larger secondaries, tertiaries, etc.
  3732. \danger The full syntax for expressions is quite long, but most of it
  3733. falls into a simple pattern. If $\alpha$, $\beta$, and~$\gamma$ are
  3734. any ``types''---numeric, boolean, string, etc.---then \<$\alpha$ variable>
  3735. refers to a variable of type~$\alpha$, \<$\beta$ primary> refers to a
  3736. primary of type~$\beta$, and so on. Almost all of the syntax rules fit into
  3737. the following general framework:
  3738. \beginsyntax
  3739. <$\alpha$ primary>\is<$\alpha$ variable>\alt<$\alpha$ constant>%
  3740.  \alt[(]<$\alpha$ expression>[)]
  3741.  \alt<operator that takes type $\beta$ to type $\alpha$><$\beta$ primary>
  3742. <$\alpha$ secondary>\is\<$\alpha$ primary>
  3743.  \alt<$\beta$ secondary><multiplicative op taking types $\beta$ and %
  3744.  $\gamma$ to $\alpha$><$\gamma$ primary>\kern-1pt
  3745. <$\alpha$ tertiary>\is\<$\alpha$ secondary>
  3746.  \alt<$\beta$ tertiary><additive op taking types $\beta$ and %
  3747.  $\gamma$ to $\alpha$><$\gamma$ secondary>
  3748. <$\alpha$ expression>\is<$\alpha$ tertiary>
  3749.  \alt<$\beta$ expression><external op taking types $\beta$ and %
  3750.  $\gamma$ to $\alpha$><$\gamma$ tertiary>
  3751. \endsyntax
  3752. These schematic rules don't give the whole story, but they do give the
  3753. general structure of the plot.
  3754. \danger Chapter 25 spells out all of the syntax rules for all types of
  3755. expressions. We shall consider only a portion of the numeric and pair
  3756. cases here, in order to have a foretaste of the complete menu:
  3757. \def\\#1{\thinspace{\tt#1}\thinspace}
  3758. \beginsyntax
  3759. <numeric primary>\is<numeric atom>
  3760.  \alt<numeric atom>[\char'133]<numeric expression>%
  3761.    [,]<numeric expression>[\char'135]
  3762.  \alt[length]<string primary>
  3763.  \alt[length]<path primary>
  3764.  \alt[length]<pair primary>
  3765.  \alt[angle]<pair primary>
  3766.  \alt[xpart]<pair primary>
  3767.  \alt[ypart]<pair primary>
  3768.  \alt<numeric operator><numeric primary>
  3769. <numeric atom>\is<numeric variable>
  3770.  \alt<numeric token primary>
  3771.  \alt[(]<numeric expression>[)]
  3772.  \alt[normaldeviate]
  3773. <numeric token primary>\is<numeric token>[/]<numeric token>
  3774.  \alt<numeric token not followed by %
  3775.   `{\tt/}$\thinspace\langle$numeric token$\rangle$'\thinspace>
  3776. <numeric operator>\is[sqrt]\alt[sind]\alt[cosd]\alt[mlog]\alt[mexp]
  3777.  \alt[floor]\alt[uniformdeviate]\alt<scalar multiplication operator>
  3778. <scalar multiplication operator>\is<plus or minus>
  3779.  \alt<numeric token primary not followed by %
  3780.   {\tt+} or {\tt-} or a numeric token>
  3781. <numeric secondary>\is<numeric primary>
  3782.  \alt<numeric secondary><times or over><numeric primary>
  3783. <times or over>\is[*]\alt[/]
  3784. <numeric tertiary>\is<numeric secondary>
  3785.  \alt<numeric tertiary><plus or minus><numeric secondary>
  3786.  \alt<numeric tertiary><Pythagorean plus or minus><numeric secondary>
  3787. <plus or minus>\is[+]\alt[-]
  3788. <Pythagorean plus or minus>\is[++]\alt[+-+]
  3789. <numeric expression>\is<numeric tertiary>
  3790. \endsyntax
  3791. All of the finicky details about ^{fractions} and such things are made
  3792. explicit by this syntax. For example, we can use the rules to deduce that
  3793. `|sind-1/3x-2|' is interpreted as `|(sind(-(1/3x)))-2|'; notice that the
  3794. first minus sign in this formula is considered to be a ``scalar multiplication
  3795. operator,'' which comes in at the primary level, while the second one denotes
  3796. subtraction and enters in the construction of \<numeric tertiary>. The
  3797. ^{mediation} or ``^{of-the-way}'' operation `$t[a,b]$' is handled at the
  3798. primary level.
  3799. \danger Several operations that haven't been discussed yet do not appear
  3800. in the syntax above, but they fit into the same general pattern; for example,
  3801. we will see later that `^|ASCII|\<string primary>' and `^|xxpart|\<transform
  3802. primary>' are additional cases of the syntax for \<numeric primary>.
  3803. On the other hand, several operations that we have discussed in this chapter
  3804. do not appear in the syntax, because they are not primitives of \MF\ itself;
  3805. they are defined in the plain \MF\ base (Appendix B\null). For example,
  3806. `^|ceiling|' is analogous to `|floor|', and `^|**|' is analogous to~`|*|'.
  3807. Chapter~20 explains how \MF\ allows extensions to its built-in syntax,
  3808. so that additional operations can be added at will.
  3809. \dangerexercise How does \MF\ interpret `|2|~|2|'\thinspace?
  3810. \ (There's a space between the 2's.)
  3811. \answer It's impossible to make an expression from `\<numeric token>
  3812. \<numeric token>', because the rule for \<scalar multiplication operator>
  3813. specifically prohibits this. \MF\ will recognize the first `|2|' as
  3814. a \<numeric primary>, which is ultimately regarded as a \<numeric
  3815. expression>; the other `|2|' will probably be an extra token that is
  3816. flushed away after an error message has been given.
  3817. \ddangerexercise According to |expr.mf|, the value of `|1/2/3/4|' is
  3818. |0.66667|; the value of `|a/2/3/4|' is |0.375a|. Explain why.
  3819. \answer If a numeric token is followed by `|/|\<numeric token>' but
  3820. not preceded by `\<numeric token>|/|', the syntax allows it to become part of
  3821. an expression only by using the first case of \<numeric token
  3822. primary>. Therefore `|1/2/3/4|' must be treated as `|(1/2)/(3/4)|',
  3823. and `|a/2/3/4|' must be treated as `|a/(2/3)/4|'.
  3824. \danger The rules of \<pair expression> are similar to those for
  3825. \<numeric expression>, so it's convenient to learn them both at the same time.
  3826. \beginsyntax
  3827. <pair primary>\is<pair variable>
  3828.  \alt[(]<numeric expression>[,]<numeric expression>[)]
  3829.  \alt[(]<pair expression>[)]
  3830.  \alt<numeric atom>[\char'133]<pair expression>%
  3831.    [,]<pair expression>[\char'135]
  3832.  \alt[point]<numeric expression>[of]<path primary>
  3833.  \alt<scalar multiplication operator><pair primary>
  3834. <pair secondary>\is<pair primary>
  3835.  \alt<pair secondary><times or over><numeric primary>
  3836.  \alt<numeric secondary>[*]<pair primary>
  3837.  \alt<pair secondary><transformer>
  3838. <transformer>\is[rotated]<numeric primary>
  3839.  \alt[scaled]<numeric primary>
  3840.  \alt[shifted]<pair primary>
  3841.  \alt[slanted]<numeric primary>
  3842.  \alt[transformed]<transform primary>
  3843.  \alt[xscaled]<numeric primary>
  3844.  \alt[yscaled]<numeric primary>
  3845.  \alt[zscaled]<pair primary>
  3846. <pair tertiary>\is<pair secondary>
  3847.  \alt<pair tertiary><plus or minus><pair secondary>
  3848. <pair expression>\is<pair tertiary>
  3849. \endsyntax
  3850. \dangerexercise Try to guess the syntax rules for \<string primary>,
  3851. \<string secondary>, $\langle$string tertiary$\rangle$, and \<string
  3852. expression>, based solely on the examples that have appeared in this
  3853. chapter.  \ [{\sl Hint:}\/ The `|&|' operation has the same precedence
  3854. as `|..|'.]
  3855. \answer \<string primary>\is\<string variable>\parbreak
  3856. \qquad\alt\<string token>\parbreak
  3857. \def\\#1{\thinspace{\tt#1}\thinspace}%
  3858. \qquad\alt\\(\<string expression>\\)\parbreak
  3859. \qquad\alt\\{substring}\<pair expression>\\{of}\<string primary>\parbreak
  3860. \<string secondary>\is\<string primary>\parbreak
  3861. \<string tertiary>\is\<string secondary>\parbreak
  3862. \<string expression>\is\<string tertiary>\parbreak
  3863. \qquad\alt\<string expression>\\{\char`\&}\<string tertiary>\par
  3864. \medskip\noindent
  3865. (The full syntax in Chapter~25 includes several more varieties of
  3866. \<string primary> that haven't been hinted at yet.)
  3867. \endchapter
  3868. A maiden was sitting there who was lovely as any picture,
  3869. % ein bildsch\"one Jungfrau,
  3870. nay, so beautiful that no words can express it.
  3871. % nein so sch\"on, dass es nicht so sagen ist.
  3872. \author JAKOB and WILHELM ^{GRIMM}, {\sl Fairy Tales\/} (1815)
  3873.  % Kinder- und hausm\"archen, vol 2, #166; translated by Margaret Hunt
  3874.  % in Strong Hans (Der starke Hans), about 4/5 of the way through
  3875.  % This quote and the next were found by online computer search at SAIL
  3876.  % in the files GRIMM[lib,doc] and WUTHER[lib,doc]
  3877. \bigskip
  3878. He looked astonished at the expression.
  3879.  % my face assumed... middle of chapter 13
  3880. \author EMILY ^{BRONT\"E},  {\sl Wuthering Heights\/} (1847)
  3881. \eject
  3882. \beginchapter Chapter 9. Equations
  3883. The variables in a \MF\ program receive their values by appearing in
  3884. {\sl^{equations}}, which express relationships that the programmer
  3885. wants to achieve. We've seen in the previous chapter that algebraic
  3886. expressions provide a rich language for dealing with both numerical
  3887. and graphical relationships. Thus it is possible to express a great
  3888. variety of design objectives in precise form by stating that certain
  3889. algebraic expressions should be equal to each other.
  3890. The most important things a \MF\ programmer needs to know about
  3891. equations are (1)~how to translate intuitive design concepts into
  3892. formal equations, and (2)~how to translate formal equations into
  3893. intuitive design concepts. In other words, it's important to be able
  3894. to {\sl write\/} equations, and it's also important to be able to
  3895. {\sl read\/} equations that you or somebody else has written. This
  3896. is not nearly as difficult as it might seem at first. The best way
  3897. to learn~(1) is to get a lot of practice with~(2) and to generalize
  3898. from specific examples. Therefore we shall begin this chapter by
  3899. translating a lot of equations into ``simple English.''
  3900. \newdimen\longesteq
  3901. \setbox0=\hbox{\indent$z_{12}-z_{11}=z_{14}-z_{13}$\quad}
  3902. \longesteq=\wd0
  3903. \def\\#1\\{\medbreak\noindent
  3904.   \hbox to\longesteq{\indent#1\hfil}%
  3905.   \hangindent\longesteq\ignorespaces}
  3906. \medskip
  3907. \noindent\hbox to\longesteq{\indent\kern-1pt\sl Equation\hfil}%
  3908. \kern-1pt{\sl Translation}\smallskip
  3909. \\$a=3.14$\\
  3910. The value of $a$ should be 3.14.
  3911. \\$3.14=a$\\
  3912. The number 3.14 should be the value of $a$. \ (This means the same
  3913. thing as `$a=3.14$'; the left and right sides of an equation can be
  3914. interchanged without affecting the meaning of that equation in any way.)
  3915. \\$"mode"="smoke"$\\
  3916. The value of ^"mode" should be equal to the value of ^"smoke". \
  3917. (Plain \MF\ assigns a special meaning to `"smoke"', so that if
  3918. ^@mode\_setup@ is invoked when $"mode"="smoke"$ the computer will
  3919. prepare ``smoke proofs'' as explained in Chapter~5 and Appendix~H.)
  3920. \\$y_3=0$\\
  3921. The $y$ coordinate of point 3 should be zero; i.e., point~3 should
  3922. be at the ^{baseline}. \ (Point~3 is also known as~$z_3$, which is an
  3923. abbreviation for the pair of coordinates $(x_3,y_3)$, if you are
  3924. using the conventions of plain \MF\!.)
  3925. \\$x_9=0$\\
  3926. The $x$ coordinate of point 9 should be zero; i.e., point~9 should
  3927. be at the left edge of the type box that encloses the current character.
  3928. \\$x_{1l}="curve\_sidebar"$\\
  3929. The $x$ coordinate of point $1l$ should be equal to the value of the
  3930. variable called "curve\_sidebar". This puts $z_{1l}$ a certain
  3931. distance from the left edge~of the type.
  3932. \\$x_1=x_2$\\
  3933. Points 1 and 2 should have the same $x$ coordinate; i.e., they should
  3934. have the same horizontal position, so that one will lie directly
  3935. above or below the other.
  3936. \\$y_4=y_5+1$\\
  3937. Point 4 should be one pixel higher than point~5.
  3938. \ (However, points 4 and~5 might be far apart; this equation
  3939. says nothing about the relation between $x_4$ and~$x_5$.)
  3940. \\$y_6=y_7+2"mm"$\\
  3941. Point 6 should be two millimeters higher than point~7. \ (Plain \MF's
  3942. ^@mode\_setup@ routine sets variable ^"mm" to the number of pixels in a
  3943. millimeter, based on the resolution determined by "mode" and "mag".)
  3944. \\$x_4=w-.01"in"$\\
  3945. Point 4 should be one-hundredth of an inch inside the right edge of
  3946. the type. \ (Plain \MF's ^@beginchar@ routine sets variable~^"w" equal
  3947. to the width of whatever character is currently being drawn, expressed in
  3948. pixels.)
  3949. \\$y_4=.5h$\\
  3950. Point 4 should be halfway between the baseline and the top of the type.
  3951. \ (Plain \MF's @beginchar@ sets ^"h" to the height of the
  3952. current character, in pixels.)
  3953. \\$y_6=-d$\\
  3954. Point 6 should be below the baseline, at the bottom edge of the type.
  3955. \ (Each character has a ``^{bounding box}'' that runs from $(0,h)$
  3956. at the upper left and $(w,h)$ at the upper right to $(0,-d)$ and~$(w,-d)$
  3957. at the lower left and lower right; variable~^"d" represents the depth of
  3958. the type. The values of $w$, $h$, and~$d$ might change from character to
  3959. character, since the individual pieces of type in a computer-produced
  3960. font need not have the same size.)
  3961. \\$y_8=.5[h,-d]$\\
  3962. Point 8 should be halfway between the top and bottom edges of the type.
  3963. \\$w-x_5={2\over3}x_6$\\
  3964. The distance from point 5 to the right edge of the type should be
  3965. two-thirds of the distance from point~6 to the left edge of the~type.
  3966. \ (Since $w$ is at the right edge, $w-x_5$ is the ^{distance} from
  3967. point~5 to the right edge.)
  3968. \\$z_0=(0,0)$\\
  3969. Point 0 should be at the ^{reference point} of the current character,
  3970. i.e., it should be on the baseline at the left edge of the type.
  3971. This equation is an abbreviation for two equations, `$x_0=0$' and `$y_0=0$',
  3972. because an equation between pairs of coordinates implies that the $x$
  3973. and~$y$ coordinates must both agree. \ (Incidentally, plain \MF\
  3974. defines a variable called ^"origin" whose value is $(0,0)$; hence
  3975. this equation could also have been written `$z_0="origin"$'.)
  3976. \\$z_9=(w,h)$\\
  3977. Point 9 should be at the upper right corner of the current character's
  3978. bounding box.
  3979. \\$"top"\,z_8=(.5w,h)$\\
  3980. If the pen that has currently been ``picked up'' is placed at point~8,
  3981. its top edge should be at the top edge of the type. Furthermore,
  3982. $x_8$~should be $.5w$; i.e., point~8 should be centered between the
  3983. left and right edges of the type. \ (Chapter~4 contains further
  3984. examples of `^"top"', as well as the corresponding operations
  3985. `"bot"', `"lft"', and `"rt"'.)
  3986. \\$z_4={3\over7}[z_5,z_6]$\\
  3987. Point 4 should be three-sevenths of the way from point~5 to  point~6.
  3988. \\$z_{12}-z_{11}=z_{14}-z_{13}$\\
  3989. The ^{vector} that moves from point 11 to point~12 should be the same
  3990. as the vector that moves from point~13 to point~14. In other words,
  3991. point~12 should have the same direction and distance from point~11
  3992. as point~14 has from point~13.
  3993. \\\smash{\vtop{\hbox{$z_3-z_2=$}
  3994.   \hbox{\quad$(z_4\!-\!z_2)$\thinspace rotated\thinspace 15}}}\\
  3995. Points 3 and 4 should be at the same distance from point~2, but
  3996. the direction to point~3 should be 15~degrees counterclockwise from
  3997. the direction to point~4.
  3998. \exercise Translate the following equations into ``simple English'':
  3999. \ (a)~$x_7-9=x_1$; \ (b)~$z_7=(x_4,.5[y_4,y_5])$; \
  4000. (c)~$"lft"\,z_{21}="rt"\,z_{20}+1$.
  4001. \answer (a)~Point 1 should lie nine pixels to the left of point~7,
  4002. considering horizontal positions only; no information is given about the
  4003. vertical positions $y_1$ or $y_7$. \ (b)~Point~7 should sit directly
  4004. above or below point~4, and its distance up from the baseline should be
  4005. halfway between that of points 4 and~5. \ (c)~The left edge of the
  4006. currently-picked-up pen, when that pen is centered at point~21, should be
  4007. one pixel to the right of its right edge when at point~20. \ (Thus there
  4008. should be one clear pixel of white space between the images of the
  4009. pen at points 20 and~21.)
  4010. \exercise Now see if your knowledge of equation reading gives you the
  4011. ability to write equations that correspond to the following objectives:
  4012. \ (a)~Point~13 should be just as far below the baseline as point~11 is
  4013. above the baseline. \ (b)~Point~10 should be one millimeter to the right
  4014. of, and one pixel below, point~12. \ (c)~Point~43 should be one-third of
  4015. the way from the top left corner of the type to the bottom right corner
  4016. of the type.
  4017. \answer (a) $y_{13}=-y_{11}$ (or $-y_{13}=y_{11}$, or $y_{13}+y_{11}=0$).
  4018. \ (b)~$z_{10}=z_{12}+("mm",-1)$. \ (c)~$z_{43}={1\over3}[(0,h),(w,-d)]$.
  4019. Let's return now to the six example points $(z_1,z_2,z_3,z_4,z_5,z_6)$
  4020. that were used so often in Chapters 2 and~3. Changing the notation
  4021. slightly, we might say that the points are
  4022. \begindisplay
  4023. $(x_1,y_1)=(0,h)$;&$(x_2,y_2)=(.5w,h)$;&$(x_3,y_3)=(w,h)$;\cr
  4024. $(x_4,y_4)=(0,0)$;&$(x_5,y_5)=(.5w,0)$;&$(x_6,y_6)=(w,0)$.\cr
  4025. \enddisplay
  4026. There are many ways to specify these points by writing a series of
  4027. equations. For example, the six equations just given would do fine;
  4028. or the short names $z_1$ through~$z_6$ could be used instead of the
  4029. long names $(x_1,y_1)$ through~$(x_6,y_6)$. But there are several
  4030. other ways to specify those points and at the same time to ``explain''
  4031. the relations they have to each other. One way is to define the
  4032. $x$ and~$y$ coordinates separately:
  4033. \begindisplay
  4034. $x_1=x_4=0;\qquad x_2=x_5=.5w;\qquad x_3=x_6=w;$\cr
  4035. $y_1=y_2=y_3=h;\qquad y_4=y_5=y_6=0$.\cr
  4036. \enddisplay
  4037. \MF\ allows you to state several equations at once, by using more than
  4038. ^^{=} one equality sign; for example, `$y_1=y_2=y_3=h$' stands for three
  4039. equations, `$y_1=y_2$', `$y_2=y_3$', and `$y_3=h$'.
  4040. In order to define the coordinates of six points, it's necessary to
  4041. write twelve equations, because each equation contributes to the
  4042. definition of one value, and because six points have twelve coordinates
  4043. in all. However, an equation between pairs of coordinates counts as
  4044. two equations between single numbers; that's why we were able to get by
  4045. with only six `$=$'~signs in the first set of equations, while twelve
  4046. were used in the second.
  4047. Let's look at yet another way to specify those six points, by giving
  4048. equations for their positions relative to each other:
  4049. \begindisplay
  4050. $z_1-z_4=z_2-z_5=z_3-z_6$\cr
  4051. $z_2-z_1=z_3-z_2=z_5-z_4=z_6-z_5$\cr
  4052. $z_4="origin"$; \ $z_3=(w,h)$.\cr
  4053. \enddisplay
  4054. ^^"origin" First we say that the vectors from $z_4$ to~$z_1$,
  4055. from $z_5$ to~$z_2$, and from $z_6$ to~$z_3$, are equal to each other;
  4056. then we say the same thing for the vectors from $z_1$ to~$z_2$,
  4057. $z_2$ to~$z_3$, $z_4$ to~$z_5$, and $z_5$ to~$z_6$. Finally the
  4058. corner points $z_4$ and $z_3$ are given explicitly. That's a total
  4059. of seven equations between pairs of coordinates, so it should be
  4060. more than enough to define the six points of interest.
  4061. However, it turns out that those seven equations are not enough!
  4062. For example, the six points
  4063. \begindisplay
  4064. $z_1=z_4=(0,0)$; \ $z_2=z_5=(.5w,.5h)$; \ $z_3=z_6=(w,h)$
  4065. \enddisplay
  4066. also satisfy the same equations. A closer look explains why:
  4067. The two formulas
  4068. \begindisplay
  4069. $z_1-z_4=z_2-z_5$\qquad and\qquad $z_2-z_1=z_5-z_4$
  4070. \enddisplay
  4071. actually say exactly the same thing. \ (Add $z_5-z_1$ to both sides
  4072. of the first equation and you get `$z_5-z_4=z_2-z_1$'.) \ Similarly,
  4073. $z_2-z_5=z_3-z_6$ is the same as $z_3-z_2=z_6-z_5$. Two of the
  4074. seven equations give no new information, so we really have specified
  4075. only five equations; that isn't enough. An additional relation
  4076. such as `$z_1=(0,h)$' is needed to make the solution unique.
  4077. \dangerexercise (For mathematicians.) \ Find a solution to the seven
  4078. equations such that $z_1=z_2$. Also find another solution in which
  4079. $z_1=z_6$.
  4080. \answer (a) $z_1=z_2=z_3=(w,h)$; $z_4=z_5=z_6=(0,0)$.
  4081. \ (b)~$z_1=z_6=(.5w,.5h)$; $z_2=(.75w,.75h)$; $z_3=(w,h)$;
  4082. $z_4=(0,0)$; $z_5=(.25w,.25h)$.
  4083. At the beginning of a \MF\ program, variables have no values,
  4084. except that plain \MF\ has assigned special values to variables
  4085. like "smoke" and "origin". Furthermore, when you begin a new
  4086. character with @beginchar@, any previous values that may have been
  4087. assigned to $x$ or $y$ variables are obliterated and forgotten.
  4088. Values are gradually established as the computer reads equations and
  4089. tries to solve them, together with any other equations that have already
  4090. appeared in the program.
  4091. It takes ten equations to define the values of ten variables.
  4092. If you have given only nine equations it may turn out that none of
  4093. the ten variables has yet been determined; for example, the
  4094. nine equations
  4095. \begindisplay
  4096. $g_0=g_1=g_2=g_3=g_4=g_5=g_6=g_7=g_8=g_9$
  4097. \enddisplay
  4098. don't tell us any of the $g$ values. However, the further equation
  4099. \begindisplay
  4100. $g_0+g_1=1$
  4101. \enddisplay
  4102. will cause \MF\ to deduce that all ten of the $g$'s are equal to $1\over2$.
  4103. \MF\ always computes the values of as many variables as possible, based
  4104. on the equations it has seen so far. For example, after the two equations
  4105. \begindisplay
  4106. $a+b+2c=3$;\cr
  4107. $a-b-2c=1$\cr
  4108. \enddisplay
  4109. the machine will know that $a=2$ (because the sum of these two equations is
  4110. `$2a=4$'); but all it will know about $b$ and~$c$ is that $b+2c=1$.
  4111. At any point in a program a variable is said to be either ``^{known}''
  4112. or ``^{unknown},'' depending on whether or not its value can be
  4113. deduced uniquely from the equations that have been stated so far.
  4114. The sample expressions in Chapter~8 indicate that \MF\ can compute a
  4115. variety of things with unknown variables; but sometimes a quantity
  4116. must be known before it can be used. For example, \MF\ can multiply
  4117. an unknown numeric or pair variable by a known numeric value, but it
  4118. cannot multiply two unknowns.
  4119. Equations can be given in any order, except that you might sometimes
  4120. need to put certain equations first in order to make critical
  4121. values known in the others. For example, \MF\ will find the
  4122. solution $(a,b,c)=(2,7,-3)$ to the equations `$a+b+2c=3$;
  4123. $a-b-2c=1$; $b+c=4$' if you give those equations in any other order,
  4124. like `$b+c=4$; $a-b-2c=1$; $a+b+2c=3$'. But if the equations had
  4125. been `$a+b+2c=3$; $a-b-2c=1$; $a\ast(b+c)=8$', you would not have
  4126. been able to give the last one first, because \MF\ would have refused
  4127. to multiply the unknown quantity~$a$ by another unknown quantity $b+c$.
  4128. Here are the main things that \MF\ can do with unknown quantities:
  4129. \begindisplay
  4130. $-\<unknown>$\cr
  4131. $\<unknown>+\<unknown>$\cr
  4132. $\<unknown>-\<unknown>$\cr
  4133. $\<unknown>\ast\<known>$\cr
  4134. $\<known>\ast\<unknown>$\cr
  4135. $\<unknown>/\<known>$\cr
  4136. $\<known>[\<unknown>,\<unknown>]$\cr
  4137. $\<unknown>[\<known>,\<known>]$\cr
  4138. \enddisplay
  4139. Some of the operations of plain \MF\!, defined in Appendix~B\null, also work
  4140. with unknown quantities. For example, it's possible to say
  4141. ^"top"\thinspace\<unknown>, ^"bot"\thinspace\<unknown>,
  4142. ^"lft"\thinspace\<unknown>, ^"rt"\thinspace\<unknown>, and even
  4143. \begindisplay
  4144. @penpos@\<suffix>(\<unknown>,\thinspace\<known>).
  4145. \enddisplay
  4146. \danger A \MF\ program can say `\<unknown>$[a,b\mkern1mu]$' when $a-b$ is
  4147. known, and variable~$a$ can be compared to variable~$b$ in boolean
  4148. expressions ^^{comparison} like `$a<b$' when $a-b$ is known. The quantity
  4149. $a-b$ might be known even when $a$ and~$b$ aren't known by themselves.
  4150. \danger You might wonder how \MF\ is able to keep its knowledge up-to-date,
  4151. based on scraps of  partial information that it receives from miscellaneous
  4152. equations. The best way to understand this is to watch how it happens,
  4153. by asking the computer to show certain calculations that it usually keeps
  4154. to itself. Here's one way to do it: Run \MF\ and say
  4155. \begintt
  4156. \tracingequations:=tracingonline:=1;
  4157. \endtt
  4158. ^^"tracingequations" ^^"tracingonline"
  4159. in response to the opening `|**|'. \ (Be sure to type the backslash `|\|',
  4160. and to use `|:=|' instead of `|=|'. We will see in Chapter~27 that \MF\
  4161. can be asked to ``trace'' many aspects of what it's doing.) \ Now type
  4162. \begintt
  4163. a+b+2c=3;
  4164. \endtt
  4165. the machine will reply by saying
  4166. \begintt
  4167. ## c=-0.5b-0.5a+1.5
  4168. \endtt
  4169. since that is how it has digested your equation. \ (The `|##|' in this
  4170. ^^{hash hash} line identifies diagnostic information that comes from
  4171. "tracingequations".) \ Now type
  4172. \begintt
  4173. a-b-2c=1;
  4174. \endtt
  4175. \MF\ will read this as if you had said `|a-b-2(-0.5b-0.5a+1.5)=1|',
  4176. since it has previously learned how to replace |c| by an expression
  4177. that involves only |a| and~|b|. This new equation can be simplified by
  4178. multiplying out the left-hand side and collecting terms. The result is
  4179. `|2a-3=1|', hence \MF\ will respond with
  4180. \begintt
  4181. ## a=2
  4182. \endtt
  4183. and it will be your turn to type something again. Say
  4184. \begintt
  4185. showdependencies;
  4186. \endtt
  4187. ^^@showdependencies@ \MF's response will be
  4188. \begintt
  4189. c=-0.5b+0.5
  4190. \endtt
  4191. indicating that there is only one variable whose value depends on others,
  4192. and that its equation of dependency is now `$c=-0.5b+0.5$'. \ (The previous
  4193. dependency equation `$c=-0.5b-0.5a+1.5$' has
  4194. been simplified to take account of the newly discovered value, $a=2$.) \
  4195. Finally type
  4196. \begintt
  4197. b+c=4;
  4198. \endtt
  4199. this spurs the computer on to say
  4200. \begintt
  4201. ## b=7
  4202. #### c=-3
  4203. \endtt
  4204. A line that begins with `|##|' states what \MF\ has deduced from
  4205. the equation it has just read; a line that begins with `|####|' states
  4206. ^^{hash hash hash hash} an indirect consequence of that direct result,
  4207. if some previously dependent variable has now become known.
  4208. \danger It's interesting to continue the computer experiment just begun
  4209. by typing the following lines, one at a time, and watching what happens:
  4210. \begintt
  4211. a'+b'+.5c'=3;
  4212. a'-b'-.5c'=1;
  4213. g0=g1=g2=g3=g4;
  4214. showdependencies;
  4215. g0+g1=1;
  4216. z1-z4=z2-z5=z3-z6;
  4217. z2-z1=z3-z2=z5-z4=z6-z5;
  4218. z4=origin;
  4219. z3=(w,h);
  4220. x1=0;
  4221. y6=0;
  4222. w=2h=100;
  4223. \endtt
  4224. Notice that on the sixth line (\thinspace`$z_1-z_4=\cdots\,$'\thinspace)
  4225. \MF\ reports four equations, but on the next line
  4226. (\thinspace`$z_2-z_1=\cdots\,$'\thinspace) it reports only two.  This
  4227. happens because most of that line is redundant, as we have already
  4228. observed.
  4229. \danger This computer session indicates that \MF\ deals with two kinds
  4230. of unknown numeric variables: {\sl^{dependent}\/} variables and
  4231. {\sl^{independent}} ones.
  4232. Every variable is independent at the beginning of its life, but every
  4233. equation causes one of the independent variables to become dependent
  4234. or ^{known}. Each `|##|' line emitted by "tracingequations" shows a
  4235. newly dependent-or-known variable, together with an equivalent expression
  4236. that involves only independent variables. For example, the line
  4237. `|##|~|c=-0.5b-0.5a+1.5|'
  4238. means that variable~$c$ has just become dependent and that it equals
  4239. $-{1\over2}b-{1\over2}a+1.5$, where variables $b$ and~$a$ are independent.
  4240. Similarly, `|##|~|a=2|' means that $a$~has just changed from
  4241. independent to known. When an independent variable~$v$ changes to dependent
  4242. or known, the equivalents of all dependent variables are updated so that
  4243. they no longer depend on~$v$; in this updating process some or all of them
  4244. may change from dependent to known, whereupon a `|####|' line will be printed.
  4245. \ddanger When \MF\ reads a numeric equation it replaces all known variables
  4246. by their numeric values and all dependent variables by their equivalents.
  4247. The resulting equation can be converted into the form
  4248. \begindisplay
  4249. $c_1v_1+\cdots+c_mv_m=\alpha$
  4250. \enddisplay
  4251. where the $c$'s are nonzero constants and the $v$'s are independent variables;
  4252. $\alpha$~is a numeric constant that might be zero. If some $c_k$ is so
  4253. small that it probably would have been zero in a calculation free of
  4254. rounding errors, it is replaced by zero and the corresponding $v_k$ is
  4255. removed from the equation. Now if $m=0$, the equation is considered to be
  4256. either {\sl^{redundant}\/} (if $\alpha$ is zero or extremely small)
  4257. or {\sl^{inconsistent}\/} (otherwise). But if $m>0$, \MF\ chooses an
  4258. independent variable~$v_k$ for which $c_k$ is maximum, and rewrites
  4259. the equation in the form
  4260. \begindisplay
  4261. {\tt\#\#} $v_k=(\alpha-c_1v_1-\cdots-c_{k-1}v_{k-1}-c_{k+1}v_{k+1}-
  4262.  \cdots-c_mv_m)/c_k$.
  4263. \enddisplay
  4264. Variable $v_k$ becomes dependent (if $m>1$) or known (if $m=1$).
  4265. \danger Inconsistent equations are equations that have no solutions.
  4266. For example, if you say `$0=1$', \MF\ will issue an error message
  4267. ^^{off by x}
  4268. saying that the equation is ``off by~1.'' A less blatant inconsistency
  4269. arises if you say, e.g, `$a=b+1$; $b=c+1$; $c=a+1$'; this last equation
  4270. is off by three, for the former equations imply that $c=b-1=a-2$.
  4271. The computer will simply ignore an inconsistent equation when you
  4272. resume processing after such an error.
  4273. \danger Redundant equations are equations that say nothing new.
  4274. For example, `$0=0$' is redundant, and so is `$a=b+c$' if you have
  4275. previously said that $c=a-b$. \MF\ stops with an error message if
  4276. you give it a redundant equation between two numeric expressions,
  4277. because this usually indicates an oversight in the program. However,
  4278. no error is reported when an equation between pairs leads to one or
  4279. two redundant equations between numerics. For example, the equation
  4280. `$z_3=(0,h)$' will not trigger an error message when the program
  4281. has previously established that $x_3=0$ or that $y_3=h$ or both.
  4282. \danger Sometimes you might have to work a little bit to put an equation
  4283. into a form that \MF\ can handle. For example, you can't say
  4284. \begindisplay
  4285. $x/y=2$
  4286. \enddisplay
  4287. when $y$ is independent or dependent, because \MF\ allows ^{division}
  4288. only by known quantities. The alternative
  4289. \begindisplay
  4290. $x=2y$
  4291. \enddisplay
  4292. says the same thing and causes the computer no difficulties;
  4293. furthermore it is a correct equation even when $y=0$.
  4294. \ddanger \MF's ability to remember previous equations is limited to
  4295. ``linear'' dependencies ^^{linear dependencies} as explained above.
  4296. A mathematician might want to introduce the condition $x\ge0$ by giving an
  4297. equation such as `$x=\mathop{\rm abs}x$'; but \MF\ is incapable
  4298. of dealing with such a constraint. Similarly, \MF\ can't cope with
  4299. an equation like `$x=\mathop{\rm floor}x$', which states that
  4300. $x$~is an integer. Systems of equations that involve the ^{absolute
  4301. value} and/or ^{floor} operation can be extremely difficult to solve,
  4302. and \MF\ doesn't pretend to be a mathematical genius.
  4303. \ddanger The rules given earlier explain how an independent variable
  4304. can become dependent or known; conversely, it's possible for a
  4305. dependent variable to become independent again, in unusual circumstances.
  4306. For example, suppose that the equation $a+b+2c=3$ in our example above
  4307. had been followed by the equation $d=b+c+a/4$. Then there would be
  4308. two dependent variables,
  4309. \begintt
  4310. ## c=-0.5b-0.5a+1.5
  4311. ## d=0.5b-0.25a+1.5
  4312. \endtt
  4313. Now suppose that the next statement is `|numeric|~|a|', meaning that the
  4314. old value of variable~$a$ should be discarded. \MF\ can't simply delete
  4315. an independent variable that has things depending on it, so it
  4316. chooses a dependent variable to take $a$'s place; the computer prints out
  4317. \begintt
  4318. ### 0.5a=-0.5b-c+1.5
  4319. \endtt
  4320. ^^{hash hash hash} meaning that $0.5a$ will be replaced by $-c-{1\over2}b
  4321. +{3\over2}$ in all dependencies, before $a$ is discarded. Variable $c$ is
  4322. now independent again; `^@showdependencies@' will reveal that the only
  4323. dependent variable is now $d$, which equals $0.75b+0.5c+0.75$. \ (This
  4324. is correct, for if the variable~$a$ is eliminated from the two given
  4325. equations we obtain $4d=3b+2c+3$.) \ The variable chosen for independence
  4326. is one that has the greatest coefficient of dependency with respect
  4327. to the variable that will disappear.
  4328. \danger A designer often wants to stipulate that a certain point lies on
  4329. a certain line. ^^{line, point to be on} This can be done easily by
  4330. using a special feature of plain \MF\ called `^"whatever"', which
  4331. stands for an anonymous numeric variable that has a different unknown
  4332. value each time you use it. For example,
  4333. \begindisplay
  4334. $z_1="whatever"[z_2,z_3]$
  4335. \enddisplay
  4336. states that point 1 appears somewhere on the straight line that passes
  4337. through points 2 and~3. \ (The expression $t[z_2,z_3]$ represents that
  4338. entire straight line, as $t$ runs through all values from $-\infty$ to
  4339. $+\infty$. We want $z_1$ to be equal to $t[z_2,z_3]$ for some value of~$t$,
  4340. but we don't care what value it is.) \ The expression `"whatever"$[z_2,z_3]$'
  4341. is legal whenever the difference $z_2-z_3$ is known; it's usually used
  4342. only when $z_2$ and $z_3$ are both known, i.e., when both points have been
  4343. determined by prior equations.
  4344. \danger Here are a few more examples of equations that involve
  4345. `"whatever"', together with their translations into English. These
  4346. equations are more fun than the ``tame'' ones we considered at the
  4347. beginning of this chapter, because they show off more of the
  4348. computer's amazing ability to deduce explicit values from implicit
  4349. statements.
  4350. \ninepoint % it's all dangerous from here on!
  4351. \setbox0=\hbox{\indent$z_7-z_6="whatever"\ast(z_3-z_2)$\quad}
  4352. \longesteq=\wd0
  4353. \noindent\hbox to\longesteq{\indent\kern-1pt\sl Equation\hfil}%
  4354. \kern-1pt{\sl Translation}\smallskip
  4355. \\$z_5-z_4="whatever"\ast\mathop{\rm dir}30$\\
  4356. The angle between points 4 and~5 will be $30^\circ$ above the horizon.
  4357. \ (This equation can also be written `$z_4=z_5+"whatever"\ast\mathop{\rm
  4358. dir}30$', which states that point~4 is obtained by starting at point~5
  4359. and moving by some unspecified multiple of ^{dir}$\,30$.)
  4360. \\$z_7-z_6="whatever"\ast(z_3-z_2)$\\
  4361. The line from point~6 to point~7 should be ^{parallel} to the
  4362. line from point~2 to point~3.
  4363. \\$\penpos8("whatever",60)$\\
  4364. The simulated pen angle at point~8 should be 60 degrees; the breadth
  4365. of the pen is unspecified, so it will be determined by other equations.
  4366. \dangerexercise If $z_1$, $z_2$, $z_3$, and $z_4$ are known points,
  4367. how can you tell \MF\ to compute the point $z$ that lies on the
  4368. ^{intersection} of the lines $z_1\to z_2$ and $z_3\to z_4$?
  4369. \answer $z="whatever"[z_1,z_2]$; $z="whatever"[z_3,z_4]$. \ (Incidentally,
  4370. it's interesting to watch this computation in action. Run \MF\ with
  4371. |\tracingequations:=|\allowbreak|tracingonline:=1| and say, for example,
  4372. \begintt
  4373. z=whatever[(1,5),(8,19)]; z=whatever[(0,17),(6,1)];
  4374. \endtt
  4375. the solution appears as if by magic.
  4376. If you use |alpha| and |beta| in place of the whatevers, the machine will
  4377. also calculate values for "alpha" and "beta".)
  4378. \dangerexercise Given five points $z_1$, $z_2$, $z_3$, $z_4$, and $z_5$,
  4379. explain how to compute $z$ on the line $z_1\to z_2$ such that the line
  4380. $z\to z_3$ is parallel to the line $z_4\to z_5$.
  4381. \answer $z="whatever"[z_1,z_2]$; $z-z_3="whatever"\ast(z_5-z_4)$.
  4382. \dangerexercise What \MF\ equation says that the line between points
  4383. 11 and~12 is {\sl^{perpendicular}\/} to the line between points 13 and~14?
  4384. \answer $z_{11}-z_{12}="whatever"\ast(z_{13}-z_{14})$ ^{rotated} 90,
  4385. assuming that $z_{13}-z_{14}$ is known.  \ (It's also possible to say
  4386. `$(z_{11}-z_{12})\mathbin{\rm dotprod} (z_{13}-z_{14})=0$', ^^{dotprod}
  4387. although this risks overflow if the coordinates are large.)
  4388. \dangerexercise (For mathematicians.) \ Given three points $z_1$, $z_2$,
  4389. and $z_3$, explain how to compute the distance from $z_1$ to the straight
  4390. line through $z_2$ and $z_3$.
  4391. \answer One solution constructs the point $z_4$ on $z_2\to z_3$ such
  4392. that $z_4\to z_1$ is perpendicular to $z_2\to z_3$, using ideas like
  4393. those in the previous two exercises: `$z_4="whatever"[z_2,z_3]$;
  4394. $z_4-z_1="whatever"\ast(z_3-z_2)$ rotated 90'. Then the requested distance
  4395. ^^{abs} ^^{ypart}
  4396. is $length(z_4-z_1)$. But there's a slicker solution: Just calculate
  4397. $$\hbox{abs ypart$((z_1-z_2)\mathbin{\rm rotated}-angle(z_3-z_2))$.}$$
  4398. \ddangerexercise (For mathematicians.) \ Given three points $z_1$,
  4399. $z_2$, $z_3$, and a length~$l$, explain how to compute the two points
  4400. on the line $z_2\to z_3$ that are at distance~$l$ from $z_1$. \ (Assume
  4401. that $l$~is greater than the distance from $z_1$ to the line.)
  4402. \answer It would be nice to say simply `$z="whatever"[z_2,z_3]$' and
  4403. then to be able to say either `length$(z-z_1)=l$' or `$z-z_1=(l,0)$
  4404. rotated "whatever"'; but neither of the second equations is legal. \
  4405. (Indeed, there couldn't possibly be a legal solution that has this general
  4406. flavor, because any such solution would determine a unique $z$, while
  4407. there are two points to be determined.) \ The best way seems to be to
  4408. compute $z_4$ as in the previous exercise, ^^{pythagorean subtraction} and
  4409. then to let
  4410. $v=(l\mathbin{+{-}+}\mathop{\rm length} (z_4-z_1))\ast\mathop{\rm
  4411. unitvector}(z_3-z_2)$; ^^{unitvector} ^^{length}
  4412. the desired points are then $z_4+v$ and $z_4-v$.
  4413. \ddangerexercise The applications of "whatever" that we have seen so far
  4414. have been in equations between {\sl pairs\/} of numeric values, not
  4415. in equations between simple numerics. Explain why an equation like
  4416. `$a+2b="whatever"$' would be useless.
  4417. \answer Such an equation tells us nothing new about $a$ or $b$. Indeed,
  4418. each use of "whatever" introduces a new independent variable, and
  4419. each new independent variable ``uses up'' one equation, since we need
  4420. $n$ equations to determine the values of $n$~unknowns. On the other hand
  4421. an equation between pairs counts as two equations; so there's a net
  4422. gain of one, when "whatever" appears in an equation between pairs.
  4423. \danger All of the equations so far in this chapter have been between numeric
  4424. expressions or pair expressions. But \MF\ actually allows equations
  4425. between any of the eight types of quantities. For example, you can write
  4426. \begintt
  4427. s1="go"; s1&s1=s2
  4428. \endtt
  4429. if $s_1$ and $s_2$ are string variables; this makes $s_1=\null$|"go"|
  4430. and $s_2=\null$|"gogo"|. Moreover, the subsequent equations
  4431. \begintt
  4432. s3=s4; s5=s6; s3=s5; s4=s1&"sh"
  4433. \endtt
  4434. will make it possible for the machine to deduce that $s_6=\null$|"gosh"|.
  4435. \danger But nonnumeric equations are not as versatile as numeric
  4436. ones, because \MF\ does not perform operations on unknown quantities
  4437. ^^{unknown quantities, nonnumeric}
  4438. of other types. For example, the equation
  4439. \begintt
  4440. "h"&s7="heck"
  4441. \endtt
  4442. cannot be used to define $s_7=\null$|"eck"|, because the ^{concatenation}
  4443. operator~|&| works only with strings that are already known.
  4444. \ddanger After the declaration `|string| |s[]|' and the equations
  4445. `|s1=s2=s3|', the statement `|show|~|s0|' will produce the result
  4446. `|unknown| |string| |s0|'; but `|show|~|s1|' will produce `|unknown|
  4447. |string| |s2|'. Similarly, `|show|~|s2|' and `|show|~|s3|' will produce
  4448. `|unknown| |string| |s3|' and `|unknown| |string| |s1|', respectively.  In
  4449. general, when several nonnumeric variables have been equated, they will
  4450. point to each other in some cyclic order.
  4451. \endchapter
  4452. Let ``X'' equal my father's signature.
  4453. \author FRED ^{ALLEN}, {\sl Vogues\/} (1924) % NYT review of show, Mar 28'24
  4454.   % quoted in Much Ado About Me, p288
  4455. \bigskip
  4456. ALL ANIMALS ARE EQUAL
  4457. BUT SOME ANIMALS ARE MORE EQUAL THAN OTHERS
  4458. \author GEORGE ^{ORWELL}, {\sl Animal Farm\/} (1945) % Chapter 10
  4459. \eject
  4460. \beginchapter Chapter 10. Assignments
  4461. Variables usually get values by appearing in equations, as described in
  4462. the preceding chapter. But there's also another way, in which `^|:=|'
  4463. is used instead of~`|=|'. For example, the |io.mf| program in Chapter~5
  4464. \begintt
  4465. stem# := trial_stem * pt#
  4466. \endtt
  4467. when it wanted to define the value of |stem#|.
  4468. The ^{colon-equal} operator `|:=|' means ``discard the previous value of
  4469. the variable and assign a new one''; we call this an {\sl^{assignment}\/}
  4470. operation. It was convenient for |io.mf| to define |stem#| with an
  4471. assignment instead of an equation, because |stem#| was getting several
  4472. different values within a single font. The alternative would have been to say
  4473. \begintt
  4474. numeric stem#; stem# = trial_stem * pt#
  4475. \endtt
  4476. (thereby specifically undefining the previous value of |stem#| before using
  4477. it in an equation); this is more cumbersome.
  4478. The variable at the left of `|:=|' might appear also in the expression on
  4479. the right. For example,
  4480. \begintt
  4481. code := code + 1
  4482. \endtt
  4483. means ``increase the value of "code" by 1.'' This assignment would make no
  4484. sense as an equation, since `$"code"="code"+1$' is inconsistent. The former
  4485. value of "code" is still relevant on the right-hand side when `$"code"+1$'
  4486. is evaluated in this example, because old values are not discarded until
  4487. the last minute; they are retained until just before a new assignment is made.
  4488. \dangerexercise Is it possible to achieve the effect of `$"code":="code"+1$'
  4489. by using equations and @numeric@ declarations but not assignments?
  4490. \answer Yes, but it must be done in two steps: `@numeric@ "newcode";
  4491. $"newcode"="code"+1$; @numeric@ "code"; $"code"="newcode"$'.
  4492. Assignments are permitted only when the quantity at the left of the `|:=|'
  4493. is a variable. For example, you can't say `|code+1:=code|'. More
  4494. significantly, things like `|(x,y):=(0,0)|' are not permitted, although
  4495. you can say `|w:=(0,0)|' if~$w$~has been declared to be a variable of
  4496. type @pair@. This means that a statement like `|z1:=z2|' is illegal, because
  4497. it's an abbreviation for the inadmissible construction `|(x1,y1):=(x2,y2)|';
  4498. we must remember that |z1| is not really a variable, it's a pair of variables.
  4499. The restriction in the previous paragraph is not terribly significant, because
  4500. assignments play a relatively minor r\^ole in \MF\ programs. The best
  4501. programming strategy is usually to specify equations instead of
  4502. assignments, because equations indicate the relationships between
  4503. variables in a declarative ^^{declarative versus imperative} ^^{imperative
  4504. versus declarative} manner. A person who makes too many assignments is
  4505. still locked into the habits of old-style ``imperative'' programming
  4506. languages in which it is necessary to tell the computer exactly how to do
  4507. everything; \MF's equation
  4508. mechanism liberates us from that more complicated style of programming,
  4509. because it lets the computer take over the job of solving equations.
  4510. The use of assignments often imposes a definite order on the statements of
  4511. a program, because the value of a variable is different before and after
  4512. an assignment takes place. Equations are simpler than assignments because
  4513. they can usually be written down in any order that comes naturally to you.
  4514. Assignments do have their uses; otherwise \MF\ wouldn't bother with
  4515. `|:=|' at all. But experienced \MF\ programmers introduce assignments
  4516. sparingly---only when there's a good reason for doing so---because
  4517. equations are generally easier to write and more enlightening to read.
  4518. \danger \MF's ^{internal quantities} like "tracingequations" always have
  4519. known numeric values, so there's no way to change them except by giving
  4520. assignments. The computer experiment in Chapter~9 began with
  4521. \begintt
  4522. \tracingequations:=tracingonline:=1;
  4523. \endtt
  4524. this illustrates the fact that multiple assignments are possible, just
  4525. like multiple equations. Here is the complete syntax for equations
  4526. and assignments:
  4527. \beginsyntax
  4528. <equation>\is<expression>[=]<right-hand side>
  4529. <assignment>\is<variable>[:=]<right-hand side>
  4530. <right-hand side>\is<expression>\alt<equation>\alt<assignment>
  4531. \endsyntax
  4532. Notice that the syntax permits mixtures like `$a+b=c:=d+e$'; this is
  4533. the same as the assignment `$c:=d+e$' and the equation `$a+b=c$'.
  4534. \ddanger In a mixed equation/assignment like `$a+b=b:=b+1$', the old
  4535. value of~$b$ is used to evaluate the expressions. For example, if $b$ equals~3
  4536. before that statement, the result will be the same as `$a+3=b:=3+1$';
  4537. therefore $b$ will be set to~4 and $a$~will be set to~1.
  4538. \dangerexercise Suppose that you want variable $x_3$ to become ``like new,''
  4539. ^^{variables, reinitializing} ^^{reinitializing} ^^{independent variables}
  4540. completely independent of any value that it formerly had; but you don't
  4541. want to destroy the values of~$x_1$ and~$x_2$. You can't say `^@numeric@
  4542. $x[\,]$', because that would obliterate all the $x_k$'s. What can you do
  4543. instead? \checkequals\xwhat\exno
  4544. \answer The assignment `$x_3:=\null$^"whatever"' does exactly what you want.
  4545. \ddangerexercise Apply \MF\ to the short program
  4546. \begindisplay
  4547. @string@ $s[\,]$; \ $s_1=s_2=s_3=s_4$; \ $s_5=s_6$; \ $s_2:=s_5$; \
  4548.  @showvariable@ $s$;
  4549. \enddisplay
  4550. and explain the results you get.
  4551. \answer The result shows that $s_1=s_3=s_4$ and $s_2=s_5=s_6$ now:
  4552. \begintt
  4553. s[]=unknown string
  4554. s1=unknown string s3
  4555. s2=unknown string s6
  4556. s3=unknown string s4
  4557. s4=unknown string s1
  4558. s5=unknown string s2
  4559. s6=unknown string s5
  4560. \endtt
  4561. (The assignment $s_2:=s_5$ broke $s_2$'s former relationship with $s_1$,
  4562. $s_3$, and $s_4$.)
  4563. \ddanger If other variables depend on $v$ when $v$ is assigned a new value,
  4564. the other variables do not change to reflect the new assignment; they still
  4565. act as if they depended on the previous (unknown) value of~$v$. For example,
  4566. if the equations `$2u=3v=w$' are followed by the assignment `$w:=6$', the
  4567. values of $u$ and~$v$ won't become known, but \MF\ will still remember the
  4568. fact that $v=.66667u$. \ (This is not a new rule; it's a consequence of
  4569. the rules already stated. When an independent variable is discarded, a
  4570. dependent variable may become independent in its place, as described in
  4571. Chapter~9.)
  4572. \ddangerexercise Apply \MF\ to the program
  4573. \begindisplay
  4574. $"tracingequations":="tracingonline":=1$;\cr
  4575. $a=1$; \ $a:=a+b$; \ $a:=a+b$; \ $a:=a+b$;\cr
  4576. @show@ $a,b$;\cr
  4577. \enddisplay
  4578. and explain the results you get.
  4579. \answer The results are
  4580. \begindisplay
  4581. |## a=1|\cr
  4582. |## a=b+1|&(after the first assignment)\cr
  4583. |## b=0.5a-0.5|&(after the second assignment)\cr
  4584. |### -1.5a=-%CAPSULEnnnn-0.5|&(after the third assignment)\cr
  4585. |## a=%CAPSULEnnnn|&(after the third, see below)\cr
  4586. |>> a|&(after `@show@'; variable $a$ is independent)\cr
  4587. |>> 0.33333a-0.33333|&(this is the final value of $b$)\cr
  4588. \enddisplay
  4589. ^^|CAPSULE| Let $a_k$ denote the value of $a$ after $k$ assignments were made.
  4590. Thus, $a_0=1$, and $a_1$ was dependent on the independent variable~$b$.
  4591. Then $a_1$ was discarded and $b$ became dependent on the independent
  4592. variable~$a_2$. The right-hand side of the third assignment was
  4593. therefore $a_2+b$. At the time $a_2$ was about to be discarded, \MF\
  4594. had two dependencies $b=0.5a_2-0.5$ and $\kappa=1.5a_2-0.5$, where
  4595. $\kappa$ was a nameless ``^{capsule}'' inside of the computer, representing
  4596. the new value to be assigned. Since $\kappa$ had a higher coefficient
  4597. of dependency than~$b$, \MF\ chose to make $\kappa$ an independent variable,
  4598. after which $-1.5a_2$ was replaced by $-\kappa-0.5$ in all dependencies; hence
  4599. $b$ was equal to $0.33333\kappa-0.33333$. After the third
  4600. assignment was finished, $\kappa$ disappeared and $a_3$ became independent
  4601. in its place. \ (The line `|##| |a=%CAPSULEnnnn|' means that $a$~was
  4602. temporarily dependent on $\kappa$, before $\kappa$ was discarded. If
  4603. the equation $a=\kappa$ had happened to make $\kappa$ dependent on~$a$, rather
  4604. than vice versa, no ^^{hash hash} `|##|' line would have been printed;
  4605. such lines are omitted when a capsule or part of a capsule has been made
  4606. dependent, unless you have made ^"tracingcapsules"$\null>0$.)
  4607. \endchapter
  4608. At first his assignment had pleased,
  4609. but as hour after hour passed
  4610. with growing weariness,
  4611. he chafed more and more.
  4612. \author C. E. ^{MULFORD},  {\sl Hopalong Cassidy\/} (1910) % Chap 17 p154
  4613. \bigskip
  4614. \<left part> ::= \<variable> :=
  4615. \<left part list> ::= \<left part> $\vert$ \<left part list>\<left part>
  4616. \<assignment statement> ::= \<left part list>\<arithmetic expression> $\vert$
  4617. \<left part list>\<Boolean expression>
  4618. \author PETER ^{NAUR} et al.,  {\sl Report %
  4619.  on the Algorithmic language ALGOL 60\/} (1960) % section 4.2.1
  4620. \eject
  4621. \beginchapter Chapter 11. Magnification\\and\\Resolution
  4622. A single \MF\ program can produce fonts of type for many different kinds
  4623. of printing equipment, if the programmer has set things up so that the
  4624. ^{resolution} can be varied. The ``plain \MF\thinspace'' base file described
  4625. in Appendix~B establishes a set of conventions that make such variability
  4626. quite simple; the purpose of the present chapter is to explain those
  4627. conventions.
  4628. For concreteness let's assume that our computer has two output devices.
  4629. One of them, called ^"cheapo", has a resolution of 200 pixels per
  4630. inch (approximately 8 per millimeter); the other, called ^"luxo",
  4631. has a resolution of 2000 pixels per inch. We would like to write \MF\
  4632. programs that are able to produce fonts for both devices. For example,
  4633. if the file |newface.mf| contains a program for a new typeface, we'd
  4634. like to generate a low-resolution font by invoking \MF\ with
  4635. \begintt
  4636. \mode=cheapo; input newface
  4637. \endtt
  4638. and the same file should also produce a high-resolution font if we start with
  4639. \begintt
  4640. \mode=luxo; input newface
  4641. \endtt
  4642. instead. Other people with different printing equipment should also be
  4643. able to use |newface.mf| with their own favorite ^"mode" values.
  4644. The way to do this with plain \MF\ is to call ^@mode\_setup@ near the
  4645. beginning of |newface.mf|; this routine establishes the values of
  4646. variables like ^"pt" and ^"mm", which represent the respective numbers of
  4647. pixels in a point and a millimeter. For example, when $"mode"= "cheapo"$,
  4648. the values will be $"pt"=2.7674$ and $"mm"=7.87402$; when $"mode"="luxo"$,
  4649. they will be $"pt"=27.674$ and $"mm"=78.74017$.  The |newface.mf| program
  4650. should be written in terms of such variables, so that the pixel patterns
  4651. for characters will be about 10~times narrower and 10~times shorter in
  4652. "cheapo" mode than they are in "luxo" mode. For example, a line that's
  4653. drawn from $(0,0)$ to $(3"mm",0)$ will produce a line that's about 23.6
  4654. pixels long in "cheapo" mode, and about 236.2 pixels long in "luxo" mode;
  4655. the former line will appear to be 3\thinspace mm long when printed by
  4656. "cheapo", while the latter will look 3\thinspace mm long when printed by
  4657. "luxo".
  4658. A further complication occurs when a typeface is being ^{magnified}; in such
  4659. cases the font does not correspond to its normal size. For example, we might
  4660. want to have a set of fonts for "cheapo" that are twice as big as usual,
  4661. so that users can make transparencies for overhead projectors. \ (Such
  4662. output could also be reduced to 50\% of its size as printed,
  4663. on suitable reproduction equipment, thereby increasing the effective
  4664. resolution from 200 to 400.) \ \TeX\ allows entire jobs to be magnified
  4665. by a factor of~2 if the user says `|\magnification=2000|'; individual
  4666. fonts can also be magnified in a \TeX\ job by saying, e.g., ^^{TeX}
  4667. `|\font\f=newface| |scaled| |2000|'. The standard way to produce a font
  4668. with two-fold magnification using the conventions of plain \MF\ is to say, e.g.,
  4669. \begintt
  4670. \mode=cheapo; mag=2; input newface;
  4671. \endtt
  4672. this will make $"pt"=5.5348$ and $"mm"=15.74803$.
  4673. The @mode\_setup@ routine looks to see if ^"mag" has a known value;
  4674. if not, it sets $"mag"=1$. Similarly, if "mode" is unknown,
  4675. ^^"proof" @mode\_setup@ sets $"mode"="proof"$.
  4676. Plain \MF\ also computes the values of several other dimension-oriented
  4677. values in addition to "pt" and "mm", corresponding to the dimensions
  4678. that are understood by \TeX. Here is the complete list:
  4679. \begindisplay \openup 1pt
  4680. "pt"&printer's point&($\rm72.27\,pt=1\,in$)\cr
  4681. ^"pc"&pica&($\rm1\,pc=12\,pt$)\cr
  4682. ^"in"&inch&($\rm1\,in=2.54\,cm$)\cr
  4683. ^"bp"&big point&($\rm72\,bp=1\,in$)\cr
  4684. ^"cm"¢imeter&($\rm100\,cm=1\,meter$)\cr
  4685. "mm"&millimeter&($\rm10\,mm=1\,cm$)\cr
  4686. ^"dd"&didot point&($\rm1157\,dd=1238\,pt$)\cr
  4687. ^"cc"&cicero&($\rm1\,cc=12\,dd$)\cr
  4688. \enddisplay
  4689. In each case the values are rounded to the nearest $1\over65536$th of a pixel.
  4690. Although such standard physical ^{dimensions} are available, they haven't
  4691. been used very much in traditional typefaces; designers usually specify
  4692. other units like `"em"' or `"x\_height"' in order to define the sizes
  4693. of letters, and such quantities generally have ad hoc values that vary
  4694. from font to font.  Plain \MF\ makes it easy to introduce ^{ad hoc
  4695. dimensions} that will vary with the resolution and the magnification just
  4696. as "pt" and "mm" do; all you have to do is define ``^{sharped}''
  4697. dimensions that have the same name as your pixel-oriented dimensions, but
  4698. with `|#|' ^^{hash} tacked on as a suffix. For example, $"em"\0$ and
  4699. $"x\_height"\0$ (typed `|em#|' and `|x_height#|'\thinspace) would be the
  4700. ^{sharped dimensions} corresponding to "em" and "x\_height". Plain \MF\ has
  4701. already defined the quantities $"pt"\0$, $"pc"\0$, $"in"\0$, $"bp"\0$,
  4702. $"cm"\0$, $"mm"\0$, $"dd"\0$, and $"cc"\0$ for the standard units named above.
  4703. Sharped dimensions like $"em"\0$ and $"x\_height"\0$ should always be
  4704. defined in terms of resolution-independent dimension variables like $"pt"\0$,
  4705. $"in"\0$, etc., so that their values do not change in any way when "mode"
  4706. and "mag" are varied. The `|#|' sign implies unchangeability.
  4707. After @mode\_setup@ has been called,
  4708. the pixel-oriented dimensions can be calculated by simply saying
  4709. \begindisplay
  4710. ^@define\_pixels@("em", "x\_height").
  4711. \enddisplay
  4712. This statement is an abbreviation for
  4713. \begindisplay
  4714. $"em":="em"\0\ast"hppp"$;&$"x\_height":="x\_height"\0\ast"hppp"$
  4715. \enddisplay
  4716. where ^"hppp" is an internal variable of \MF\ that represents the number
  4717. of pixels per point in the horizontal dimension. Any number of ad hoc
  4718. dimensions can be listed in a single @define\_pixels@ statement.
  4719. Notice that `\#' is not an operator that could convert "em" to $"em"\0$;
  4720. rounding errors would be mode-dependent.
  4721. Chapter 5's demonstration program |io.mf| contains several examples of ad hoc
  4722. dimensions defined in this way, and it also contains the statement
  4723. \begindisplay
  4724. ^@define\_blacker\_pixels@("thin", "thick");
  4725. \enddisplay
  4726. what's this? Well, Appendix B makes that statement an abbreviation for
  4727. \begindisplay
  4728. $"thin":="thin"\0\ast"hppp"+"blacker"$;&
  4729. $"thick":="thick"\0\ast"hppp"+"blacker"$;\cr
  4730. \enddisplay
  4731. in other words, the sharped dimensions are being unsharped in this case
  4732. by converting them to pixels and then adding `"blacker"'. The variable
  4733. ^"blacker" is a special correction intended to help adapt a font to the
  4734. idiosyncrasies of the current output device; @mode\_setup@ uses the value
  4735. of "mode" to establish the value of "blacker". For example, "cheapo" mode
  4736. might want $"blacker"=0.65$, while "luxo" mode might give best results
  4737. when $"blacker"=0.1$. The general convention is to add "blacker" to
  4738. pixel-oriented variables that determine the breadth of pens and the
  4739. thickness of stems, so that the letters will be slightly darker on machines
  4740. that otherwise would make them appear too light. Different machines treat
  4741. pixels quite differently, because they are often based on quite different
  4742. physical principles. For example, the author once worked with an extremely
  4743. high-resolution device that tended to shrink stem lines rather drastically
  4744. when it used a certain type of photographic paper, and it was necessary
  4745. to set $"blacker"=4$ to get proper results on that machine; another
  4746. high-resolution device seems to want "blacker" to be only~$0.2$. Experimentation
  4747. is necessary to tune \MF's output to particular devices, but the author's
  4748. experience suggests strongly that such a correction is worthwhile. When
  4749. ^^"proof" $"mode"="proof"$ or ^"smoke", the value of "blacker" is taken to
  4750. be zero, since the output in these modes is presumably undistorted.
  4751. \exercise Does `$"mode"="cheapo"$; $"mag"=10$' produce exactly the same
  4752. font as `$"mode"="luxo"$', under the assumptions of this chapter?
  4753. \answer Almost, but not quite. The values of standard dimension variables
  4754. like "pt" and "mm" will be identical in both setups, as will the values of
  4755. ad~hoc dimension variables like "em" and "x\_height". But pen-oriented
  4756. dimensions that are defined via @define\_blacker\_pixels@ will be slightly
  4757. different, because "cheapo" mode has $"blacker"=0.65$ while "luxo" mode
  4758. has $"blacker"=0.1$ (since the "luxo" printer has different physical
  4759. characteristics).  Similarly, @define\_corrected\_pixels@ (which we are
  4760. just about to discuss) will produce slightly different results in the two
  4761. given modes.
  4762. \danger Line 7 of |io.mf| says `^@define\_corrected\_pixels@($o$)', and
  4763. this is yet a third way of converting from true physical dimensions to
  4764. pixel-oriented values. According to Appendix~B\null, variable~$o$ is
  4765. defined by the assignment
  4766. \begindisplay
  4767. $o:=\round(o\0\ast"hppp"\ast"o\_correction")+"eps"$
  4768. \enddisplay
  4769. ^^{round} ^^"eps" ^^"o"
  4770. where ^"o\_correction", like "blacker", is a magic number that depends on
  4771. the output device for which fonts are being made. On a high-resolution
  4772. device like "luxo", the appropriate value for the "o\_correction" factor
  4773. is~1; but on a low-resolution device like "cheapo", the author has obtained
  4774. more satisfactory results with $"o\_correction"=0.4$. The reason is that
  4775. `$o$' is used to specify the number of pixels by which certain features
  4776. of characters ``^{overshoot}'' the baseline or some other line to which
  4777. they are visually related. High-resolution curves look better when they
  4778. overshoot in this way, but low-resolution curves do not; therefore it is
  4779. usually wise to curtail the amount of overshoot by applying the
  4780. "o\_correction" factor. In "proof" and "smoke" modes the factor is
  4781. equal to 1.0, since these modes correspond to high resolution.
  4782. %\danger Plain \MF\ also provides a fourth way to define unsharped
  4783. %dimensions from sharped ones, if you want the unsharped dimensions
  4784. %to be rounded to the nearest integer number of pixels: Just say
  4785. %`^@define\_whole\_pixels@'. For example,
  4786. %\begindisplay
  4787. %@define\_whole\_pixels@("foo")
  4788. %\enddisplay
  4789. %stands for `$"foo":=\round("foo"\0\ast"hppp")$'.
  4790. \ddanger The properties of output devices are modeled also by a
  4791. parameter that's called ^"fillin", which represents the amount by which
  4792. diagonal strokes tend to be darker than horizontal or vertical strokes.
  4793. More precisely, let us say that a ``^{corner}'' pixel is one whose color
  4794. matches the color of five of its neighbors but not the other three, where the
  4795. three exceptions include one horizontal neighbor, one vertical neighbor,
  4796. and the diagonal neighbor between them. If a white corner pixel has
  4797. apparent darkness $f_1$ and if a black corner pixel has apparent darkness
  4798. $1-f_2$, then the "fillin" is $f_1-f_2$. \ (A ``true'' raster image would
  4799. have $f_1=f_2=0$, but physical properties often cause pixels to influence
  4800. their neighbors.)
  4801. \ddanger Each output device for which you will be generating fonts should
  4802. be represented by a symbolic ^"mode" name in the implementation of \MF\
  4803. that you are using. Since these mode names vary from place to place, they
  4804. are not standard aspects of the \MF\ language; for example, it is doubtful
  4805. whether the hypothetical "cheapo" and "luxo" modes discussed in this
  4806. chapter actually exist anywhere. The plain \MF\ base is intended to be
  4807. extended to additional modes in a disciplined way, as described at the
  4808. end of Appendix~B.
  4809. \ddanger It's easy to create a new symbolic mode, using plain \MF's
  4810. `^@mode\_def@\kern.75pt' convention. For example, the "luxo" mode we have been
  4811. talking about could be defined by saying
  4812. \begindisplay
  4813. @mode\_def@ "luxo" $=$\cr
  4814. \quad$"pixels\_per\_inch":=2000$;&|%| high res, almost 30 per point\cr
  4815. \quad$"blacker":=.1$;&|%| make pens a teeny bit blacker\cr
  4816. \quad$"o\_correction":=1$;&|%| keep the full overshoot\cr
  4817. \quad$"fillin":=0.1$;&|%| compensate for darkened corners\cr
  4818. \quad$"proofing":=0$;&|%| no, we're not making proofs\cr
  4819. \quad$"fontmaking":=1$;&|%| yes, we are making a font\cr
  4820. \quad$"tracingtitles":=1$; \ @enddef@;&|%| yes, show titles online\cr
  4821. \enddisplay
  4822. The name of the mode should be a single symbolic token. The resolution
  4823. should be specified by assigning a value to "pixels\_per\_inch"; all other
  4824. dimension values ("pt", "mm", etc.)\ will be computed from this one by
  4825. @mode\_setup@. A mode definition should also assign values to the
  4826. internal variables "blacker", "o\_correction", and "fillin" (which describe
  4827. the device characteristics), as well as ^"proofing", ^"fontmaking", and
  4828. ^"tracingtitles" (which affect the amount of output that will be produced).
  4829. In general, "proofing" and "fontmaking" are usually
  4830. set to 0 and~1, respectively, in modes that are intended for font
  4831. production rather than initial font design; "tracingtitles" is usually
  4832. 0~for low-resolution fonts (which are generated quickly), but 1~for
  4833. high-resolution fonts (which go more slowly), because detailed online
  4834. progress reports are desirable when comparatively long jobs are running.
  4835. \ddanger Besides the seven mandatory quantities `"pixels\_per\_inch"',
  4836. \dots, `"tracingtitles"' just discussed, a mode definition might assign
  4837. a value to `^"aspect\_ratio"'. In the normal case when no
  4838. "aspect\_ratio" is specified, it means that the fonts to be output are
  4839. are assumed to have square pixels. But if, for
  4840. example, the @mode\_def@ sets $"aspect\_ratio":=5/4$,
  4841. it means that the output pixels
  4842. are assumed to be ^{nonsquare} in the ratio of 5 to~4; i.e.,
  4843. 5~vertical pixel units are equal to 4~horizontal pixel units. The
  4844. pixel-oriented dimensions of plain \MF\ are given in terms of horizontal
  4845. pixel units, so an aspect ratio of 5/4 together with 2000 pixels per inch
  4846. would mean that there are 2500 vertical pixel units per inch; a square
  4847. inch would consist of 2500 rows of pixels, with 2000 pixels in each row. \
  4848. (Stating this another way, each pixel would be $1\over2000$ inches wide and
  4849. $1\over2500$ inches high.) \ In such a case, plain \MF\ will set the
  4850. ^"currenttransform" variable so that all @draw@ and @fill@ commands
  4851. stretch the curves by a factor of 5/4 in the vertical dimension; this
  4852. compensates for the nonsquare pixels, so the typeface designer doesn't have to
  4853. be aware of the fact that pixels aren't square.
  4854. %\ddanger A mode definition might also do other things besides setting
  4855. %the values of numeric variables like "blacker" or "aspect\_ratio".
  4856. %For example, the @mode\_def@ for "smoke" in Appendix~B includes the
  4857. %statements `@grayfont@ black; @let@ $"makebox"="maketicks"$';
  4858. %this changes the style of proofsheets that you get in ^"smoke" mode.
  4859. Let's look now at a concrete example, so that it will be clear how the
  4860. ideas of device-independent font design can be implemented in practice.
  4861. We shall study a file |logo.mf| that generates the seven letters of
  4862. \MF's ^{logo}. There also are ``^{parameter}'' files |logo10.mf|, |logo9.mf|,
  4863. etc., which use |logo.mf| to produce fonts in various sizes. For
  4864. example, a font containing the 10-point characters `\thinspace\MF\thinspace'
  4865. could be generated for the hypothetical "luxo" printer by running \MF\ with
  4866. the command line
  4867. \begintt
  4868. \mode=luxo; input logo10
  4869. \endtt
  4870. if "luxo" mode really existed.
  4871. The main purpose of |logo10.mf| is to establish the ``sharped'' values of
  4872. several ad hoc dimensions; then it inputs |logo.mf|, which does the
  4873. rest of the work. Here is the entire file |logo10.mf|:
  4874. \begintt
  4875. % 10-point METAFONT logo|smallskip
  4876. font_size 10pt#;   % the "design size" of this font
  4877. ht#:=6pt#;         % height of characters
  4878. xgap#:=0.6pt#;     % horizontal adjustment
  4879. u#:=4/9pt#;        % unit width
  4880. s#:=0;             % extra space at the left and the right
  4881. o#:=1/9pt#;        % overshoot
  4882. px#:=2/3pt#;       % horizontal thickness of pen
  4883. input logo         % now generate the font
  4884. end                % and stop.
  4885. \endtt
  4886. Similar files |logo9.mf| and |logo8.mf| will produce 9-point
  4887. `\thinspace{\manual hijklmnj}\thinspace' and \hbox{8-point}
  4888. `\thinspace{\manual opqrstuq}\thinspace'; the letters get a little
  4889. wider in relation to their height, and the inter-character spacing
  4890. gets significantly wider, as the size gets smaller:
  4891. \begintt
  4892. % 9-point METAFONT logo        % 8-point METAFONT logo|smallskip
  4893. font_size 9pt#;                font_size 8pt#;
  4894. ht#:=.9*6pt#;                  ht#:=.8*6pt#;
  4895. xgap#:=.9*0.6pt#;              xgap#:=.8*0.6pt#;
  4896. u#:=.91*4/9pt#;                u#:=.82*4/9pt#;
  4897. s#:=.08pt#;                    s#:=.2pt#;
  4898. o#:=1/10pt#;                   o#:=1/12pt#;
  4899. px#:=.9*2/3pt#;                px#:=.8*2/3pt#;
  4900. input logo                     input logo
  4901. end                            end
  4902. \endtt
  4903. It is interesting to compare the font generated by |logo10.mf| to the
  4904. font generated by |logo8.mf| with |mag=10/8|: Both fonts will have
  4905. the same values of "ht", "xgap", and "px", when the magnification has been
  4906. taken into account. But the magnified 8-point font has a slightly larger
  4907. value of "u" and a positive value of "s"; this changes
  4908. `\thinspace\MF\thinspace' to `\thinspace{\manual/0123451}\thinspace'.
  4909. \danger Every font has a ``^{design size},'' which is a more-or-less
  4910. arbitrary number that reflects the size of type it is intended to blend
  4911. with.  ^^{TeX} Users of \TeX\ select magnified fonts in two ways, either
  4912. by specifying an ``at size'' or by specifying a scale factor (times 1000).
  4913. For example, the 8-point \MF\ logo can be used at 10/8 magnification by
  4914. referring either to `|logo8| |at|~|10pt|' or to `|logo8| |scaled|~|1250|'
  4915. in a \TeX\ document.  When an ``^{at size}'' is specified, the amount of
  4916. magnification is the stated size divided by the design~size. A typeface
  4917. designer can specify the design size by using plain \MF's `^@font\_size@'
  4918. command as illustrated on the previous page. \ (If no design size is
  4919. specified, \MF\ will set it to $128\pt$, by default.)
  4920. The file |logo.mf| itself begins by defining three more ad hoc dimensions
  4921. in terms of the parameters that were set by the parameter file; these
  4922. dimensions will be used in several of the programs for individual letters.
  4923. Then |logo.mf| makes the conversion to pixel units:
  4924. \begintt
  4925. % Routines for the METAFONT logo
  4926. % (logo10.mf is a typical parameter file)
  4927. mode_setup;
  4928. ygap#:=(ht#/13.5u#)*xgap#;        % vertical adjustment
  4929. leftstemloc#:=2.5u#+s#;           % position of left stems
  4930. barheight#:=.45ht#;               % height of bar lines
  4931. define_pixels(s,u,xgap,ygap,leftstemloc,barheight);
  4932. py#:=.9px#; define_blacker_pixels(px,py); % pen dimensions
  4933. pickup pencircle xscaled px yscaled py; logo_pen:=savepen;
  4934. define_corrected_pixels(o);
  4935. \endtt
  4936. There's nothing new here except the use of `^"savepen"' in the
  4937. second-last line; this, as we will see in Chapter~16, makes the
  4938. currently-picked-up pen available for repeated use in the
  4939. subsequent program.
  4940. After the initial definitions just shown, |logo.mf| continues with
  4941. programs for each of the seven letters. For example,
  4942. here is the program for `{\manual ^{E}}', which illustrates the
  4943. \rightfig 11a ({224\apspix} x {216\apspix}) ^-11pt
  4944. use of $u\0$, $s\0$, $"ht"\0$, "leftstemloc", "barheight", "xgap",
  4945. and "logo\_pen":
  4946. \begintt
  4947. beginchar("E",14u#+2s#,ht#,0);
  4948. pickup logo_pen;
  4949. x1=x2=x3=leftstemloc;
  4950. x4=x6=w-x1+o; x5=x4-xgap;
  4951. y1=y6; y2=y5; y3=y4;
  4952. bot y1=0; top y3=h;
  4953. y2=barheight;
  4954. draw z6--z1--z3--z4; draw z2--z5;
  4955. labels(1,2,3,4,5,6);
  4956. endchar;
  4957. \endtt
  4958. We have seen the essentials of the {\manual M} and the {\manual T} in
  4959. Chapter~4; programs for the other letters will appear later.
  4960. \exercise The ad hoc dimensions $"ht"\0$, $"xgap"\0$, $u\0$, $s\0$,
  4961. $o\0$, and $"px"\0$ defined in the parameter files all affect the letter
  4962. `{\manual E}' defined by this program. For each of these dimensions,
  4963. tell what would happen to the `{\manual E}' if that dimension were
  4964. increased slightly while all the others stayed the same.
  4965. \answer Increasing $"ht"\0$ would make the letter shape and the bounding
  4966. box taller; increasing $"xgap"\0$ would move point~5 to the left, thereby
  4967. making the middle bar shorter; increasing $u\0$ would make the shape and
  4968. its bounding box wider; increasing $s\0$ would widen the bounding box
  4969. at both sides without changing the letter shape; increasing $o\0$ would
  4970. move points 4,~5, and~6 to the right; increasing $"px"\0$ would make
  4971. the pen thicker (preserving the top edge of the upper bar, the bottom
  4972. edge of the lower bar, and the center of the middle bar and the stem).
  4973. \dangerexercise Guess the program for `{\manual l}' (which is ^^{F}
  4974. almost the same as `{\manual i}'\thinspace).
  4975. \answer The only possible surprise is the position of $y_1$,
  4976. which should match similar details in the `{\manual h}'
  4977. and the~`\kern1pt{\manual j}\kern1pt' of Chapter~4:
  4978. \begintt
  4979. beginchar("F",14*u#+2s#,ht#,0); pickup logo_pen;
  4980. x1=x2=x3=leftstemloc; x4=w-x1+o; x5=x4-xgap;
  4981. y2=y5; y3=y4; bot y1=-o; top y3=h; y2=barheight;
  4982. draw z1--z3--z4; draw z2--z5;
  4983. labels(1,2,3,4,5); endchar;
  4984. \endtt
  4985. \dangerexercise Write the complete programs for `{\manual h}' ^^{M} ^^{T}
  4986. and `\kern1pt{\manual j}\kern1pt', based on the information in Chapter~4,
  4987. but using the style of the program for `{\manual E}' above.  The character
  4988. widths should be $18u\0+2s\0$ and $13u\0+2s\0$, respectively.
  4989. \checkequals\metaT\exno
  4990. \answer The quantity called "ss" in Chapter~4 is now "leftstemloc".
  4991. \begintt
  4992. beginchar("M",18*u#+2s#,ht#,0); pickup logo_pen;
  4993. x1=x2=leftstemloc; x4=x5=w-x1; x3=w-x3;
  4994. y1=y5; y2=y4; bot y1=-o; top y2=h+o; y3=y1+ygap;
  4995. draw z1--z2--z3--z4--z5;
  4996. labels(1,2,3,4,5); endchar;|smallskip
  4997. beginchar("T",13*u#+2s#,ht#,0); pickup logo_pen;
  4998. lft x1=0; x2=w-x1; x3=x4=.5w;
  4999. y1=y2=y3; top y1=h; bot y4=-o;
  5000. draw z1--z2; draw z3--z4;
  5001. labels(1,2,3,4); endchar;
  5002. \endtt
  5003. \danger The file |logo.mf| also contains the following cryptic instructions,
  5004. which cause the letter pairs `\kern1pt{\manual jk}' and `{\manual lm}' to
  5005. be typeset closer together than their bounding boxes would imply:
  5006. \begintt
  5007. ligtable "T": "A" kern -.5u#;
  5008. ligtable "F": "O" kern -u#;|smallskip
  5009. \endtt
  5010. Without these corrections `\MF\kern1pt' would be ^^{kerning} ^^@kern@
  5011. `{\manual hij\/kl\/mnj}\kern1pt'.  Uppercase letters are often subject to
  5012. such spacing corrections, especially in logos; \TeX\ will adjust the spacing
  5013. if the typeface designer has supplied ^@ligtable@ information like this.
  5014. \danger Finally, |logo.mf| closes with four more commands, which provide
  5015. further information about how to typeset with this font:
  5016. \begintt
  5017. font_quad  18u#+2s#;
  5018. font_normal_space  6u#+2s#;
  5019. font_normal_stretch  3u#;
  5020. font_normal_shrink  2u#;
  5021. \endtt
  5022. A ^@font\_quad@ is the unit of measure that a \TeX\ user calls one `|em|'
  5023. when this font is selected. The normal space, stretch, and shrink parameters
  5024. ^^@font\_normal\_space@ ^^@font\_normal\_stretch@ ^^@font\_normal\_shrink@
  5025. define the interword spacing when text is being typeset in this font.
  5026. Actually a font like |logo10| is rarely used to typeset anything except
  5027. the one word, `\MF\kern1pt'; but the spacing parameters have been
  5028. included just in case somebody wants to typeset a sentence like
  5029. `{\manual kn illiji jmhkjm ml hmnjknk mljin kji nmnlkj jmllii}'.
  5030. \danger An optional `^|=|' or `^|:=|' sign may be typed after `@font\_size@',
  5031. `@font\_quad@', etc., in case you think the file looks better that way.
  5032. \danger Notice that ``sharped'' units must be given in the ^@ligtable@
  5033. kerning commands and in the definition of device-independent
  5034. parameters like @font\_size@
  5035. and @font\_quad@. Appendix~F discusses the complete rules of @ligtable@
  5036. and other commands by which \MF\ programs can send important information
  5037. to typesetting systems like \TeX. Adding these extra bits of information
  5038. to a \MF\ program after a font has been designed is something like
  5039. adding an index to a book after that book has been written and proofread.
  5040. \ddangerexercise What's the longest English word that can be typeset
  5041. with the font |logo9|?
  5042. \answer `{\manual nmnkjmnihinj\/}'; possibly also `{\manual hijklmmjnmji}';
  5043. and Georgia ^{Tobin} suggests that `{\manual knjiinlimllhinj\/}'
  5044. might be a legal term.
  5045. \ninepoint  % nothing but danger from here on, folks
  5046. \danger Let's summarize the general contents of |logo.mf|, now that we
  5047. have seen it all, because it provides an example of a complete typeface
  5048. description (even though there are only seven letters):\enddanger
  5049. \smallskip
  5050. \item\bull The file begins by defining ad hoc dimensions and converting
  5051. them to pixel units, using @mode\_setup@, @define\_pixels@, etc.
  5052. \smallskip
  5053. \item\bull Then come programs for individual letters. \ (These programs
  5054. are often preceded by macro definitions for subroutines that occur several
  5055. times. For example, we will see later that the `{\manual k}' and the
  5056. `{\manual m}' of the logo are drawn with the help of a subroutine that makes
  5057. half of a superellipse; the definition of this macro actually comes near
  5058. the beginning of |logo.mf|, just before the programs for the letters.)
  5059. \smallskip
  5060. \item\bull Finally there are special commands like ^@ligtable@ and
  5061. ^@font\_quad@, to define parameters of the font that are helpful
  5062. when typesetting.
  5063. \smallskip
  5064. \item\bull The file is accompanied by parameter files that define
  5065. ad hoc dimensions for different incarnations of the typeface.
  5066. \smallskip\noindent
  5067. We could make lots of different parameter files, which would produce
  5068. lots of different (but related) variations on the \MF\ logo; thus, |logo.mf|
  5069. defines a ``^{meta-font}'' in the sense of Chapter~1.
  5070. \dangerexercise What changes would be necessary to generalize the |logo|
  5071. routines so that the bar-line height is not always 45 per~cent of the
  5072. character height?
  5073. \answer Delete the line of |logo.mf| that defines |barheight#|, and
  5074. insert that line into each of the parameter files |logo10.mf|, |logo9.mf|,
  5075. |logo8.mf|. Then other bar-line heights are possible by providing new
  5076. parameter files; another degree of ``meta-ness'' has therefore been added
  5077. to the meta-font.
  5078. \danger ^{Assignments} (\thinspace`|:=|'\thinspace) have been used instead
  5079. of equations (\thinspace`|=|'\thinspace) in the parameter files |logo10.mf|,
  5080. |logo9.mf|, and |logo8.mf|, as well as
  5081. in the opening lines of |io.mf| in Chapter~5; this contradicts the
  5082. advice in Chapter~10, where we are told to stick to equations unless
  5083. assignments are absolutely necessary. The author has found it convenient
  5084. to develop the habit of using assignments whenever ad hoc dimensions
  5085. are being defined, because he often makes experimental files in which
  5086. the ad hoc dimensions are changed several times. For example, it's a good
  5087. idea to test a particular letter with respect to a variety of different
  5088. parameter settings when that letter is first being designed; such
  5089. experiments can be done easily by copying the ad hoc parameter definitions
  5090. from parameter files into a test file, provided that the parameters
  5091. have been defined with assignments instead of equations.
  5092. \danger \TeX\ users have found it convenient to have fonts in a series
  5093. of magnifications that form a geometric series. A font is said
  5094. to be scaled by `^{magstep}~1' if it has been magnified by~1.2;
  5095. it is scaled by `magstep~2' if it has been magnified by $1.2\times1.2=1.44$;
  5096. it is scaled by `magstep~3' if it has been magnified by $1.2\times1.2\times1.2=
  5097. 1.728$; and so on. Thus, if a job uses a font that is scaled by magstep~2,
  5098. and if that entire job is magnified by magstep~1, the font actually used
  5099. for printing will be scaled by magstep~3. The additive nature of magsteps
  5100. makes it more likely that fonts will exist at the desired sizes when
  5101. jobs are magnified. Plain \MF\ supports this convention by allowing
  5102. constructions like
  5103. \begintt
  5104. \mode=cheapo; mag=magstep 2; input logo9
  5105. \endtt
  5106. if you want to generate the 9-point \MF\ logo for the "cheapo" printer,
  5107. magnified by 1.44 (i.e., by magstep~2). You can also write `|magstep|~|0.5|'
  5108. ^^{TeX} for what \TeX\ calls `|\magstephalf|'; this magnifies by $\sqrt{1.2}$.
  5109. \ddanger The sharped forms of dimensions are actually represented by plain
  5110. \MF\ in terms of printer's points, so that `$"pt"\0$' turns out to be
  5111. equal to~1.  However, it is best for programmers not to make use of this
  5112. fact; a program ought to say, e.g., `$"em"\0:=10"pt"\0$', even though
  5113. the `$"pt"\0$' in this construction is redundant, and even though the
  5114. computer would run a few microseconds faster without it.
  5115. \ddangerexercise Suppose you want to simulate a low-resolution printer
  5116. on a high resolution device; for concreteness, let's say that
  5117. "luxo" is supposed to produce the output of "cheapo", with each black
  5118. "cheapo" pixel replaced by a $10\times10$ square of black "luxo" pixels.
  5119. Explain how to do this to the |logo10| font, by making appropriate
  5120. changes to |logo.mf|. Your output file should be called |cheaplogo10.2000gf|.
  5121. \answer (This is tricky.) \ Insert the lines
  5122. \begintt
  5123. if known pixmag: begingroup interim hppp:=pixmag*hppp;
  5124.  special "title cheapo simulation" endgroup;
  5125.  extra_endchar:="currentpicture:=currentpicture scaled pixmag;"
  5126.   & "w:=w*pixmag;" & extra_endchar; fi
  5127. \endtt
  5128. right after `|mode_setup|' in |logo.mf|, and also include the line
  5129. \begintt
  5130. if known pixmag: hppp:=pixmag*hppp; vppp:=pixmag*vppp; fi
  5131. \endtt
  5132. at the very end of that file. Then run \MF\ with
  5133. \begintt
  5134. \mode="cheapo"; input cheaplogo10
  5135. \endtt
  5136. where the file `|cheaplogo10.mf|' says simply `|pixmag=10;| |input| |logo10|'.
  5137. \ (The interim "hppp" setting and the ^@special@ command are
  5138. used to fool \MF\ into giving the appropriate extension to the
  5139. ^|gf| file name.  Incidentally, you could print with this font on "cheapo"
  5140. at ten-fold magnification if you told \TeX\ to use the font `|cheaplogo10|
  5141. |scaled| |10000|'; but on "luxo" you would simply call this font
  5142. `|cheaplogo10|'.)
  5143. \endchapter
  5144. A great Temptation must be withstood with great Resolution.
  5145. \author WILLIAM ^{BURKITT},  {\sl Expository Notes on the New Testament\/} %
  5146.  (c.\thinspace1700) % commenting on Matt 4:10
  5147.  % I examined only the fifth edition (1712), title page says `New-Testament'
  5148.  % Another edition printed at New Haven in 1794 says `should' not `must'!
  5149. \bigskip
  5150. What some invent, the rest enlarge.
  5151. \author JONATHAN ^{SWIFT},  {\sl Journal of a Modern Lady\/} (1729) % line 145
  5152. \eject
  5153. \beginchapter Chapter 12. Boxes
  5154. \looseness=-1
  5155. Let's pause now to take a closer look at the ``bounding boxes'' that enclose
  5156. individual characters. In olden days, metal type was cast on a
  5157. rectangular body in which each piece of type had the same vertical
  5158. extent, although the type widths would vary from character to character.
  5159. Nowadays we are free of the mechanical constraints imposed by metal type,
  5160. but the former metaphors are still useful: A~typesetting system like ^^{TeX}
  5161. \TeX\ imagines that each character fits into a rectangular box, and words are
  5162. typeset by putting such boxes snugly next to each other.
  5163. % Here are some macros borrowed from The TeXbook
  5164. \def\dolist{\afterassignment\dodolist\let\next= }%
  5165. \def\dodolist{\ifx\next\endlist \let\next\relax
  5166.   \else \\\let\next\dolist \fi
  5167.   \next}
  5168. \def\endlist{\endlist}
  5169. \def\\{\expandafter\if\space\next\ \else \setbox0=\hbox{\next}\maketypebox\fi}
  5170. \def\demobox#1{\setbox0=\hbox{\dolist#1\endlist}%
  5171.   \copy0\kern-\wd0\makelightbox}
  5172.  The main difference
  5173. between the old conventions and the new~ones is that type boxes are now
  5174. allowed to vary in height as well as in width. For example, when \TeX\
  5175. typesets `A~line~of~type.' it puts boxes together that essentially look
  5176. like this: `\thinspace\demobox{A line of type.}\thinspace'. \ (The `A'
  5177. appears in a box `\thinspace\setbox0\hbox{A}\maketypebox\thinspace' that
  5178. sits on a given baseline, while the `y' appears in a box
  5179. `\thinspace\setbox0\hbox{y}\maketypebox\thinspace' that descends below the
  5180. baseline.) \ \TeX\ never looks inside a box to see what character actually
  5181. appears there; \TeX's job is to put boxes together in the right places
  5182. on a page, based only on the box sizes. It is a typeface designer's job
  5183. to decide how big the boxes should be and to create the characters inside
  5184. the boxes.
  5185. Boxes are two-dimensional objects, but we ascribe three dimensions to them
  5186. because the vertical component is divided into two quantities, the
  5187. {\sl^{height}\/} (above the ^{baseline}) and the {\sl^{depth}\/}
  5188. (below the baseline). The horizontal dimension is, of course, called
  5189. the {\sl^{width}}. Here is a picture of a typical box, showing its
  5190. so-called ^{reference point} and baseline:
  5191. {\eightpoint
  5192. \setbox0=\hbox{$\uparrow$}
  5193. \setbox1=\hbox to \wd0{$\hss\mid\hss$} % with luck, they'll line up
  5194. \setbox2=\vbox{\copy0
  5195.   \nointerlineskip \kern-.5pt \copy1
  5196.   \nointerlineskip \kern-.5pt \copy1
  5197.   \moveleft 1em\hbox{height}
  5198.   \copy1 \nointerlineskip \kern-.5pt
  5199.   \copy1 \nointerlineskip \kern-.5pt
  5200.   \hbox{$\downarrow$}
  5201.   \kern.2pt}
  5202. \setbox3=\vbox{\kern.2pt\copy0
  5203.   \moveleft 1em\hbox{depth}
  5204.   \hbox{$\downarrow$}
  5205.   \kern0pt}
  5206. \setbox4=\vtop{\kern-3pt % this cancels the null text above the samplebox
  5207.   \hbox{\samplebox{\ht2}{\ht3}{6em}{}%
  5208.     \kern-6em
  5209.     \raise3pt\hbox to 6em{\hss Baseline\hss}}
  5210.   \kern3pt
  5211.   \arrows{6em}{width}}
  5212. \medskip\indent
  5213. \setbox0=\hbox{$\vcenter{}$}% \ht0 is the axis height
  5214. \lower\ht0\hbox{Reference point$-$\kern-.2em$\rightarrow$\kern2pt}%
  5215. \raise\ht2\box4
  5216. \kern1.5em
  5217. \raise\ht2\vtop{\kern0pt\box2\nointerlineskip\box3}}
  5218. \medskip\noindent
  5219. The example characters in previous chapters have all had zero depth, but
  5220. we will soon be seeing examples in which both height and depth are relevant.
  5221. A character shape need not fit inside the boundaries of its box. Indeed,
  5222. {\it italic\/} and {\sl slanted\/} letters are put into ordinary boxes
  5223. just as if they were not slanted, so they frequently stick out at the right.
  5224. For example, the letter `g\/' in the font you are now reading (^|cmr10|)
  5225. can be compared with the `{\sl g\/}' in the corresponding slanted
  5226. font (^|cmsl10|):
  5227. \begindisplay
  5228. \vbox to 40pt{\ifproofmode\hrule\vfill
  5229.   \hsize=2.5in \baselineskip 6pt \fiverm\noindent
  5230.   (A figure will be inserted here; too bad you can't see it now.
  5231.   It shows two g's, as claimed. In fact, the same figure appeared
  5232.   on page 63 of The TeXbook.)
  5233.   \vfill\hrule\fi}
  5234. \enddisplay
  5235. The slanted `{\sl g\/}' has been drawn as if its box were skewed right at the
  5236. top and left at the bottom, keeping the baseline fixed; but \TeX\ is told
  5237. in both cases that the box is $5\pt$ wide, $4.3055\pt$ high, and $1.9444\pt$
  5238. deep. Slanted letters will be spaced properly in spite of the fact that their
  5239. boxes have been straightened up, because the letters will match correctly
  5240. at the baseline.
  5241. \danger Boxes also have a fourth dimension called the {\sl^{italic
  5242. correction}}, which gives \TeX\ additional information about whether or
  5243. not a letter protrudes at the right. For example, the italic correction
  5244. for an unslanted `g\/' in |cmr10| is $0.1389\pt$, while the corresponding
  5245. slanted letter in |cmsl10| has an italic correction of $0.8565\pt$. The
  5246. italic correction is added to a box's width when math formulas like ${\rm
  5247. g}^2$ or ${\sl g}^2$ are being typeset, and also in other cases as
  5248. explained in {\sl The \TeX book}.
  5249. Plain \MF's ^@beginchar@ command establishes the width, height, and depth
  5250. of a box. These dimensions should be given in terms of ``^{sharped}''
  5251. quantities that do not vary with the resolution or magnification, because
  5252. the size of a character's type box should not depend in any way on the device
  5253. that will be used to output that character. It is important to be able to
  5254. define documents that will not change even though the technology for printing
  5255. those documents is continually evolving. \MF\ can be used to produce fonts for
  5256. new devices by introducing new ``modes,'' as we have seen in Chapter~11,
  5257. but the new fonts should still give the same box dimensions to each character.
  5258. Then the device-independent files output by \TeX\ will not have to be
  5259. changed in any way when they are printed or displayed with the help of
  5260. new equipment.
  5261. The three dimensions in a @beginchar@ command are given in reverse
  5262. alphabetical order: First comes the width, then the height, then the depth.
  5263. The @beginchar@ routine converts these quantities into pixel units
  5264. and assigns them to the three variables ^"w", ^"h", and~^"d". In fact,
  5265. @beginchar@ rounds these dimensions to the nearest whole number of
  5266. pixels; hence $w$, $h$, and~$d$ will always be integers.
  5267. \MF's pixels are like squares on ^{graph paper}, with pixel boundaries
  5268. at points with integer coordinates. The left edge of the type box lies
  5269. on the line $x=0$, and the right edge lies on the line $x=w$; we have
  5270. $y=h$ on the top edge and $y=-d$ on the bottom edge. There are $w$ pixels
  5271. in each row and $h+d$ in each column, so there are exactly $wh+wd$ pixels
  5272. inside the type box.
  5273. Since $w$, $h$, and $d$ are integers, they probably do not exactly match
  5274. the box dimensions that are assumed by device-independent typesetting
  5275. systems like \TeX. Some characters will be a fraction of a pixel too wide;
  5276. others will be a fraction of a pixel too narrow. However, it's still possible
  5277. to obtain satisfactory results if the pixel boxes are stacked together
  5278. based on their $w$ values and if the accumulated error is removed in the
  5279. spaces between words, provided that the box positions do not ^{drift}
  5280. too far away from their true device-independent locations. A designer should
  5281. strive to obtain letterforms that work well together when they are placed
  5282. together in boxes that are an integer number of pixels wide.
  5283. \ddanger You might not like the value of $w$ that @beginchar@ computes by
  5284. rounding the device-independent width to the nearest pixel boundary.
  5285. For example, you might want to make the letter~`m' one pixel wider, at
  5286. certain resolutions, so that its three stems are equally spaced or so that
  5287. it will go better with your `n'. In such a case you can assign a new value
  5288. to~$w$, at any time between @beginchar@ and ^@endchar@. This new value
  5289. will not affect the device-independent box width assumed by \TeX, but it
  5290. should be respected by the software that typesets ^|dvi| files using your font.
  5291. \def\hidecoords(#1,#2){\hbox to 0pt{\hss$\scriptstyle(#1,#2)$\hss}}
  5292. \setbox0=\vtop{\kern -94pt
  5293.   \rightline{\vbox{\hbox to 140\apspix{\hidecoords(0,h)\hfil
  5294.         \hidecoords(w\mkern-2mu,h)}
  5295.       \kern3pt
  5296.       \figbox{12a}{140\apspix}{360\apspix}\vbox
  5297.       \kern-3pt
  5298.       \hbox to 140\apspix{\hidecoords(0,-d)\hfil
  5299.         \hidecoords(w\mkern-2mu,-d)}}\quad}}
  5300. \dp0=0pt
  5301. Here's an example of a character that has nonzero width, height, and depth;
  5302. it's the left ^{parenthesis} in ^{Computer Modern} fonts like |cmr10|.
  5303. Computer Modern typefaces are generated by \MF\ programs that involve
  5304. lots of parameters, so this example also illustrates the principles of
  5305. ``^{meta-design}'': Many different varieties of left parentheses can be
  5306. drawn by this one program. But let's focus our attention first on the
  5307. comparatively simple way in which the box dimensions are established and
  5308. used, before looking into the details of how a meta-parenthesis has
  5309. actually been specified.
  5310. % "hair", "thin", "thick" are actually "vair", "hair", "stem" in the code
  5311. \def\xs(#1,#2){\{(z_{#1}-z_{#2})\,{\rm xscaled}\,3\}}%
  5312. \begindisplay
  5313. |"Left parenthesis"|;\cr
  5314. @numeric@ $"ht"\0$, $"dp"\0$;\cr
  5315. $"ht"\0="body\_height"\0$; \ $.5["ht"\0,-"dp"\0]="axis"\0$;\cr
  5316. @beginchar@\kern1pt(|"("|$,7u\0,"ht"\0,"dp"\0)$;\cr
  5317. @italcorr@ $"ht"\0\ast"slant"-.5u\0$;\cr
  5318. @pickup@ "fine.nib";\cr
  5319. $\penpos1("hair"-"fine",0)$;\strut\vadjust{\box0}\cr
  5320. $\penpos2(.75["thin","thick"]-"fine",0)$;\cr
  5321. $\penpos3("hair"-"fine",0)$;\cr
  5322. $\mathop{"rt"}x_{1r}=\mathop{"rt"}x_{3r}= w-u$; \
  5323.  $\mathop{"lft"}x_{2l}=x_1-4u$;\cr
  5324. $\mathop{"top"}y_1=h$; \
  5325.  $y_2=.5[y_1,y_3]="axis"$;\cr
  5326. @filldraw@ $z_{1l}\xs(2l,1l)\ldots z_{2l}$\cr
  5327. \qquad$\ldots\xs(3l,2l)z_{3l}$\cr
  5328. \qquad$\dashto z_{3r}\xs(2r,3r)\ldots z_{2r}$\cr
  5329. \qquad$\ldots\xs(1r,2r)z_{1r}\dashto\cycle$;\cr
  5330. @penlabels@$(1,2,3)$; \ @endchar@;\cr
  5331. \enddisplay
  5332. The width of this left parenthesis is $7u\0$, where $u\0$
  5333. is an ad hoc parameter that figures in all the widths of the Computer
  5334. Modern characters. The height and depth have been calculated in such a way
  5335. that the top and bottom of the bounding box are equally distant from an
  5336. imaginary line called the {\sl^{axis}}, which is important in mathematical
  5337. typesetting. \ (For example, \TeX\ puts the bar line at the axis
  5338. in fractions like $1\over2$; many symbols like `$+$' and `$=$', as well as
  5339. parentheses, are centered on the axis line.) \ Our example program puts the
  5340. axis midway between the top and bottom of the type by saying that
  5341. `$.5["ht"\0,-"dp"\0]="axis"\0$'.  We also place the top at position
  5342. `$"ht"\0="body\_height"\0$'\thinspace; here $"body\_height"\0$ is the
  5343. height of the tallest characters in the entire typeface.
  5344. It turns out that $"body\_height"\0$ is exactly $7.5"pt"\0$ in |cmr10|, and
  5345. $"axis"\0=2.5"pt"\0$; hence $"dp"\0=2.5"pt"\0$,
  5346. and the parenthesis is exactly $10\pt$ tall.
  5347. The program for `(' uses a ^@filldraw@ command, which we haven't
  5348. seen before in this book; it's basically a combination of @fill@
  5349. and @draw@, where the filling is done with the currently-picked-up pen.
  5350. Some of the Computer Modern fonts have characters with ``^{soft}'' edges
  5351. while others have ``^{crisp}'' edges; the difference is due to the pen that
  5352. is used to @filldraw@ the shapes. This pen is a circle whose diameter
  5353. is called ^"fine"; when "fine" is fairly large, @filldraw@ will produce
  5354. rounded corners, but when $"fine"=0$ (as it is in |cmr10|) the corners
  5355. will be sharp.
  5356. % (actually it isn't zero in cmr10, but this makes a better example)
  5357. The statement `$\penpos1("hair"-"fine",0)$' makes the breadth of a
  5358. simulated broad-edge pen equal to $"hair"-"fine"$ at position~1; i.e.,
  5359. the distance between $z_{1l}$ and $z_{1r}$ will be $"hair"-"fine"$.
  5360. We will be filling a region between $z_{1l}$ and $z_{1r}$ with a
  5361. circle-shaped pen nib whose diameter is "fine"; the center of that
  5362. nib will pass through $z_{1l}$ and $z_{1r}$, hence the pen will
  5363. effectively add ${1\over2}"fine"$ to the breadth of the stroke at
  5364. either side. The overall breadth at position~1 will therefore be
  5365. ${1\over2}"fine"+("hair"-"fine")+{1\over2}"fine"\;=\;"hair"$.
  5366. (Computer Modern's ``^{hairline} thickness'' parameter, which governs
  5367. the breadth of the thinnest strokes, is called "hair".) \ Similarly,
  5368. the statement `$\penpos2(.75["thin","thick"]-"fine",0)$'  makes the
  5369. overall breadth of the pen at position~2 equal to $.75["thin","thick"]$,
  5370. which is $3\over4$ of the way between two other parameters that govern
  5371. stroke breadths in Computer Modern routines.  If "fine" is increased while
  5372. "hair", "thin", and "thick" stay the same, the effect will simply be to
  5373. produce more rounded corners at positions 1 and~3, with little or no effect
  5374. on the rest of the shape, provided that "fine" doesn't get so large
  5375. that it exceeds "hair".
  5376. \def\paren #1 #2 #3 #4 #5 #6 #7 #8 #9
  5377. {\vbox{\dimen0=#3\apspix \hsize=7\dimen0
  5378.     \centerline{\tt#1}
  5379.     \medskip \kern3pt \kern270\apspix \kern-#4\apspix
  5380.     \dimen2=#4\apspix \advance\dimen2 by -#5\apspix
  5381.     \figbox{#2}{7\dimen0}{2\dimen2}\vbox
  5382.     \kern-2\dimen2 \kern#4\apspix \kern90\apspix \kern-3pt \medskip
  5383.     \tabskip 0pt plus 1fil
  5384.     \halign to\hsize{$##$\cr
  5385.       u=\hfil#3\cr
  5386.       "ht"=\hfil#4\cr
  5387.       "axis"=\hfil#5\cr
  5388.       "fine"=\hfil#6\cr
  5389.       "hair"=\hfil#7\cr
  5390.       "thin"=\hfil#8\cr
  5391.       "thick"=\hfil#9\cr}}}
  5392. Here, for example, are five different left parentheses, drawn by our example
  5393. program with various settings of the parameters:
  5394. $$\line{\paren cmr10 12a 20 270 90 0 8 9 25
  5395.   \hfil\paren cmbx10 12b 23 270 90 0 13 17 41
  5396.   \hfil\paren cmvtt10 12c 21 250 110 22 22 25 25
  5397.   \hfil\paren cmssdc10 12d 19 270 95 8 23 40 40
  5398.   \hfil\paren cmti10 12e 18.4 270 90 7 8 11 23 }$$
  5399. Parameter values are shown here in ^"proof"\kern-1pt\ mode pixel units,
  5400. 36 to the point. \ (Thus, for example, the value of $u\0$ in |cmr10| is
  5401. ${20\over36}"pt"\0$.) \ Since |cmbx10| is a ``bold extended'' font,
  5402. its unit width~$u$ is slightly larger than the unit width of |cmr10|,
  5403. and its pen widths (especially "thick") are significantly larger.
  5404. The ``variable-width typewriter'' font |cmvtt10| has soft edges and
  5405. strokes of almost uniform thickness, because "fine" and "hair" are almost
  5406. as large as "thin" and "thick". This font also has a raised axis and a smaller
  5407. height. An intermediate situation occurs in |cmssdc10|, a ``sans serif
  5408. demibold condensed'' font that is similar to the type used in the chapter titles
  5409. of this book; $"thick"="thin"$ in this font, but hairlines are noticeably
  5410. thinner, and "fine" provides slightly rounded corners. The ``text italic''
  5411. font |cmti10| has rounded ends, and the character shape has been ^{slanted}
  5412. by .25; this means that each point $(x,y)$ has been moved to position
  5413. $(x+.25y,y)$, in the path that is filled by @filldraw@.
  5414. \danger The vertical line just to the right of the italic left parenthesis
  5415. shows the ^{italic correction} of that character, i.e., the fourth box
  5416. dimension mentioned earlier. This quantity was defined by the statement
  5417. `^@italcorr@ $"ht"\0\ast"slant"-.5u\0$' in our program; here ^"slant" is
  5418. a parameter of Computer Modern that is zero in all the unslanted fonts,
  5419. but $"slant"=.25$ in the case of |cmti10|. The expression following
  5420. @italcorr@ should always be given in sharped units. If the value is
  5421. negative, the italic correction will be zero; otherwise the italic
  5422. correction will be the stated amount.
  5423. \danger The author has obtained satisfactory results by making the italic
  5424. correction roughly equal to $.5u$ plus the maximum amount by which the
  5425. character sticks out to the right of its box. For example, the top right
  5426. end of the left parenthesis will be nearly at position $(w-u,"ht")$ before
  5427. slanting, so its $x$~coordinate after slanting will be $w-u+"ht"\ast"slant"$;
  5428. this will be the rightmost point of the
  5429. character, if we assume that $"slant"\ge0$. Adding $.5u$, subtracting~$w$,
  5430. and rewriting in terms of sharped units gives the stated formula. Notice
  5431. that when $"slant"=0$ the statement reduces to `@italcorr@ $-.5u\0$';
  5432. this means that unslanted left parentheses will have an italic correction
  5433. of zero.
  5434. \dangerexercise Write a program for right parentheses, to go with these
  5435. left parentheses.
  5436. \answer The changes are straightforward, except for the italic correction
  5437. (for which a rough estimate like the one shown here is good enough):
  5438. \def\xs(#1,#2){\{(z_{#1}-z_{#2})\,{\rm xscaled}\,3\}}%
  5439. \begindisplay
  5440. |"Right parenthesis"|;\cr
  5441. @numeric@ $"ht"\0,"dp"\0$; \
  5442.  $"ht"\0="body\_height"\0$; \
  5443.  $.5["ht"\0,-"dp"\0]="axis"\0$;\cr
  5444. @beginchar@\kern1pt(|")"|$,7u\0,"ht"\0,"dp"\0)$;
  5445.  \ @italcorr@ $"axis"\0\ast"slant"-.5u\0$;\cr
  5446. @pickup@ "fine.nib"; \ $\penpos1("hair"-"fine",0)$;\cr
  5447. $\penpos2(.75["thin","thick"]-"fine",0)$; \ $\penpos3("hair"-"fine",0)$;\cr
  5448. $\mathop{"lft"}x_{1l}=\mathop{"lft"}x_{3l}=u$; \
  5449.  $\mathop{"rt"}x_{2r}=x_1+4u$; \
  5450. $\mathop{"top"}y_1=h$; \
  5451.  $y_2=.5[y_1,y_3]="axis"$;\cr
  5452. @filldraw@ $z_{1l}\xs(2l,1l)\ldots z_{2l}\ldots\xs(3l,2l)z_{3l}$\cr
  5453. \qquad$\dashto z_{3r}\xs(2r,3r)
  5454.  \ldots z_{2r}\ldots\xs(1r,2r)z_{1r}\dashto\cycle$;\cr
  5455. @penlabels@$(1,2,3)$; \ @endchar@;\cr
  5456. \enddisplay
  5457. We will see in Chapter 15 that it's possible to guarantee perfect symmetry
  5458. between left and right parentheses by using picture transformations.
  5459. The reader should bear in mind that the conventions of plain \MF\ and of
  5460. Computer Modern are not hardwired into the \MF\ language; they are merely
  5461. examples of how a person might use the system, and other typefaces may well
  5462. be better served by quite different approaches. Our program for left
  5463. parentheses makes use of @beginchar@, @endchar@, @italcorr@, @penlabels@,
  5464. @pickup@, "penpos", "lft", "rt", "top", "z", and @filldraw@, all of which
  5465. are defined somewhat arbitrarily in Appendix~B as part of the plain base;
  5466. it also uses the quantities "u", "body\_height", "axis", "fine", "hair",
  5467. "thin", "thick", and "slant", all of which are arbitrary parameters that
  5468. the author decided to introduce in his programs for Computer Modern. Once
  5469. you understand how to use arbitrary conventions like these, you will be
  5470. able to modify them to suit your own purposes.
  5471. \exercise (For people who know \TeX.) \ It's fairly clear that the width of
  5472. a type box is important for typesetting, but what use does \TeX\ make of
  5473. the height and depth?
  5474. \answer When horizontal lines are being typeset, \TeX\ keeps track of the
  5475. maximum height and maximum depth of all boxes on the line; this determines
  5476. whether or not extra space is needed between baselines. The height and depth
  5477. are also used to position an accent above or below a character, and to
  5478. place symbols in mathematical formulas. Sometimes
  5479. boxes are also stacked~up vertically, in which case their heights and depths
  5480. are just as important as their widths are for horizontal setting.
  5481. \ddanger The primitive commands by which \MF\ actually learns the dimensions
  5482. of each box are rarely used directly, since they are intended to be embedded
  5483. in higher-level commands like @beginchar@ and @italcorr@. But if you must
  5484. know how things are done at the low level, here is the secret: There are
  5485. four internal quantities called ^"charwd", ^"charht", ^"chardp", and ^"charic",
  5486. whose values at the time of every ^@shipout@ command are assumed to be the
  5487. box dimensions for the character being shipped out, in units of printer's
  5488. points. \ (See
  5489. the definitions of @beginchar@ and @italcorr@ in Appendix~B for examples
  5490. of how these quantities can be manipulated.)
  5491. \ninepoint % all dangerous from here on
  5492. \ddanger Besides "charwd" and its cousins, \MF\ also has four other
  5493. internal variables whose values are recorded at the time of every
  5494. @shipout@:\enddanger
  5495. \smallskip\textindent\bull^"charcode" is rounded to the nearest integer
  5496. and then converted to a number between 0 and~255, by adding or subtracting
  5497. multiples of~256 if necessary; this ``$c$~code'' is the ^{location} of the
  5498. ^^{c code} character within its font.
  5499. \smallskip\textindent\bull^"charext" is rounded to the nearest integer;
  5500. the resulting number is a secondary code that can be used to distinguish
  5501. between two or more characters with equal $c$ codes. \ (\TeX\ ignores
  5502. "charext" and assumes that each font contains at most 256 characters; but
  5503. extensions to \TeX\ for ^{oriental} languages can use "charext" to handle
  5504. much larger fonts.)
  5505. \smallskip\textindent\bull^"chardx" and "chardy" represent horizontal and
  5506. vertical {\sl escapement\/} in units of pixels. \ (Some typesetting
  5507. systems use both of these device-dependent amounts to change their current
  5508. position on a page, just after typesetting each character. Other systems,
  5509. like the ^|dvi| software associated with \TeX, assume that $"chardy"=0$
  5510. but use "chardx" as the horizontal escapement whenever a horizontal
  5511. movement by "chardx" does not cause the subsequent position to ^{drift}
  5512. too far from the device-independent position defined by accumulated
  5513. "charwd" values. Plain \MF's @endchar@ routine keeps $"chardy"=0$, but
  5514. sets $"chardx":=w$ just before shipping a character to the output.  This
  5515. explains why a change to~^"w" will affect the spacing between adjacent
  5516. letters, as discussed earlier.) \looseness=-1
  5517. \ddanger Two characters with the same $c$ code
  5518. should have the same box dimensions and escapements; otherwise
  5519. the second character will override the specifications of the first. The boolean
  5520. expression `^{charexists}~$c$' can be used to determine whether or not
  5521. a character with a particular $c$~code has already been shipped out.
  5522. \danger Let's conclude this chapter by contemplating a \MF\ program that
  5523. generates the ``^{dangerous bend}'' symbol, since that symbol appears so
  5524. often in this book. It's a custom-made character intended to be used only at
  5525. the very beginnings of paragraphs in which the baselines of the text are
  5526. exactly $11\pt$ apart. Therefore it extends below its baseline by $11\pt$;
  5527. but it is put into a box of depth zero, because \TeX\ would otherwise
  5528. think that the first line of the paragraph contains an extremely deep
  5529. character, and such depth would cause the second line to be moved down.
  5530. $$\def\comment{\hfill{\tt\%} }
  5531. \halign{\hbox to\hsize{\indent#\hfil}\cr
  5532. $"baselinedistance"\0:=11"pt"\0$; \ ^@define\_pixels@("baselinedistance");\cr
  5533. $"heavyline"\0:=50/36"pt"\0$; \ ^@define\_blacker\_pixels@("heavyline");\cr
  5534. $@beginchar@\kern1pt(127,25u\0,"h\_height"\0+"border"\0,0)$; \
  5535.  |"Dangerous bend symbol"|;\cr
  5536. \pickup @pencircle@ scaled "rulethickness";
  5537.  \ $\mathop{"top"}y_1={25\over27}h$; \ $\mathop{"lft"}x_4=0$;\cr
  5538. $x_1+x_1=x_{1a}+x_{1b}=x_{4b}+x_{2a}=x_4+x_2=x_{4a}+x_{2b}=x_{3b}+x_{3a}=
  5539.  x_3+x_3=w$;\cr
  5540. $x_{4a}=x_{4b}=x_4+u$; \ $x_{3b}=x_{1a}=x_1-2u$;\cr
  5541. $y_4+y_4=y_{4a}+y_{4b}=y_{3b}+y_{1a}=y_3+y_1=y_{3a}+y_{1b}=y_{2b}+y_{2a}=
  5542.  y_2+y_2=0$;\cr
  5543. $y_{1a}=y_{1b}=y_1-{2\over27}h$; \ $y_{4b}=y_{2a}=
  5544.  y_4+{4\over27}h$;\cr
  5545. @draw@ $z_{1a}\to z_1\to z_{1b}\ddashto z_{2a}\to z_2\to z_{2b}\ddashto$\cr
  5546. \indent $z_{3a}\to z_3\to z_{3b}\ddashto z_{4a}\to z_4\to z_{4b}
  5547.  \ddashto \rm cycle$;\comment the signboard\cr
  5548. $x_{10}=x_{11}=x_{12}=x_{13}=.5w-u$;
  5549.  \ $x_{14}=x_{15}=x_{16}=x_{17}=w-x_{10}$;\cr
  5550. $y_{10}=y_{14}={28\over27}h$; \ $\mathop{"bot"}y_{13}=-"baselinedistance"$;\cr
  5551. $z_{11}=(z_{10}\to z_{13})\;{\rm intersectionpoint}\;
  5552.  (z_{1a}\{z_{1a}-z_{4b}\}\to z_1\{"right"\})$;\cr
  5553. $y_{15}=y_{11}$; \ $y_{16}=y_{12}=-y_{11}$; \ $y_{17}=y_{20}=y_{21}=y_{13}$;\cr
  5554. @draw@ $z_{11}\dashto z_{10}\dashto z_{14}\dashto z_{15}$;
  5555.  @draw@ $z_{12}\dashto z_{13}$;
  5556.  @draw@ $z_{16}\dashto z_{17}$; \comment the signpost\cr
  5557. $x_{20}=w-x_{21}$; \ $x_{21}-x_{20}=16u$;
  5558.  \ @draw@ $z_{20}\dashto z_{21}$; \comment ground level\cr
  5559. $x_{36}=w-x_{31}$; \ $x_{36}-x_{31}=8u$;
  5560.  \ $x_{32}=x_{33}=x_{36}$; \ $x_{31}=x_{34}=x_{35}$;\cr
  5561. $y_{31}=-y_{36}={12\over27}h$; \ $y_{32}=-y_{35}={9\over27}h$;
  5562.  \ $y_{33}=-y_{34}={3\over27}h$;\cr
  5563. \pickup @pencircle@ scaled "heavyline";\cr
  5564. @draw@ $z_{32}\{z_{32}-z_{31}\}\to z_{33}\ddashto
  5565.   z_{34}\to z_{35}\{z_{36}-z_{35}\}$;
  5566.  \comment the dangerous bend\cr
  5567. \pickup ^@penrazor@ xscaled "heavyline"
  5568.   ^{rotated} (^{angle}$(z_{32}-z_{31})+90$);\cr
  5569. @draw@ $z_{31}\dashto z_{32}$;
  5570.  \ @draw@ $z_{35}\dashto z_{36}$; \comment upper and lower bars\cr
  5571. ^@labels@$(1a,1b,2a,2b,3a,3b,4a,4b,@range@ 1 @thru@ 36)$;^^@range@^^@thru@\cr
  5572. \setbox0=\vtop{\kern -5pt
  5573.   \figbox{12f}{500\apspix}{4.2in}\vbox}
  5574. \dp0=0pt
  5575. \vskip 18pt
  5576. {\tolerance=2000 \hbadness=2000 \spaceskip=.3333em plus .25em minus .12em
  5577. \hangindent 515\apspix
  5578. \noindent\hbox to 515\apspix{\box0\hfil}%
  5579. This program has several noteworthy points of~interest:
  5580. (1)~The first parameter to ^@beginchar@ here is 127, not a
  5581. string; this puts the character into font ^{location}~127. \ (2)~A sequence
  5582. of equations like `$a=w-b$; $a'=w-b'$' can conveniently be shortened to
  5583. `$a+b=a'+b'=w$'. \ (3)~Three hyphens `$\ddashto$' is an abbreviation for a
  5584. line with ``infinite'' tension, ^^{---} i.e., an almost straight line that
  5585. connects smoothly to its curved neighbors. \ (4)~An `intersectionpoint'
  5586. operation finds out where ^^{intersectionpoint}
  5587. two paths cross; we'll learn more about this in Chapter~14.\par}
  5588. \endchapter
  5589. Well, we are in the same box.
  5590. \author RIDER ^{HAGGARD},  {\sl Dawn\/} (1884) % beginning of chapter 47
  5591. \bigskip
  5592. A story, too,
  5593. may be boxed.
  5594. \author DOROTHY ^{COLBURN},  {\sl Newspaper Nomenclature\/} (1927)
  5595.  % American Speech v2 Feb 27 p240
  5596. \eject
  5597. \beginchapter Chapter 13. Drawing, Filling,\\and Erasing
  5598. The pictures that \MF\ produces are made up of tiny pixels that are either
  5599. ``on'' or ``off''; therefore you might imagine that the computer works
  5600. behind the scenes with some sort of ^{graph paper}, and that it darkens some
  5601. of the squares whenever you tell it to @draw@ a line or to @fill@ a region.
  5602. \newdimen\tinypix \setbox0=\hbox{\sixrm0} \tinypix=5pt
  5603. \newdimen\pixcorr \pixcorr=\tinypix \advance\pixcorr by-\wd0
  5604. \def\spread#1{\if#1!\let\next\relax\else#1\kern\pixcorr\let\next\spread\fi
  5605.   \next}
  5606. \def\beginpixdisplay{$$\advance\abovedisplayskip by 2pt
  5607.   \advance\belowdisplayskip by-2pt
  5608.   \baselineskip=\tinypix
  5609.   \halign\bgroup\sixrm\indent\spread##!\hfil\cr}
  5610. \MF's internal graph paper is actually more sophisticated than this.
  5611. Pixels aren't simply ``on'' or ``off'' when \MF\ is working on a picture;
  5612. they can be ``doubly on'' or ``triply off.'' Each pixel contains a
  5613. small {\sl integer\/} value, and when a character is finally shipped out
  5614. to a font the black pixels are those whose value is greater than zero.
  5615. For example, the two commands
  5616. \begindisplay
  5617. ^@fill@ $(0,3)\dashto(9,3)\dashto(9,6)\dashto(0,6)\dashto\cycle$;\cr
  5618. @fill@ $(3,0)\dashto(3,9)\dashto(6,9)\dashto(6,0)\dashto\cycle$
  5619. \enddisplay
  5620. yield the following $9\times9$ pattern of pixel values:
  5621. \beginpixdisplay
  5622. 000111000\cr
  5623. 000111000\cr
  5624. 000111000\cr
  5625. 111222111\cr
  5626. 111222111\cr
  5627. 111222111\cr
  5628. 000111000\cr
  5629. 000111000\cr
  5630. 000111000\cr
  5631. \enddisplay
  5632. Pixels that have been filled twice now have a value of 2.
  5633. When a simple region is ``filled,'' its pixel values are all increased by~1;
  5634. when it is ``unfilled,'' they are all decreased by~1. The command
  5635. \begindisplay
  5636. ^@unfill@ $(1,4)\dashto(8,4)\dashto(8,5)\dashto(1,5)\dashto\cycle$
  5637. \enddisplay
  5638. will therefore change the pattern above to
  5639. \beginpixdisplay
  5640. 000111000\cr
  5641. 000111000\cr
  5642. 000111000\cr
  5643. 111222111\cr
  5644. 100111001\cr
  5645. 111222111\cr
  5646. 000111000\cr
  5647. 000111000\cr
  5648. 000111000\cr
  5649. \enddisplay
  5650. The pixels in the center have not been erased (i.e., they will still be
  5651. black if this picture is output to a font), because they still have a
  5652. positive value.
  5653. Incidentally, this example illustrates the fact that the edges between
  5654. \MF's pixels are lines that have integer ^{coordinates}, just as the
  5655. squares on graph paper do. For example, the lower left `{\sixrm0}' in
  5656. the $9\times9$ array above corresponds to the pixel whose boundary is
  5657. `$(0,0)\dashto(1,0)\dashto(1,1)\dashto(0,1)\dashto\cycle$'. The $(x,y)$
  5658. coordinates of the points inside this pixel lie between 0 and~1.
  5659. \exercise What are the $(x,y)$ coordinates of the four corners of the
  5660. {\sl middle\/} pixel in the $9\times9$ array?
  5661. \answer $(4,4)$, $(4,5)$, $(5,5)$, $(5,4)$. \ (Therefore the command
  5662. \begindisplay
  5663. @unfill@ $(4,4)\dashto(4,5)\dashto(5,5)\dashto(5,4)\dashto\cycle$
  5664. \enddisplay
  5665. will decrease the value of this pixel by 1.)
  5666. \exercise What picture would have been obtained if the @unfill@ command
  5667. had been given {\sl before\/} the two @fill@ commands in the examples
  5668. above?
  5669. \answer The result would be exactly the same; @fill@ and @unfill@ commands
  5670. can be given in any order. \ (After an initial @unfill@ command, some
  5671. pixel values will be $-1$, the others will be zero.)
  5672. \exercise Devise an @unfill@ command that will produce the pixel values
  5673. \beginpixdisplay
  5674. 000111000\cr
  5675. 000101000\cr
  5676. 000101000\cr
  5677. 111212111\cr
  5678. 100101001\cr
  5679. 111212111\cr
  5680. 000101000\cr
  5681. 000101000\cr
  5682. 000111000\cr
  5683. \enddisplay
  5684. when it is used just after the @fill@ and @unfill@ commands already given.
  5685. \answer @unfill@ $(4,1)\dashto(4,8)\dashto(5,8)\dashto(5,1)\dashto\cycle$.
  5686. A ``simple'' region is one whose boundary does not intersect itself; more
  5687. complicated effects occur when the boundary lines cross. For example,
  5688. \begindisplay
  5689. @fill@ $(0,1)\dashto(9,1)\dashto(9,4)\dashto(4,4)\dashto$\cr
  5690. \indent$(4,0)\dashto(6,0)\dashto
  5691.  (6,3)\dashto(8,3)\dashto(8,2)\dashto(0,2)\dashto\cycle$\cr
  5692. \enddisplay
  5693. produces the pixel pattern
  5694. \beginpixdisplay
  5695. 000011111\cr
  5696. 000011001\cr
  5697. 111122111\cr
  5698. 000011000\cr
  5699. \enddisplay
  5700. Notice that some pixels receive the value 2, because they're ``^{doubly
  5701. filled}.'' There's also a ``^{hole}'' where the pixel values remain zero,
  5702. even though they are surrounded by filled pixels; the pixels in that hole
  5703. are not considered to be in the region, but the doubly filled pixels
  5704. are considered to be in the region twice.
  5705. \exercise Show that the first $9\times9$ cross pattern on the previous
  5706. page can be generated by a single @fill@ command. \ (The nine pixel
  5707. values in the center should be~2, as if two separate regions had been
  5708. filled, even though you are doing only one @fill@.)
  5709. \answer Here are two of the many solutions:
  5710. \begindisplay
  5711. @fill@ $(0,3)\dashto(9,3)\dashto(9,6)\dashto(6,6)\dashto(6,9)\dashto$\cr
  5712. \indent $(3,9)\dashto(3,0)\dashto(6,0)\dashto(6,6)\dashto(0,6)\dashto\cycle$;\cr
  5713. @fill@ $(0,3)\dashto(9,3)\dashto(9,6)\dashto(0,6)\dashto(0,3)\dashto$\cr
  5714. \indent $(3,3)\dashto(3,0)\dashto(6,0)\dashto(6,9)\dashto(3,9)\dashto
  5715.   (3,3)\dashto\cycle$.\cr
  5716. \enddisplay
  5717. (It turns out that {\sl any\/} pixel pattern can be obtained by a single,
  5718. sufficiently hairy @fill@ command. But unnatural commands are usually also
  5719. inefficient and unreadable.)
  5720. \exercise What do you think is the result of `@fill@ $(0,0)\dashto(1,0)\dashto
  5721. (1,1)\dashto(0,1)\dashto(0,0)\dashto(1,0)\dashto(1,1)\dashto(0,1)\dashto
  5722. \cycle$'\thinspace?
  5723. \answer The value of the enclosed pixel is increased by 2. \ (We'll see later
  5724. that there's a simpler way to do this.)
  5725. A @fill@ command can produce even stranger effects when its boundary lines
  5726. cross in only one place. If you say, for example,
  5727. \begindisplay
  5728. @fill@ $(0,2)\dashto(4,2)\dashto(4,4)\dashto(2,4)\dashto(2,0)
  5729.  \dashto(0,0)\dashto\cycle$
  5730. \enddisplay
  5731. \MF\ will produce the $4\times4$ pattern
  5732. \setbox0=\hbox to\tinypix{\hss
  5733.   $\scriptscriptstyle{\hbox to3pt{}\over}$\hss\kern\pixcorr}
  5734. \dp0=0pt
  5735. \beginpixdisplay
  5736. 0011\cr
  5737. 0011\cr
  5738. !\copy0\copy0 \spread00\cr
  5739. !\copy0\copy0 \spread00\cr
  5740. \enddisplay
  5741. where `$\hbox to3pt{}\over$' stands for the value $-1$. Furthermore the
  5742. machine will report that you have a ``^{strange path}'' whose ``^{turning
  5743. number}'' is zero!  What does this mean? Basically, it means that your
  5744. path loops around on itself something like a figure~8; this causes a
  5745. breakdown in \MF's usual rules for distinguishing the ``inside'' and
  5746. ``outside'' of a curve.
  5747. \danger Every cyclic path has a {\sl turning number\/} that can be understood
  5748. as follows. Imagine that you are driving a car along the path and that you
  5749. have a digital compass that tells in what direction you're heading. For
  5750. example, if the path is
  5751. \begindisplay
  5752. $(0,0)\dashto(2,0)\dashto(2,2)\dashto(0,2)\dashto\cycle$
  5753. \enddisplay
  5754. you begin driving in direction $0^\circ$, then you make four left turns.
  5755. After the first turn, your compass heading is $90^\circ$; after the
  5756. second, it is $180^\circ$; and after the third it is $270^\circ$. \ (The
  5757. compass direction increases when you turn left and decreases when you turn
  5758. right; therefore it now reads $270^\circ$, not $-90^\circ$.) \ At the
  5759. end of this cycle the compass will read $360^\circ$, and if you go around
  5760. again the reading will be $720^\circ$. Similarly, if you had traversed the
  5761. \begindisplay
  5762. $(0,0)\dashto(0,2)\dashto(2,2)\dashto(2,0)\dashto\cycle$
  5763. \enddisplay
  5764. (which is essentially the same, but in the opposite direction), your compass
  5765. heading would have started at $90^\circ$ and ended at $-270^\circ$;
  5766. in this case each circuit would have {\sl decreased\/} the reading
  5767. by~$360^\circ$. It is clear that a drive around any cyclic path will
  5768. change the compass heading by some multiple of~$360^\circ$, since you
  5769. end in the same direction you started. The turning number of a path is
  5770. defined to be $t$ if the compass heading changes by exactly $t$~times
  5771. $360^\circ$ when the path is traversed. Thus, the two example cycles we have
  5772. just discussed have turning numbers of $+1$ and $-1$, respectively; and
  5773. the ``strange path'' on the previous page that produced both positive and
  5774. negative pixel values does indeed have a turning number of~0.
  5775. \danger Here's how \MF\ actually implements a @fill@ command, assuming that
  5776. the cyclic path being filled has a {\sl positive\/} turning number:
  5777. The path is first ``^{digitized},'' if necessary, so that it lies entirely on
  5778. the edges of pixels; in other words, it is distorted slightly so that it
  5779. is confined to the lines between pixels on graph paper. \ (Our examples so
  5780. far in this chapter have not needed any such adjustments.) \ Then each
  5781. individual pixel value is increased by~$j$ and decreased by~$k$ if an
  5782. infinite horizontal line to the left of that pixel intersects the
  5783. digitized path $j$~times when the path is traveling downward and $k$~times
  5784. when it is traveling upward. For example, let's look more closely at the
  5785. non-simple path on the previous page that enclosed a hole:
  5786. $$\def\\#1{\hbox to 11pt{\hss$#1$\hss}}
  5787. \def\up{\hbox to0pt{\hss\lower3pt\vbox to 11pt{
  5788.       \hbox{\tenex\char'77}\vss\hbox{\tenex\char'170}\kern0pt}\hss}}
  5789. \def\down{\hbox to0pt{\hss\lower3pt\vbox to 11pt{
  5790.       \hbox{\tenex\char'171}\vss\hbox{\tenex\char'77}\kern0pt}\hss}}
  5791. \def\under{\smash{\rlap{\lower3.2pt\vbox{\hrule width 11pt}}}}
  5792. \def\over{\smash{\rlap{\raise7.8pt\vbox{\hrule width 11pt}}}}
  5793. \halign{\indent#\cr
  5794. \\a\\a\\a\\a\over\down\\b\over\\b\over\under\\b\over\under\\b\over\\b\up\cr
  5795. \under\\a\under\\a\under\\a\under\\a\down\under\\b\under\\b\up
  5796.  \under\\c\under\\c\down\\d\up\cr
  5797. \down\under\\e\under\\e\under\\e\under\\e\down\under\\f\under\\f\up
  5798.  \under\\g\under\\g\under\\g\up\cr
  5799. \\a\\a\\a\\a\down\under\\b\under\\b\up\\h\\h\\h\cr}$$
  5800. Pixel $d$ has $j=2$ descending edges and $k=1$ ascending edges to its left,
  5801. so its net value increases by $j-k=1$; pixels~$g$ are similar.
  5802. Pixels~$c$ have $j=k=1$, so they lie in a ``hole'' that is unfilled;
  5803. pixels~$f$ have $j=2$ and $k=0$, so they are doubly filled. This rule
  5804. works because, intuitively, the inside of a region lies at the {\sl left\/}
  5805. of a path whose turning number is positive.
  5806. \dangerexercise True or false: When the turning number of a cyclic path is
  5807. positive, a @fill@ command increases each individual pixel value by $l-m$,
  5808. if an infinite horizontal line to the {\sl right\/} of that pixel intersects
  5809. the digitized path $l$~times when the path is traveling upward and $m$~times
  5810. when it is traveling downward. \ (For example, pixels~$e$ have $l=2$ and
  5811. $m=1$; pixels~$c$ have $l=m=1$.)
  5812. \answer True; $j-k=l-m$, since $k+l=j+m$. \ (What comes up must go down.)
  5813. \danger When the turning number is negative, a similar rule applies,
  5814. except that the pixel values are {\sl decreased\/} by~$j$ and {\sl
  5815. increased\/} by~$k$; in this case the inside of the region lies at the
  5816. {\sl right\/} of the path.
  5817. \danger But when the turning number is zero, the inside of the region
  5818. lies sometimes at the left, sometimes at the right. \MF\ uses the rule
  5819. for positive turning number and reports that the path is ``strange.''
  5820. You can avoid this error message by setting `$"turningcheck":=0$';
  5821. ^^"turningcheck" in this case the rule for positive turning number is
  5822. always used for filling, even when the turning number is negative.
  5823. Plain \MF's ^@draw@ command is different from @fill@ in two important ways.
  5824. First, it uses the currently-picked-up pen, thereby ``thickening'' the path.
  5825. Second, it does not require that the path be cyclic. There is also a third
  5826. difference, which needs to be mentioned although it is not quite as important:
  5827. A @draw@ command may increase the value of certain pixels by more than~1,
  5828. even if the shape being drawn is fairly simple. For example, the pixel pattern
  5829. {\parindent=0pt
  5830. \beginpixdisplay
  5831. 0000000000000000000000000000000000000000000000000000000000000000000000\cr
  5832. 0000001111122222111110000000000000000000000000011111111000000000000000\cr
  5833. 0000111111111211111111100000000000000000000011111111111111000000000000\cr
  5834. 0001111111111011111111110000000000000000001111111111111111110000000000\cr
  5835. 0001111111111011111111110000000000000000111111111111111111111100000000\cr
  5836. 0011111111110001111111111000000000000001111111111111111111111110000000\cr
  5837. 0011111111110001111111111000000000000011111111111111111111111111000000\cr
  5838. 0011111111110001111111111000000000000111111111111111111111111111100000\cr
  5839. 0111111111100000111111111100000000001111111111111111111111111111110000\cr
  5840. 0111111111100000111111111100000000001111111111111111111111111111110000\cr
  5841. 0111111111100000111111111100000000011111111111111111111111111111111000\cr
  5842. 0111111111100000111111111100000000011111111111111111111111111111111000\cr
  5843. 0111111111100000111111111100000000111111111111111112111111111111111100\cr
  5844. 0111111111100000111111111100000000111111111111111112111111111111111100\cr
  5845. 0111111111100000111111111100000001111111111111111122111111111111111110\cr
  5846. 0111111111100000111111111100000001111111111111211121111211111111111110\cr
  5847. 0111111111100000111111111100000001111111111111112122221111111111111110\cr
  5848. 0111111111100000111111111100000001111111111111111100111111111111111110\cr
  5849. 0111111111100000111111111100000001111111111111112000011111111111111110\cr
  5850. 0111111111100000111111111100000001111111111112211000011211111111111110\cr
  5851. 0111111111100000111111111100000000111111111111110000001111111111111100\cr
  5852. 0111111111100000111111111100000000111111111111110000001111111111111100\cr
  5853. 0111111111100000111111111100000000011111111111100000000111111111111000\cr
  5854. 0111111111100000111111111100000000001111111111000000000011111111110000\cr
  5855. 0111111111100000111111111100000000000011111100000000000000111111000000\cr
  5856. 0000000000000000000000000000000000000000000000000000000000000000000000\cr
  5857. \enddisplay}%
  5858. was produced by two @draw@ commands. The left-hand shape came from
  5859. \begindisplay
  5860. \pickup ^@penrazor@ scaled 10;\quad \% a pen of width 10 and height 0\cr
  5861. @draw@ $(6,1)\{"up"\}\to(13.5,25)\to\{"down"\}(21,1)$;\cr
  5862. \enddisplay
  5863. it's not difficult to imagine why some of the top pixels get the value~2
  5864. here because an actual razor-thin pen would cover those pixels twice as it
  5865. follows the given path. But the right-hand shape, which came from
  5866. \begindisplay
  5867. \pickup @pencircle@ scaled 16; \ @draw@ $(41,9)\to(51,17)\to(61,9)$
  5868. \enddisplay
  5869. is harder to explain; there seems to be no rhyme or reason to the pattern
  5870. of 2's in that case. \MF's method for drawing curves with thick pens is
  5871. too complicated to explain here, so we shall just regard it as a curious
  5872. process that occasionally shoots out extra spurts of ink in the interior
  5873. of the shape that it's filling. Sometimes a pixel value even gets as high
  5874. as 3~or more; but if we ignore such anomalies and simply consider the set
  5875. of pixels that receive a positive value, we find that a reasonable shape
  5876. has been drawn.
  5877. The left-parenthesis example in Chapter 12 illustrates the ^@filldraw@
  5878. command, which is like @fill@ in that it requires a cyclic path, and like
  5879. @draw@ in that it uses the current pen. Pixel values are increased inside
  5880. the region that you would obtain by drawing the specified path with the current
  5881. pen and then filling in the interior. Some of the pixel values in this
  5882. region may increase by 2~or more.  The turning number of the path
  5883. should be nonzero.
  5884. Besides @fill@, @draw@, and @filldraw@, you can also say `^@drawdot@',
  5885. as illustrated at the beginning of Chapter~5. In this case you should specify
  5886. only a single point; the currently-picked-up pen will be used to increase
  5887. pixel values by~1 around that point. Chapter~24 explains that this gives
  5888. slightly better results than if you were to draw a one-point path.
  5889. \danger There's also an ^@undraw@ command, analogous to @unfill@; it
  5890. decreases pixel values by the same amount that @draw@ would increase them.
  5891. Furthermore---as you might expect---^@unfilldraw@ and ^@undrawdot@ are the
  5892. respective opposites of @filldraw@ and @drawdot@.
  5893. \danger If you try to use @unfill@ and/or @undraw@ in connection with
  5894. @fill@ and/or @draw@, you'll soon discover that something else is
  5895. necessary. Plain \MF\ has a ^@cullit@ command that replaces all
  5896. negative pixel values by~0 and all positive pixel values by~1. This
  5897. ``^{culling}'' operation makes it possible to erase unwanted sections
  5898. of a picture in spite of the vagaries of @draw@ and @undraw@, and in spite of
  5899. the fact that overlapping regions may be doubly filled.
  5900. \danger The command `^@erase@ @fill@ $c$' is an abbreviation for
  5901. `@cullit@; @unfill@~$c$; @cullit@'; this zeros out the pixel values inside
  5902. the cyclic path~$c$, and sets other pixel values to~1 if they were positive
  5903. before erasing took place. \ (It works because the initial @cullit@ makes
  5904. all the values 0 or~1, then the @unfill@ changes the values inside~$c$
  5905. to 0 or negative. The final @cullit@ gets rid of the negative values,
  5906. so that they won't detract from future filling and drawing.) \ You can
  5907. also use `@draw@', `@filldraw@', or `@drawdot@' with `@erase@'; for example,
  5908. `@erase@ @draw@~$p$' is an abbreviation for `@cullit@; @undraw@~$p$;
  5909. @cullit@', which uses the currently-picked-up pen as if it were an
  5910. eraser applied to path~$p$.
  5911. {\ninepoint
  5912. \medbreak
  5913. \parshape 7 3pc 17pc 3pc 17pc
  5914. 0pc 20pc 0pc 20pc 0pc 20pc 0pc 20pc 0pc 29pc
  5915. \noindent
  5916. \hbox to0pt{\hskip-3pc\dbend\hfill}
  5917. \rightfig 13a ({166.66667\apspix} x {133.33333\apspix}) ^9pt
  5918. The cube at the right of this paragraph illustrates one of the effects that
  5919. is easily obtained by erasing. First the eight points are defined, and
  5920. the ``back'' square is drawn; then two lines of the ``front'' square are
  5921. erased, using a somewhat thicker pen; finally the remaining lines are
  5922. drawn with the ordinary pen:
  5923. \begindisplay
  5924. $s\0:=5"pt"\0$; \ @define\_pixels@$(s)$; \ |%| side of the square\cr
  5925. $z_1=(0,0)$; \ $z_2=(s,0)$; \ $z_3=(0,s)$; $z_4=(s,s)$;\cr
  5926. ^@for@ $k=1$ @upto@ 4: $z_{k+4}=z_k+({2\over3}s,{1\over3}s)$; \ @endfor@\cr
  5927. \pickup @pencircle@ scaled $.4"pt"$; \
  5928. @draw@ $z_5\dashto z_6\dashto z_8\dashto z_7\dashto \cycle$;\cr
  5929. \pickup @pencircle@ scaled $1.6"pt"$; \
  5930. @erase@ @draw@ $z_2\dashto z_4\dashto z_3$;\cr
  5931. \pickup @pencircle@ scaled $.4"pt"$; \
  5932. @draw@ $z_1\dashto z_2\dashto z_4\dashto z_3\dashto \cycle$;\cr
  5933. @for@ $k=1$ @upto@ 4: @draw@ $z_k\dashto z_{k+4}$; \ @endfor@.\cr
  5934. \enddisplay
  5935. At its true size the resulting ^{cube} looks like this:
  5936. `\thinspace{\manual\cubea}\thinspace'.\par}
  5937. \dangerexercise Modify the draw-and-erase construction in the preceding
  5938. paragraph so that you get the {\sl^{impossible cube}\/}
  5939. `\thinspace{\manual\cubeb}\thinspace' instead.
  5940. \answer The tricky part is to remember that `@erase@ @draw@ $z_i\dashto z_j$'
  5941. will erase pixels near $z_i$ and $z_j$. Therefore if $z_3\dashto z_4$ is
  5942. drawn before $z_4\dashto z_2$, we can't erase $z_4\dashto z_2$ without losing
  5943. some of $z_3\dashto z_4$; it's necessary to erase only part of one line.
  5944. One way to solve the problem is to do the following, after defining the
  5945. points and picking up the pen as before:
  5946. \begindisplay
  5947. @draw@ $z_3\dashto z_4$; \ @draw@ $z_5\dashto z_6$;\cr
  5948. ^@cullit@; \ \pickup @pencircle@ scaled $1.6"pt"$;\cr
  5949. ^@undraw@ $z_7\dashto {1\over2}[z_7,z_5]$; \
  5950.  @undraw@ $z_2\dashto {1\over2}[z_2,z_4]$;\cr
  5951. @cullit@; \ \pickup @pencircle@ scaled $.4"pt"$;\cr
  5952. @draw@ $z_3\dashto z_1\dashto z_2\dashto z_4$; \
  5953.  @draw@ $z_5\dashto z_7\dashto z_8\dashto z_6$;\cr
  5954. @for@ $k=1$ @upto@ 4: \ @draw@ $z_k\dashto z_{k+4}$; \ @endfor@.\cr
  5955. \enddisplay
  5956. (Note that it would not be quite enough to erase only from $z_7$ to
  5957. ${1\over3}[z_7,z_5]$!)\par
  5958. It's also possible to solve this problem without partial erasing, if we
  5959. use additional features of \MF\ that haven't been explained yet. Let's
  5960. consider only the job of drawing $z_7\dashto z_5\dashto z_6$ and
  5961. $z_3\dashto z_4\dashto z_2$, since the other eight lines can easily be
  5962. added later. Alternative Solution~1 uses picture operations:
  5963. \begindisplay
  5964. @pen@ "eraser"; \ $"eraser"=@pencircle@$ scaled $1.6"pt"$;\cr
  5965. @draw@ $z_3\dashto z_4$; \
  5966. @erase@ @draw@ $z_7\dashto z_5$ ^@withpen@ "eraser"; \
  5967. @draw@ $z_7\dashto z_5$;\cr
  5968. @picture@ "savedpicture"; \ $"savedpicture"="currentpicture"$; \ ^@clearit@;\cr
  5969. @draw@ $z_6\dashto z_5$; \
  5970. @erase@ @draw@ $z_2\dashto z_4$ ^@withpen@ "eraser"; \
  5971. @draw@ $z_2\dashto z_4$;\cr
  5972. ^@addto@ "currentpicture" @also@ "savedpicture".\cr
  5973. \enddisplay
  5974. Alternative Solution 2 is trickier, but still instructive; it uses
  5975. `^@withweight@' options and the fact that @draw@ does not increase any
  5976. pixel values by more than the stated weight when the path is a straight
  5977. line:
  5978. \begindisplay
  5979. @draw@ $z_3\dashto z_4$; \
  5980. ^@undraw@ $z_7\dashto z_5$ @withpen@ "eraser";\cr
  5981. @draw@ $z_7\dashto z_5$ @withweight@ 2; \
  5982. ^@cullit@ @withweight@ 2;\cr
  5983. @draw@ $z_6\dashto z_5$; \
  5984. ^@undraw@ $z_2\dashto z_4$ @withpen@ "eraser";\cr
  5985. @draw@ $z_2\dashto z_4$ @withweight@ 2;\cr
  5986. \enddisplay
  5987. (These alternative solutions were suggested by Bruce ^{Leban}.)
  5988. \dangerexercise Write a \MF\ program to produce the symbol
  5989. `{\manual\bicentennial}'. \ [{\sl Hints:\/} The character is $10\pt$
  5990. wide, $7\pt$ high, and $2\pt$ deep. The starlike path can be defined by
  5991. five points connected by ``tense'' lines as follows:
  5992. \begindisplay
  5993. @pair@ "center"; \ $"center"=(.5w,2"pt")$;\cr
  5994. @numeric@ "radius"; \ $"radius"=5"pt"$;\cr
  5995. @for@ $k=0$ @upto@ 4: \ $z_k="center"+("radius",0)$
  5996.   ^{rotated}$(90+{360\over5}k)$; \ @endfor@\cr
  5997. @def@ :: = ^^{tension} $\to\tension 5\to$ @enddef@;\cr
  5998. @path@ "star"; \  $"star"=z_0::z_2::z_4::z_1::z_3::\cycle$;\cr
  5999. \enddisplay
  6000. You probably want to work with ^{subpaths} of ^"star" instead of drawing the
  6001. whole path at once, in order to give the illusion that the curves cross over
  6002. and under each other.]
  6003. \answer Here's an analog of the first solution to the previous
  6004. exercise:
  6005. \begindisplay
  6006. @beginchar@\kern1pt(|"*"|$,10"pt"\0,7"pt"\0,2"pt"\0)$;\cr
  6007. @pair@ "center"; \dots  \<as in the hint>\cr
  6008. \pickup @pencircle@ scaled $.4"pt"$; \ @draw@ "star";\cr
  6009. @cullit@; \ \pickup @pencircle@ scaled $1.6"pt"$;\cr
  6010. @for@ $k=0$ @upto@ 4:
  6011.  \ @undraw@ subpath$(k+.55,k+.7)$ @of@ "star"; \ @endfor@\cr
  6012. @cullit@; \ \pickup @pencircle@ scaled $.4"pt"$;\cr
  6013. @for@ $k=0$ @upto@ 4: \ @draw@ subpath$(k+.47,k+.8)$ @of@ "star"; \ @endfor@\cr
  6014. @labels@(0,1,2,3,4); \ @endchar@.\cr
  6015. \enddisplay
  6016. However, as in the previous case, there's an Alternate Solution~1
  6017. by Bruce ^{Leban} that is preferable because it doesn't depend
  6018. on magic constants like .55 and~.47:
  6019. \begindisplay
  6020. @beginchar@ $\ldots$ \<as above> $\ldots$ scaled $.4"pt"$;\cr
  6021. @picture@ "savedpicture"; \ $"savedpicture"=@nullpicture@$;\cr
  6022. @pen@ "eraser"; \ $"eraser":=@pencircle@$ scaled $1.6"pt"$;\cr
  6023. @for@ $k=0$ @upto@ 4:\cr
  6024. \indent @draw@ subpath$(k,k+1)$ @of@ "star"; @cullit@;\cr
  6025. \indent @undraw@ subpath$(k+3,k+4)$ @of@ "star" @withpen@ "eraser"; @cullit@;\cr
  6026. \indent @addto@ "savedpicture" @also@ "currentpicture"; @clearit@; @endfor@\cr
  6027. $"currentpicture":="savedpicture"$; \ @labels@(0,1,2,3,4); \ @endchar@.\cr
  6028. \enddisplay
  6029. \dangerexercise What does the command `@fill@ "star"' do, if "star" is the
  6030. path defined above?
  6031. \answer It increases pixel values by 1 in the five lobes of the star, and by~2
  6032. in the central pentagon-like region.
  6033. \decreasehsize 6pc
  6034. \dangerexercise Devise a ^{macro} called `^@overdraw@' such that the command
  6035. \rightfig 13aa (50pt x 100pt) ^11pt
  6036. `@overdraw@~$c$' will erase the inside of region~$c$ and will then draw the
  6037. boundary of~$c$ with the currently-picked-up pen, assuming that $c$~is a
  6038. cyclic path that doesn't intersect itself. \ (Your macro could be used, for
  6039. example, in the program
  6040. \begindisplay
  6041. @path@ $S$; \ $S=((0,1)\to(2,0)\to(4,2)\to$\cr
  6042. \indent$(2,5.5)\to(0,8)\to(2,10)\to(3.5,9))$ scaled $9"pt"$;\cr
  6043. @for@ $k=0$ @upto@ 35: @overdraw@ ^"fullcircle" scaled 3"mm"\cr
  6044. \indent shifted ^{point} $k/35\ast \mathop{\rm length} S$ @of@ $S$;
  6045.  @endfor@\cr
  6046. \enddisplay
  6047. to create the curious ^{S} shown here.)
  6048. \answer @def@ @overdraw@ @expr@ $c$ = @erase@ @fill@ $c$; @draw@ $c$ @enddef@.
  6049. \restorehsize
  6050. \ddangerexercise The ^{M\"obius} Watchband Corporation has a logo that
  6051. looks like this:
  6052. \displayfig 13bb (.5in)
  6053. Explain how to produce it (or something very similar) with \MF\!.
  6054. \answer First we need to generalize the ^@overdraw@ macro of the previous
  6055. exercise so that it applies to arbitrary cycles~$c$, even those that are
  6056. self-intersecting:
  6057. \begindisplay
  6058. @def@ @overdraw@ @expr@ $c$ = ^@begingroup@\cr
  6059. \indent@picture@ "region"; $"region":=@nullpicture@$;\cr
  6060. \indent^@interim@ $"turningcheck":=0$; ^@addto@ "region" @contour@ $c$;\cr
  6061. \indent^@cull@ "region" @dropping@ $(0,0)$;\cr
  6062. \indent^@cullit@; @addto@ "currentpicture" ^@also@ $-"region"$; @cullit@;\cr
  6063. \indent@draw@ $c$ ^@endgroup@ @enddef@;\cr
  6064. \enddisplay
  6065. (This code uses operations defined later in this chapter; it erases the
  6066. "region" of pixels that would be made nonzero by the command `@fill@~$c$'.)
  6067. \ The watchband is now formed by overdrawing its links, one at a time,
  6068. doing first the ones that are underneath:
  6069. \begindisplay
  6070. @beginchar@$("M",1.25"in"\0,.5"in"\0,0)$; \
  6071.  \pickup @pencircle@ scaled .4"pt";\cr
  6072. $z_1=(20,-13)$; \ $z_2=(30,-6)$; \ $z_3=(20,1)$; $z_4=(4,-7)$;\cr
  6073. \indent $z_5=(-12,-13)$; \ $z_6=(-24,-4)$; \ $z_7=(-15,6)$;\cr
  6074. @path@ $M$; $M=("origin"\to z1\to z2\to z3\to z4\to z5\to z6\to z7\to$\cr
  6075. \indent$"origin"\to -z7\to -z6\to -z5\to -z4\to -z3\to -z2\to -z1\to\cycle)$\cr
  6076. ^^"origin" \indent\indent scaled $(h/26)$ shifted $(.5w,.5h)$;\cr
  6077. @def@ @link@(@expr@ $n$) =\cr
  6078. \indent @overdraw@ subpath ${1\over3}(n,n+1)$ of $M\;\dashto$\cr
  6079. \indent\indent  subpath ${1\over3}(n+25,n+24)$ of $M\;\dashto\;\cycle\;$
  6080.  @enddef@;\cr
  6081. @for@ $k=1$ @upto@ 12: @link@$(k+11)$; @link@$(12-k)$; @endfor@
  6082. @endchar@;\cr
  6083. \enddisplay
  6084. \danger Chapter 7 points out that variables can be of type `^@picture@',
  6085. and Chapter~8 mentions that expressions can be of type `@picture@', but
  6086. we still haven't seen any examples of picture variables or picture
  6087. expressions. Plain \MF\ keeps the currently-worked-on picture in a
  6088. picture variable called ^"currentpicture", and you can copy it by
  6089. equating it to a picture variable of your own. For example, if you
  6090. say `@picture@ $v[\,]$' at the beginning of your program, you can write
  6091. equations like
  6092. \begindisplay
  6093. $v_1="currentpicture"$;
  6094. \enddisplay
  6095. this makes $v_1$ equal to the picture that has been drawn so far; i.e.,
  6096. it gives $v_1$ the same array of pixel values that "currentpicture" now has.
  6097. \begingroup\def\dbend{{\manual\char0}} % reverse-video dangerous bend sign
  6098. \danger Pictures can be added or subtracted; for example, $v_1+v_2$
  6099. ^^{sum of pictures} ^^{negative of a picture} ^^{inverse video}
  6100. stands for the picture whose pixel values are the sums of the pixel
  6101. values of $v_1$ and~$v_2$. The ``^{reverse-video} ^{dangerous bend}'' sign that
  6102. heads this paragraph was made by substituting the following code for
  6103. the `@endchar@' in the program at the end of Chapter~12:
  6104. \begindisplay
  6105. @picture@ "dbend"; \ $"dbend"="currentpicture"$;\cr
  6106. @endchar@; \ |%| end of the normal dangerous bend sign\cr
  6107. @beginchar@$(0,25u\0,"h\_height"\0+"border"\0,0)$;\cr
  6108. @fill@ $(0,-11"pt")\dashto(w,-11"pt")\dashto(w,h)\dashto(0,h)\dashto\cycle$;\cr
  6109. $"currentpicture":="currentpicture"-"dbend"$;\cr
  6110. @endchar@;\ |%| end of the reversed dangerous bend sign\cr
  6111. \enddisplay
  6112. ^^{black/white reversal} The pixel values in "dbend" are all zero or more;
  6113. thus the pixels with a positive value, after "dbend" has been subtracted from
  6114. a filled rectangle, will be those that are inside the rectangle
  6115. but zero in "dbend".
  6116. \endgroup % back to normal \dbend
  6117. \danger We will see in Chapter 15 that pictures can also be shifted,
  6118. reflected, and rotated by multiples of $90^\circ$. For example,
  6119. the statement `$"currentpicture":="currentpicture"$~shifted~3"right"'
  6120. shifts the entire current picture three pixels to the right.
  6121. \danger There's a ``constant'' picture called ^@nullpicture@, whose pixel
  6122. values are all zero;
  6123. plain \MF\ defines `^@clearit@' to be an abbreviation for the
  6124. assignment `"currentpicture":=@nullpicture@'. The current picture is
  6125. cleared automatically by every ^@beginchar@ and ^@mode\_setup@ command,
  6126. so you usually don't have to say `@clearit@' in your own programs.
  6127. \danger Here's the formal syntax for picture expressions. Although \MF\ has
  6128. comparatively few built-in operations that deal with entire pictures,
  6129. the operations that do exist have the same syntax as the similar operations
  6130. we have seen applied to numbers and pairs.
  6131. \beginsyntax
  6132. <picture primary>\is<picture variable>
  6133.  \alt[nullpicture]
  6134.  \alt[(]<picture expression>[)]
  6135.  \alt<plus or minus><picture primary>
  6136. <picture secondary>\is<picture primary>
  6137.  \alt<picture secondary><transformer>
  6138. <picture tertiary>\is<picture secondary>
  6139.  \alt<picture tertiary><plus or minus><picture secondary>
  6140. <picture expression>\is<picture tertiary>
  6141. \endsyntax
  6142. \danger The ``total weight'' of a picture is the sum of all its pixel
  6143. values, divided by 65536; you can compute this numeric quantity by
  6144. saying
  6145. \begindisplay
  6146. ^|totalweight| \<picture primary>.
  6147. \enddisplay
  6148. \MF\ divides by 65536 in order to avoid overflow in case of huge pictures.
  6149. If the totalweight function returns a number whose absolute
  6150. value is less than~.5, as it almost always is, you can safely divide that number
  6151. by ^"epsilon" to obtain the integer sum of all pixel values
  6152. (since $"epsilon"=1/65536$).
  6153. \danger Let's turn to the computer again and try to evaluate some simple
  6154. picture expressions interactively, using the general routine |expr.mf|
  6155. of Chapter~8. When \MF\ says `|gimme|', you can type
  6156. \begintt
  6157. hide(fill unitsquare) currentpicture
  6158. \endtt
  6159. and the machine will respond as follows:
  6160. \begintt
  6161. >> Edge structure at line 5:
  6162. row 0: 0+ 1- ||
  6163. \endtt
  6164. What does this mean? Well, `^@hide@' is plain \MF's sneaky way to insert
  6165. a command or sequence of commands into the middle of an expression; such
  6166. commands are executed before the rest of the expression is looked at. In
  6167. this case the command `@fill@ "unitsquare"' sets one pixel value of the
  6168. current picture to~1, because ^"unitsquare" is plain \MF's abbreviation
  6169. for the path $(0,0)\dashto(1,0)\dashto(1,1)\dashto(0,1)\dashto\cycle$. The
  6170. value of "currentpicture" is displayed as `|row|~|0:| |0+|~|1-|', because
  6171. this means
  6172. ``in row~0, the pixel value increases at $x=0$ and decreases at $x=1$.''
  6173. \danger \MF\ represents pictures internally by remembering only the vertical
  6174. ^{edges} where pixel values change. For example, the picture just displayed
  6175. has just two edges, both in row~0, i.e., both in the row between $y$~coordinates
  6176. 0 and~1. \ (Row~$k$ contains vertical edges whose $x$~coordinates are integers
  6177. and whose $y$~coordinates run between $k$ and $k+1$.) \ The fact that edges
  6178. are represented, rather than entire arrays of pixels, makes it possible for
  6179. \MF\ to operate efficiently at high resolutions, because the number of edges
  6180. in a picture is essentially proportional to the ^{resolution} while the total
  6181. number of pixels is proportional to the resolution {\sl squared}. A ten-fold
  6182. increase in resolution therefore calls for only a ten-fold (rather than a
  6183. hundred-fold) increase in memory space and execution time.
  6184. \def\pixpat#1#2#3#4{\vcenter{\sixrm\baselineskip=\tinypix
  6185.   \hbox{#1\kern\pixcorr#2}\hbox{#3\kern\pixcorr#4}}}
  6186. \ddanger Continuing our computer experiments, let's declare a picture variable
  6187. and fill a few more pixels:
  6188. \begintt
  6189. hide(picture V; fill unitsquare scaled 2; V=currentpicture) V
  6190. \endtt
  6191. The resulting picture has pixel values $\pixpat1121\,$,
  6192. and its edges are shown thus:
  6193. \begintt
  6194. >> Edge structure at line 5:
  6195. row 1: 0+ 2- ||
  6196. row 0: 0+ 2- 0+ 1- ||
  6197. \endtt
  6198. If we now type `|-V|', the result is similar but with the signs changed:
  6199. \begintt
  6200. >> Edge structure at line 5:
  6201. row 1: 0- 2+ ||
  6202. row 0: 0- 2+ 0- 1+ ||
  6203. \endtt
  6204. (You should be doing the experiments as you read this.) \ A more interesting
  6205. picture transformation occurs if we ask for `|V|~|rotated-90|'; the picture
  6206. $\pixpat2111$ appears below the baseline, hence the following edges are shown:
  6207. \begintt
  6208. >> Edge structure at line 5:
  6209. row -1: || 0++ 1- 2-
  6210. row -2: || 0+ 2-
  6211. \endtt
  6212. Here `^|++|' denotes an edge where the weight increases by 2. The edges appear
  6213. ^^|+++| {\sl after\/} ^{vertical line}s `\|' in this case, while they appeared
  6214. {\sl before\/} vertical lines in the previous examples; this means that \MF\
  6215. has sorted the edges by their $x$~coordinates. Each @fill@ or @draw@ instruction
  6216. contributes new edges to a picture, and unsorted edges accumulate until
  6217. \MF\ needs to look at them in left-to-right order. \ (Type
  6218. \begintt
  6219. V rotated-90 rotated 90
  6220. \endtt
  6221. to see what $V$ itself looks like when its edges have been sorted.) \ The
  6222. expression
  6223. \begintt
  6224. V +  V rotated 90 shifted 2right
  6225. \endtt
  6226. produces an edge structure with both sorted and unsorted edges:
  6227. \begintt
  6228. >> Edge structure at line 5:
  6229. row 1: 0+ 2- || 0+ 2-
  6230. row 0: 0+ 2- 0+ 1- || 0+ 1+ 2--
  6231. \endtt
  6232. In general, addition of pictures is accomplished by simply combining the
  6233. unsorted and sorted edges of each row separately.
  6234. \ddangerexercise Guess what will happen if you type `|hide(cullit)|
  6235. |currentpicture|' now; and verify your guess by actually doing the experiment.
  6236. \answer The pixel pattern $\pixpat1121$ is culled to $\pixpat1111\,$,
  6237. and \MF\ needs to sort the edges as it does this; so the result is simply
  6238. \begintt
  6239. row 1: || 0+ 2-
  6240. row 0: || 0+ 2-
  6241. \endtt
  6242. \ddangerexercise Guess (and verify) what will happen when you type the
  6243. expression
  6244. \begintt
  6245. (V + V + V rotated 90 shifted 2right
  6246.   - V rotated-90 shifted 2up) rotated 90.
  6247. \endtt
  6248. [You must type this monstrous formula all on one line, even though it's too
  6249. long to fit on a single line in this book.]
  6250. \answer The pixel pattern is $\pixpat1121+\pixpat1121+\pixpat1112-\pixpat2111
  6251. =\pixpat1243$ before the final rotation, with the reference point at the
  6252. lower left corner of the~4; after rotation it is $\pixpat2314\,$, with the
  6253. reference point at the lower {\sl right\/} corner of the~4. Rotation causes
  6254. \MF\ to sort the edges, but the transition values per edge are never
  6255. more than $\pm3$. You weren't expected to know about this limit of $\pm3$,
  6256. but it accounts for what is actually reported:
  6257. \begintt
  6258. row 1: || -2++ -1+ 0---
  6259. row 0: || -2+ -1+++ 0--- 0-
  6260. \endtt
  6261. \ddanger If you ask for `|V| |rotated| |45|', \MF\ will complain that
  6262. $45^\circ$ rotation is too hard. \ (Try it.) \ After all, square pixels
  6263. can't be ^{rotated} unless the angle of rotation is a multiple of $90^\circ$.
  6264. On the other hand, `|V|~|scaled-1|' does work; you get
  6265. \begintt
  6266. >> Edge structure at line 5:
  6267. row -1: 0- -2+ 0- -1+ ||
  6268. row -2: 0- -2+ ||
  6269. \endtt
  6270. \ddangerexercise Why is `|V| |scaled-1|' different from `|-V|'\thinspace?
  6271. \answer `|V| |scaled-1|' should be the same as `|V| |rotated| |180|',
  6272. because transformations apply to coordinates rather than to pixel values.
  6273. \ (Note, incidentally, that the reflections `|V|~^|xscaled-1|' and
  6274. `|V|~^|yscaled-1|' both work, and that `|V|~|scaled-1|' is the same as
  6275. `|V|~|xscaled-1| |yscaled-1|'.)
  6276. \ddangerexercise Experiment with `|V| |shifted| |(1.5,3.14159)|' and
  6277. ^^{shifted}  explain what happens.
  6278. \answer The result is the same as `|V| |shifted| |(2,3)|'; the coordinates
  6279. of a shift are rounded to the nearest integers when a picture is being shifted.
  6280. \ddangerexercise Guess and verify the result of `|V| |scaled| |2|'.
  6281. \answer |row 3: 0+ 4- |\|\parbreak
  6282. |row 2: 0+ 4- |\|\parbreak
  6283. |row 1: 0+ 4- 0+ 2- |\|\parbreak
  6284. |row 0: 0+ 4- 0+ 2- |\|\par\nobreak
  6285. \smallskip\noindent
  6286. (Scaling of pictures must be by an integer.)
  6287. \ddangerexercise Why does the machine always speak of an ^{edge structure}
  6288. `|at| |line|~|5|'\thinspace?
  6289. \answer \MF\ is currently executing instructions after having read
  6290. as far as line~5 of the file |expr.mf|.
  6291. \ddanger That completes our computer experiments. But before you log off,
  6292. you might want to try typing `|totalweight V/epsilon|', just to verify
  6293. that the sum of all pixel values in~$V$ is~5.
  6294. \danger The commands we have discussed so far in this chapter---@fill@,
  6295. @draw@, @filldraw@, @unfill@, etc.---are not really primitives of \MF;
  6296. they are macros of plain \MF\!, defined in Appendix~B\null. Let's look now
  6297. at the low-level operations on pictures that \MF\ actually performs
  6298. behind the scenes. Here is the syntax:
  6299. \beginsyntax
  6300. <picture command>\is<addto command>\alt<cull command>
  6301. <addto command>\is[addto]<picture variable>[also]<picture expression>
  6302.  \alt[addto]<picture variable>[contour]<path expression><with list>
  6303.  \alt[addto]<picture variable>[doublepath]<path expression><with list>
  6304. <with list>\is<empty>\alt<with list><with clause>
  6305. <with clause>\is[withpen]<pen expression>%
  6306.  \alt[withweight]<numeric expression>\kern-3.5pt
  6307. <cull command>\is[cull]<picture variable><keep or drop><pair expression>
  6308.  \alt<cull command>[withweight]<numeric expression>
  6309. <keep or drop>\is[keeping]\alt[dropping]
  6310. \endsyntax
  6311. The \<picture variable> in these commands should contain a known picture;
  6312. the command modifies that picture, and assigns the resulting new value
  6313. to the variable.
  6314. \danger The first form of \<addto command>, `@addto@ $V$ @also@~$P$',
  6315. has essentially the same meaning as `$V:=V+P$'. But the @addto@ statement
  6316. is more efficient, because it destroys the old value of~$V$ as it adds~$P$;
  6317. this saves both time and space.  Earlier in this chapter we discussed
  6318. the ^{reverse-video} ^{dangerous bend}, which was said to have been
  6319. formed by the statement `$"currentpicture":="currentpicture"-"dbend"$'.
  6320. That was a little white lie; the actual command was
  6321. `@addto@ "currentpicture" @also@ $-"dbend"$'.
  6322. \danger The details of the other forms of `@addto@' are slightly more
  6323. complex, but (informally) they work like this, when $V="currentpicture"$
  6324. and $q=\null$^"currentpen":
  6325. \begindisplay
  6326. Plain \MF&Corresponding \MF\ primitives\cr
  6327. \noalign{\smallskip}
  6328. ^@fill@ $c$&@addto@ $V$ @contour@ $c$\cr
  6329. ^@unfill@ $c$&@addto@ $V$ @contour@ $c$ @withweight@ $-1$\cr
  6330. ^@draw@ $p$&@addto@ $V$ @doublepath@ $p$ @withpen@ $q$\cr
  6331. ^@undraw@ $p$&@addto@ $V$ @doublepath@ $p$ @withpen@ $q$ @withweight@ $-1$\cr
  6332. ^@filldraw@ $c$&@addto@ $V$ @contour@ $c$ @withpen@ $q$\cr
  6333. ^@unfilldraw@ $c$&@addto@ $V$ @contour@ $c$ @withpen@ $q$ @withweight@ $-1$\cr
  6334. \enddisplay
  6335. \ddanger The second form of \<addto command> is `@addto@ $V$ @contour@ $p$',
  6336. followed by optional clauses that say either `@withpen@~$q$' or
  6337. `@withweight@~$w$'. In this case $p$~must be a cyclic path; each pen~$q$
  6338. must be known; and each weight~$w$ must be either $-3$,~$-2$, $-1$, $+1$,
  6339. $+2$, or~$+3$, when rounded to the nearest integer. If more than one pen or
  6340. weight is given, the last specification overrides all previous ones. If no
  6341. pen is given, the pen is assumed to be `@nullpen@'; if no weight is given,
  6342. the weight is assumed to be~$+1$. Thus, the second form of \<addto command>
  6343. basically identifies a picture variable~$V$, a cyclic path~$p$, a pen~$q$,
  6344. and a weight~$w$; and it has the following meaning, assuming that
  6345. "turningcheck" is $\le0$: If~$q$~is the null pen, path~$p$ is digitized
  6346. and each pixel value is increased by $(j-k)w$, where $j$ and~$k$ are the
  6347. respective numbers of downward and upward path edges lying to the left
  6348. of the pixel (as explained earlier in this chapter). If $q$ is not the
  6349. null pen, the action is basically the same except that $p$ is converted to
  6350. another path that ``^{envelope}s'' $p$ with respect to the shape of~$q$;
  6351. this modified path is digitized and filled as before. \ (The modified path
  6352. may cross itself in unusual ways, producing strange squirts of ink as
  6353. illustrated earlier. But it will be well behaved if path~$p$ defines a
  6354. ^{convex} region, i.e., if a car that drives counterclockwise
  6355. around $p$ never turns toward the right at any time.)
  6356. \ddanger If $"turningcheck">0$ when an `$@addto@\ldots@contour@$' command
  6357. ^^"turningcheck" is being performed, the action is the same as just
  6358. described, provided that path~$p$ has a positive ^{turning number}.
  6359. However, if $p$'s turning number is negative, the action depends on
  6360. whether or not pen~$q$ is simple or complex; a complex pen is one whose
  6361. boundary contains at least two points. If the turning number is negative
  6362. and the pen is simple, the weight~$w$ is changed to~$-w$. If the turning
  6363. number is negative and the pen is complex, you get an error message about
  6364. a ``^{backwards path}.''  Finally, if the turning number is zero, you get
  6365. an error message about a ``^{strange path},'' unless the pen is simple and
  6366. $"turningcheck"<=1$.  Plain \MF\ sets $"turningcheck":=2$; the ^@filldraw@
  6367. macro in Appendix~B avoids the ``backwards path'' error by explicitly
  6368. reversing a path whose turning number is negative.
  6369. \danger We mentioned that the command `@fill@ $(0,2)\dashto(4,2)\dashto
  6370. (4,4)\dashto(2,4)\dashto(2,0)\dashto(0,0)\dashto\cycle$' causes \MF\
  6371. to complain about a strange path; let's take a closer look at the
  6372. error message that you get:
  6373. \begintt
  6374. > 0 ENE 1 NNE 2 (NNW WNW) WSW 3 SSW 4 WSW 5 (WNW NNW) NNE 0
  6375. ! Strange path (turning number is zero).
  6376. \endtt
  6377. What does this mean? The numbers represent ``^time'' on the cyclic path,
  6378. from the starting point at time~0, to the next key point at time~1,
  6379. and so on, finally returning to the starting point. Code names like
  6380. `^|ENE|' stand for ^{compass directions} like ``East by North East'';
  6381. \MF\ decides in which of eight ``^{octants}'' each part of a path travels,
  6382. and |ENE| stands for all directions between the angles~$0^\circ$
  6383. and~$45^\circ$, inclusive.  Thus, this particular strange path starts in
  6384. octant |ENE| at time~0, then it turns to octant ^|NNE| after time~1.
  6385. An octant name is parenthesized when the path turns through that octant
  6386. without moving; thus, for example, octants ^|NNW| and ^|WNW| are bypassed
  6387. on the way to octant ^|WSW|. It's possible to compute the turning number
  6388. from the given ^^|SSW| sequence of octants; therefore, if you don't think
  6389. your path is really strange, the abbreviated octant codes should reveal
  6390. where \MF\ has decided to take an unexpected turn. \ (Chapter~27 explains
  6391. more about strange paths.)
  6392. \ddanger The third form of \<addto command> is `@addto@ $V$ @doublepath@~$p$',
  6393. followed by optional clauses that define a pen~$q$ and a weight~$w$ as in
  6394. the second case. If $p$ is not a cyclic path, this case reduces to the
  6395. second case, with $p$ replaced by the doubled-up path
  6396. `$p\mathbin{\&}\mathop{\rm reverse}p \mathbin{\&}\cycle$' (unless $p$
  6397. consists of only a single point, when the new path is simply
  6398. `$p\to\cycle$'\thinspace). On the other hand if $p$ is a cyclic
  6399. path, this case reduces to {\sl two\/} addto commands of the second type,
  6400. in one of which $p$ is reversed; "turningcheck" is ignored during both of
  6401. those commands.
  6402. \danger An anomalous result may occur in the statement `@draw@~$p$'
  6403. or, more generally, in `@addto@~$V$ @doublepath@~$p$ @withpen@~$q$' when
  6404. $p$~is a very small cyclic path and the current pen~$q$ is very large: Pixels
  6405. that would be covered by the pen regardless of where it is placed on~$p$
  6406. might retain their original value. If this unusual circumstance hits you,
  6407. the cure is simply to include the additional statement `@draw@~$z$' or
  6408. `@addto@~$V$ @doublepath@~$z$ @withpen@~$q$', where $z$ is any point
  6409. of~$p$, since this will cover all of the potentially uncovered pixels.
  6410. \danger The ^@cull@ command transforms a picture variable so that
  6411. all of its pixel values are either 0 or a specified weight~$w$, where $w$~is
  6412. determined as in an @addto@ command. A pair of numbers $(a,b)$ is given,
  6413. where $a$ must be less than or equal to~$b$. To cull ``@keeping@ $(a,b)$''
  6414. means that each new pixel value is $w$ if and only if the corresponding
  6415. old pixel value~$v$ was included in the range $a\le v\le b$; to cull
  6416. ``@dropping@ $(a,b)$'' means that each new pixel value is $w$ if and only
  6417. if the corresponding old pixel value~$v$ was {\sl not\/} in that range.
  6418. Thus, for example, `^@cullit@' is an abbreviation for
  6419. \begindisplay \advance\belowdisplayskip by -4pt
  6420. @cull@ "currentpicture" @keeping@ $(1,"infinity")$
  6421. \enddisplay
  6422. or for
  6423. \begindisplay \advance\abovedisplayskip by -4pt
  6424. @cull@ "currentpicture" @dropping@ $(-"infinity",0)$
  6425. \enddisplay
  6426. (which both mean the same thing). A more complicated example is
  6427. \begindisplay
  6428. @cull@ $V_5$ @dropping@ $(-3,2)$ @withweight@ $-2$;
  6429. \enddisplay
  6430. this changes the pixel values of $V_5$ to $-2$ if they were $-4$ or less,
  6431. or if they were 3 or~more; pixel values between $-3$ and $+2$, inclusive,
  6432. are zeroed.
  6433. \danger A cull command must not change pixel values from zero to nonzero.
  6434. For example, \MF\ doesn't let you say `@cull@ $V_1$ @keeping@ $(0,0)$',
  6435. since that would give a value of~1 to infinitely many pixels.
  6436. \dangerexercise What is the effect of the following sequence of commands?
  6437. \begindisplay
  6438. @picture@ $V[\,]$;\cr
  6439. $V_1=V_2="currentpicture"$;\cr
  6440. @cull@ $V_1$ @dropping@ $(0,0)$;\cr
  6441. @cull@ $V_2$ @dropping@ $(-1,1)$;\cr
  6442. $"currentpicture":=V_1-V_2$;\cr
  6443. \enddisplay
  6444. \answer The pixel values of "currentpicture" become 1 if they were $\pm1$,
  6445. otherwise they become~0.
  6446. \dangerexercise Given two picture variables $V_1$ and $V_2$, all of whose
  6447. pixel values are known to be either 0 or~1, explain how to replace $V_1$ by
  6448. (a)~$V_1\cap V_2$; \ (b)~$V_1\cup V_2$; \ (c)~$V_1\oplus V_2$. \ [The
  6449. {\sl^{intersection}\/} $V_1\cap V_2$ has 1's where $V_1$ and $V_2$ both are~1;
  6450. the {\sl^{union}\/} $V_1\cup V_2$ has 0's where $V_1$ and $V_2$ both are~0;
  6451. the {\sl^{symmetric difference}\/} or {\sl^{selective complement}\/} ^^{xor}
  6452. $V_1\oplus V_2$ has 1's where $V_1$ and $V_2$ are unequal.]
  6453. \answer (a) @addto@ $V_1$ @also@ $V_2$; @cull@ $V_1$
  6454. @keeping@ $(2,2)$. \ (b) Same, but cull keeping $(1,2)$.
  6455. \ (c)~Same, but cull keeping $(1,1)$.
  6456. \ddangerexercise Explain how to test whether or not two picture variables
  6457. are equal.
  6458. \answer Subtract one from the other, and cull the result dropping $(0,0)$;
  6459. then test to see if the total weight is zero.
  6460. \ddangerexercise Look at the definitions of @fill@, @draw@, etc., in
  6461. Appendix~B and determine the effect of the following statements:
  6462. \begindisplay
  6463. \llap{a) }@draw@ $p$ @withpen@ $q$;\cr
  6464. \llap{b) }@draw@ $p$ @withweight@ 3;\cr
  6465. \llap{c) }@undraw@ $p$ @withweight@ $w$;\cr
  6466. \llap{d) }@fill@ $c$ @withweight@ $-2$ @withpen@ $q$;\cr
  6467. \llap{e) }@erase@ @fill@ $c$ @withweight@ 2 @withpen@ "currentpen";\cr
  6468. \llap{f) }@cullit@ @withweight@ 2.\cr
  6469. \enddisplay
  6470. \answer (a)~Same as `@draw@ $p$', but using $q$ instead of the
  6471. currently-picked-up pen. \ (b)~Same effect as `@draw@~$p$; @draw@~$p$;
  6472. @draw@~$p$' (but faster).  \ (c)~Same as `@draw@~$p$ @withweight@~$w$',
  6473. because @undraw@'s `@withweight@~$-1$' is overridden.
  6474. \ (d)~Same as `@unfilldraw@~$c$; @unfilldraw@~$c$',
  6475.  but using $q$ instead of "currentpen".
  6476. \ (e)~Same as `@erase@ @filldraw@~$c$', because the `@withweight@~2' is
  6477. overridden. \ [Since @erase@ has culled all weights to 0 or~1, there's
  6478. no need to ``doubly erase.'']
  6479. \ (f)~Same effect as `@cullit@; @addto@ "currentpicture" @also@
  6480. "currentpicture"' (but faster).
  6481. \ddangerexercise Devise a ^@safefill@ macro such that `@safefill@ $c$' increases
  6482. the pixel values of "currentpicture" by~1 in all pixels whose value would
  6483. be changed by the command `@fill@~$c$'. \ (Unlike @fill@, the @safefill@ command
  6484. never stops with a ``^{strange path}'' error; furthermore, it never increases
  6485. a pixel value by more than~1, nor does it decrease any pixel values, even
  6486. when the cycle~$c$ is quite wild.)
  6487. \answer @vardef@ @safefill@ @expr@ $c$ $=$ ^@save@ "region";\parbreak
  6488. \quad@picture@ "region"; "region"=@nullpicture@;\parbreak
  6489. \quad^@interim@ ^"turningcheck"$\null:=0$;\parbreak
  6490. \quad @addto@ "region" @contour@ $c$; \
  6491.  @cull@ "region" @dropping@ $(0,0)$;\parbreak
  6492. \quad @addto@ "currentpicture" @also@ "region" @enddef@.
  6493. \ddangerexercise Explain how to replace a character by its ``^{outline}'':
  6494. All black pixels whose four closest neighbors are also
  6495. black should be changed to white, because they are in the interior.
  6496. \ (Diagonally adjacent neighbors don't count.)
  6497. \answer @cull@ "currentpicture" @keeping@ $(1,"infinity")$;\parbreak
  6498. @picture@ $v$; \  $v:="currentpicture"$;\parbreak
  6499. @cull@ "currentpicture" @keeping@ $(1,1)$ @withweight@ 3;\parbreak
  6500. @addto@ "currentpicture" @also@
  6501.  $v\;-\;v$ shifted "right"\parbreak
  6502. \qquad $\null-\;v$ shifted "left"
  6503.  $\null-\;v$ shifted "up"
  6504.  $\null-\;v$ shifted "down";\parbreak
  6505. @cull@ "currentpicture" @keeping@ $(1,4)$.
  6506. \ddangerexercise In John ^{Conway}'s ``Game of ^{Life},'' pixels are said to
  6507. be either alive or dead. Each pixel is in contact with eight neighbors.
  6508. The live pixels in the $(n+1)$st generation are those who were dead and
  6509. had exactly three live neighbors in the $n$th generation, or those
  6510. who were alive and had exactly two or three live neighbors in the $n$th
  6511. generation. Write a short \MF\ program that displays successive
  6512. generations on your screen.
  6513. \answer (We assume that "currentpicture" initially has some configuration
  6514. in which all pixel values are zero or one; one means ``alive.'')
  6515. \begindisplay
  6516. @picture@ $v$; @def@ "c" $=$ "currentpicture" @enddef@;\cr
  6517. @forever@: \ $v:=c$; \ @showit@;\cr
  6518. \quad @addto@ $c$ @also@ $c$ shifted "left" $+$ "c" shifted "right";\cr
  6519. \quad @addto@ $c$ @also@ $c$ shifted "up" $+$ "c" shifted "down";\cr
  6520. \quad @addto@ $c$ @also@ $c-v$; \ @cull@ $c$ @keeping@ $(5,7)$; \ @endfor@.\cr
  6521. \enddisplay
  6522. (It is wise not to waste too much computer time watching this program.)
  6523. \endchapter
  6524. Blot out, correct, insert, refine,
  6525. Enlarge, diminish, interline;
  6526. Be mindful, when Invention fails,
  6527. To scratch your Head, and bite your Nails.
  6528. \author JONATHAN ^{SWIFT}, {\sl On Poetry: A Rapsody\/} (1733) % lines 87--90
  6529. % Rapsody: stet!
  6530. \bigskip
  6531. The understanding that can be gained from computer drawings
  6532. is more valuable than mere production.
  6533. \author IVAN E. ^{SUTHERLAND}, {\sl Sketchpad\/} (1963) % chapter 9, section E
  6534. \eject
  6535. \beginchapter Chapter 14. Paths
  6536. The ^{boundaries} of regions to be filled, and the ^{trajectories} of
  6537. moving pens, are ``^{paths}'' that can be specified by the general methods
  6538. introduced in Chapter~3. \MF\ allows variables and expressions to be of
  6539. type @path@, so that a designer can build new paths from old ones in many
  6540. ways. Our purpose in this chapter will be to complete what Chapter~3
  6541. began; we shall look first at some special features of plain \MF\ that
  6542. facilitate the creation of paths, then we shall go into the details of
  6543. everything that \MF\ knows about pathmaking.
  6544. A few handy paths have been predefined in Appendix~B as part of plain \MF\!,
  6545. because they turn out to be useful in a variety of applications. For example,
  6546. ^"quartercircle" is a path that represents one-fourth of a ^{circle} of
  6547. diameter~1; it runs from point $(0.5,0)$ to point~$(0,0.5)$.
  6548. The \MF\ program
  6549. \begindisplay
  6550. @beginchar@\kern1pt(|"a"|$,5"pt"\0,5"pt"\0,0)$;\cr
  6551. @pickup@ @pencircle@ scaled $(.4"pt"+"blacker")$;\cr
  6552. @draw@ "quartercircle" scaled 10"pt"; \ @endchar@;\cr
  6553. \enddisplay
  6554. therefore produces the character `\kern1pt{\manual\circa}' in position
  6555. `{\tt a}' of a font.
  6556. \exercise
  6557. Write a program that puts a {\sl filled\/} quarter-circle
  6558. `\kern1pt{\manual\circb}' into font position~`{\tt b}'.
  6559. \answer @beginchar@\kern1pt(|"b"|$,5"pt"\0,5"pt"\0,0)$;\parbreak
  6560. @fill@ $((0,0)\dashto"quartercircle"\dashto{\rm cycle})$
  6561. scaled 10"pt"; \ @endchar@.
  6562. \exercise
  6563. Why are the `\kern1pt{\manual\circa}' and `\kern1pt{\manual\circb}'
  6564. characters of these examples only $5\,$pt wide and $5\,$pt high, although
  6565. they are made with the path `"quartercircle" scaled 10"pt"'?
  6566. \answer A "quartercircle" corresponds to a circle whose diameter
  6567. is~1; the radius is~$1\over2$.
  6568. \exercise
  6569. Use a {\sl rotated\/} quarter-circle to produce `{\manual\circc}\kern1pt'
  6570. in font position `{\tt c}'.
  6571. \answer @beginchar@\kern1pt(|"c"|$,5"pt"\0,5"pt"\0,0)$;\parbreak
  6572. @pickup@ @pencircle@ scaled $(.4"pt"+"blacker")$;\parbreak
  6573. @draw@ "quartercircle" rotated 90 scaled 10"pt" shifted $(5"pt",0)$;
  6574.  \ @endchar@.
  6575. \dangerexercise
  6576. Use "quartercircle" to produce `\kern1pt{\manual\circd}\kern1pt'
  6577. in font position `{\tt d}'.
  6578. \answer @beginchar@\kern1pt(|"d"|$,5"pt"\0\ast\rmsqrt2,5"pt"\0,0)$;\parbreak
  6579. @pickup@ @pencircle@ scaled $(.4"pt"+"blacker")$;\parbreak
  6580. @draw@ $((0,0)\dashto"quartercircle"\dashto{\rm cycle})$
  6581.  rotated 45 scaled 10"pt" shifted $(.5w,0)$;\parbreak
  6582. @endchar@.
  6583. Plain \MF\ also provides a path called ^"halfcircle" that gives you
  6584. `{\manual\circc\circa}'; this path is actually made from two
  6585. quarter-circles, by defining
  6586. \begindisplay
  6587. "halfcircle" $=$ "quartercircle" \& $"quartercircle"\,{\rm rotated}\,90$.
  6588. \enddisplay
  6589. And of course there's also ^"fullcircle", a complete circle of unit diameter:
  6590. \begindisplay
  6591. "fullcircle" $=$ "halfcircle" \& $"halfcircle"\,{\rm rotated}\,180$ \& cycle.
  6592. \enddisplay
  6593. You can draw a circle of diameter $D$ centered at $(x,y)$ by saying
  6594. \begindisplay
  6595. @draw@ "fullcircle" scaled $D$ shifted $(x,y)$;
  6596. \enddisplay
  6597. similarly,\kern-.4pt\ `@draw@ "fullcircle" \kern-.5pt
  6598. xscaled \kern-1pt$A$ yscaled \kern-1pt$B$'
  6599. yields an ^{ellipse} with axes $A$~and~$B$\kern-1.3pt.\kern-.5pt
  6600. Besides circles and parts of circles, there's also a standard square path
  6601. called "unitsquare"; this is a cycle that runs from $(0,0)$ to $(1,0)$
  6602. to $(1,1)$ to $(0,1)$ and back to~$(0,0)$. For example, the command
  6603. `@fill@ "unitsquare"' adds~1 to a single pixel value, as discussed in
  6604. the previous chapter.
  6605. \exercise Use "fullcircle" and "unitsquare" to produce the characters
  6606. `{\manual\circe}' and `{\manual\circf}' in font positions `{\tt e}'
  6607. and~`{\tt f}', respectively. These characters should be $10\,$pt wide
  6608. and $10\,$pt tall, and their centers should be $2.5\,$pt above
  6609. the baseline.
  6610. \answer @beginchar@\kern1pt(|"e"|$,10"pt"\0,7.5"pt"\0,2.5"pt"\0)$;\parbreak
  6611. @pickup@ @pencircle@ scaled $(.4"pt"+"blacker")$;\parbreak
  6612. @for@ $D=.2w,.6w,w$: \
  6613. @draw@ "fullcircle" scaled $D$ shifted $(.5w,.5[-d,h])$;\parbreak
  6614. @endfor@ @endchar@.
  6615. \par\medskip\noindent
  6616. The program for `{\manual\circf}' is similar, but `"fullcircle"
  6617. scaled~$D$' is replaced by
  6618. \begindisplay
  6619. "unitsquare" shifted $-(.5,.5)$ rotated 45 scaled $(D/\rmsqrt2)$.
  6620. \enddisplay
  6621. \hrule
  6622. \medskip
  6623. \line{\figbox{14a}{220\apspix}{690\apspix}\vbox \hfil
  6624. \vbox{\hsize=18pc \def\\{\vskip1.5pt} \parindent=0pt
  6625. \eightpoint
  6626. \obeylines
  6627. \leavevmode @path@ $"branch"[\,]$, "trunk";
  6628. $"branch"_1= "flex"((0,660),(-9,633),(-22,610))$
  6629.  \quad\& "flex"$((-22,610),(-3,622),(17,617))$
  6630.  \quad\& "flex"$((17,617),(7,637),(0,660))$ \& cycle;
  6631. $"branch"_2="flex"((30,570),(10,590),(-1,616))$
  6632.  \quad\& "flex"$((-1,616),(-11,592),(-29,576),(-32,562))$
  6633.  \quad\& "flex"$((-32,562),(-10,577),(30,570))$ \& cycle;
  6634. $"branch"_3="flex"((-1,570),(-17,550),(-40,535))$
  6635.  \quad\& "flex"$((-40,535),(-45,510),(-60,477))$
  6636.  \quad\& "flex"$((-60,477),(-20,510),(40,512))$
  6637.  \quad\& "flex"$((40,512),(31,532),(8,550),(-1,570))$ \& cycle;
  6638. $"branch"_4="flex"((0,509),(-14,492),(-32,481))$
  6639.  \quad\& "flex"$((-32,481),(-42,455),(-62,430))$
  6640.  \quad\& "flex"$((-62,430),(-20,450),(42,448))$
  6641.  \quad\& "flex"$((42,448),(38,465),(4,493),(0,509))$ \& cycle;
  6642. $"branch"_5="flex"((-22,470),(-23,435),(-44,410))$
  6643.  \quad\& "flex"$((-44,410),(-10,421),(35,420))$
  6644.  \quad\& "flex"$((35,420),(15,455),(-22,470))$ \& cycle;
  6645. $"branch"_6="flex"((18,375),(9,396),(5,420))$
  6646.  \quad\& "flex"$((5,420),(-5,410),(-50,375),(-50,350))$
  6647.  \quad\& "flex"$((-50,350),(-25,375),(18,375))$ \& cycle;
  6648. $"branch"_7="flex"((0,400),(-13,373),(-30,350))$
  6649.  \quad\& "flex"$((-30,350),(0,358),(30,350))$
  6650.  \quad\& "flex"$((30,350),(13,373),(0,400))$ \& cycle;
  6651. $"branch"_8="flex"((50,275),(45,310),(3,360))$
  6652.  \quad\& "flex"$((3,360),(-20,330),(-70,300),(-100,266))$
  6653.  \quad\& "flex"$((-100,266),(-75,278),(-60,266))$
  6654.  \quad\& "flex"$((-60,266),(0,310),(50,275))$ \& cycle;
  6655. $"branch"_9="flex"((10,333),(-15,290),(-43,256))$
  6656.  \quad\& "flex"$((-43,256),(8,262),(58,245))$
  6657.  \quad\& "flex"$((58,245),(34,275),(10,333))$ \& cycle;
  6658. $"branch"_{10}="flex"((8,262),(-21,249),(-55,240))$
  6659.  \quad\& "flex"$((-55,240),(-51,232),(-53,220))$
  6660.  \quad\& "flex"$((-53,220),(-28,229),(27,235))$
  6661.  \quad\& "flex"$((27,235),(16,246),(8,262))$ \& cycle;
  6662. $"branch"_{11}="flex"((0,250),(-25,220),(-70,195))$
  6663.  \quad\& "flex"$((-70,195),(-78,180),(-90,170))$
  6664.  \quad\& "flex"$((-90,170),(-5,188),(74,183))$
  6665.  \quad\& "flex"$((74,183),(34,214),(0,250))$ \& cycle;
  6666. $"branch"_{12}="flex"((8,215),(-35,175),(-72,155))$
  6667.  \quad\& "flex"$((-72,155),(-75,130),(-92,110),(-95,88))$
  6668.  \quad\& "flex"$((-95,88),(-65,117),(-54,104))$
  6669.  \quad\& "flex"$((-54,104),(10,151),(35,142))$
  6670.  \qquad$\to"flex"((42,130),(60,123),(76,124))$
  6671.  \quad\& "flex"$((76,124),(62,146),(26,180),(8,215))$ \& cycle;
  6672. $"trunk"=(0,660)\ddashto(-12,70)\to\{\curl 5\}(-28,-8)$
  6673.  \quad\& "flex"$((-28,-8),(-16,-4),(-10,-11))$
  6674.  \quad\& "flex"$((-10,-11),(0,-5),(14,-10))$
  6675.  \quad\& "flex"$((14,-10),(20,-6),(29,-11))$
  6676.  \quad\& $(29,-11)\{\curl 4\}\to(10,100)\ddashto{\rm cycle}$;
  6677. Sometimes it's necessary to draw rather complicated curves, and plain \MF\
  6678. provides a `^"flex"' operation that can simplify this task. The
  6679. construction `$"flex"(z_1,z_2,z_3)$' stands for the path
  6680. `$z_1\to z_2\{z_3-z_1\}\to z_3$',
  6681. and similarly `$"flex"(z_1,z_2,z_3,z_4)$' stands for
  6682. `$z_1\to z_2\{z_4-z_1\}\to z_3\{z_4-z_1\}\to z_4$'; in general
  6683. \begindisplay
  6684. $"flex"(z_1,z_2,\ldots,z_{n-1},z_n)$
  6685. \enddisplay
  6686. is an abbreviation for the path
  6687. \begindisplay
  6688. $z_1\to z_2\{z_n-z_1\}\to\;\cdots\;\to z_{n-1}\{z_n-z_1\}\to z_n$.
  6689. \enddisplay
  6690. The idea is to specify two endpoints, $z_1$ and $z_n$, together with
  6691. one or more intermediate points where the path is traveling in the
  6692. same direction as the straight line from $z_1$ to~$z_n$; these
  6693. intermediate points are easy to see on a typical curve, so they
  6694. are natural candidates for key points.
  6695. For example, the command
  6696. \begindisplay
  6697. @fill@ \ $"flex"(z_1,z_2,z_3)$ \& $"flex"(z_3,z_4,z_5)$\cr
  6698. \indent\& $"flex"(z_5,z_6,z_7)$ \& $"flex"(z_7,z_8,z_9,z_1)$ \& cycle\cr
  6699. \enddisplay
  6700. will fill the shape
  6701. \displayfig 14b (7pc)
  6702. after the points $z_1$, \dots, $z_9$ have been suitably defined. This
  6703. shape occurs as the fourth branch from the top of ``^{El Palo Alto},''
  6704. a tree that is often used to symbolize ^{Stanford University}. The thirteen
  6705. paths on the opposite page were defined by simply sketching the tree on
  6706. a piece of graph paper, then reading off approximate values of key
  6707. points ``by eye'' while typing the code into a computer. \ (A good radio
  6708. or television program helps to stave off boredom when you're typing
  6709. a bunch of data like this.) \ The entire
  6710. figure involves a total of 47~flexes, most of which are pretty mundane;
  6711. but $"branch"_{12}$ does contain an interesting subpath of the form
  6712. \begindisplay
  6713. $"flex"(z_1,z_2,z_3)\to"flex"(z_4,z_5,z_6)$,
  6714. \enddisplay
  6715. which is an abbreviation for
  6716. \begindisplay
  6717. $z_1\to z_2\{z_3-z_1\}\to z_3\to z_4\to z_5\{z_6-z_4\}\to z_6$.
  6718. \enddisplay
  6719. Since $z_3\ne z_4$ in this example, a smooth curve runs through all six
  6720. points, although two different flexes are involved.
  6721. \hangindent -1in \hangafter-2
  6722. Once the paths have been defined,
  6723. \rightfig 14aa (.5in x 1.25in) ^-8pt
  6724. it's easy to use them to make
  6725. symbols like the white-on-black medallion shown here:
  6726. \begindisplay
  6727. @beginchar@\kern1pt(|"T"|$,.5"in"\0,1.25"in"\0,0)$;\cr
  6728. \<Define the thirteen paths on the preceding pages>;\cr
  6729. @fill@ "superellipse"$((w,.5h),(.5w,h),(0,.5h),(.5w,0),.8)$;\cr
  6730. $"branch"_0="trunk"$;\cr
  6731. @for@ $n=0$ @upto@ 12:\cr
  6732. \quad ^@unfill@ $"branch"[n]$ shifted $(150,50)$ scaled $(w/300)$;\cr
  6733. @endfor@ @endchar@;\cr
  6734. \enddisplay
  6735. The oval shape that encloses this tree is a ^"superellipse", which is
  6736. another special kind of path provided by plain \MF\!\null. To get a general
  6737. shape of this kind, you can write
  6738. \begindisplay
  6739. "superellipse"$("right\_point","top\_point","left\_point","bottom\_point",
  6740.  "superness")$
  6741. \enddisplay
  6742. where `"superness"' controls the amount by which the curve differs from a
  6743. true ^{ellipse}. For example, here are four superellipses, drawn with varying
  6744. amounts of ^{superness}, using a
  6745. @pencircle@ xscaled~0.7"pt" yscaled 0.2"pt" rotated~30:
  6746. \displayfig 14c (150\apspix)
  6747. The "superness" should be between 0.5 (when you get a diamond) and 1.0
  6748. (when you get a square); values in the vicinity of 0.75 are usually preferred.
  6749. The zero symbol `{\tt 0}' in this book's typewriter font was
  6750. drawn as a superellipse of superness $2^{-.5}\approx.707$, which
  6751. corresponds to a normal ellipse; the uppercase letter `{\tt O}' was
  6752. drawn with superness $2^{-.25}\approx.841$, to help distinguish it
  6753. from the zero. The ambiguous symbol `{\cmman0}' (which is not in the
  6754. font, but \MF\ can of course draw it) lies between these two extremes; its
  6755. superness is 0.77.
  6756. \ddanger A mathematical superellipse satisfies the equation $\vert
  6757. x/a\vert^\beta+\vert y/b\vert^\beta=1$, for some exponent $\beta$.  It has
  6758. extreme points $(\pm a,0)$ and $(0,\pm b)$, as well as the ``corner''
  6759. points $(\pm\sigma a,\pm\sigma b)$, where $\sigma=2^{-1/\beta}$ is the
  6760. superness.  The tangent to the curve at $(\sigma a,\sigma b)$ runs in the
  6761. direction $(-a,b)$, hence it is parallel to a line from $(a,0)$ to
  6762. $(0,b)$. Gabriel ^{Lam\'e} invented the superellipse in 1818, and
  6763. Piet ^{Hein} popularized the special case
  6764. $\beta=2.5$ [see Martin ^{Gardner}, {\sl Mathematical
  6765. Carnival\/} (New York: Knopf, 1975), 240--254]; this special case
  6766. corresponds to a superness of $2^{-.4}\approx.7578582832552$. Plain \MF's
  6767. "superellipse" routine does not produce a perfect superellipse, nor does
  6768. ^"fullcircle" yield a true circle, but the results are close enough for
  6769. practical purposes.
  6770. \ddangerexercise Try "superellipse" with superness values less than 0.5
  6771. or greater than~1.0; explain why you get weird shapes in such cases.
  6772. \answer There are inflection points, because there are no bounding triangles
  6773. for the `$\ldots$' operations in the "superellipse" macro of Appendix~B,
  6774. unless $.5\le s\le1$.
  6775. Let's look now at the symbols that are used between key points, when we
  6776. specify a path. There are five such tokens in plain \MF:
  6777. \begindisplay
  6778. $\to$&free curve;\cr
  6779. $\ldots$&bounded curve;\cr
  6780. $\dashto$&straight line;\cr
  6781. $\ddashto$&``tense'' line;\cr
  6782. \&&splice.\cr
  6783. \enddisplay
  6784. ^^{..}^^{...}^^{--}^^{---}^^{ampersand}
  6785. In general, when you write `$z_0\to z_1\to\<etc.>\to z_{n-1}\to z_n$',
  6786. \MF\ will compute the path of length~$n$ that represents its idea of the
  6787. ``most pleasing curve'' through the given points $z_0$ through~$z_n$.
  6788. The symbol `$\ldots$' is essentially the same as `$\to$'\thinspace, except
  6789. that it confines the path to a bounding triangle whenever possible, as
  6790. explained in Chapter~3. A straight line segment `$z_{k-1}\dashto z_k$'
  6791. usually causes the path to change course abruptly at $z_{k-1}$ and $z_k$.
  6792. By contrast, a segment specified by `$z_{k-1}\ddashto z_k$' will be a
  6793. straight line that blends smoothly with the neighboring curves; i.e., the
  6794. path will enter $z_{k-1}$ and leave~$z_k$ in the direction of
  6795. $z_k-z_{k-1}$.  \ (The "trunk" of El Palo Alto makes use of this option,
  6796. and we have also used it to draw the signboard of the dangerous bend
  6797. symbol at the end of Chapter~12.) \ Finally, the `\&' operation joins two
  6798. independent paths together at a common point, just as `\&' concatenates
  6799. two strings together.
  6800. Here, for example, is a somewhat silly path that illustrates all five
  6801. basic types of joinery:
  6802. \displayfig 14d (120\apspix)
  6803. \begindisplay
  6804. $z_0=(0,100)$; \ $z_1=(50,0)$; \ $z_2=(180,0)$;\cr
  6805. @for@ $n=3$ @upto@ 9: $z[n]=z[n-3]+(200,0)$; \ @endfor@\cr
  6806. @draw@ $z_0\to z_1\ddashto z_2\ldots\{"up"\}z_3$\cr
  6807. \qquad\& $z_3\to z_4\dashto z_5\ldots\{"up"\}z_6$\cr
  6808. \qquad\& $z_6\ldots z_7\ddashto z_8\to\{"up"\}z_9$.\cr
  6809. \enddisplay
  6810. \danger The `$\ldots$' operation is usually used only when one or both of the
  6811. adjacent directions have been specified (like `$\{"up"\}$' in this example).
  6812. Plain \MF's ^"flex" construction actually uses `$\ldots$'\thinspace,
  6813. not `$\to$' as stated earlier, because this avoids inflection points in
  6814. certain situations.
  6815. \danger A path like `$z_0\ddashto z_1\ddashto z_2$' is almost indistinguishable
  6816. from the broken line `$z_0\dashto z_1\dashto z_2$', except that if you
  6817. enlarge the former path you will see that its lines aren't perfectly
  6818. straight; they bend just a little, so that the curve is ``smooth'' at
  6819. $z_1$ although there's a rather sharp turn there. \ (This means that
  6820. the ^{autorounding} operations discussed in Chapter~24 will apply.) \
  6821. For example, the path $(0,3)\ddashto(0,0)\ddashto(3,0)$ is equivalent to
  6822. \begindisplay
  6823. $(0,3)\to \controls\,(-0.0002,2.9998)\and (-0.0002,0.0002)$\cr
  6824. $\quad\to(0,0)\to \controls\,(0.0002,-0.0002) \and (2.9998,-0.0002)\to(3,0)$\cr
  6825. \enddisplay
  6826. while $(0,3)\dashto(0,0)\dashto(3,0)$ consists of two perfectly straight
  6827. segments:
  6828. \begindisplay
  6829. $(0,3)\to \controls\,(0,2)\and (0,1)$\cr
  6830. $\quad\to(0,0)\to \controls\,(1,0) \and (2,0)\to(3,0)$.\cr
  6831. \enddisplay
  6832. \dangerexercise Plain \MF's ^"unitsquare" path is defined to be
  6833. `$(0,0)\dashto(1,0)\dashto(1,1)\dashto(0,1)\dashto\cycle$'.
  6834. Explain how the same path could have been defined using only `$\to$' and~`\&',
  6835. not `$\dashto$' or explicit directions.
  6836. \answer $(0,0)\to(1,0)\;\&\;(1,0)\to(1,1)\;\&\;(1,1)\to(0,1)
  6837. \;\&\;(0,1)\to(0,0)\;\&\;\cycle$. Incidentally, if each `\&' in this path
  6838. is changed to `$\to$', we get a path that goes through the same points;
  6839. but it is a path of length~8 that comes to a complete stop at each
  6840. corner. In other words, the path remains motionless between times $1\le t\le2$,
  6841. $3\le t\le4$, etc. This length-8 path therefore behaves somewhat strangely
  6842. with respect to the `^{directiontime}' operation. It's better to use `\&'
  6843. than to repeat points of a path.
  6844. \ddanger Sometimes it's desirable to take a path and change all its
  6845. connecting links to `$\ddashto$', regardless of what they were originally;
  6846. the key points are left unchanged. Plain \MF\ has a ^"tensepath" operation
  6847. that does this. For example, "tensepath"~"unitsquare"~$=$
  6848. $(0,0)\ddashto(1,0)\ddashto(1,1)\ddashto(0,1)\ddashto\cycle$.
  6849. When \MF\ is deciding what curves should be drawn in place of `$\to$' or
  6850. `$\ldots$', it has to give special consideration to the beginning and
  6851. ending points, so that the path will start and finish as gracefully as
  6852. possible. The solution that usually works out best is to make the first
  6853. and last path segments very nearly the same as arcs of circles; an
  6854. unadorned path of length~2 like `$z_0\to z_1\to z_2$' will therefore turn
  6855. out to be a good approximation to the unique circular arc that passes
  6856. through $(z_0,z_1,z_2)$, except in extreme cases.  You can change this
  6857. default behavior at the endpoints either by specifying an explicit
  6858. direction or by specifying an amount of ``^{curl}.'' If you call for
  6859. curliness less than~1, the path will decrease its curvature in the
  6860. vicinity of the endpoint (i.e., it will begin to turn less sharply); if
  6861. you specify curliness greater than~1, the curvature will increase.
  6862. \ (See the definition of El Palo Alto's "trunk", earlier in this chapter.)
  6863. Here, for example, are some pairs of parentheses that were drawn using
  6864. various amounts of curl. In each case the shape was drawn by a statement
  6865. of the form `@penstroke@ $z_{0e}\{\curl c\}\to z_{1e}\to\{\curl c\}z_{2e}$';
  6866. different values of $c$ produce different-looking parentheses:\def\\{\kern1pt}
  6867. \begindisplay
  6868. curl value\hidewidth&\hfil0&\hfil1&\hfil2&\hfil4&\kern-10pt"infinity"\cr
  6869. yields\quad&\cmman 1\\2&\cmman 3\\4&\cmman 5\\6&\cmman 7\\8&\cmman 9\\:\cr
  6870. \enddisplay
  6871. (The parentheses of Computer Modern typefaces are defined by the
  6872. somewhat more general scheme described in Chapter~12; explicit directions are
  6873. specified at the endpoints, instead of curls, because this produces
  6874. better results in unusual cases when the characters are extremely
  6875. tall or extremely wide.)
  6876. \danger The amount of curl should not be negative. When the curl is
  6877. very large, \MF\ doesn't actually make an extremely sharp turn at the endpoint;
  6878. instead, it changes the rest of the path so that there is comparatively
  6879. little curvature at the neighboring point.
  6880. \danger Chapter 3 points out that we can change \MF's default curves
  6881. by specifying nonstandard ``^{tension}'' between points, or even by
  6882. specifying explicit control points to be used in the four-point method.
  6883. Let us now study the full syntax of path expressions, so that we
  6884. can come to a complete understanding of the paths that \MF\ is able to make.
  6885. Here are the general rules:
  6886. \beginsyntax
  6887. <path primary>\is<path variable>
  6888.  \alt[(]<path expression>[)]
  6889.  \alt[reverse]<path primary>
  6890.  \alt[subpath]<pair expression>[of]<path primary>
  6891. <path secondary>\is<path primary>
  6892.  \alt<path secondary><transformer>
  6893. <path tertiary>\is<path secondary>
  6894. <path expression>\is<path subexpression>
  6895.  \alt<path subexpression><direction specifier>
  6896.  \alt<path subexpression><path join>[cycle]
  6897. <path subexpression>\is<path tertiary>\alt<pair tertiary>
  6898.  \alt<path expression><path join><path tertiary>
  6899. <path join>\is<direction specifier><basic path join><direction specifier>
  6900. <direction specifier>\is<empty>
  6901.  \alt[\char'173][curl]<numeric expression>[\char'175]
  6902.  \alt[\char'173]<pair expression>[\char'175]
  6903.  \alt[\char'173]<numeric expression>[,]<numeric expression>[\char'175]
  6904. <basic path join>\is[\&]\alt[..]\alt[..]<tension>[..]\alt[..]<controls>[..]
  6905. <tension>\is[tension]<tension amount>
  6906.  \alt[tension]<tension amount>[and]<tension amount>
  6907. <tension amount>\is<numeric primary>
  6908.  \alt[atleast]<numeric primary>
  6909. <controls>\is[controls]<pair primary>
  6910.  \alt[controls]<pair primary>[and]<pair primary>
  6911. \endsyntax
  6912. The operations `$\ldots$' and `$\dashto$' and `$\ddashto$' are conspicuously
  6913. absent from this syntax; that is because Appendix~B defines them as macros:
  6914. \begindisplay
  6915. $\ldots$&is an abbreviation for `$\to\tension\atleast1\to$'\thinspace;\cr
  6916. $\dashto$&is an abbreviation for `$\{\curl1\}\to\{\curl1\}$'\thinspace;\cr
  6917. $\ddashto$&is an abbreviation for `$\to\tension"infinity"\to$'\thinspace.\cr
  6918. \enddisplay
  6919. \danger These syntax rules specify a wide variety of possibilities, even though
  6920. they don't mention `$\dashto$' and such things explicitly, so we shall
  6921. now spend a little while looking carefully at their implications.
  6922. A path expression essentially has the form
  6923. \begindisplay
  6924. $p_0\quad j_1\quad p_1\quad j_2\quad\cdots\quad j_n\quad p_n$
  6925. \enddisplay
  6926. where each $p_k$ is a tertiary expression of type pair or path, and where
  6927. each $j_k$ is a ``path join.''  A path join begins and ends with a
  6928. ``direction specifier,'' and has a ``basic path join'' in the middle.
  6929. A direction specifier can be empty, or it can be `$\{\curl c\}$'
  6930. for some $c\ge0$, or it can be a direction vector enclosed in braces.
  6931. For example, `$\{"up"\}$' specifies an upward direction, because plain
  6932. \MF\ defines ^"up" to be the pair $(0,1)$. This same direction could be
  6933. specified by `$\{(0,1)\}$' or `$\{(0,10)\}$', or without parentheses as
  6934. `$\{0,1\}$'. If a specified direction vector turns out to be $(0,0)$,
  6935. \MF\ behaves as if no direction had been specified; i.e., `$\{0,0\}$'
  6936. is equivalent to `\<empty>'. An empty direction specifier is implicitly
  6937. filled in by rules that we shall discuss later.
  6938. \danger A basic path join has three essential forms: \ (1)~`\&' simply
  6939. concatenates two paths, which must share a common endpoint.
  6940. \ (2)~`$\to\tension\alpha\and\beta\to$' means that a curve should be
  6941. defined, having respective ``tensions'' $\alpha$ and~$\beta$.
  6942. Both $\alpha$ and~$\beta$ must be equal to 3/4 or~more;
  6943. we shall discuss ^{tension} later in this chapter.
  6944. \ (3)~`$\to\controls u\and v\to$' defines a curve with intermediate
  6945. control points $u$ and~$v$.
  6946. \danger Special abbreviations are also allowed, so that the long forms
  6947. of basic path joins can usually be avoided: `$\to$' by itself stands for
  6948. `$\to\tension 1\and1\to$'\thinspace,
  6949.  while `$\to\tension\alpha\to$' stands for
  6950. `$\to\tension\alpha\and\alpha\to$'\thinspace,
  6951.  and `$\to\controls u\to$' stands for
  6952. `$\to\controls u\and u\to$'\thinspace.
  6953. \danger Our examples so far have always constructed paths from points;
  6954. but the syntax shows that it's also possible to write, e.g.,
  6955. `$p_0\to p_1\to p_2$' when the $p$'s themselves are paths. What does
  6956. this mean? Well, every such path will already have been changed into a
  6957. sequence of curves with explicit control points; \MF\ expands such
  6958. paths into the corresponding sequence of points and basic path joins
  6959. of type~(3). For example, `$((0,0)\to(3,0))\to(3,3)$' is essentially
  6960. the same as `$(0,0)\to\controls\,(1,0)\and(2,0)\to(3,0)\to(3,3)$',
  6961. because `$(0,0)\to(3,0)$' is the path
  6962. `$(0,0)\to\controls\,(1,0)\and(2,0)\to(3,0)$'.
  6963. If a cycle is expanded into a subpath in this way, its cyclic
  6964. nature will be lost; its last point will simply be a copy of its first point.
  6965. \danger Now let's consider the rules by which empty direction specifiers
  6966. can inherit specifications from their environment.
  6967. An empty direction specifier at the beginning or end of a path, or just next
  6968. to the `\&' operator, is effectively replaced by `$\{\curl1\}$'.
  6969. This rule should be interpreted properly with respect to cyclic paths, which
  6970. have no beginning or end; for example, `$z_0\to z_1\,\&\,z_1\to z_2\to\cycle$'
  6971. is equivalent to `$z_0\to z_1\{\curl1\}\&\{\curl1\}z_1\to z_2\to\cycle$'.
  6972. \danger If there's a nonempty direction specifier after a point but not
  6973. before it, the nonempty one is copied into both places. Thus, for example,
  6974. `$\to z\{w\}$' is treated as if it were `$\to\{w\}z\{w\}$'. If there's
  6975. a nonempty direction specifier before a point but not after it, the
  6976. nonempty one is, similarly, copied into both places, except if it
  6977. follows a basic path join that gives explicit control points.
  6978. The direction specifier that immediately follows `$\to\controls u\and v\to$'
  6979. is always ignored.
  6980. \danger An empty direction specifier next to an explicit control point
  6981. inherits the direction of the adjacent path segment. More precisely,
  6982. `$\to z\to\controls u\and v\to$' is treated as if it were
  6983. `$\to\{u-z\}z\to\controls u\and v\to$' if $u\ne z$, or as if it were
  6984. `$\to\{\curl1\}z\to\controls u\and v\to$' if $u=z$. Similarly,
  6985. `$\to\controls u\and v\to z\to$' is treated as if $z$ were followed by
  6986. $\{z-v\}$ if $z\ne v$, by $\{\curl1\}$ otherwise.
  6987. \ddanger After the previous three rules have been applied, we might still
  6988. be left with cases in which there are points surrounded on both sides
  6989. by empty direction specifiers. \MF\ must choose appropriate directions
  6990. at such points, and it does so by applying the following algorithm
  6991. due to John ^{Hobby} [{\sl Discrete and Computational Geometry\/ \bf1}
  6992. (1986), 123--140]: Given a sequence
  6993. \begindisplay
  6994. $z_0\{d_0\}\to\tension\alpha_0\and\beta_1\to z_1
  6995.  \to\tension\alpha_1\and\beta_2\to z_2$\cr
  6996. $\hskip5em\<etc.>\;z_{n-1}\to\tension\alpha_{n-1}\and\beta_n\to\{d_n\}z_n$\cr
  6997. \enddisplay
  6998. for which interior directions need to be determined, we will regard the
  6999. $z$'s as if they were complex numbers. Let $l_k=\vert z_k-z_{k-1}\vert$ be
  7000. the distance from $z_{k-1}$ to $z_k$, and let
  7001. $\psi_k=\arg\bigl((z_{k+1}-z_k)/(z_k-z_{k-1} )\bigr)$ be the turning angle
  7002. at~$z_k$. We wish to find direction vectors $w_0$, $w_1$, \dots,~$w_n$ so
  7003. that the given sequence can effectively be replaced by
  7004. \begindisplay
  7005. $z_0\{w_0\}\to\tension\alpha_0\and\beta_1\to\{w_1\}z_1
  7006.  \{w_1\}\to\tension\alpha_1\and\beta_2\to\{w_2\}z_2$\cr
  7007. $\hskip5em\<etc.>\;z_{n-1}\{w_{n-1}\}\to
  7008.  \tension\alpha_{n-1}\and\beta_n\to\{w_n\}z_n$.\cr
  7009. \enddisplay
  7010. Since only the directions of the $w$'s are significant, not the magnitudes,
  7011. it suffices to determine the angles $\theta_k=\arg\bigl(w_k/(z_{k+1}-z_k
  7012. )\bigr)$. For convenience, we also let $\phi_k=\arg\bigl((z_k-z_{k-1})/w_k
  7013. \bigr)$, so that
  7014. $$\line{\indent$\theta_k+\phi_k+\psi_k\;=\;0$.\hfil$(\ast)$}$$
  7015. Hobby's paper introduces the notion of ``^{mock curvature}'' according to
  7016. which the following equations should hold at interior points:
  7017. $$\line{\indent$\beta_k^2l_k^{-1}\bigl(\alpha_{k-1}^{-1}(\theta_{k-1}
  7018. +\phi_k)-3\phi_k\bigr)=\alpha_k^2l_{k+1}^{-1}\bigl(\beta_{k+1}^{-1}
  7019. (\theta_k+\phi_{k+1})-3\theta_k\bigr)$.\hfil$({\ast}{\ast})$}$$
  7020. We also need to consider boundary conditions. If $d_0$ is an explicit
  7021. direction vector~$w_0$, we know $\theta_0$; otherwise $d_0$ is
  7022. `$\curl\gamma_0$' and we set up the equation
  7023. $$\line{\indent$\alpha_0^2\bigl(\beta_1^{-1}(\theta_0+\phi_1)-3\theta_0\bigr)
  7024. =\gamma_0\beta_1^2\bigl(\alpha_0^{-1}(\theta_0+\phi_1)-3\phi_1\bigr)$.
  7025. \hfil$({\ast}{\ast}{\ast})$}$$
  7026. If $d_n$ is an explicit vector~$w_n$, we know $\phi_n$; otherwise
  7027. $d_n$ is `$\curl\gamma_n$' and we set
  7028. $$\line{\indent$\beta_n^2\bigl(\alpha_{n-1}^{-1}(\theta_{n-1}+\phi_n)-3\phi_n
  7029. \bigr)=\gamma_n\alpha_{n-1}^2\bigl(\beta_n^{-1}(\theta_{n-1}+\phi_n)-3
  7030. \theta_{n-1}\bigr)$.\hfil$({\ast}{\ast}{\ast}')$}$$
  7031. It can be shown that the conditions $\alpha_k\ge3/4$, $\beta_k\ge
  7032. 3/4$, $\gamma_k\ge0$ imply that there is a unique solution to the
  7033. system of equations consisting of $(\ast)$ and $({\ast}{\ast})$ for $0<k<n$
  7034. plus the two boundary equations; hence the desired quantities $\theta_0$,
  7035. \dots,~$\theta_{n-1}$ and $\phi_1$, \dots,~$\phi_n$ are uniquely determined.
  7036. \ (The only exception is the degenerate case $n=\gamma_0\gamma_1=1$.)
  7037. \ddanger A similar scheme works for cycles, when there is no `$\{d_0\}$'
  7038. or `$\{d_n\}$'. In this case equations $(\ast)$ and $({\ast}{\ast})$
  7039. hold for all~$k$.
  7040. \ddangerexercise Write out the equations that determine the directions chosen
  7041. for the general cycle
  7042. `$z_0\to\tension\alpha_0\and\beta_1\to
  7043.  z_1\to\tension\alpha_1\and\beta_2\to
  7044.  z_2\to\tension\alpha_2\and\beta_3\to\cycle$'
  7045. of length~3. \ (You needn't try to solve the equations.)
  7046. \answer Let $\delta_1=z_1-z_0$, $\delta_2=z_2-z_1$, $\delta_3=z_0-z_2$;
  7047. $l_1=\vert\delta_1\vert$, $l_2=\vert\delta_2\vert$, $l_3=\vert\delta_3\vert$;
  7048. $\psi_1=\arg(\delta_2/\delta_1)$, $\psi_2=\arg(\delta_3/\delta_2)$,
  7049. $\psi_3=\arg(\delta_1/\delta_3)$. The equations to be solved are
  7050. $(\ast)$ and $({\ast}{\ast})$ for $1\le k\le3$, where $\alpha_3=\alpha_0$
  7051. and $\beta_4=\beta_1$. These six equations determine
  7052. $\theta_1,\theta_2,\theta_3$ and $\phi_1,\phi_2,\phi_3$.
  7053. \ddanger Whew\thinspace---\thinspace
  7054. these rules have determined the directions at all points.
  7055. To complete the job of path specification, we need merely explain how
  7056. to change a segment like `$z_0\{w_0\}\to\tension\alpha\and\beta\to\{w_1\}
  7057. z_1$' into a segment of the form
  7058. `$z_0\to\controls u\and v\to z_1$'\thinspace;
  7059. i.e., we finally want to know \MF's
  7060. magic recipe for choosing the control points $u$ and~$v$.
  7061. If $\theta=\arg\bigl(w_0/(z_1-z_0)\bigr)$ and
  7062. $\phi=\arg\bigl((z_1-z_0)/w_1\bigr)$, the control points are
  7063. \begindisplay
  7064. $u=z_0+e^{i\theta}(z_1-z_0)f(\theta,\phi)/\alpha,\qquad
  7065. v=z_1-e^{-i\phi}(z_1-z_0)f(\phi,\theta)/\beta$,
  7066. \enddisplay
  7067. where $f(\theta,\phi)$ is another formula due to John Hobby:
  7068. \begindisplay
  7069. $\displaystyle f(\theta,\phi)=
  7070. {2+\sqrt2\,(\sin\theta-{1\over16}\sin\phi)
  7071.  (\sin\phi-{1\over16}\sin\theta)(\cos\theta-\cos\phi)\over
  7072. 3\,\bigl(1+{1\over2}(\sqrt5-1)\cos\theta+{1\over2}(3-\sqrt5\,)\cos\phi\bigr)}.$
  7073. \enddisplay
  7074. \ddanger There's yet one more complication. If the tensions $\alpha$ and/or
  7075. $\beta$ have been preceded by the keyword `^{atleast}', the values of
  7076. $\alpha$ and/or $\beta$ are increased, if necessary, to the minimum
  7077. values such that $u$ and~$v$ do not lie outside the ``^{bounding triangle},''
  7078. which is discussed near the end of Chapter~3.
  7079. \danger What do these complex rules imply, for \MF\ users who aren't ``into''
  7080. mathematics? The most important fact is that the rules for paths are
  7081. invariant under shifting, scaling, and rotation. In other words, if the
  7082. key points $z_k$ of a path are all shifted, scaled, and/or rotated in the
  7083. same way, the resulting path will be the same as you would get by
  7084. shifting, scaling, and/or rotating the path defined by the unmodified
  7085. $z_k$'s (except of course for possible rounding errors). However,
  7086. this invariance property does not hold if the points or paths are
  7087. xscaled and yscaled by separate amounts.
  7088. \danger Another consequence of the rules is that ^{tension} specifications
  7089. have a fairly straightforward interpretation in terms of control points,
  7090. when the adjacent directions have been given: The formulas for $u$ and~$v$
  7091. simply involve division by $\alpha$ and~$\beta$. This means, for example,
  7092. that a tension of~2 brings the control points halfway~in towards the
  7093. neighboring key points, and a tension of "infinity" makes the points very
  7094. close indeed; contrariwise, tensions less than~1 move the control
  7095. points out.
  7096. \danger Tension and curl specifications also influence \MF's choices of
  7097. directions at the key points. That is why, for example, the construction
  7098. `$z_{k-1}\ddashto z_k$' (which means `$z_{k-1}\to\tension"infinity"\to
  7099. z_k$'\thinspace) affects the direction of a larger path as it enters
  7100. $z_{k-1}$ and leaves $z_k$.
  7101. \danger The rules imply that a change in the position of point~$z_n$
  7102. causes a change in the curve near point~$z_0$, when \MF\ has to choose
  7103. directions at all points between $z_0$ and $z_n$. However, this effect
  7104. is generally negligible except in the vicinity of the changed point.
  7105. You can verify this by looking, for example, at the control
  7106. points that \MF\ chooses for the path `$(0,0)\to(1,0)\to(2,0)\to
  7107. (3,0)\to(4,0)\ldots\{"up"\}(5,y)$', as $y$ varies.
  7108. \ddangerexercise Run \MF\ on the `|expr|' file of Chapter~8, and ask
  7109. to see the path expression `^"unitsquare" shifted~$(0,1)\;\to\;$
  7110. "unitsquare" shifted~$(1,0)$'. Account for the results that you get.
  7111. \answer The path is of length~9, and it is equivalent to
  7112. `$(0,1)\dashto(1,1)\dashto(1,2)\dashto(0,2)\dashto(0,1)\{"down"\}
  7113. \to\{"right"\}(1,0)\dashto(2,0)\dashto(2,1)\dashto(1,1)\dashto(1,0)$'.
  7114. Although "unitsquare" is a cycle, the cycle is broken when it is used
  7115. inside a larger path; the resulting non-cyclic square path goes "down"
  7116. when it ends and "right" when it begins.
  7117. \ddangerexercise We've said that `$\dashto$' is plain \MF's abbreviation
  7118. for `$\{\curl1\}\to\{\curl1\}$'. Would there be any essential difference
  7119. if `$\dashto$' were defined to mean `$\{\curl2\}\to\{\curl2\}$'\thinspace?
  7120. \answer Yes; for example, `$z_0\to z_1\to z_2\dashto z_3$' would be
  7121. equivalent to `$z_0\to z_1\to\{\curl2\}z_2\{\curl2\}\to\{\curl2\}z_3$'.
  7122. But a path like $z_0\dashto z_1\dashto z_2\dashto z_3$ would not be
  7123. affected, because all directions would turn out to be the same as before.
  7124. (The path `$z_0\{\curl a\}\to\{\curl b\}z_1$' is a straight line regardless
  7125. of the values of $a$ and~$b$, because equations $({\ast}{\ast}{\ast})$
  7126. and $({\ast}{\ast}{\ast}')$ always have the solution $\theta_0=\phi_1=0$
  7127. when $n=1$.)
  7128. \ddangerexercise Look closely at the syntax of \<path expression> and
  7129. explain what \MF\ does with the specification `$(0,0)\to(3,3)\to\cycle
  7130. \{\curl1\}$'.
  7131. \answer It treats this as `$((0,0)\to(3,3)\to\cycle)\{\curl1\}$'; i.e.,
  7132. the part up to and including `cycle' is treated as a subpath
  7133. (cf.~`|p2|' in Chapter~8). The cycle is broken, after which we have
  7134. `$(0,0)\to\controls\,(2,-2)\and(5,1)\to(3,3)\to\controls\,(1,5)\and
  7135. (-2,2)\to(0,0)\{\curl1\}$'. Finally the `$\{\curl1\}$' is dropped,
  7136. because all control points are known. \ (The syntax by itself isn't
  7137. really enough to answer this question, as you probably realize.
  7138. You also need to be told that the computation of directions and
  7139. control points is performed whenever \MF\ uses the second or third
  7140. alternative in the definition of \<path expression>.)
  7141. \danger Now let's come back to simpler topics relating to paths.
  7142. Once a path has been specified, there are lots of things you can
  7143. do with it, besides drawing and filling and suchlike. For example,
  7144. if $p$ is a path, you can reverse its direction by saying `reverse~$p$';
  7145. the ^{reverse} of `$z_0\to\controls u\and v\to z_1$' is
  7146. `$z_1\to\controls v\and u\to z_0$'.
  7147. \dangerexercise True or false: length reverse $p$ $=$ length $p$,
  7148. for all paths~$p$.
  7149. \answer True. The length of a path is the number of
  7150. `$z_k\to\controls u_k\and v_{k+1}\to z_{k+1}$' segments that it contains,
  7151. after all control points have been chosen.
  7152. \danger It's convenient to associate ``^{time}'' with paths,
  7153. by imagining that we move along a path of length~$n$ as time passes
  7154. from 0 to~$n$. \ (Chapter~8 has already illustrated this notion, with
  7155. respect to an almost-but-not-quite-circular path called~|p2|; it's a good idea
  7156. to review the discussion of paths and ^{subpaths} in Chapter~8 now before
  7157. you read further.) \ Given a path
  7158. \begindisplay
  7159. $p=z_0\to\controls u_0\and v_1\to z_1\,\<etc.>\,z_{n-1}\to
  7160.  \controls u_{n-1}\and v_n\to z_n$
  7161. \enddisplay
  7162. and a number $t$, \MF\ determines `point $t$ of $p$' as follows:
  7163. If $t\le0$, the result is~$z_0$; if $t\ge n$, the result is~$z_n$;
  7164. otherwise if $k\le t<k+1$, it is $(t-k)[z_k,u_k,v_{k+1},z_{k+1}]$,
  7165. where we generalize the ^^{mediation} `$t[\alpha,\beta]$' notation
  7166. so that $t[\alpha,\beta,\gamma]$ means
  7167. $t\bigl[t[\alpha,\beta],t[\beta,\gamma]\bigr]$
  7168. and $t[\alpha,\beta,\gamma,\delta]$ means
  7169. $t\bigl[t[\alpha,\beta,\gamma],t[\beta,\gamma,\delta]\bigr]$. \ (This
  7170. is a ^{Bernshte\u\i n} polynomial in~$t$, cf.~Chapter~3.) \
  7171. Given a cyclic path
  7172. \begindisplay
  7173. $c=z_0\to\controls u_0\and v_1\to z_1\,\<etc.>\,z_{n-1}\to
  7174.  \controls u_{n-1}\and v_n\to\cycle$
  7175. \enddisplay
  7176. and a number $t$, \MF\ determines `point $t$ of $c$' in essentially the
  7177. same way, except that $t$ is first reduced modulo~$n$ so as to lie
  7178. in the range $0\le t<n$.
  7179. \ddangerexercise True or false:\quad point $t$ of $(z_0\dashto z_1)$ $=$
  7180. $t[z_0,z_1]$.
  7181. \answer True if $0\le t\le1$, except perhaps for rounding errors;
  7182. otherwise false. The path $z_0\dashto z_1$ expands into `$z_0\to
  7183. \controls1/3[z_0,z_1]\and2/3[z_0,z_1]\to z_1$', and the ^{Bernshte\u\i n}
  7184. polynomial simplifies because $t[w,w+\delta,w+2\delta,w+3\delta]=w+3t\delta$.
  7185. Incidentally, `point~$t$ of $(z_0\ddashto z_1)$' is usually quite
  7186. different from $t[z_0,z_1]$.
  7187. \danger Given a path $p$ and two time values $t_1\le t_2$,
  7188. `subpath~$(t_1,t_2)$ of~$p$' contains all the values
  7189. `point~$t$ of~$p$' as $t$ varies from $t_1$ to~$t_2$. There's no problem
  7190. understanding how to define this subpath when $t_1$ and $t_2$ are integers;
  7191. for example,
  7192. \begindisplay
  7193. subpath $(2,4)$ of $p$ $=$ $z_2\to\controls u_2\and v_3\to z_3
  7194.  \to\controls u_3\and v_4\to z_4$
  7195. \enddisplay
  7196. in the notation above, if we assume that $n\ge 4$. The fractional case is
  7197. handled by ``stretching time'' in one segment of the curve; for example,
  7198. if $0<t<1$ we have
  7199. \begindisplay
  7200. subpath $(0,t)$ of $p$ $=$ $z_0\to\controls t[z_0,u_0]\and
  7201.  t[z_0,u_0,v_1]\to t[z_0,u_0,v_1,z_1]$;\cr
  7202. subpath $(t,1)$ of $p$ $=$ $t[z_0,u_0,v_1,z_1]\to\controls
  7203.  t[u_0,v_1,z_1]\and t[v_1,z_1]\to z_1$.\cr
  7204. \enddisplay
  7205. These two subpaths together account for all points of
  7206. `$z_0\to\controls u_0\and v_1\to z_1$'. To get subpath~$(t_1,t_2)$ of~$p$
  7207. when $0<t_1<t_2<1$, \MF\ applies this construction twice, by computing
  7208. subpath~$(t_1/t_2,1)$ of subpath~$(0,t_2)$ of~$p$.
  7209. \ddanger The operation `subpath $(t_1,t_2)$ of $p$' is defined for all
  7210. combinations of times $(t_1,t_2)$ and paths~$p$ by the following rules:
  7211. Let $n={\rm length}\,p$. \ (1)~If $t_1>t_2$, subpath~$(t_1,t_2)$ of~$p$~$=$
  7212. reverse subpath~$(t_2,t_1)$ of~$p$. Henceforth we shall assume that
  7213. $t_1\le t_2$.  \ (2)~If $t_1=t_2$, subpath~$(t_1,t_2)$ of~$p$~$=$
  7214. point~$t_1$ of~$p$, a path of length zero. Henceforth we shall assume that
  7215. $t_1<t_2$.
  7216. \ (3)~If $t_1<0$ and $p$ is a cycle, subpath~$(t_1,t_2)$ of~$p$~$=$
  7217.  subpath~$(t_1+n,t_2+n)$ of~$p$. If $t_1<0$ and $p$ is not a cycle,
  7218.  subpath~$(t_1,t_2)$ of~$p$~$=$ subpath~$\bigl(0,\max(0,t_2)\bigr)$ of~$p$.
  7219. Henceforth we shall assume that $t_1\ge0$.
  7220. \ (4)~If $t_1\ge n$ and $p$ is a cycle, subpath~$(t_1,t_2)$ of~$p$~$=$
  7221.  subpath~$(t_1-n,t_2-n)$ of~$p$.
  7222. If $t_1<n<t_2$ and $p$ is a cycle, subpath~$(t_1,t_2)$ of~$p$~$=$
  7223.  subpath~$(t_1,t_2)$ of~$(p\,\&\,p\,\&\,\cycle)$.
  7224. If $t_2>n$ and $p$ is not a cycle, subpath~$(t_1,t_2)$ of~$p$~$=$
  7225.  subpath~$\bigl(\min(t_1,n),n\bigr)$ of~$p$.
  7226. Henceforth we shall assume that $0\le t_1<t_2\le n$.
  7227. \ (5)~If $t_1\ge1$, subpath~$(t_1,t_2)$ of~$p$~$=$
  7228.  subpath~$(t_1-1,t_2-1)$ of subpath~$(1,n)$ of~$p$, where
  7229. subpath~$(1,n)$ of~$p$ is obtained by removing the first segment of~$p$.
  7230. Henceforth we shall assume that $0\le t_1<1$.
  7231. \ (6)~If $t_2>1$, subpath~$(t_1,t_2)$ of~$p$~$=$
  7232.  subpath~$(t_1,1)$ of~$p$~\& subpath~$(1,t_2)$ of~$p$.
  7233. Henceforth we shall assume that $0\le t_1<t_2\le 1$.
  7234. \ (7)~The remaining cases were defined in the preceding paragraph.
  7235. \ddangerexercise What is the length of
  7236.  `subpath $(2.718,3.142)$ of~$p$'\thinspace?
  7237. \answer If $p$ is a cycle, or if $p$ is a path of length $\ge4$, the
  7238. stated subpath has length~2. Otherwise the length is
  7239. $\max(0,{\rm length}\,p-2)$.
  7240. \danger Besides `point $t$ of $p$', \MF\ allows you to speak of
  7241. `^{postcontrol}~$t$ of~$p$' and `^{precontrol}~$t$ of~$p$';
  7242. this gives access to the control points of a path. Let
  7243. \begindisplay
  7244. $p=z_0\to\controls u_0\and v_1\to z_1\,\<etc.>\,z_{n-1}\to
  7245.  \controls u_{n-1}\and v_n\to z_n$.
  7246. \enddisplay
  7247. If $t<n$, postcontrol $t$ of $p$ is the first control point in
  7248. subpath~$(t,n)$ of~$p$; if $t\ge n$, postcontrol~$t$ of~$p$ is~$z_n$.
  7249. If $t>0$, precontrol~$t$ of~$p$ is the last control point in
  7250. subpath~$(0,t)$ of~$p$; if $t\le 0$, precontrol~$t$ of~$p$ is~$z_n$.
  7251. In particular, if $t$ is an integer, postcontrol~$t$ of~$p$ is $u_t$
  7252. for $0\le t<n$, and precontrol~$t$ of~$p$ is $v_t$ for $0<t\le n$.
  7253. \danger The ability to extract key points and control points makes it
  7254. possible to define interesting operations such as plain \MF's ^"interpath"
  7255. function, which allows you to ^{interpolate between paths}. For example,
  7256. `"interpath"$(1/3,p,q)$' will produce a path of length~$n$ whose
  7257. points are 1/3[point~$t$~of~$p,\,$~point~$t$~of~$q$] for $0\le t\le n$,
  7258. given any paths $p$ and~$q$ of length~$n$. It can be defined by a
  7259. fairly simple program:
  7260. \begindisplay
  7261. @vardef@ "interpath"(@expr@ $a,p,q) =$\cr
  7262. \quad @for@ $t=0$ @upto@ length$\,p\;-1$: $a$[point $t$ of $p,\,$
  7263.   point $t$ of $q$]\cr
  7264. \qquad$\to\controls$ $a$[postcontrol $t$ of $p,\,$
  7265.   postcontrol $t$ of $q$]\cr
  7266. \qquad\quad and $a$[precontrol $t+1$ of $p,\,$
  7267.   precontrol $t+1$ of $q$] $\to$ @endfor@\cr
  7268. \quad @if@ cycle $p$: cycle\qquad\% assume that $p,q$ are both cycles
  7269.  or both noncycles\cr
  7270. \quad @else@: $a$[point "infinity" of $p$, point "infinity" of $q$]
  7271.  @fi@ @enddef@;\cr
  7272. \enddisplay
  7273. \danger On February 14, 1979, the author ^^{Knuth, D E}
  7274. bought a box of chocolates and placed the box on a piece of
  7275. graph paper (after suitably disposing of the contents). ^^{Knuth, J C}
  7276. The experimental data gathered in this way led to a ``definitive''
  7277. ^^{valentine} heart shape:
  7278. \begindisplay
  7279. $"heart"=(100,162)\to(140,178)\{"right"\}\to(195,125)\{"down"\}$\cr
  7280. \qquad$\to(100,0)\{\curl0\}
  7281.  \to\{"up"\}(5,125)\to\{"right"\}(60,178)\to(100,162)$;\cr
  7282. \enddisplay
  7283. It is interesting to interpolate between ^"heart" and other paths, by using
  7284. a program like
  7285. \begindisplay
  7286. @for@ $n=0$ @upto@ 10: @draw@ "interpath"$(n/10,p,"heart")$; @endfor@.
  7287. \enddisplay
  7288. For example, the left illustration below was obtained by taking
  7289. \begindisplay
  7290. $p=(100,0)\dashto(300,0)\dashto(200,0)\dashto(100,0)\dashto(0,0)
  7291.  \dashto(-100,0)\dashto(100,0)$;
  7292. \enddisplay
  7293. notice that "interpath" doesn't necessarily preserve smoothness at the key
  7294. points.  The right illustration was obtained by duplicating point
  7295. $(100,0)$ in~$heart$ (thereby making it a path of length~7) and taking
  7296. \begindisplay
  7297. $p=(100,200)\dashto(200,200)\dashto(200,100)$\cr
  7298. \qquad$\dashto(200,0)\dashto(0,0)\dashto(0,100)\dashto(0,200)\dashto(100,200)$.
  7299. \enddisplay
  7300. \displayfig 14bb\&cc (1in)
  7301. \danger Plain \MF\ allows you to say `^{direction}~$t$ of~$p$' in order
  7302. to determine the direction in which path~$p$ is moving at time~$t$. This is
  7303. simply an abbreviation for `(postcontrol~$t$~of~$p)-($precontrol~$t$~of~$p$)'.
  7304. Sometimes a path veers abruptly and has no unique direction; in this case
  7305. the direction function gives a result somewhere between the two possible
  7306. extremes. For example, the "heart" path above turns a corner at
  7307. time~3; `direction~3 of~"heart"' turns out to be
  7308. $(-93.29172,0)$, but `direction~$3-"epsilon"$ of~"heart"' is
  7309. $(-46.64589,-31.63852)$ and `direction~$3+"epsilon"$ of~"heart"' is
  7310. $(-46.64589,31.63852)$.
  7311. \outer\def\begindemo#1{$$\advance\baselineskip by2pt
  7312.   \catcode`\"=\other
  7313.   \halign\bgroup\indent\hbox to #1{\tt##\hfil}&\tt##\hfil\cr
  7314.   \noalign{\vskip-2pt}}
  7315. \outer\def\enddemo{\egroup$$}
  7316. \def\demohead{\it\kern-2pt You type&\it\kern-1pt And the result is\cr
  7317.   \noalign{\nobreak\vskip2pt}}
  7318. \danger Conversely, \MF\ can tell you when a path heads in
  7319. a given direction. You just ask for `^{directiontime}~$w$ of~$p$', where
  7320. $w$~is a direction vector and $p$~is a path. This operation is best
  7321. understood by looking at examples, so let's resume our dialog with the
  7322. computer by applying \MF\ to the `|expr|' file as in Chapter~8. When
  7323. \MF\ first says `|gimme|', our opening strategy this time will be
  7324. to type
  7325. \begintt
  7326. hide(p3 = (0,0){right}..{up}(1,1)) p3
  7327. \endtt
  7328. so that we have a new path to play with. Now the fun begins:
  7329. ^^{dir}^^{angle}
  7330. \begindemo{230pt}
  7331. \demohead
  7332. directiontime right of p3&0\cr
  7333. directiontime up of p3&1\cr
  7334. directiontime down of p3&-1\cr
  7335. directiontime (1,1) of p3&0.5\cr
  7336. directiontime left of reverse p3&1\cr
  7337. direction directiontime (1,2) of p3 of p3&(0.23126,0.46251)\cr
  7338. directiontime right of subpath(epsilon,1) of p3&0\cr
  7339. directiontime right of subpath(2epsilon,1)of p3&-1\cr
  7340. directiontime (1,1) of subpath(epsilon,1) of p3&0.49998\cr
  7341. direction epsilon of p3&(0.55226,0)\cr
  7342. direction 2epsilon of p3&(0.55229,0.00003)\cr
  7343. directiontime dir 30 of p3&0.32925\cr
  7344. angle direction 0.32925 of p3&29.99849\cr
  7345. angle direction 0.32925+epsilon of p3&30.00081\cr
  7346. directionpoint up of p3&(1,1)\cr
  7347. \enddemo
  7348. Note that directiontime yields $-1$ if the specified direction doesn't occur.
  7349. At time ^"epsilon", path~$p_3$ is still traveling right, but at time
  7350. 2"epsilon" it has begun to turn upward. The `^{directionpoint}' operation
  7351. is analogous to directiontime, but it gives the point on the path rather
  7352. than the time of arrival. ^^"fullcircle"
  7353. \begindemo{230pt}
  7354. \demohead
  7355. directiontime up of fullcircle&0\cr
  7356. directiontime left of fullcircle&2\cr
  7357. directiontime right of fullcircle&6\cr
  7358. directiontime (-1,1) of fullcircle&1\cr
  7359. directiontime (epsilon,infinity) of fullcircle&8\cr
  7360. directiontime right of unitsquare&0\cr
  7361. directiontime up of unitsquare&1\cr
  7362. directiontime (1,1) of unitsquare&1\cr
  7363. directiontime (-1,1) of unitsquare&2\cr
  7364. \enddemo
  7365. If a path travels in a given direction more than once, directiontime
  7366. reports only the first time.  The ^"unitsquare" path has sharp turns at
  7367. the corners; directiontime considers that all directions between the
  7368. incoming and outgoing ones are instantaneously present.
  7369. \ddanger It's possible to construct pathological paths in which unusual
  7370. things happen. For example, the path $p=(0,0)\to\controls\,(1,1)\and(0,1)
  7371. \to(1,0)$ has a ``^{cusp}'' at time~0.5, when it comes to a dead stop and
  7372. turns around. \ $\bigl($If you ask for `direction~0.5 of~$p$', the answer
  7373. is zero, while direction~$0.5-\epsilon$ of~$p$ is $(0,2\epsilon)$ and
  7374. direction~$0.5+\epsilon$ of~$p$ is $(0,-2\epsilon)$.$\bigr)$ \ The
  7375. directiontime operation assumes that all possible directions actually
  7376. occur when a path comes to a standstill, hence `directiontime~"right"
  7377. of~$p$' will be 0.5 in this case even though it might be argued that
  7378. $p$~never turns to the right.  Paths with cusps are numerically unstable,
  7379. and they might become ``^{strange}'' after transformations are applied,
  7380. because rounding errors might change their ^{turning numbers}. The path~$p$
  7381. in this example has control points that correspond to tensions of only
  7382. 0.28 with respect to the initial and final directions; since \MF\ insists
  7383. that ^{tension}s be at least~0.75, this anomalous path could never have arisen
  7384. if the control points hadn't been given explicitly.
  7385. \ddangerexercise Write macros called ^"posttension" and ^"pretension"
  7386. that determine the effective tensions of a path's control points at
  7387. integer times~$t$. For example, `"pretension"~1 of ($z_0\to
  7388. \tension\alpha\and\beta\to z_1$)' should be $\beta$ (approximately).
  7389. Test your macro by computing "posttension"~0 of $\bigl((0,0)\{"right"\}
  7390. \ldots\{"up"\}(1,10)\bigr)$.
  7391. \answer @vardef@ "posttension" @expr@ $t$ of $p$ $=$\parbreak
  7392. \quad@save@ $q$; @path@ $q$;\parbreak
  7393. \quad$q={\rm point}\,t\,{\rm of}\,p\,\{{\rm direction}\,t\,{\rm of}\,p\}
  7394.  \to\{{\rm direction}\,t\!+\!1\,{\rm of}\,p\}\,
  7395.  {\rm point}\,t\!+\!1\,{\rm of}\,p$;\parbreak
  7396. \quad length(postcontrol 0 of $q$ $-$ point 0 of $q$)\parbreak
  7397. \qquad/length(postcontrol $t$ of $p$ $-$ point t of $p$) @enddef@;\parbreak
  7398. @vardef@ "pretension" @expr@ $t$ of $p$ $=$\parbreak
  7399. \quad@save@ $q$; @path@ $q$;\parbreak
  7400. \quad$q={\rm point}\,t\!-\!1\,{\rm of}\,p\,\{{\rm direction}\,
  7401.  t\!-\!1\,{\rm of}\,p\}\to\{{\rm direction}\,t\,{\rm of}\,p\}\,
  7402.  {\rm point}\,t\,{\rm of}\,p$;\parbreak
  7403. \quad length(precontrol 1 of $q$ $-$ point 1 of $q$)\parbreak
  7404. \qquad/length(precontrol $t$ of $p$ $-$ point t of $p$) @enddef@;
  7405. \par\nobreak\smallskip\noindent
  7406. The stated posttension turns out to be 4.54019.
  7407. \danger We have now discussed almost all of the things that \MF\ can do
  7408. with paths; but there's one more important operation to consider,
  7409. namely ^{intersection}. Given two paths $p$ and~$q$, you can write
  7410. \begindisplay
  7411. $p$ intersectiontimes $q$
  7412. \enddisplay
  7413. and the result will be a pair of times $(t,u)$ such that point~$t$
  7414. of~$p$~$\approx$ point~$u$ of~$q$. For example, using the
  7415. |expr| routine,^^"halfcircle"
  7416. \begindemo{245pt}
  7417. \demohead
  7418. unitsquare intersectiontimes fullcircle&(0.50002,0)\cr
  7419. unitsquare intersectiontimes fullcircle rotated 90&(0.50002,6)\cr
  7420. reverse unitsquare intersectiontimes fullcircle&(0.50002,2)\cr
  7421. fullcircle intersectiontimes unitsquare&(0,0.50002)\cr
  7422. halfcircle rotated 45 intersectiontimes unitsquare&(1,3.5)\cr
  7423. halfcircle rotated 89 intersectiontimes unitsquare&(0.02196,3.5)\cr
  7424. halfcircle rotated 90 intersectiontimes unitsquare&(0,3.50002)\cr
  7425. halfcircle rotated 91 intersectiontimes unitsquare&(-1,-1)\cr
  7426. halfcircle rotated 45 intersectiontimes fullcircle&(0,1)\cr
  7427. fullcircle intersectiontimes (-0.5,0)&(4,0)\cr
  7428. unitsquare intersectionpoint fullcircle&(0.5,0)\cr
  7429. reverse unitsquare intersectionpoint fullcircle&(0,0.5)\cr
  7430. \enddemo
  7431. Notice that the result is $(-1,-1)$ if the paths don't intersect.
  7432. The last two examples illustrate the `^{intersectionpoint}'
  7433. operator, which yields the common point of intersection. Both
  7434. intersectiontimes and intersectionpoint apply at the ^{tertiary level} of
  7435. ^{precedence}, hence parentheses were not needed in these examples.
  7436. \dangerexercise J. H. ^{Quick} (a student) wanted to construct a path~$r$
  7437. that started on some previously defined path~$p$ and proceeded
  7438. up to the point where it touched another path~$q$, after which $r$ was
  7439. supposed to continue on path~$q$. So he wrote
  7440. \begindisplay
  7441. @path@ $r$; \ @numeric@ $t,u$; \ $(t,u)=p$ intersectiontimes $q$;\cr
  7442. $r={\rm subpath}\,(0,t)\,{\rm of}\,p\;\;\&\;\;
  7443.  {\rm subpath}\,(u,"infinity")\,{\rm of}\,q$;\cr
  7444. \enddisplay
  7445. but it didn't work. Why not?
  7446. \answer The `\&' had to be changed to `$\to$', because point~$t$ of~$p$
  7447. might not be exactly equal to point~$u$ of~$q$.
  7448. \ddanger If the paths intersect more than once, \MF\ has a somewhat
  7449. peculiar way of deciding what times $(t,u)$ should be reported by
  7450. `$p$~intersectiontimes~$q$'. Suppose $p$ has length~$m$ and $q$ has
  7451. length~$n$. \ (Paths of length~0 are first changed into motionless paths
  7452. of length~1.) \ \MF\ proceeds to examine subpath~$(k,k+1)$ of~$p$
  7453. versus subpath~$(l,l+1)$ of~$q$, for $k=0$, \dots,~$m-1$ and $l=0$,
  7454. \dots,~$n-1$, with $l$ varying most rapidly. This reduces the general
  7455. problem to the special case of paths of length~1, and the times $(t,u)$
  7456. for the first such intersection found are added to $(k,l)$. But within
  7457. paths of length~1 the search for intersection times is somewhat
  7458. different: Instead of reporting the ``lexicographically smallest'' pair
  7459. $(t,u)$ that corresponds to an intersection, \MF\ finds the $(t,u)$
  7460. whose ``^{shuffled binary}'' representation $(.t_1u_1t_2u_2\ldots\,)_2$
  7461. is minimum, where $(.t_1t_2\ldots\,)_2$ and $(.u_1u_2\ldots\,)_2$ are
  7462. the radix-2 representations of $t$ and~$u$.
  7463. \ddangerexercise (A mathematical puzzle.) \ The path
  7464. $p=(0,0)\to\controls\,(2,2)\and(0,1)\to(1,0)$ loops on itself, so there
  7465. are times $t<u$ such that point~$t$ of~$p$~$\approx$ point~$u$ of~$p$.
  7466. Devise a simple way to compute $(t,u)$ in a \MF\ program, without
  7467. using the subpath operation.
  7468. \answer Since $p$ intersects itself infinitely often at times $(t,t)$,
  7469. the task may seem impossible; but \MF's shuffled-binary search procedure
  7470. provides a way. Namely, $p$~intersectiontimes reverse~$p$~$=$
  7471. $(0.17227,0.28339)$, from which we can deduce that $t=0.17227$ and
  7472. $1-u=0.28339$.
  7473. \danger Let's conclude this chapter by applying what we've learned about
  7474. paths to a real-life example. The {\sl^{Journal of Algorithms}\/} has been
  7475. published since 1980 by Academic Press, and its cover page carries the
  7476. following ^{logo}, which was designed by J.~C. Knuth ^^{Knuth, J C}
  7477. to blend with the style of type % namely, `Cairoli' by Chartpak
  7478. used elsewhere on that page:
  7479. \displayfig 14dd (25mm)
  7480. A \MF\ program to produce this logo will make it possible for the editors
  7481. of the journal to use it on letterheads in their correspondence.
  7482. Here is one way to do the job, without needing to erase anything:
  7483. ^^"superellipse" ^^"whatever" ^^{rotatedaround} ^^{reflectedabout}
  7484. ^^@forsuffixes@
  7485. $$\halign{\hbox to\parindent{\hfil\sevenrm#\ \ \ }&#\hfil\cr
  7486. 1&@beginchar@\kern1pt(|"A"|$,29"mm"\0,25"mm"\0,0)$; \
  7487.  $"thick"\0:=2"mm"\0$; \ $"thin"\0:=5/4"mm"\0$;\cr
  7488. 2&@define\_whole\_blacker\_pixels@$("thick","thin")$;\cr
  7489. 3&@forsuffixes@ $\$=a,b,c$: \ @transform@ \$;\cr
  7490. 4&\quad @forsuffixes@ $e=l,r$: \ @path@ $\$e,\$'e$; \
  7491.  @numeric@ $t\$[\,]e$; \ @endfor@ @endfor@\cr
  7492. 5&$\penpos1("thick",0)$; $\penpos2("thick",90)$;
  7493.  $\penpos3("thick",180)$; $\penpos4("thick",270)$;\cr
  7494. 6&$\penpos5("thick",0)$; $\penpos6("thick",90)$;
  7495.  $\penpos7("thick",180)$; $\penpos8("thick",270)$;\cr
  7496. 7&$x_2=x_4=x_6=x_8=.5[x_5,x_7]=.5w$; \ $x_{1r}=w$; \ $x_{3r}=0$; \
  7497.  $x_5-x_7=y_6-y_8$;\cr
  7498. 8&$y_1=y_3=y_5=y_7=.5[y_6,y_8]=.5h$; \ $y_{2r}=h$; \ $y_{4r}=0$; \
  7499.  $y_{6r}=.75h$;\cr
  7500. 9&@forsuffixes@ $e=l,r$: \ $a.e=b'e=c'e="superellipse"
  7501.  (z_{1e},z_{2e},z_{3e},z_{4e},.75)$;\cr
  7502. 10&\quad $a'e=b.e=c.e="superellipse"
  7503.  (z_{5e},z_{6e},z_{7e},z_{8e},.72)$; \ @endfor@\cr
  7504. 11&$\penpos{a1}("thin",0)$; \ $\penpos{a5}("whatever",-90)$; \
  7505.  $\penpos{a9}("thin",180)$;\cr
  7506. 12&$x_{a1l}-x_{a9l}=1/3(x_{5l}-x_{7l})$;\ $x_{a5}=.5w$; \
  7507.  $y_{a1}=y_{a9}$; \ $y_{a5r}=4/7h$;\cr
  7508. 13&$x_{a3l}=x_{a1l}$; \ $x_{a3r}=x_{a1r}$; \ $x_{a4r}=1/6[x_{a3r},x_{1l}]$; \
  7509.  $x_0=.5w$; \ $y_0=.52h$;\cr
  7510. 14&$x_{a6l}+x_{a4l}=x_{a6r}+x_{a4r}=
  7511.  x_{a7l}+x_{a3l}=x_{a7r}+x_{a3r}=x_{a9}+x_{a1}=w$;\cr
  7512. 15&\thickmuskip=4mu $y_{a3r}=y_{a4r}=y_{a6r}=y_{a7r}=.2[y_{2l},y_0]$; \
  7513.  $y_{a3l}=y_{a4l}=y_{a6l}=y_{a7l}=y_{a3r}-"thin"$;\cr
  7514. 16&$z_{a4l}=z_{a4r}
  7515.  +("thin",0)\,{\rm rotated}({\rm angle}(z_{a4r}-z_{a5r})+90)$\cr
  7516. 17&\qquad$\null+"whatever"\ast(z_{a4r}-z_{a5r})$; \
  7517.  $z_{a4l}-z_{a5l}="whatever"\ast(z_{a4r}-z_{a5r})$;\cr
  7518. 18&$z=a.r\;\hbox{intersectionpoint}\;(z_0\dashto(w,0))$; \
  7519.  $y_{a1}-y_{a5}=\hbox{length}(z-z_0)$;\cr
  7520. 19&$b="identity"$ shifted $(0,y_0-y_{a1})$
  7521.  rotatedaround$(z_0,90-\hbox{angle}(z_0-(w,0)))$;\cr
  7522. 20&$c=b$ reflectedabout $(z_2,z_4)$;\cr
  7523. 21&@for@ $n=1,3,4,5,6,7,9$:
  7524.  \ @forsuffixes@ $e=l,,r$: \ @forsuffixes@ $\$=b,c$:\cr
  7525. 22&\quad $z_{\$[n]e}=z_{a[n]e}$ transformed \$; \ @endfor@ @endfor@ @endfor@\cr
  7526. 23&@forsuffixes@ $e=l,r$: \  @forsuffixes@ $\$=a,b,c$:\cr
  7527. 24&\quad $z_{\$2e}=\$r$ intersectionpoint $(z_{\$1e}\dashto z_{\$3e})$;\cr
  7528. 25&\quad $z_{\$8e}=\$r$ intersectionpoint $(z_{\$9e}\dashto z_{\$7e})$;\cr
  7529. 26&\quad $t_{\$1e}=\hbox{xpart}(\$e$
  7530.  intersectiontimes $(z_{\$1l}\dashto z_{\$3l}))$;\cr
  7531. 27&\quad $t_{\$9e}=\hbox{xpart}(\$e$
  7532.  intersectiontimes $(z_{\$9l}\dashto z_{\$7l}))$;\cr
  7533. 28&\quad $t_{\$4e}=\hbox{xpart}(\$'e$
  7534.  intersectiontimes $(z_{\$5r}\dashto z_{\$4l}))$;\cr
  7535. 29&\quad $t_{\$6e}=\hbox{xpart}(\$'e$
  7536.  intersectiontimes $(z_{\$5r}\dashto z_{\$6l}))$; \ @endfor@ @endfor@\cr
  7537. 30&^@penstroke@ subpath$(t_{a9e},t_{b6e})$ of $a.e$;\cr
  7538. 31&@penstroke@ subpath$(t_{b4e},t_{c4e})$ of $b'e$;\cr
  7539. 32&@penstroke@ subpath$(t_{c6e},t_{a1e}+8)$ of $c'e$;\cr
  7540. 33&@penstroke@ subpath$(t_{a6e},t_{b9e})$ of $a'e$;\cr
  7541. 34&@penstroke@ subpath$(t_{b1e},t_{c1e})$ of $b.e$;\cr
  7542. 35&@penstroke@ subpath$(t_{c9e},t_{a4e}+8)$ of $c.e$;\cr
  7543. 36&@forsuffixes@ $\$=a,b,c$: \
  7544.  @penlabels@$(\$1,\$2,\$3,\$4,\$5,\$6,\$7,\$8,\$9)$;\cr
  7545. 37&\quad @penstroke@ $z_{\$2e}\dashto z_{\$3e}\dashto z_{\$4e}\dashto
  7546.  z_{\$5e}\dashto z_{\$6e}\dashto z_{\$7e}\dashto z_{\$8e}$; \ @endfor@\cr
  7547. 38&@penlabels@(^@range@ 0 ^@thru@ 8); \ @endchar@;\cr
  7548. Lines 5--10 of this program define the main superellipses of the figure.
  7549. The outer superellipse is eventually drawn as three separate strokes
  7550. in lines 30--32, and the inner one is drawn as three strokes in lines 33--35.
  7551. The rest of the figure consists of three arrows, whose point labels are
  7552. prefaced by the respective labels $a,b,c$. Lines 11--18 define the `$a$'
  7553. arrow; then lines 19--22 transform these points into the `$b$' and~`$c$'
  7554. arrows, anticipating some of the things we shall discuss in Chapter~15.
  7555. Thirty-six intersections between arrows and superellipses are computed
  7556. in lines 23--29, and the arrows are finally drawn by the penstrokes
  7557. specified in lines 36--37.
  7558. \displayfig 14e (4.5in)
  7559. \endchapter
  7560. % se se\~nala con puntos el camino,
  7561. The route is indicated by dots,
  7562. % se expressan por numeros las jornadas,
  7563. the days' journeys are expressed by numbers,
  7564. % y se distinguen por abecedario los lugares \^o parages particulares.
  7565. and letters are used to locate notable places and sites.
  7566. % ... Hasta llegar al arroyo de S$\rm^n$ Francisco,
  7567. .\thinspace.\thinspace. We arrived at the Arroyo de San Francisco,
  7568. % en cuya orilla esta el pinabete que dixe ayer,
  7569. beside which stream is the redwood tree ^^{El Palo Alto} I spoke of yesterday;
  7570. % cuya altura medi con el Grafometro
  7571. I measured its height with the Graphometer
  7572. % y lo halle a poco mas o menos segun el calculo que hize,
  7573. % de unas cincuenta varas de alto.
  7574. and reckoned it to be fifty yards high, more or less.
  7575. \author FRAY PEDRO ^{FONT}, {\sl Diary\/} (1776)
  7576.  % from the second paragraph, then skipping to the entry for March 30
  7577. \bigskip
  7578. The practical teaching of the masters of Art %
  7579. was summed by the O of ^{Giotto}.
  7580. \author JOHN ^{RUSKIN},  {\sl The Cestus of Aglaia\/} (1865)
  7581.  % in Art Journal, new series, vol 4, p197
  7582.  % later published in section 144 of his Queen of the Air (1869)
  7583. \eject
  7584. \beginchapter Chapter 15. Transformations
  7585. Points, paths, pens, and pictures can be shifted, scaled, rotated,
  7586. and revamped in a variety of ways. Our aim in this chapter will be to
  7587. learn all about the built-in metamorphoses of \MF\kern-1pt, because
  7588. they can make programs simpler and more versatile.
  7589. The basic ^{transformations} have already appeared in many examples, but let's
  7590. start by reviewing them here:
  7591. \begindisplay
  7592. $(x,y)$ ^{shifted} $(a,b)$&$=(x+a,y+b)$;\cr
  7593. $(x,y)$ ^{scaled} $s$&$=(sx,sy)$;\cr
  7594. $(x,y)$ ^{xscaled} $s$&$=(sx,y)$;\cr
  7595. $(x,y)$ ^{yscaled} $s$&$=(x,sy)$;\cr
  7596. $(x,y)$ ^{slanted} $s$&$=(x+sy,y)$;\cr
  7597. $(x,y)$ ^{rotated} $\theta$&$=(x\cos\theta-y\sin\theta,
  7598.   x\sin\theta+y\cos\theta)$;\cr
  7599. $(x,y)$ ^{zscaled} $(u,v)$&$=(xu-yv,xv+yu)$.\cr
  7600. \enddisplay
  7601. One of the nice things about \MF\ is that you don't have to remember the
  7602. sine-and-cosine formulas of trigonometry; you just have to know that
  7603. `$(x,y)$~rotated~$\theta$' means `the vector~$(x,y)$ rotated $\theta$~degrees
  7604. counterclockwise around~$(0,0)$', and the computer does all the necessary
  7605. calculations by itself. The operation of zscaling may look a bit strange,
  7606. but it is simply a combination of rotating by angle$\,(u,v)$ and scaling
  7607. by length$\,(u,v)$.
  7608. Plain \MF\ provides two more transformations that are commonly needed: You can
  7609. say `$(x,y)$ ^{rotatedaround} $(z_0,\theta\mkern1mu)$' if you want to rotate
  7610. around point~$z_0$ instead of point~$(0,0)$. And you can say
  7611. `$(x,y)$~^{reflectedabout}~$(z_1,z_2)$' if you want to find the point directly
  7612. opposite $(x,y)$ on the other side of the straight line that runs through
  7613. $z_1$ and~$z_2$.
  7614. All of these operations are special manifestations of a single glorious
  7615. maneuver that can be written in the general form
  7616. \begindisplay
  7617. $(x,y)$ ^{transformed} $t$.
  7618. \enddisplay
  7619. Here $t$ is a variable (or primary expression) of type ^@transform@; it
  7620. stands for any desired sequence of shiftings, scalings, slantings, etc.,
  7621. all in one fell swoop.
  7622. You can give ^{equations} between transforms, just as you can give equations
  7623. between other types of things in \MF\ programs. Thus, for example,
  7624. you might say
  7625. \begindisplay
  7626. @transform@ $t[\,]$; \ $t_2=t_1$ shifted $(2,2)$ rotated 30;
  7627. \enddisplay
  7628. then an expression like `$(x,y)$ transformed $t_1$ shifted $(2,2)$ rotated 30'
  7629. can be abbreviated to `$(x,y)$ transformed $t_2$', which is simpler and faster.
  7630. There's a special transform variable called ^"identity" with the amazing
  7631. property that
  7632. \begindisplay
  7633. $(x,y)$ transformed "identity" $=$ $(x,y)$
  7634. \enddisplay
  7635. for all $x$ and $y$. You might think that "identity" is useless, since it
  7636. does nothing, but in fact it's a natural starting point for building other
  7637. transforms. For example, line~19 of the program at the end of the previous
  7638. chapter says
  7639. \begindisplay
  7640. $b="identity"$ shifted $(0,y_0-y_{a1})$ rotatedaround$(z_0,"theta")$;
  7641. \enddisplay
  7642. this defines the transform variable $b$ to be a compound transformation
  7643. that is used on lines 21 and~22 to construct the lower left arrow
  7644. as a shifted and rotated copy of the upper arrow, in the character being drawn.
  7645. \danger A @transform@ variable $t$ represents six numbers
  7646. $(t_x,t_y,t_{xx},t_{xy},t_{yx},t_{yy})$, in much the same way
  7647. as a @pair@ variable represents two numbers $(x,y)$. The general
  7648. transformation `$(x,y)$~transformed~$t$' is simply an abbreviation for
  7649. \begindisplay
  7650. $(t_x+x\,t_{xx}+y\,t_{xy},\;t_y+x\,t_{yx}+y\,t_{yy})$;
  7651. \enddisplay
  7652. thus, for example, `$t_{xy}$' appears in the xpart of the transform as the
  7653. coefficient of~$y$. If you say `^@show@~$t$' when $t$~is a completely
  7654. unknown transform, the computer will type
  7655. \begintt
  7656. >> (xpart t,ypart t,xxpart t,xypart t,yxpart t,yypart t)
  7657. \endtt
  7658. just as it would type `{\tt>> (xpart u,ypart u)}' for a completely
  7659. unknown variable~$u$ of type @pair@. You can access individual components
  7660. of a transform by referring to `^{xpart}~$t$', `^{ypart}~$t$',
  7661. ^^{xypart}^^{yxpart}^^{yypart}
  7662. `^{xxpart}~$t$', etc.
  7663. \outer\def\begindemo#1{$$\advance\baselineskip by2pt
  7664.   \catcode`\"=\other
  7665.   \halign\bgroup\indent\hbox to #1{\tt##\hfil}&\tt##\hfil\cr
  7666.   \noalign{\vskip-2pt}}
  7667. \outer\def\enddemo{\egroup$$}
  7668. \def\demohead{\it\kern-2pt You type&\it\kern-1pt And the result is\cr
  7669.   \noalign{\nobreak\vskip2pt}}
  7670. \danger Once again, we can learn best by computer experiments with the
  7671. |expr| file (cf.~Chapter~8); this time the idea is to play with transforms:
  7672. \begindemo{175pt}
  7673. \demohead
  7674. identity&(0,0,1,0,0,1)\cr
  7675. identity shifted (a,b)&(a,b,1,0,0,1)\cr
  7676. identity scaled s&(0,0,s,0,0,s)\cr
  7677. identity xscaled s&(0,0,s,0,0,1)\cr
  7678. identity yscaled s&(0,0,1,0,0,s)\cr
  7679. identity slanted s&(0,0,1,s,0,1)\cr
  7680. identity rotated 90&(0,0,0,-1,1,0)\cr
  7681. identity rotated 30&(0,0,0.86603,-0.5,0.5,0.86603)\cr
  7682. identity rotatedaround ((2,3),90)&(5,1,0,-1,1,0)\cr
  7683. (x,y) rotatedaround ((2,3),90)&(-y+5,x+1)\cr
  7684. (x,y) reflectedabout ((0,0),(0,1))&(-x,y)\cr
  7685. (x,y) reflectedabout ((0,0),(1,1))&(y,x)\cr
  7686. (x,y) reflectedabout ((5,0),(0,10))&(-0.8y-0.6x+8,0.6y-0.8x+4)\cr
  7687. \enddemo
  7688. \dangerexercise Guess the result of `|(x,y) reflectedabout ((0,0),(1,0))|'.
  7689. \answer |(x,-y)|.
  7690. \dangerexercise What transform takes $(x,y)$ into $(-x,-y)$?
  7691. \answer $(x,y)$ rotated 180, or $(x,y)$ scaled $-1$.
  7692. \dangerexercise True or false:\quad $\bigl(-(x,y)\bigr)$ transformed $t$
  7693. $=$ $-\bigl((x,y)$ transformed $t\bigr)$.
  7694. \answer True if and only if ${\rm xpart}\,t={\rm ypart}\,t=0$. If the
  7695. stated equation holds for at least one pair $(x,y)$, it holds for all $(x,y)$.
  7696. According to the syntax of Chapter~8, \MF\ interprets `$-(x,y)$ transformed~$t$'
  7697. as $\bigl(-(x,y)\bigr)$ transformed~$t$. \ (Incidentally, mathematicians
  7698. call \MF's transformers ``^{affine transformations},'' and the special case in
  7699. which the xpart and ypart are zero is called ``^{homogeneous}.'')
  7700. \danger In order to have some transform variables to work with, it's necessary
  7701. to `^{hide}' some declarations and commands before giving the next exprs:
  7702. \begindemo{175pt}
  7703. \demohead
  7704. hide(transform t[]) t1&(xpart t1,ypart t1,xxpart...)\cr
  7705. hide(t1=identity zscaled(1,2)) t1&(0,0,1,-2,2,1)\cr
  7706. hide(t2=t1 shifted (1,2)) t2&(1,2,1,-2,2,1)\cr
  7707. t2 xscaled s&(s,2,s,-2s,2,1)\cr
  7708. unknown t2&false\cr
  7709. transform t2&true\cr
  7710. t1=t2&false\cr
  7711. t1<t2&true\cr
  7712. inverse t2&(-1,0,0.2,0.4,-0.4,0.2)\cr
  7713. inverse t2 transformed t2&(0,0,0.99998,0,0,0.99998)\cr
  7714. hide(t3 transformed t2=identity) t3&(-1,0,0.2,0.4,-0.4,0.2)\cr
  7715. \enddemo
  7716. The ^"inverse" function finds the transform that undoes the work
  7717. of another; the equation that defines $t_3$ above shows how to
  7718. calculate an inverse indirectly, without using "inverse".
  7719. \danger Like numeric expressions and pair expressions, transform
  7720. expressions can be either ``^{known}'' or ``^{unknown}'' at any given
  7721. point in a program.  \ (If any component of a transform is unknown, the
  7722. whole transform is regarded as unknown.) \ You are always allowed to use
  7723. the constructions
  7724. \begindisplay
  7725. \<known> transformed \<known>\cr
  7726. \<unknown> transformed \<known>\cr
  7727. \<known> transformed \<unknown>\cr
  7728. \enddisplay
  7729. but \MF\ will balk at `\<unknown> transformed \<unknown>'. This is
  7730. not the most lenient rule that could have been implemented, but it
  7731. does have the virtue of being easily remembered.
  7732. \dangerexercise If $z_1$ and $z_2$ are unknown pairs, you can't
  7733. say `$z_1$ shifted~$z_2$', because `shifted~$z_2$' is an unknown
  7734. transform. What can you legally say instead?
  7735. \answer $z_1+z_2$.
  7736. \begingroup\def\dbend{{\manual\char126}} % lefty dangerous bend sign
  7737. \dangerexercise Suppose "dbend" is a picture variable that contains
  7738. a normal dangerous bend sign, as in the ``reverse-video'' example
  7739. of Chapter~13. Explain how to transform it into the ^{left-handed
  7740. dangerous bend} that heads this paragraph.
  7741. \answer @beginchar@$(126,25u\0,"hheight"\0+"border"\0,0)$;
  7742. |"Dangerous left bend"|;\parbreak
  7743. $"currentpicture":="dbend"$ reflectedabout $\bigl((.5w,0),(.5w,h)\bigr)$; \
  7744. @endchar@;\medskip\noindent
  7745. The same idea can be used to create right ^{parentheses} as perfect mirror
  7746. images of left parentheses, etc., if the parentheses aren't slanted.
  7747. \endgroup
  7748. \danger The next three lines illustrate the fact that you can specify
  7749. a transform completely by specifying the images of three points:
  7750. \begindemo{175pt}
  7751. \demohead
  7752. hide((0,0)transformed t4=(1,2)) t4&(1,2,xxpart t4,xypart t4,...)\cr
  7753. hide((1,0)transformed t4=(4,5)) t4&(1,2,3,xypart t4,3,yypart t4)\cr
  7754. hide((1,4)transformed t4=(0,0)) t4&(1,2,3,-1,3,-1.25)\cr
  7755. \enddemo
  7756. The points at which the transform is given shouldn't all lie on
  7757. a straight line.
  7758. \danger Now let's use transformation to make a little ^{ornament}, based
  7759. on a `{\manual\oneu\kern1pt}' shape replicated four times:
  7760. \qquad\xleaders\hbox{$\vcenter{\hbox{\manual\fouru}}$}\hfill\
  7761. \vskip-6mm
  7762. \displayfig 15a (396\apspix)
  7763. \begingroup\ninepoint\noindent The following program merits careful study:
  7764. $$\halign{\hbox to\parindent{\hfil\sevenrm#\ \ \ }&#\hfil\cr
  7765. 1&@beginchar@\kern1pt(|"4"|$,11"pt"\0,11"pt"\0,0)$;\cr
  7766. 2&@pickup@ @pencircle@ scaled 3/4"pt" yscaled 1/3 rotated 30;\cr
  7767. 3&@transform@ $t$;\cr
  7768. 4&$t="identity"$ ^{rotatedaround}$\bigl((.5w,.5h),-90\bigr)$;\cr
  7769. 5&$x_2=.35w$; \ $x_3=.6w$;\cr
  7770. 6&$y_2=.1h$; \ $"top"\,y_3=.4h$;\cr
  7771. 7&@path@ $p$; \ $p=z_2\{"right"\}\ldots\{"up"\}z_3$;\cr
  7772. 8&$"top"\,z_1$ $=$ point .5 of $p$ transformed $t$;\cr
  7773. 9&@draw@ $z_1\ldots p$;\cr
  7774. 10&@addto@ "currentpicture" @also@ "currentpicture" transformed $t$;\cr
  7775. 11&@addto@ "currentpicture" @also@ "currentpicture"
  7776.  transformed ($t$ transformed $t$);\cr
  7777. 12&@labels@$(1,2,3)$; \ @endchar@;\cr
  7778. ^^@addto@
  7779. Lines 3 and 4 compute the transform that moves each
  7780. `{\manual\oneu\kern1pt}' to its clockwise neighbor. Lines 5--7 compute the
  7781. right half of the `{\manual\oneu\kern1pt}'.  Line~8 is the most
  7782. interesting: It puts point $z_1$ on the rotated path.  Line~9 draws the
  7783. `{\manual\oneu\kern1pt}', line~10 changes it into two, and line~11 changes
  7784. two into four. The parentheses on line~11 could have been omitted, but it
  7785. is much faster to transform a transform than to transform a picture.
  7786. \endgroup
  7787. \ddanger \MF\ will transform a ^{picture} expression only when $t_{xx}$,
  7788. $t_{xy}$, $t_{yx}$, and~$t_{yy}$ are integers and either $t_{xy}=t_{yx}=0$
  7789. or $t_{xx}=t_{yy}=0$; furthermore, the values of $t_x$ and~$t_y$ are
  7790. rounded to the nearest integers. Otherwise the transformation would not
  7791. take pixel boundaries into pixel boundaries.
  7792. \ddangerexercise Explain how to rotate the ornament by $45^\circ$.
  7793. \qquad\xleaders\hbox{\kern1pt$\vcenter{\hbox{\manual\fourc}}$}\hfill\
  7794. \answer Change line 9 to
  7795. \begindisplay
  7796. @draw@ $(z_1\ldots p)$ rotatedaround$\bigl((.5w,.5h),-45\bigr)$\cr
  7797. \quad @withpen@ @pencircle@ scaled 3/4"pt" yscaled 1/3 rotated $-15$;\cr
  7798. \enddisplay
  7799. Plain \MF\ maintains a special variable called ^"currenttransform",
  7800. behind the scenes. Every ^@fill@ and ^@draw@ command is affected by this
  7801. variable; for example, the statement `@fill@~$p$' actually fills the
  7802. interior of the path
  7803. \begindisplay
  7804. $p$ transformed "currenttransform"
  7805. \enddisplay
  7806. instead of $p$ itself. We haven't mentioned this before, because
  7807. "currenttransform" is usually equal to "identity"; but nonstandard
  7808. settings of "currenttransform" can be used for special effects that
  7809. are occasionally desired. For example, it's possible to change
  7810. `\MF\kern1pt' to `{\manual 89:;<=>:}\kern3pt' by simply saying
  7811. \begindisplay
  7812. $"currenttransform":="identity"$ slanted 1/4
  7813. \enddisplay
  7814. and executing the programs of |logo.mf| that are described in Chapter~11;
  7815. no other changes to those programs are necessary.
  7816. It's worth noting that the pen nib used to draw `{\manual 89:;<=>:}\kern3pt'
  7817. was not slanted when "currenttransform" was changed; only the ``tracks'' of
  7818. the pen, the paths in @draw@ commands, were modified. Thus the slanted image
  7819. was not simply obtained by slanting the unslanted image.
  7820. \ddanger When fonts are being made for devices with ^{nonsquare pixels},
  7821. plain \MF\ will set "currenttransform" to `"identity" yscaled
  7822. ^"aspect\_ratio"', and ^@pickup@ will similarly yscale the pen nibs
  7823. that are used for drawing. In this case the slanted
  7824. `{\manual 89:;<=>:}\kern3pt' letters should be drawn with
  7825. \begindisplay
  7826. $"currenttransform":="identity"$ slanted 1/4 yscaled "aspect\_ratio".
  7827. \enddisplay
  7828. \ddangerexercise Our program for
  7829. `\kern1pt\lower2.5pt\hbox{\manual\fouru}\kern1pt' doesn't work when pixels
  7830. aren't square. Fix it so that it handles a general "aspect\_ratio".
  7831. \answer Replace line 10 by
  7832. \begindisplay
  7833. @pickup@ @pencircle@ scaled 3/4"pt" yscaled 1/3 rotated $-60$;\cr
  7834. @draw@ ($z_1\ldots p$) transformed $t$;\cr
  7835. \enddisplay
  7836. \endchapter
  7837. Change begets change. Nothing propagates so fast.
  7838. \author CHARLES ^{DICKENS},  {\sl Martin Chuzzlewit\/} (1843)
  7839.  % opening lines of chapter 18
  7840. \bigskip
  7841. There are some that never know how to change.
  7842. \author MARK ^{TWAIN},  {\sl Joan of Arc\/} (1896)
  7843.  % book 2, chapter 26, second page
  7844. \eject
  7845. \beginChapter Chapter 16. Calligraphic\\Effects
  7846. ^{Pens} were introduced in Chapter 4, and we ought to make a systematic study
  7847. of what \MF\ can do with them before we spill any more ink. The purpose
  7848. of this chapter will be to explore the uses of ``fixed'' pen nibs---i.e.,
  7849. variables and expressions of type ^@pen@---rather than to consider
  7850. the creation of shapes by means of outlines or penstrokes.
  7851. When you say `^@pickup@ ^\<pen expression>', the macros of plain \MF\ do
  7852. several things for you: They create a representation of the specified
  7853. pen~nib, and assign it to a pen variable called ^"currentpen"; then they
  7854. store away information about the top, bottom, left, and right extents of
  7855. that pen, for use in ^"top", ^"bot", ^"lft", and ^"rt" operations.
  7856. A ^@draw@ or ^@drawdot@ or ^@filldraw@ command will make use of
  7857. "currentpen" to modify the current picture.
  7858. You can also say `@pickup@ \<numeric expression>'; in this case the numeric
  7859. expression designates the code number of a previously picked-up pen
  7860. that was saved by `^@savepen@'. For example, the |logo.mf| file in Chapter~11
  7861. begins by picking up the pen that's used to draw `\MF\kern1pt', then
  7862. it says `$"logo\_pen":=@savepen@$'. Every character program later in that
  7863. file begins with the command `@pickup@ "logo\_pen"', which is a fast
  7864. operation because it doesn't require the generation of a new
  7865. pen representation inside the computer.
  7866. \danger Caution: Every time you use @savepen@, it produces a new integer
  7867. value and stashes away another pen for later use. If you keep doing this,
  7868. \MF's memory will become cluttered with the representations of pens
  7869. that you may never need again. The command `^@clear\_pen\_memory@'
  7870. discards all previously saved pens and lets \MF\ start afresh.
  7871. \danger But what is a \<pen expression>? Good question. So far in this book,
  7872. almost everything that we've picked up was a pencircle followed by
  7873. some sequence of transformations; for example, the "logo\_pen" of
  7874. Chapter~11 was `@pencircle@ xscaled~"px" yscaled~"py"'. Chapter~13
  7875. also made brief mention of another kind of pen, when it said
  7876. \begindisplay
  7877. @pickup@ ^@penrazor@ scaled 10;
  7878. \enddisplay
  7879. this command picks up an infinitely thin pen that runs from point
  7880. $(-5,0)$ to point $(5,0)$ with respect to its center. Later in this
  7881. chapter we shall make use of pens like
  7882. \begindisplay
  7883. ^@pensquare@ xscaled 30 yscaled 3 rotated 30;
  7884. \enddisplay
  7885. this pen has a rectangular boundary measuring 30 pixels $\times$ 3 pixels,
  7886. inclined at an angle of $30^\circ$ to the baseline.
  7887. \danger You can define pens of any ^{convex polygon}al shape by saying
  7888. `^@makepen@~$p$', where $p$ is a cyclic path. It turns out that \MF\
  7889. looks only at the key points of~$p$, not the control points, so we may
  7890. as well assume that $p$ has the form $z_0\dashto z_1\dashto\<etc.>\dashto
  7891. \cycle$. This path must have the property that it turns left at every
  7892. key point (i.e., $z_{k+1}$ must lie to the left of the line from $z_{k-1}$
  7893. to~$z_k$, for all~$k$), unless the cycle contains fewer than three key
  7894. points; furthermore the path must have a ^{turning number} of~1 (i.e.,
  7895. it must not make more than one counterclockwise loop). Plain \MF's
  7896. @penrazor@ stands for
  7897. `@makepen@ $\bigl((-.5,0)\dashto(.5,0)\dashto cycle\bigr)$',
  7898. and @pensquare@ is an abbreviation for
  7899. `@makepen@ $\bigl("unitsquare"$ shifted $-(.5,.5)\bigr)$'.
  7900. But @pencircle@ is not defined via @makepen@; it is a
  7901. primitive operation of \MF. It represents a true ^{circle} of diameter~1,
  7902. passing through the points $(\pm.5,0)$ and $(0,\pm.5)$.
  7903. \danger The complete syntax for pen expressions is rather short, because
  7904. you can't really do all that much with pens. But it also contains a
  7905. surprise:
  7906. \beginsyntax
  7907. <pen primary>\is<pen variable>
  7908.  \alt[(]<pen expression>[)]
  7909.  \alt[nullpen]
  7910. <future pen primary>\is[pencircle]
  7911.  \alt[makepen]<path primary>
  7912. <pen secondary>\is<pen primary>
  7913. <future pen secondary>\is<future pen primary>
  7914.  \alt<future pen secondary><transformer>
  7915.  \alt<pen secondary><transformer>
  7916. <pen tertiary>\is<pen secondary>
  7917.  \alt<future pen secondary>
  7918. <pen expression>\is<pen tertiary>
  7919. \endsyntax
  7920. The constant `^@nullpen@' is just the single point $(0,0)$, which is
  7921. invisible---unless you use it in ^@filldraw@, which then reduces to
  7922. ^@fill@. \ (A ^@beginchar@ command initializes "currentpen" to @nullpen@,
  7923. in order to reduce potentially dangerous dependencies between the programs
  7924. for different characters.) \
  7925. The surprise in these rules is the notion of a ``^{future pen},''
  7926. which stands for a path or an ellipse that has not yet been converted
  7927. into \MF's internal representation of a true pen. The conversion process
  7928. is rather complicated, so \MF\ procrastinates until being sure that no
  7929. more transformations are going to be made. A true pen is formed at the
  7930. tertiary level, when future pens are no longer permitted in the syntax.
  7931. \danger The distinction between pens and future pens would make no
  7932. difference to a user, except for another surprising fact: All of \MF's
  7933. pens are convex polygons, even the pens that are made from @pencircle@
  7934. and its variants! Thus, for example, the pen you get from an
  7935. untransformed pencircle is identical to the pen you get by specifying
  7936. the ^{diamond-shaped nib}
  7937. \begindisplay
  7938. @makepen@$\,\bigl((.5,0)\dashto(0,.5)\dashto(-.5,0)\dashto
  7939.  (0,-.5)\dashto\cycle\bigr)$.
  7940. \enddisplay
  7941. And the pens you get from `@pencircle@ scaled 20' and `@pencircle@
  7942. xscaled~30 yscaled~20' are polygons with 32 and 40 sides, respectively:
  7943. \displayfig 16a\&b (220\apspix)
  7944. The vertices of the polygons, shown as heavy dots in this illustration,
  7945. all have ``half-integer'' coordinates; i.e., each coordinate is either
  7946. an integer or an integer plus 1/2. Every polygon that comes from a
  7947. @pencircle@ is symmetric under $180^\circ$ rotation; furthermore,
  7948. there will be reflective left/right and top/bottom symmetry if the future
  7949. pen is a circle, or if it's an ellipse that has not been rotated.
  7950. \danger This conversion to polygons explains why future pens must, in
  7951. general, be distinguished from ordinary ones. For example, the extra
  7952. parentheses in `(@pencircle@ xscaled~30) yscaled~20' will yield
  7953. a result quite different from the elliptical polygon just illustrated.
  7954. The parentheses force conversion of `@pencircle@ xscaled~30' from
  7955. future pen to pen, and this polygon turns out to be
  7956. \begindisplay
  7957. $(12.5,-0.5) \dashto (15,0) \dashto (12.5,0.5)$\cr
  7958. \qquad$\dashto (-12.5,0.5) \dashto
  7959. (-15,0) \dashto (-12.5,-0.5) \dashto\cycle$,\cr
  7960. \enddisplay
  7961. an approximation to a $30\times1$ ellipse. Then yscaling by 20 yields
  7962. \displayfig 16c (220\apspix)
  7963. \danger Why does \MF\ work with polygonal approximations to circles,
  7964. instead of true circles? That's another good question. The main reason is
  7965. that suitably chosen polygons give better results than the real thing,
  7966. when ^{digitization} is taken into account. For example, suppose we want
  7967. to draw a straight line of slope 1/2 that's exactly one pixel thick, from
  7968. $(0,y)$ to $(200,y+100)$. The image of a perfectly circular pen of
  7969. diameter~1 that travels along this line has outlines that run from
  7970. $(0,y\pm\alpha)$ to $(200,y+100\pm\alpha)$, where
  7971. $\alpha=\sqrt5/4\approx0.559$. If we digitize these outlines and fill the
  7972. region between them, we find that for some values of~$y$ (e.g., $y=0.1$)
  7973. the result is a repeating pixel pattern like
  7974. `\smash{\hbox{$\vcenter{\offinterlineskip
  7975. \setbox4=\hbox{\manual R}
  7976. \hbox{\hphantom{$\,\ldots\,$}\kern5\wd4\copy4$\,\ldots\,$}
  7977. \hbox{\hphantom{$\,\ldots\,$}\kern3\wd4\copy4\copy4}
  7978. \hbox{\hphantom{$\,\ldots\,$}\kern\wd4\copy4\copy4}
  7979. \hbox{\smash{$\,\ldots\,$}\copy4}}$}}'; but for other values of~$y$ (e.g.,
  7980. $y=0.3$) the repeating pattern of pixels is \vbox to11pt{}50 percent darker:
  7981. `\smash{\raise2pt\hbox{$\vcenter{\offinterlineskip
  7982. \setbox4=\hbox{\manual R}
  7983. \hbox{\hphantom{$\,\ldots\,$}\kern4\wd4\copy4\copy4$\,\ldots\,$}
  7984. \hbox{\hphantom{$\,\ldots\,$}\kern2\wd4\copy4\copy4\copy4}
  7985. \hbox{\hphantom{$\,\ldots\,$}\copy4\copy4\copy4}
  7986. \hbox{\smash{$\,\ldots\,$}\copy4}}$}}'. Similarly, some diagonal
  7987. lines of slope~1 digitize to be twice as dark as others, when a truly
  7988. circular pen is considered. But the diamond-shaped nib that \MF\ uses
  7989. for a pencircle of diameter~1 does not have this defect; all straight
  7990. lines of the same slope will digitize to lines of uniform darkness.
  7991. Moreover, curved lines drawn with the diamond nib always yield one pixel per
  7992. column when they move more-or-less horizontally (with slopes between $+1$
  7993. and $-1$), and they always yield one pixel per row when they move vertically.
  7994. By contrast, the outlines of curves drawn with circular pens produce
  7995. occasional ``blots.'' Circles and ellipses of all diameters can profitably
  7996. be replaced by polygons whose sub-pixel corrections to the ideal shape
  7997. will produce better digitizations; \MF\ does this in accordance with the
  7998. interesting theory developed by John~D. ^{Hobby} in his Ph.D.
  7999. dissertation (Stanford University, 1985).
  8000. \ddanger It's much easier to compute the outlines of a polygonal pen that
  8001. follows a given curve than to figure out the corresponding outlines of
  8002. a truly circular pen; thus polygons win over circles with respect
  8003. to both quality and speed. When a curve is traveling in a
  8004. direction between the edge vectors $z_{k+1}-z_k$ and~$z_k-z_{k-1}$ of
  8005. a polygonal pen, the curve's outline will be offset from its center
  8006. by~$z_k$. If you want fine control over this curve-drawing process,
  8007. \MF\ provides the primitive operation `^{penoffset}~$w$ of~$p$', where
  8008. $w$~is a vector and $p$~is a pen. If $w=(0,0)$, the result is $(0,0)$;
  8009. if the direction of~$w$ lies strictly between $z_{k+1}-z_k$ and $z_k
  8010. -z_{k-1}$, the result is~$z_k$; and if $w$ has the same direction as
  8011. $z_{k+1}-z_k$ for some~$k$, the result is either $z_k$ or~$z_{k+1}$,
  8012. whichever \MF\ finds most convenient to compute.
  8013. \ddangerexercise Explain how to use penoffset to find the point or
  8014. points at the ``top'' of a pen (i.e., the point or points with largest
  8015. $y$~coordinate).
  8016. \answer If there are two points $z_k$ and $z_{k+1}$ with maximum
  8017. $y$~coordinate, the value of `penoffset $(-"infinity","epsilon")$ of~$p$'
  8018. will be~$z_k$ and `penoffset $(-"infinity",-"epsilon")$ of~$p$' will
  8019. be~$z_{k+1}$; `penoffset~"left" of~$p$' will be one or the other. If
  8020. there's only one top point, all three of these formulas will produce it.
  8021. \ (Actually \MF\ also allows pens to be made with three or more
  8022. vertices in a straight line. If there are more than two top vertices,
  8023. you can use penoffset to discover the first and the last, as above;
  8024. furthermore, if you really want to find them all, ^@makepath@ will produce
  8025. a path from which they can be deduced in a straightforward manner.)
  8026. \ddanger The primitive operation `^@makepath@ $p$', where $p$ is
  8027. a (polygonal) pen whose vertices are $z_0$, $z_1$, \dots,~$z_{n-1}$,
  8028. produces the path `$z_0\to\controls z_0\and z_1\to z_1\to\<etc.>\to
  8029. z_{n-1}\to\controls z_{n-1}\and z_0\to\cycle$', which is one of the
  8030. paths that might have generated~$p$. This gives access to all the
  8031. offsets of a pen.
  8032. \ddanger When a @pencircle@ is transformed by any of the operations
  8033. in Chapter~15, it changes into an ellipse of some sort, since all of
  8034. \MF's transformations preserve ellipse-hood. The diameter of the
  8035. ellipse in each direction~$\theta$ is decreased by $2\min\bigl(
  8036. \vert\sin\theta\vert,\vert\cos\theta\vert\bigr)$ times the current
  8037. value of~^"fillin", before converting to a polygon; this helps to
  8038. compensate for the variation in thickness of diagonal strokes with
  8039. respect to horizontal or vertical strokes, on certain output devices.
  8040. \ (\MF\ uses "fillin" only when creating polygons from ellipses,
  8041. but users can of course refer to "fillin" within their own routines
  8042. for drawing strokes.) \ The final polygon will never be perfectly flat
  8043. like ^@penrazor@, even if you say `xscaled~0' and/or `yscaled~0';
  8044. its center will always be surrounded at least by the basic diamond nib
  8045. that corresponds to a circle of diameter~1.
  8046. \dangerexercise Run \MF\ on the |expr| file of Chapter~8 and look at
  8047. what is typed when you ask for `|pencircle|' and `|pencircle|
  8048. |scaled|~|1.1|'. \ (The first will exhibit the diamond nib, while
  8049. the second will show a polygon that's equivalent to @pensquare@.) \
  8050. Continue experimenting until you find the ``threshold'' diameter where
  8051. \MF\ decides to switch between these two polygons.
  8052. \answer `@pencircle@ scaled 1.06060' is the diamond but
  8053. `@pencircle@ scaled 1.06061' is~the square. \ (This assumes that
  8054. ^"fillin"$\null=0$. If, for example, $"fillin"=.1$, the change doesn't
  8055. occur until the diameter is 1.20204.) \ The next change is at diameter
  8056. 1.5, which gives a diamond twice the size of the first.
  8057. \danger \MF's polygonal pens work well for drawing lines and curves,
  8058. but this pleasant fact has an unpleasant corollary: They do not always
  8059. digitize well at the ^{endpoints}, where curves start and stop. The
  8060. reason for this is explored further in Chapter~24; polygon vertices that
  8061. give nice uniform stroke widths might also be ``ambiguous'' points that
  8062. cause difficulties when we consider rounding to the raster. Therefore a
  8063. special ^@drawdot@ routine is provided for drawing one-point paths.
  8064. It is sometimes advantageous to apply @drawdot@ to the first and last
  8065. points of a path~$p$, after having said `^@draw@~$p$'; this can
  8066. fatten up the endpoints slightly, making them look more consistent with
  8067. each other.
  8068. \danger Plain \MF\ also provides two routines that can be used to clean~up
  8069. endpoints in a different way: The command `^@cutoff@$\,(z,\theta)$'
  8070. removes half of the ^"currentpen" image at point~$z$, namely all points
  8071. of the pen that lie in directions between $(\theta-90)^\circ$ and
  8072. $(\theta+90)^\circ$ from the center point. And the command `^@cutdraw@~$p$'
  8073. is an abbreviation for the following three commands:
  8074. \begindisplay
  8075. @draw@ $p$; \ @cutoff@\thinspace(point 0 of $p$, $180+\null$angle
  8076. direction 0 of $p$);\cr
  8077. @cutoff@\thinspace(point "infinity" of $p$, angle
  8078. direction "infinity" of $p$).\cr
  8079. \enddisplay
  8080. The effect is to draw a curve whose ends are clipped perpendicular to the
  8081. starting and ending directions. For example, the command
  8082. \begindisplay
  8083. @cutdraw@ $z_4\to\controls z_1\and z_2\to z_6$
  8084. \enddisplay
  8085. produces the following curve, which invites comparison with the corresponding
  8086. uncut version at the end of Chapter~3:
  8087. \displayfig 16d (5pc)
  8088. \decreasehsize 48mm
  8089. \danger Here's another example of @cutoff@, in which the endpoints of
  8090. \rightfig 16e ({208\apspix} x {216\apspix}) ^15pt
  8091. \MF's~`^{T}' have been cropped at $10^\circ$ angles to the
  8092. perpendicular of the stroke direction:
  8093. \begintt
  8094. pickup logo_pen;
  8095. top lft z1=(0,h); top rt z2=(w,h);
  8096. top z3=(.5w,h); z4=(.5w,0);
  8097. draw z1--z2;
  8098. cutoff(z1,170); cutoff(z2,-10);
  8099. draw z3--z4; cutoff(z4,-80).
  8100. \endtt
  8101. \restorehsize
  8102. \ddanger The @cutoff@ macro of Appendix~B deals with several things
  8103. that we've been studying recently, so it will be instructive to look
  8104. at it now (slightly simplified):
  8105. \begindisplay
  8106. @def@ @cutoff@\thinspace(@expr@ $z,"theta"$) $=$\cr
  8107. \quad$"cut\_pic":=@nullpicture@$;\cr
  8108. \quad^@addto@ "cut\_pic" @doublepath@ $z$ @withpen@ "currentpen";\cr
  8109. \quad@addto@ "cut\_pic" @contour@
  8110.  $((0,-1)\dashto(1,-1)\dashto(1,1)\dashto(0,1)\dashto\cycle)$\cr
  8111. \qquad   scaled $1.42(1+\max("pen\_lft","pen\_rt","pen\_top","pen\_bot"))$\cr
  8112. \qquad   rotated "theta" shifted "z";\cr
  8113. \quad^@cull@ "cut\_pic" @keeping@ $(2,2)$ @withweight@ $-1$;\cr
  8114. \quad@addto@ "currentpicture" @also@ "cut\_pic" @enddef@.\cr
  8115. \enddisplay
  8116. The main work is done in a separate ^{picture} variable called "cut\_pic",
  8117. so that neighboring strokes won't be affected. First "cut\_pic" is set to
  8118. the full digitized pen image (by making a ^@doublepath@ from a single
  8119. point). Then a rectangle that includes the cutoff region is added in;
  8120. ^"pen\_lft", "pen\_rt", "pen\_top", and "pen\_bot" are the quantities used
  8121. to compute the functions ^"lft", ^"rt", ^"top", and ^"bot", so they bound
  8122. the size of the pen. The culling operation produces the intersection of
  8123. pen and rectangle, which is finally subtracted from "currentpicture".
  8124. \ddanger We shall conclude this chapter by studying two examples of how
  8125. \MF's pen-and-curve-drawing facilities can combine in interesting ways.
  8126. First, let's examine two ``^{tilde}'' characters
  8127. \displayfig 16f\&g (50\apspix)
  8128. which were both created by a single command of the form
  8129. \begindisplay
  8130. @draw@ $z_1\to\controls z_2\and z_3\to z_4$.
  8131. \enddisplay
  8132. The left example was done with a ^@pencircle@ xscaled .8"pt" yscaled .2"pt"
  8133. rotated~50, and the right example was exactly the same but with ^@pensquare@.
  8134. The control points $z_2$ and~$z_3$ that made this work were defined by
  8135. \begindisplay
  8136. $y_2-y_1=y_4-y_3=3(y_4-y_1)$;\cr
  8137. $z_2-z_1=z_4-z_3="whatever"\ast{\rm dir}\,50$.\cr % partly redundant
  8138. \enddisplay
  8139. The second pair of equations is an old calligrapher's trick, namely to start
  8140. and finish a~stroke in the direction of the pen you're holding.
  8141. The first pair of equations is a mathematician's trick, based on the
  8142. fact that the ^{Bernshte{\u\i}n polynomial} $t[0,3,-2,1]$ goes from
  8143. 0~to~1 to~0~to~1 as $t$ goes from 0 to~.25 to~.75~to~1.
  8144. \ddanger Next, let's try to draw a fancy ^{serif} with
  8145. the same two pens, holding them at a $20^\circ$~angle instead of a
  8146. $50^\circ$~angle. Here are two examples
  8147. \displayfig 16h\&i (195\apspix)
  8148. that can be created by `^@filldraw@' commands:
  8149. \begindisplay
  8150. @filldraw@ $z_1\to\controls z_2\to z_3$\cr
  8151. \qquad$\dashto("flex"(z_3,.5[z_3,z_4]+"dishing",z_4))$
  8152.  shifted$\,(0,-"epsilon")$\cr
  8153. \qquad$\dashto z_4\to\controls z_5\to z_6\dashto\cycle$.\cr
  8154. \enddisplay
  8155. The ^"dishing" parameter causes a slight rise between $z_3$ and~$z_4$;
  8156. the ^"flex" has been lowered by ^"epsilon" in order to avoid the danger
  8157. of ``^{strange paths},'' which might otherwise be caused by tiny loops
  8158. at $z_3$ or~$z_4$. But the most interesting thing about this example
  8159. is the use of double control points, $z_2$ and~$z_5$, in two of the
  8160. path segments. \ (Recall that `$\controls z_2$' means the same thing
  8161. ^^{controls} as `$\controls z_2\and z_2$'.) \ These points were determined
  8162. by the equations
  8163. \begindisplay
  8164. $x_2=x_1$; \ $z_2=z_3+"whatever"\ast{\rm dir}\,20$;\cr
  8165. $x_5=x_6$; \ $z_5=z_4+"whatever"\ast{\rm dir}\,{-20}$;\cr
  8166. \enddisplay
  8167. thus, they make the strokes vertical at $z_1$ and $z_6$, parallel to the
  8168. pen angle at~$z_3$, and parallel to the complementary angle at~$z_4$.
  8169. \endchapter
  8170. The pen, probably more than any other tool,
  8171. has had the strongest influence upon lettering
  8172. in respect of serif design .\thinspace.\thinspace.
  8173. It is probable that the letters [of the Trajan column]
  8174. were painted before they were incised,
  8175. and though their main structure is attributed to the pen
  8176. and their ultimate design to the technique of the chisel,
  8177. they undoubtedly owe much of their freedom
  8178. to the influence of the brush.
  8179. \author L. C. ^{EVETTS},  {\sl Roman Lettering\/} (1938) % pp 3 and 13
  8180. \bigskip
  8181. Remember that it takes time, patience, critical practice
  8182. and knowledge to learn any art or craft.
  8183. No ``art experience'' is going to result from any busy work
  8184. for a few hours experimenting with the edged pen.
  8185. .\thinspace.\thinspace. Take as much time as you require,
  8186. and do not become impatient.
  8187. If it takes a month to get it,
  8188. then be happy that it takes only a month.
  8189. \author LLOYD ^{REYNOLDS},  {\sl Italic Calligraphy \& Handwriting\/} (1969)
  8190. \eject
  8191. \beginchapter Chapter 17. Grouping
  8192. We have now covered all the visual, graphic aspects of \MF---its
  8193. points, paths, pens, and pictures; but we still don't know everything
  8194. about \MF's organizational, administrative aspects---its programs.
  8195. The next few chapters of this book therefore concentrate on
  8196. how to put programs together effectively.
  8197. A \MF\ program is a sequence of statements separated by semicolons and
  8198. followed by `^@end@'. More precisely, the syntax rules
  8199. \beginsyntax
  8200. <program>\is<statement list>[end]
  8201. <statement list>\is<empty>\alt<statement>[;]<statement list>
  8202. \endsyntax
  8203. define a \<program> in terms of a \<statement>.
  8204. But what are ^{statements}? Well, they are of various kinds. An ``equation''
  8205. states that two expressions are supposed to be equal. An ``assignment''
  8206. assigns the value of an expression to a variable. A ``declaration''
  8207. states that certain variables will have a certain type.
  8208. A ``definition'' defines a macro.  A ``title'' gives a descriptive name to
  8209. the character that is to follow.  A ``command'' orders \MF\ to do some
  8210. specific operation, immediately.  The ``^{empty statement}'' tells \MF\ to
  8211. do absolutely nothing.  And a ``^{compound statement}'' is a list of other
  8212. statements treated as a ^{group}.
  8213. \beginsyntax
  8214. <statement>\is<equation>\alt<assignment>\alt<declaration>
  8215.  \alt<definition>\alt<title>\alt<command>\alt<empty>
  8216.  \alt[begingroup] <statement list> <statement> [endgroup]
  8217. \endsyntax
  8218. We've given the syntax for \<equation> and \<assignment> in Chapter~10;
  8219. the syntax for \<declaration> appeared in Chapter~7; \<definition> and
  8220. \<title> and \<command> will appear in later chapters. Our main concern
  8221. just now is with the final type of \<statement>, where @begingroup@
  8222. and @endgroup@ bind other statements into a unit, just as parentheses
  8223. add structure to the elements of an algebraic expression.
  8224. The main purpose of grouping is to protect the values of variables in
  8225. one part of the program from being clobbered in another. A symbolic token
  8226. can be given a new meaning inside a group, without changing the
  8227. meaning it had outside that group. \ (Recall that \MF\ deals with
  8228. three basic kinds of tokens, as discussed in Chapter~6; it is impossible
  8229. to change the meaning of a numeric token or a string token, but
  8230. symbolic tokens can change meanings~freely.)
  8231. There are two ways to protect the values of variables in a group. One
  8232. is called a \<save command>, and the other is called an \<interim command>:
  8233. \beginsyntax
  8234. <save command>\is[save]<symbolic token list>
  8235. <symbolic token list>\is<symbolic token>
  8236.  \alt<symbolic token list>[,]<symbolic token>
  8237. <interim command>\is\kern-1.5pt[interim]%
  8238.  <internal quantity>[:=]<right-hand side>\kern-1pt
  8239. \endsyntax
  8240. The symbolic tokens in a @save@ command all lose their current meanings, but
  8241. those old meanings are put into a safe place and restored at the end of
  8242. the current group. Each token becomes undefined, as if it had never
  8243. appeared before. For example, the command
  8244. \begindisplay
  8245. @save@ $x,y$
  8246. \enddisplay
  8247. effectively causes all previously known variables like $x_1$ and $y_{5r}$ to
  8248. become inaccessible; the variable $x_1$ could now appear in a new equation,
  8249. where it would have no connection with its out-of-group value. You could
  8250. also give the silly command
  8251. \begindisplay
  8252. @save@ @save@;
  8253. \enddisplay
  8254. this would make the token `|save|' itself into a ^\<tag> instead of a
  8255. ^\<spark>, so you couldn't use it to save anything else until the group ended.
  8256. \danger An @interim@ command is more restrictive than a @save@, since it
  8257. applies only to an ^\<internal quantity>. \ (Recall that internal
  8258. quantities are special variables like "tracingequations" that take numeric
  8259. values only; a complete list of all the standard internal quantities can
  8260. be found in Chapter~25, but that list isn't exhaustive because you can
  8261. define new ones for your own use.) \ \MF\ treats an interim command just
  8262. like an ordinary assignment, except that it undoes the assignment when the
  8263. group~ends.
  8264. \danger If you save something two or more times in the same group,
  8265. the first saved value takes precedence. For example, in the construction
  8266. \begindisplay
  8267. @begingroup@\cr
  8268. \noalign{\vskip-3pt}\dots\cr
  8269. @interim@ $"autorounding":=0$; \ @save@ $x$;\cr
  8270. \noalign{\vskip-3pt}\dots\cr
  8271. @interim@ $"autorounding":=1$; \ @save@ $x$;\cr
  8272. \noalign{\vskip-3pt}\dots\cr
  8273. @endgroup@\cr
  8274. \enddisplay
  8275. the values of "autorounding" and $x$ after the end of the group will be
  8276. their previous values just before the statement `@interim@ $"autorounding":=0$'.
  8277. (Incidentally, these might not be the values they had upon entry to the group).
  8278. \danger Tokens and internal quantities regain their old meanings and
  8279. values at the end of a group only if they were explicitly saved in a
  8280. @save@ or @interim@ command. All other changes in meaning and/or value
  8281. will survive outside the group.
  8282. \danger The ^@beginchar@ operation of plain \MF\ includes a @begingroup@,
  8283. and ^@endchar@ includes @endgroup@. Thus, for example, interim assignments
  8284. can be made in a program for one character without any effect on other
  8285. characters.
  8286. \danger A \<save command> that's not in a group simply clears the meanings
  8287. of the symbolic tokens specified; their old meanings are not actually saved,
  8288. because they never will have to be restored. An \<interim command>
  8289. outside a group acts just like a normal assignment.
  8290. \danger If you set the internal quantity ^"tracingrestores" to a positive
  8291. value, \MF\ will make a note in your transcript file whenever it is
  8292. restoring the former value of a symbolic token or internal quantity.
  8293. This can be useful when you're debugging a program that doesn't seem
  8294. to make sense.
  8295. Groups can also be used within algebraic expressions. This is
  8296. the other important reason for grouping; it allows \MF\ to do arbitrarily
  8297. complicated things while in the middle of other calculations, thereby
  8298. greatly increasing the power of macro definitions (which we shall study
  8299. in the next chapter). A {\sl^{group expression}\/} has the general form
  8300. \begindisplay
  8301. {\tt begingroup}\thinspace\<statement list>\thinspace\<expression>
  8302. \thinspace{\tt endgroup}
  8303. \enddisplay
  8304. and it fits into the syntax of expressions at the primary level. The
  8305. meaning of a group expression is: ``Perform the list of statements,
  8306. then evaluate the expression, then restore anything that was saved
  8307. in this group.''
  8308. \danger Group expressions belong in the syntax rules for each type
  8309. of expression, but they were not mentioned in previous chapters because
  8310. it would have been unnecessarily distracting. Thus, for example, the syntax for
  8311. \<numeric primary> actually includes the additional alternative
  8312. \begindisplay
  8313. |begingroup|\thinspace\<statement list>\<numeric expression>%
  8314.  \thinspace|endgroup|.
  8315. \enddisplay
  8316. The same goes for \<pair primary>, \<picture primary>, etc.; Chapter~25
  8317. has the complete rules of syntax for all types of expressions.
  8318. \dangerexercise What is the value of the expression
  8319. \begintt
  8320. begingroup x:=x+1; x endgroup + begingroup x:=2x; x endgroup
  8321. \endtt
  8322. if $x$ initially has the value $a$? What would the value have been if
  8323. the two group expressions had appeared in the opposite order?
  8324. Verify your answers using the |expr| routine of Chapter~8.
  8325. \answer $(a+1)+(2a+2)=3a+3$ and $(2a)+(2a+1)=4a+1$, respectively.
  8326. The final value of~$x$ in the first case is $2a+2$, hence $a=.5x-1$;
  8327. |expr| will report the answer as |1.5x| (in terms of $x$'s new value),
  8328. since it has not been told about `$a$'. In the second case |expr| will,
  8329. similarly, say |2x-1|.\par
  8330. This example shows that $\alpha+\beta$ is not necessarily equal
  8331. to ^^{commutativity} $\beta+\alpha$, when $\alpha$ and~$\beta$ involve
  8332. group expressions. \MF\ evaluates expressions strictly from left to
  8333. right, performing the statements within groups as they appear.
  8334. \dangerexercise Appendix B defines ^"whatever" to be an abbreviation for
  8335. the group expression `@begingroup@ @save@ ?; ? @endgroup@'. Why
  8336. does this work? \checkequals\Xwhat\exno
  8337. \answer The save instruction gives `?' a fresh meaning, hence `?' is
  8338. a numeric variable unconnected to any other variables. When the group
  8339. ends and `?' is restored to its old meaning, the value of the group
  8340. expression no longer has a name. \ (It's called a ``^{capsule}'' if
  8341. you try to @show@ it.) \ Therefore the value of the group expression
  8342. is a new, nameless variable, as desired.
  8343. \ddangerexercise What is the value of `@begingroup@ @save@ ?; \
  8344. $(?,?)$ @endgroup@'\thinspace?
  8345. \answer It's a nameless pair whose xpart and ypart are equal; thus it
  8346. is essentially equivalent to `$"whatever"\ast(1,1)$'.
  8347. \ddangerexercise According to exercise 10.\xwhat, the assignment
  8348. `$x_3:="whatever"$' will make the numeric variable $x_3$ behave like new,
  8349. without affecting other variables like $x_2$. Devise a similar stratagem
  8350. that works for arrays of @picture@ variables.
  8351. \answer `$v_3:=@begingroup@$ @save@ ?; @picture@ ?; ?\ @endgroup@'
  8352. refreshes the picture variable~$v_3$ without changing other variables
  8353. like~$v_2$. This construction works also for pairs, pens, strings, etc.
  8354. \endchapter
  8355. It is often difficult
  8356. to account for some beginners grouping right away
  8357. and others proving almost hopeless.
  8358. \author A. G. ^{FULTON},  {\sl Notes on Rifle Shooting\/} (1913)
  8359.  % according to OED Supplement, but this pamphlet has vanished from their files!
  8360. \bigskip
  8361. Rock bands prefer San Francisco groupies to New York groupies.
  8362. \author ELLEN ^{WILLIS},  {\sl But Now I'm Gonna Move\/} (1971)
  8363.  % New Yorker, 23 Oct 71, p170
  8364. \eject
  8365. \beginchapter Chapter 18. Definitions\\(also called Macros)
  8366. You can often save time writing \MF\ programs by letting single tokens
  8367. stand for sequences of other tokens that are used repeatedly. For example,
  8368. Appendix~B defines `$\ddashto$' to be an abbreviation for ^^{---}
  8369. `$\to\tension"infinity"\to$', and this definition is preloaded as
  8370. part of the plain \MF\ base. Programs that use such definitions are not
  8371. only easier to write, they're also easier to read. But Appendix~B
  8372. doesn't contain every definition that every programmer might want;
  8373. the present chapter therefore explains how you can make ^{definitions}
  8374. of your own.
  8375. In the simplest case, you just say
  8376. \begindisplay
  8377. @def@ \<symbolic token> $=$ \<replacement text> @enddef@
  8378. \enddisplay
  8379. and the symbolic token will henceforth expand into the tokens of the
  8380. replacement text. For example, Appendix~B says
  8381. \begintt
  8382. def --- = ..tension infinity.. enddef.
  8383. \endtt
  8384. The ^{replacement text} can be any sequence of tokens not including
  8385. `@enddef@\kern1pt'; or it can include entire subdefinitions like
  8386. `@def@~$\ldots$~@enddef@\kern1pt', according to certain rules
  8387. that we shall explain later.
  8388. Definitions get more interesting when they include {\sl^{parameters}},
  8389. which are replaced by {\sl^{arguments}\/} when the definition is expanded.
  8390. For example, Appendix~B also says
  8391. \begintt
  8392. def rotatedaround(expr z,theta) =
  8393.  shifted -z rotated theta shifted z enddef;
  8394. \endtt
  8395. this means that an expression like `$z_1$ ^{rotatedaround}$\,(z_2,30)$' will
  8396. expand into `$z_1$ shifted~$-z_2$ rotated~30 shifted~$z_2$'.
  8397. The parameters `|z|' and `|theta|' in this definition could have been any
  8398. symbolic tokens whatever; there's no connection between them and
  8399. appearances of `|z|' and `|theta|' outside the definition. \ (For example,
  8400. `|z|'~would ordinarily stand for `|(x,y)|', but it's just a simple token
  8401. here.) \ The definition could even have been written with ``primitive''
  8402. tokens as parameters, like
  8403. \begintt
  8404. def rotatedaround(expr;,+) =
  8405.  shifted-; rotated+shifted; enddef;
  8406. \endtt
  8407. the effect would be exactly the same. \ (Of course, there's no point in
  8408. doing such a thing unless you are purposely trying to make your
  8409. definition inscrutable.)
  8410. When `|rotatedaround|' is used, the arguments that are substituted for |z|
  8411. and |theta| are first evaluated and put into ``^{capsules},'' so that they
  8412. will behave like primary expressions. Thus, for example, `$z_1$
  8413. rotatedaround$\,(z_2+z_3,30)$' will not expand into `$z_1$ shifted~$-z_2+z_3$
  8414. rotated~30 shifted~$z_2+z_3$'---which means something entirely different---but
  8415. rather into `$z_1$ shifted~$-\alpha$ rotated~30 shifted~$\alpha$', where
  8416. $\alpha$ is a nameless internal variable that contains the value of
  8417. $z_2+z_3$.
  8418. \danger A capsule value cannot be changed, so an @expr@ parameter should not
  8419. ^^{:=} appear at the left of the ^{assignment} operator `$:=$'.
  8420. \danger Macros are great when they work, but complicated macros sometimes
  8421. surprise their creators.  \MF\ provides ``tracing'' facilities so that you
  8422. can see what the computer thinks it's doing, when you're trying to
  8423. diagnose the reasons for unexpected behavior. If you say
  8424. `^"tracingmacros"$\null:=1$', the transcript file of your run will record
  8425. every macro that is subsequently expanded, followed by the values of its
  8426. arguments as soon as they have been computed.
  8427. For example, `rotatedaround$\,("up",30)$' might produce the
  8428. ^^|EXPR0| following lines of diagnostic information:
  8429. \begintt
  8430. rotatedaround(EXPR0)(EXPR1)->shifted-(EXPR0)rotated(EXPR1)sh
  8431. ifted(EXPR0)
  8432. (EXPR0)<-(0,1)
  8433. (EXPR1)<-30
  8434. \endtt
  8435. \danger Here's another example from Appendix B\null. It illustrates the
  8436. usefulness of ^{group expressions} in macro definitions:
  8437. \begindisplay
  8438. @def@ ^{reflectedabout}$\,(@expr@\ p,q)$ $=$\cr
  8439. \quad transformed @begingroup@\cr
  8440. \qquad ^@save@ $T$; \ ^@transform@ $T$;\cr
  8441. \qquad $p$ transformed $T$ $=$ $p$;\cr
  8442. \qquad $q$ transformed $T$ $=$ $q$;\cr
  8443. \qquad ^{xxpart} $T$ $=$ $-$^{yypart} $T$;\cr
  8444. \qquad ^{xypart} $T$ $=$ ^{yxpart} $T$;\cr
  8445. \qquad $T$ @endgroup@ @enddef@;\cr
  8446. \enddisplay
  8447. thus a new transform, $T$, is computed in the midst of another expression,
  8448. and the macro `reflectedabout($p,q$)' essentially expands into
  8449. `transformed $T$'.
  8450. Some macros, like `rotatedaround', are meant for general-purpose use.
  8451. But it's also convenient to write ^{special-purpose macros} that simplify
  8452. the development of particular typefaces. For example, let's consider the
  8453. \MF\ logo from this standpoint. The program for `{\manual E}' in
  8454. Chapter~11 starts with
  8455. \begintt
  8456. beginchar("E",14u#+2s#,ht#,0); pickup logo_pen;
  8457. \endtt
  8458. and the programs for `{\manual M}', `\kern1pt{\manual T}\kern1pt',
  8459. etc., all have almost the same beginning. Therefore we might as
  8460. well put the following definition near the top of the file |logo.mf|:
  8461. \begintt
  8462. def beginlogochar(expr code, unit_width) =
  8463.  beginchar(code,unit_width*u#+2s#,ht#,0);
  8464.  pickup logo_pen enddef;
  8465. \endtt
  8466. Then we can start the `{\manual E}' by saying simply ^^|beginlogochar|
  8467. \begintt
  8468. beginlogochar("E",14);
  8469. \endtt
  8470. similar simplifications apply to all seven letters. Notice from
  8471. this example that macros can be used inside macros (since `|beginchar|'
  8472. and `|pickup|' are themselves macros, defined in Appendix~B\null); once you
  8473. have defined a macro, you have essentially extended the \MF\ language.
  8474. Notice also that ^@expr@ parameters can be expressions of any type;
  8475. for example, |"E"| is a string, and the first parameter of
  8476. `rotatedaround' is a pair.
  8477. \decreasehsize 48mm
  8478. Chapter 11 didn't give the programs for `{\manual A}' or `{\manual O}'.
  8479. \rightfig 18a ({240\apspix} x {216\apspix}) ^15pt
  8480. It turns out that those programs can be simplified if we write
  8481. them in terms of an auxiliary subroutine called `|super_half|'.
  8482. For example, here is how the `{\manual O}' is made:
  8483. \begintt
  8484. beginlogochar("O",15);
  8485. x1=x4=.5w; top y1=h+o; bot y4=-o;
  8486. x2=w-x3=1.5u+s; y2=y3=barheight;
  8487. super_half(2,1,3);
  8488. super_half(2,4,3);
  8489. labels(1,2,3,4); endchar;
  8490. \endtt
  8491. \restorehsize\medbreak\noindent
  8492. The |super_half| routine is supposed to draw half of a ^{superellipse},
  8493. through three points whose subscripts are specified.
  8494. \restorehsize
  8495. We could define |super_half| as a macro with three @expr@ parameters,
  8496. referring to the first point as `|z[i]|', say; but there's a better way.
  8497. Parameters to macros can be classified as suffixes, by saying ^@suffix@
  8498. instead of @expr@. In this case
  8499. the actual arguments may be any ^\<suffix>, i.e., any sequence of
  8500. subscripts and tags that complete the name of a variable as explained
  8501. in Chapter~7. Here's what |super_half| looks like, using this idea:
  8502. \begintt
  8503. def super_half(suffix i,j,k) =
  8504.  draw z.i{0,y.j-y.i}
  8505.   ... (.8[x.j,x.i],.8[y.i,y.j]){z.j-z.i}
  8506.   ... z.j{x.k-x.i,0}
  8507.   ... (.8[x.j,x.k],.8[y.k,y.j]){z.k-z.j}
  8508.   ... z.k{0,y.k-y.j} enddef;
  8509. \endtt
  8510. \exercise Would the program for `{\manual O}' still work if the two calls of
  8511. |super_half| had been `|super_half(3,1,2)|' and `|super_half(3,4,2)|'\thinspace?
  8512. \answer Yes; the direction at |z.j| will be either "left" or "right".
  8513. \exercise Guess the program for \MF's `{\manual A}', which has the
  8514. same width as `{\manual O}'.
  8515. \answer |beginlogochar("A",15);|
  8516. \rightfig A18a ({240\apspix} x {216\apspix}) ^3pt \parbreak
  8517. |x1=.5w;|\parbreak
  8518. |x2=x4=leftstemloc;|\parbreak
  8519. |x3=x5=w-x2;|\parbreak
  8520. |top y1=h+o;|\parbreak
  8521. |y2=y3=barheight;|\parbreak
  8522. |bot y4=bot y5=-o;|\parbreak
  8523. |draw z4--z2--z3--z5;|\parbreak
  8524. |super_half(2,1,3);|\parbreak
  8525. |labels(1,2,3,4,5);|\parbreak
  8526. |endchar;|\par\smallskip\noindent
  8527. Notice that all three calls of |super_half| in |logo.mf| are of the form
  8528. `"super\_half"$(2,j,3)$'. But it would not be good style to eliminate
  8529. parameters $i$ and~$k$, even though |super_half| is a ^{special-purpose}
  8530. subroutine; that would make it too too special.
  8531. \danger Besides parameters of type @expr@ and @suffix@, \MF\ also
  8532. allows a third type called ^@text@. In this case the actual argument
  8533. is any sequence of tokens, and this sequence is not evaluated
  8534. beforehand; a text argument is simply copied in place of the
  8535. corresponding parameter. This makes it possible to write macros that
  8536. deal with lists of things. For example, Appendix~B's `@define\_pixels@'
  8537. macro is defined thus:
  8538. \begintt
  8539. def define_pixels(text t) =
  8540.  forsuffixes a=t: a := a# * hppp; endfor enddef;
  8541. \endtt
  8542. This means that `|define_pixels(em,cap)|' will expand into
  8543. \begintt
  8544. forsuffixes a=em,cap: a := a# * hppp; endfor
  8545. \endtt
  8546. which, in turn, expands into the tokens `|em|~|:=|~|em#|~|*|~|hppp;|
  8547. |cap|~|:=|~|cap#|~|*|~|hppp;|' as we will see in Chapter~19.
  8548. \danger Let's look now at a subroutine for drawing ^{serifs}, since
  8549. this typifies the sort of special-purpose macro one expects to see
  8550. in the design of a meta-typeface. Serifs can take many forms,
  8551. so we must choose from myriads of possibilities. We shall consider
  8552. two rather different approaches, one based on outline-filling and the
  8553. other based on the use of a fixed pen nib. In both cases it will be
  8554. necessary to omit some of the refinements that would be desirable
  8555. in a complete typeface design, to keep the examples from
  8556. getting too complicated.
  8557. \danger
  8558. \parshape 13
  8559. 3pc 13pc
  8560. 3pc 13pc
  8561. 0pc 16pc
  8562. 0pc 16pc
  8563. 0pc 16pc
  8564. 0pc 16pc
  8565. 0pc 16pc
  8566. 0pc 16pc
  8567. 0pc 16pc
  8568. 0pc 16pc
  8569. 0pc 16pc
  8570. 0pc 16pc
  8571. 0pc 29pc
  8572. Our first example is a serif routine that
  8573. constructs six points $z_{\$a}$, $z_{\$b}$, \dots,~$z_{\$\mkern-1muf}$ around a
  8574. \rightfig 18b (48mm x 40mm) ^26pt
  8575. given triple of ``^{penpos}'' points $z_{\$l}$, $z_{\$}$, $z_{\$r}$; here
  8576. \$ is a suffix that's a parameter to the "serif" macro.  Other parameters
  8577. are: "breadth", the distance between the parallel lines that run from
  8578. $z_{\$l}$ to $z_{\$a}$ and from $z_{\$r}$ to $z_{\$\mkern-1muf}$; "theta", the
  8579. direction angle of those two lines; "left\_jut", the distance from
  8580. $z_{\$l}$ to $z_{\$b}$; and "right\_jut", the distance from $z_{\$r}$ to
  8581. $z_{\$e}$.  \ (The serif ``juts out'' by the amounts of the
  8582. ^{jut} parameters.) \ There's also a "serif\_edge" macro, which constructs
  8583. the path shown.  The routines refer to three variables that are assumed to
  8584. apply to all serifs:  "slab", the vertical distance from $z_{\$b}$~%
  8585. and~$z_{\$e}$ to $z_{\$c}$~and~$z_{\$d}$; "bracket", the vertical distance
  8586. from $z_{\$a}$~and~$z_{\$\mkern-1muf}$ to $z_{\$l}$~and~$z_{\$r}$; and
  8587. "serif\_darkness", a fraction that controls how much of the triangular
  8588. regions $(z_{\$a},z_{\$l},z_{\$b})$ and $(z_{\$\mkern-1muf},z_{\$r},z_{\$e})$
  8589. ^^{]]} will be filled in.
  8590. \begindisplay
  8591. @def@ "serif"\thinspace(@suffix@ \$)(@expr@
  8592.  $"breadth","theta","left\_jut","right\_jut")=$\cr
  8593. \quad $\penpos\$("breadth"/{\rm abs\,sind}\,"theta",0)$;\cr
  8594. \quad $z_{\$a}-z_{\$l}=z_{\$\mkern-1muf}-z_{\$r}=
  8595.  ("bracket"/{\rm abs\,sind}\,"theta")\ast {\rm dir}\,"theta"$;\cr
  8596. \quad $y_{\$c}=y_{\$d}$; \ $y_{\$b}=y_{\$e}=y_\$$; \
  8597.  $y_{\$b}-y_{\$c}=@if@\;"theta"<0:\;{-}\;@fi@\;"slab"$;\cr
  8598. \quad $x_{\$b}=x_{\$c}=x_{\$l}-"left\_jut"$; \
  8599.  $x_{\$d}=x_{\$e}=x_{\$r}+"right\_jut"$;\cr
  8600. \quad @labels@$(\$a,\$b,\$c,\$d,\$e,\$\mkern-1muf)$ @enddef@;\cr
  8601. \noalign{\smallskip}
  8602. @def@ "serif\_edge" @suffix@ \$ "="\cr
  8603. \quad $\bigl("serif\_bracket"(\$a,\$l,\$b)\dashto z_{\$c}$\cr
  8604. \qquad $\dashto z_{\$d}\dashto {\rm reverse}\,
  8605.   "serif\_bracket"(\$\mkern-1muf,\$r,\$e)\bigr)$ @enddef@;\cr
  8606. \noalign{\smallskip}
  8607. @def@ "serif\_bracket"(@suffix@ $i,j,k$) $=$\cr
  8608. \quad $\bigl(z.i\{z.j-z.i\}
  8609.  \ldots"serif\_darkness"[z.j,.5[z.i,z.k]\,]\{z.k-z.i\}$\cr
  8610. \qquad$\ldots z.k\{z.k-z.j\}\bigr)$ @enddef@;\cr
  8611. \enddisplay
  8612. \dangerexercise Under what circumstances will the "serif\_edge"
  8613. go through points $z_{\$l}$ and $z_{\$r}$?
  8614. \answer If $"bracket"=0$ or $"serif\_darkness"=0$. \ (It's probably
  8615. not a good idea to make $"serif\_darkness"=0$, because this would lead to
  8616. an extreme case of the `$\ldots$' triangle, ^^{...} which might not
  8617. be numerically stable in the presence of rounding errors.)
  8618. Another case, not really desirable, is $"left\_jut"="right\_jut"=0$.
  8619. \dangerexercise Should this "serif" macro be used before
  8620. points $z_{\$l}$, $z_\$$, and $z_{\$r}$ have been defined, or should those
  8621. points be defined first?
  8622. \answer That's a strange question. The "serif" routine includes a
  8623. "penpos" that defines $z_{\$l}$, $z_\$$, and $z_{\$r}$ relative
  8624. to each other, and it defines the other six points relative to them.
  8625. Outside the routine the user ought to specify just one $x$~coordinate
  8626. and one $y$~coordinate, in order to position all of the points.
  8627. This can be done either before or after "serif" is called, but
  8628. \MF\ has an easier job if it's done beforehand.
  8629. \danger Here are two sample letters that show how these serif routines
  8630. might be used. The programs assume that the font has several additional
  8631. ad~hoc parameters:  $u$,~a~unit of character width; "ht",~the character
  8632. height; "thin" and "thick", the two stroke weights; and "jut", the amount
  8633. by which serifs protrude on a ``normal'' letter like `H'.
  8634. \begingroup\ninepoint\noindent
  8635. \displayfig 18c (252\apspix)
  8636. $$\halign to\hsize\bgroup\indent#\hfil\tabskip1em plus1fil minus1fil
  8637.  &\tabskip0pt\hfil\%\ #\cr
  8638. @beginchar@\kern1pt(|"A"|$,13u\0,ht\0,0)$;\cr
  8639. $z_1=(.5w,1.05h)$;&top point\cr
  8640. $x_{4l}=w-x_{5r}=u$; \ $y_{4l}=y_{5r}="slab"$;&bottom points\cr
  8641. @numeric@ $"theta"[\,]$;\cr
  8642. $"theta"_4={\rm angle}(z_1-z_{4l})$;&left stroke angle\cr
  8643. $"theta"_5={\rm angle}(z_1-z_{5r})$;&right stroke angle\cr
  8644. $"serif"(4,"thin","theta"_4,.6"jut","jut")$;&left serifs\cr
  8645. $"serif"(5,"thick","theta"_5,"jut",.6"jut")$;&right serifs\cr
  8646. $z_0=z_{4r}+"whatever"\ast{\rm dir}\,"theta"_4$\cr
  8647. \qquad$=z_{5l}+"whatever"\ast{\rm dir}\,"theta"_5$;&inside top point\cr
  8648. @fill@ $z_1\dashto "serif\_edge"_4\dashto z_0$&the left stroke\cr
  8649. \qquad$\&\;z_0\dashto "serif\_edge"_5\dashto z_1\;\&\;\cycle$;&the
  8650.  right stroke\cr
  8651. $\penpos2("whatever","theta"_4)$;\cr
  8652. $\penpos3("whatever","theta"_5)$;\cr
  8653. $y_{2r}=y_{3r}=.5[y_4,y_0]$;&crossbar height\cr
  8654. $y_{2l}=y_{3l}=y_{2r}-"thin"$;&crossbar thickness\cr
  8655. $z_2="whatever"[z_1,z_{4r}]$;\cr
  8656. $z_3="whatever"[z_1,z_{5l}]$;\cr
  8657. @penstroke@ $z_{2e}\dashto z_{3e}$;&the crossbar\cr
  8658. @penlabels@$(0,1,2,3,4,5)$; \ @endchar@;\cr
  8659. \noalign{\medskip}
  8660. @beginchar@\kern1pt(|"I"|$,6u\0,ht\0,0)$;\cr
  8661. $x_1=x_2=.5w$;\cr
  8662. $y_1=h-y_2$; \ $y_2="slab"$;\cr
  8663. "serif"$(1,"thick",-90,1.1jut,1.1jut)$;&upper serifs\cr
  8664. "serif"$(2,"thick",90,1.1jut,1.1jut)$;&lower serifs\cr
  8665. @fill@ $"serif\_edge"_2\dashto{\rm reverse}\,"serif\_edge"_1\dashto\cycle$;
  8666.  &the stroke\cr
  8667. @penlabels@$(1,2)$; \ @endchar@;\cr
  8668. \enddisplay
  8669. The illustration was prepared with $"thin"=.5"pt"$, $"thick"=1.1"pt"$,
  8670. $u=.6"pt"$, $"ht"=7"pt"$, $"slab"=.25"pt"$, $"jut"=.9"pt"$, $"bracket"="pt"$,
  8671. and $"serif\_darkness"=1/3$.
  8672. \par\endgroup
  8673. \dangerexercise Could the equations defining $y_1$ and $y_2$ in the program
  8674. for~|"I"| have been replaced by `$y_{1c}=h$' and `$y_{2c}=0$'?
  8675. \answer Yes; see the previous exercise. \ (But in the program for |"A"|
  8676. it's necessary to define $y_{4l}$ and $y_{5r}$, so that $"theta"_4$
  8677. and~$"theta"_5$ can be calculated.)
  8678. \dangerexercise Write the program for an |"H"| to go with these letters.
  8679. \answer \rightfig A18b (48mm x 43mm) ^10pt
  8680. @beginchar@\kern1pt(|"H"|$,13u\0,"ht"\0,0)$;\parbreak
  8681. $x_1=x_2=x_5=3u$;\parbreak
  8682. $x_3=x_4=x_6=w-x_1$;\parbreak
  8683. $y_{1c}=y_{3c}=h$; \ $y_{2c}=y_{4c}=0$;\parbreak
  8684. $"serif"(1,"thick",-90,"jut","jut")$;\parbreak
  8685. $"serif"(2,"thick",90,"jut","jut")$;\parbreak
  8686. $"serif"(3,"thick",-90,"jut","jut")$;\parbreak
  8687. $"serif"(4,"thick",90,"jut","jut")$;\parbreak
  8688. @fill@ $"serif\_edge"_2$\parbreak
  8689. \quad$\dashto{\rm reverse}\,"serif\_edge"_1\dashto\cycle$;\parbreak
  8690. @fill@ $"serif\_edge"_4$\parbreak
  8691. \quad$\dashto{\rm reverse}\,"serif\_edge"_3\dashto\cycle$;\parbreak
  8692. $\penpos5("thin",90)$; \ $\penpos6("thin",90)$;\parbreak
  8693. $y_5=y_6=.52h$; \ @penstroke@ $z_{5e}\dashto z_{6e}$;\parbreak
  8694. @penlabels@$(1,2,3,4,5,6)$; \ @endchar@.
  8695. \ddanger A second approach to serifs can be based on the example at
  8696. the end of Chapter~16. In this case we assume that "broad\_pen" is
  8697. a `@pensquare@ xscaled~"px" yscaled~"py" rotated~"phi"' for
  8698. some $"px">"py"$ and some small angle~"phi". Thicker strokes will
  8699. be made by using this pen to fill a larger region; the serif routine
  8700. is given the distance "xx" between $z_{\$l}$ and $z_{\$r}$.
  8701. There's a pair variable called "dishing" that
  8702. controls the curvature between $z_{\$c}$ and~$z_{\$d}$. Top and
  8703. bottom serifs are similar, but they are sufficiently different that it's
  8704. easier to write separate macros for each case.
  8705. \begindisplay
  8706. @def@ "bot\_serif"(@suffix@ \$)(@expr@ $"xx","theta",
  8707.  "left\_jut","right\_jut")=$\cr
  8708. \quad $\penpos\$("xx",0)$; \
  8709.  $z_{\$a}-z_{\$l}=z_{\$\mkern-1muf}-z_{\$r}=
  8710.  ("bracket"/{\rm abs\,sind\,}"theta")\ast{\rm dir}\,"theta"$;\cr
  8711. \quad $y_{\$c}="top"\,y_{\$l}$; \ $y_{\$d}=y_{\$r}$; \
  8712.  $x_{\$c}=x_{\$l}-"left\_jut"$; \ $x_{\$d}=x_{\$r}+"right\_jut"$;\cr
  8713. \quad $z_{\$b}=z_{\$l}+"whatever"\ast{\rm dir}\,"theta"
  8714.  =z_{\$c}+"whatever"\ast{\rm dir}\,"phi"$;\cr
  8715. \quad $z_{\$e}=z_{\$r}+"whatever"\ast{\rm dir}\,"theta"
  8716.  =z_{\$d}+"whatever"\ast{\rm dir}\,{-"phi"}$;\cr
  8717. \quad @labels@$(\$a,\$b,\$c,\$d,\$e,\$\mkern-1muf)$ @enddef@;\cr
  8718. \noalign{\smallskip}
  8719. @def@ "bot\_serif\_edge" @suffix@ \$ $=$\cr
  8720. \quad $\bigl(z_{\$a}\to\controls z_{\$b}\to z_{\$c}$\cr
  8721. \qquad $\dashto("flex"(z_{\$c},.5[z_{\$c},z_{\$d}]+"dishing",
  8722.  z_{\$d}))$ shifted $(0,-"epsilon")$\cr
  8723. \qquad $\dashto z_{\$d}\to\controls z_{\$e}\to z_{\$\mkern-1muf}
  8724.  \bigr)$ @enddef@;\cr
  8725. \enddisplay
  8726. \displayfig 18d (272\apspix)
  8727. \begindisplay
  8728. @beginchar@\kern1pt(|"A"|$,13u\0,"ht"\0,0)$; \ @pickup@ "broad\_pen";\cr
  8729. $z_1=(.5w,"top"\,h)$; \ $"lft"\,x_{4l}=w-"rt"\,x_{5r}=1.2u$; \
  8730.  $y_{4l}=y_{5r}=0$;\cr
  8731. @numeric@ $"theta"[\,]$; \ $"theta"_4={\rm angle}(z_1-z_{4l})$; \
  8732.  $"theta"_5={\rm angle}(z_1-z_{5r})$;\cr
  8733. @numeric@ "xxx";
  8734. \hbox spread-8pt{%
  8735. $"px"\ast{\rm sind}("theta"_5-"phi")+"xxx"\ast{\rm sind}\,"theta"_5
  8736.  = "px"\ast{\rm cosd}\,"phi"+"xx"$};\cr
  8737. $"bot\_serif"(4,0,"theta"_4,.8"jut",.8"jut")$; \
  8738. $"bot\_serif"(5,"xxx","theta"_5,.6"jut",.8"jut")$;\cr
  8739. $z_0=z_{4r}+"whatever"\ast{\rm dir}\,"theta"_4
  8740.  =z_{5l}+"whatever"\ast{\rm dir}\,"theta"_5$;\cr
  8741. @filldraw@ $z_1\dashto "bot\_serif\_edge"_4
  8742.  \dashto z_0\;\&\;z_0\dashto "bot\_serif\_edge"_5
  8743.  \dashto z_1\;\&\;\cycle$;\cr
  8744. $"top"\,y_2="top"\,y_3=.45"bot"\,y_0$; \
  8745.   $z_2="whatever"[z_1,z_{4r}]$; \ $z_3="whatever"[z_1,z_{5l}]$;\cr
  8746. @draw@ $z_2\dashto z_3$; \ @penlabels@$(0,1,2,3,4,5)$; @endchar@;\cr
  8747. \noalign{\medskip}
  8748. @beginchar@\kern1pt(|"I"|$,6u\0,"ht"\0,0)$; \ @pickup@ "broad\_pen";\cr
  8749. $x_1=x_2=.5w$; \ $y_1=h$; \ $y_2=0$;\cr
  8750. $"top\_serif"(1,"xx",-90,1.1"jut",1.1"jut")$; \
  8751. $"bot\_serif"(2,"xx",90,1.1"jut",1.1"jut")$;\cr
  8752. @filldraw@ $"bot\_serif\_edge"_2\dashto
  8753.  {\rm reverse}\,"top\_serif\_edge"_1\dashto\cycle$;\cr
  8754. @penlabels@$(1,2)$; \ @endchar@;\cr
  8755. \enddisplay
  8756. In the illustration, $"px"=.8"pt"$, $"py"=.2"pt"$, $"phi"=20$,
  8757. $"xx"=.3"pt"$, $u=.6"pt"$, $"ht"=7"pt"$, $"jut"=.9"pt"$, $"bracket"="pt"$,
  8758. and $"dishing"=(.25"pt",0)$ rotated~20.
  8759. \ddangerexercise Write the missing code for "top\_serif" and
  8760. "top\_serif\_edge".
  8761. \answer @def@ "top\_serif"(@suffix@ \$)(@expr@ $"xx","theta",
  8762.  "left\_jut","right\_jut")=$\parbreak
  8763. \quad $\penpos\$("xx",0)$; \
  8764. $z_{\$a}-z_{\$l}=z_{\$\mkern-1muf}-z_{\$r}=
  8765.  ("bracket"/{\rm abs\,sind\,}"theta")\ast{\rm dir}\,"theta"$;\parbreak
  8766. \quad $y_{\$c}=y_{\$d}=y_\$$; \
  8767.  $x_{\$c}=x_{\$l}-"left\_jut"$; \ $x_{\$d}=x_{\$r}+"right\_jut"$;\parbreak
  8768. \quad $z_{\$b}=z_{\$l}+"whatever"\ast{\rm dir}\,"theta"
  8769.  =z_{\$c}+"whatever"\ast{\rm dir}\,{-"phi"}$;\parbreak
  8770. \quad $z_{\$e}=z_{\$r}+"whatever"\ast{\rm dir}\,"theta"
  8771.  =z_{\$d}+"whatever"\ast{\rm dir}\,"phi"$;\parbreak
  8772. \quad @labels@$(\$a,\$b,\$c,\$d,\$e,\$\mkern-1muf)$ @enddef@;\par
  8773. \smallskip\indent
  8774. @def@ "top\_serif\_edge" @suffix@ \$ $=$\parbreak
  8775. \quad $\bigl(z_{\$a}\to\controls z_{\$b}\to z_{\$c}$\parbreak
  8776. \qquad $\dashto("flex"(z_{\$c},.5[z_{\$c},z_{\$d}]-"dishing",
  8777.  z_{\$d}))$ shifted $(0,+"epsilon")$\parbreak
  8778. \qquad $\dashto z_{\$d}\to\controls z_{\$e}\to z_{\$\mkern-1muf}
  8779.  \bigr)$ @enddef@;
  8780. \ddangerexercise (For mathematicians.) \
  8781. Explain the equation for "xxx" in the program for~|"A"|.
  8782. \answer Assuming that $"py"=0$, the effective right stroke weight would be
  8783. $"px"\cdot\sin(\theta_5-\phi)$ if it were drawn with one stroke of "broad\_pen",
  8784. and $"xxx"\cdot\sin\theta_5$ is the additional weight corresponding to separate
  8785. strokes "xxx" apart. The right-hand side of the equation is the same
  8786. calculation in the case of vertical strokes ($\theta=90^\circ$), when the
  8787. stroke weight of |"I"| is considered. \ (Since a similar calculation
  8788. needs to be done for the letters K, V, W, X, Y, and Z, it would be a good
  8789. idea to embed these details in another macro.)
  8790. \ddangerexercise Write the program for an |"H"| to go with these letters.
  8791. \answer \rightfig A18c (48mm x 45mm) ^10pt
  8792. @beginchar@\kern1pt(|"H"|$,13u\0,"ht"\0,0)$;\parbreak
  8793. $x_1=x_2=x_5=3u$;\parbreak
  8794. $x_3=x_4=x_6=w-x_1$;\parbreak
  8795. $y_1=y_3=h$; \ $y_2=y_4=0$;\parbreak
  8796. $"top\_serif"(1,"xx",-90,"jut","jut")$;\parbreak
  8797. $"bot\_serif"(2,"xx",90,"jut","jut")$;\parbreak
  8798. $"top\_serif"(3,"xx",-90,"jut","jut")$;\parbreak
  8799. $"bot\_serif"(4,"xx",90,"jut","jut")$;\parbreak
  8800. @filldraw@ $"bot\_serif\_edge"_2$\parbreak
  8801. \quad$\dashto{\rm reverse}\,"top\_serif\_edge"_1\dashto\cycle$;\parbreak
  8802. @fill@ $"bot\_serif\_edge"_4$\parbreak
  8803. \quad$\dashto{\rm reverse}\,"top\_serif\_edge"_3\dashto\cycle$;\parbreak
  8804. $y_5=y_6=.52h$; \ @draw@ $z_5\dashto z_6$;\parbreak
  8805. @penlabels@$(1,2,3,4,5,6)$; \ @endchar@.
  8806. \danger A close look at the "serif\_edge" routines in these examples
  8807. will reveal that some parentheses are curiously lacking: We said
  8808. `@def@ "serif\_edge" @suffix@~\$' instead of
  8809. `@def@ "serif\_edge"(@suffix@~\$)', and we used the macro by saying
  8810. `$"serif\_edge"_5$' instead of
  8811. `$"serif\_edge"(5)$'. The reason is that \MF\ allows the final parameter
  8812. of a macro to be without delimiters; this is something that could not
  8813. have been guessed from a study of previous examples. It is time now
  8814. to stop looking at specific cases and to start examining the complete
  8815. set of rules for macro definitions. Here is the syntax:
  8816. \beginsyntax
  8817. <definition>\is<definition heading><is><replacement text>[enddef]
  8818. <is>\is[=]\alt[:=]
  8819. <definition heading>\is[def]<symbolic token><parameter heading>
  8820.  \alt<vardef heading>
  8821.  \alt<leveldef heading>
  8822. <parameter heading>\is<delimited parameters><undelimited parameters>
  8823. <delimited parameters>\is<empty>
  8824.  \alt<delimited parameters>[(]<parameter type><parameter tokens>[)]
  8825. <parameter type>\is[expr]
  8826.  \alt[suffix]
  8827.  \alt[text]
  8828. <parameter tokens>\is<symbolic token>
  8829.  \alt<parameter tokens>[,]<symbolic token>
  8830. <undelimited parameters>\is<empty>
  8831.  \alt[primary]<symbolic token>
  8832.  \alt[secondary]<symbolic token>
  8833.  \alt[tertiary]<symbolic token>
  8834.  \alt[expr]<symbolic token>
  8835.  \alt[expr]<symbolic token>[of]<symbolic token>
  8836.  \alt[suffix]<symbolic token>
  8837.  \alt[text]<symbolic token>
  8838. \endsyntax
  8839. (We'll discuss ^\<vardef heading> and ^\<leveldef heading> in Chapter~20.)
  8840. \ The basic idea is that we name the macro to be defined, then we name
  8841. zero or more delimited parameters (i.e., parameters in parentheses),
  8842. then we name zero or more undelimited parameters. Then comes an `$=$'~sign,
  8843. followed by the replacement text, and @enddef@. The `$=$'~sign might also
  8844. be~`$:=$'\thinspace; both mean the same thing.
  8845. \danger Delimited parameters are of type @expr@, @suffix@, or @text@;
  8846. two or more parameters of the same type may be listed together, separated
  8847. by commas. For example, `(@expr@~$a,b$)' means exactly the same thing as
  8848. `(@expr@~$a$)(@expr@~$b$)'. Undelimited parameters have eight possible
  8849. forms, as shown in the syntax.
  8850. \ninepoint % all dangerous from here on
  8851. \danger The \<replacement text> is simply filed away for future use,
  8852. not interpreted, when \MF\ reads a definition. But a few tokens are
  8853. treated specially:\enddanger\nobreak
  8854. \medskip
  8855. \item\bull @def@, ^@vardef@, ^@primarydef@, ^@secondarydef@, and
  8856. ^@tertiarydef@ are considered to introduce definitions inside definitions.
  8857. \smallskip
  8858. \item\bull @enddef@ ends the replacement text, unless it matches a
  8859. previous @def@-like token (as listed in the preceding rule).
  8860. \smallskip
  8861. \item\bull Each \<symbolic token> that stands for a parameter, by
  8862. virtue of its appearance in the \<parameter heading> or \<leveldef
  8863. heading>, is changed to a special in\-ternal ``parameter
  8864. token'' wherever it occurs in the
  8865. replacement text. Whenever this special token is subsequently encountered,
  8866. \MF\ will substitute the appropriate argument.
  8867. \smallskip
  8868. \item\bull ^@quote@ disables any special interpretation of the immediately
  8869. following token. A~`@quote@' doesn't survive in the replacement text
  8870. (unless, of course, it has been quoted).
  8871. \dangerexercise Check your understanding of these rules by
  8872. figuring out what the replacement text is, in the following weird definition:
  8873. \begintt
  8874. def foo(text t) expr e of p :=
  8875.  def t = e enddef; quote def quote t = p enddef
  8876. \endtt
  8877. \answer The replacement text contains ten tokens,
  8878. \begindisplay
  8879. \ttok{def}\quad\<t>\quad\ttok{=}\quad\<e>\quad\ttok{enddef}
  8880. \quad\ttok{;}\quad\ttok{def}\quad\ttok{t}\quad\ttok{=}\quad\<p>
  8881. \enddisplay
  8882. where \<t>, \<e>, and \<p> are placeholders for argument insertion.
  8883. When this macro is expanded with $"tracingmacros">0$, \MF\ will type
  8884. \begintt
  8885. foo(TEXT0)<expr>of<primary>->def(TEXT0)=(EXPR1)enddef;def.t=(EXPR2)
  8886. \endtt
  8887. followed by the arguments |(TEXT0)|, |(EXPR1)|, and |(EXPR2)|.
  8888. \danger \MF\ does not expand macros when it reads a \<definition>;
  8889. but at almost all other times it will replace a defined token by the
  8890. corresponding replacement text, after finding all the arguments.
  8891. The replacement text will then be read as if it had been present
  8892. in the program all along.
  8893. \danger How does \MF\ determine the arguments to a macro? Well,
  8894. it knows what kinds of arguments to expect, based on the parameter
  8895. heading. Let's consider delimited arguments first:\enddanger\nobreak
  8896. \medskip
  8897. \item\bull A delimited
  8898. @expr@ argument should be of the form `(\<expression>)'; the expression
  8899. is evaluated and put into a special ``^{capsule}'' token that will be
  8900. substituted for the parameter wherever it appears in the replacement text.
  8901. \smallskip
  8902. \item\bull A delimited @suffix@ argument should be of the form
  8903. `(\<suffix>)'; subscripts that occur in the suffix are evaluated
  8904. and replaced by numeric tokens. The result is a list of zero or more
  8905. tokens that will be substituted for the parameter wherever it appears
  8906. in the replacement text.
  8907. \smallskip
  8908. \item\bull A delimited @text@ argument should be of the form
  8909. `(\<text>)', where \<text> is any sequence of tokens that is balanced
  8910. with respect to the delimiters surrounding it. This sequence of tokens
  8911. will be substituted for the parameter wherever it appears in the
  8912. replacement text.
  8913. \smallskip
  8914. \item\bull When there are two or more delimited parameters, you can
  8915. separate the arguments by commas instead of putting parentheses around
  8916. each one. For example, three delimited arguments could be written
  8917. either as `$(a)(b)(c)$' or `$(a,b)(c)$' or `$(a)(b,c)$' or `$(a,b,c)$'.
  8918. However, this abbreviation doesn't work after text arguments, which
  8919. must be followed by~`)' because text arguments can include commas.
  8920. \ddanger Chapter 8 points out that you can use other ^{delimiters}
  8921. besides parentheses. In general, a comma following a delimited
  8922. @expr@ or @suffix@ argument is equivalent to two tokens `)\thinspace(',
  8923. corresponding to whatever delimiters enclose that comma.
  8924. \ddangerexercise After `|def| |f(expr| |a)(text| |b,c)=...enddef|'
  8925. and `|delimiters|~|{{|~|}}|', what are the arguments in
  8926. `|f{{x,(,}}((}}))|'?
  8927. \answer According to the rule just stated, the first comma is an
  8928. abbreviation for `|}}|~|{{|'. Hence the first argument is a capsule
  8929. containing the value of~$x$; the second is the text `|(,|'\thinspace;
  8930. the third is the text `|(}})|'.
  8931. \danger The rules for undelimited arguments are similar. An
  8932. undelimited @primary@, @secondary@, @tertiary@, or @expr@ is the
  8933. longest syntactically correct ^\<primary>, ^\<secondary>, ^\<tertiary>,
  8934. or ^\<expression> that immediately follows the delimited arguments.
  8935. An undelimited `@expr@~$x$~^{of}~$y$' specifies two arguments, found
  8936. by taking the longest syntactically correct \<expression>~of~\<primary>.
  8937. In each of these cases, the expression might also be preceded by an
  8938. optional `^{=}' or~`^{:=}'.  An undelimited @suffix@ is the longest
  8939. \<suffix> that immediately follows the delimited arguments; \MF\ also
  8940. allows `(\<suffix>)' in this case, but not `=\<suffix>' or `:=\<suffix>'.
  8941. An undelimited @text@ essentially runs to the end of the current
  8942. statement; more precisely, it runs to the first `;'\ or `^@endgroup@' or
  8943. `^@end@' that is not part of a ^{group} within the argument.
  8944. \danger Appendix B contains lots of macros that illustrate these
  8945. rules. For example,
  8946. \begindisplay
  8947. @def@ ^@fill@ @expr@ $c$ $=$ @addto@ "currentpicture" @contour@ $c$ @enddef@;\cr
  8948. @def@ ^@erase@ @text@ $t$ $=$ @cullit@; \ $t$ @withweight@ $-1$;
  8949.  @cullit@ @enddef@;\cr
  8950. \enddisplay
  8951. these are slight simplifications of the real definitions, but they retain the
  8952. basic ideas. The command `@erase@~@fill@~$p$' causes `@fill@~$p$' to be
  8953. the @text@ argument to~@erase@, after which `$p$' becomes the @expr@
  8954. argument to~@fill@.
  8955. \ddangerexercise The `@pickup@' macro in Appendix B starts with
  8956. `@def@~@pickup@~@secondary@~$q$'; why is the argument a secondary
  8957. instead of an expression?
  8958. \answer This snares ^{future pen}s before they're converted to pens, because
  8959. @pickup@ wants to yscale by "aspect\_ratio" before ellipses change to
  8960. polygons.
  8961. \ddangerexercise Explain why the following `^"hide"' macro allows you to
  8962. hide any sequence of statements in the midst of an expression:
  8963. \begindisplay
  8964. @def@ "hide"(@text@ $t)="gobble"@begingroup@\,t;$ @endgroup@ @enddef@;\cr
  8965. @def@ "gobble" @primary@ $g=@enddef@$;\cr
  8966. \enddisplay
  8967. \answer The construction `"hide"\thinspace(\<statement list>)' expands into
  8968. `"gobble" @begingroup@ \<statement list>; @endgroup@', so the
  8969. argument to "gobble" must be evaluated. The @begingroup@ causes \MF\
  8970. to start executing statements. When that has been done, the final
  8971. statement turns out to be \<empty>, so the argument to "gobble"
  8972. turns out to be a ^{vacuous} expression (cf.\ Chapter~25). Finally,
  8973. "gobble"'s replacement text is empty, so the hidden text has indeed
  8974. disappeared. \ (The "hide" macro in Appendix~B is actually a bit
  8975. more efficient, but a bit trickier.)
  8976. \endchapter
  8977. DEFINI\/$'$\kern-.5ptTION, {\rm s. \ [definitio}, Latin.{\rm]}
  8978. 1. A short description of a thing by its properties.
  8979. \author SAMUEL ^{JOHNSON},  {\sl A Dictionary of the English Language\/} (1755)
  8980. \bigskip
  8981. DEFINI\/$''$\kern-.5ptTION, {\rm n. \ [{\sl L.} definitio}. See\/ {\rm Define.]}
  8982. 1. A brief description of a thing by its properties;
  8983. as a\/ {\rm definition} \kern-.5pt of wit or of a circle.
  8984. \author NOAH~^{WEBSTER},  {\sl An~American~%
  8985.   Dictionary~of~the~English~Language\/}~(1828)
  8986. \eject
  8987. \beginchapter Chapter 19. Conditions\\and Loops
  8988. If decisions never had to be made, life would be much easier, and so would
  8989. programming. But sometimes it is necessary to choose between alternatives,
  8990. and \MF\ allows programs to take different paths depending on the circumstances.
  8991. You just say something like
  8992. \begindisplay
  8993. @if@ not "decisions": \ $"life":="programming":="easier"("much")$\cr
  8994. @elseif@ $"choice"=a$: \ "program\_a"\cr
  8995. @else@: \ "program\_b" \ @fi@\cr
  8996. \enddisplay
  8997. which reduces, for example, to `"program\_b"' if and only if
  8998. $"decisions"=@true@$ and $"choice"\ne a$. The normal left-to-right
  8999. order of program interpretation can also be modified by specifying
  9000. ``^{loops},'' which tell the computer to read certain tokens repeatedly,
  9001. with minor variations, until some ^{condition} becomes true. We have
  9002. seen many examples of these mechanisms already; the purpose of the
  9003. present chapter is to discuss the entire range of possibilities.
  9004. \MF's conditions and loops are different from those in most other
  9005. programming languages, because the conditional or iterated code does
  9006. not have to fit into the syntactic structure. For example, you can
  9007. write strange things like
  9008. \begintt
  9009. p = (if b: 0,0)..(1,5 else: u,v fi)
  9010. \endtt
  9011. where the conditional text `$0,0)\to(1,5$' makes no sense by itself,
  9012. although it becomes meaningful when read in context. In this respect
  9013. conditions and loops behave like macros. They specify rules of
  9014. token transformation that can be said to take place in \MF's ``^{mouth}''
  9015. before the tokens are actually digested in the computer's ``^{stomach}.''
  9016. The first conditional example above has three alternatives, in the form
  9017. \begindisplay
  9018. @if@ \<boolean$_1$>: \<text$_1$> \
  9019. @elseif@ \<boolean$_2$>: \<text$_2$> \
  9020. @else@: \<text$_3$> \ @fi@
  9021. \enddisplay
  9022. and the second example has just two; there can be any number of
  9023. `^@elseif@\kern1pt' clauses before `^@else@:'. Only one of the conditional
  9024. texts will survive, namely the first one whose condition is true;
  9025. `@else@:'\ is always true.  You can also omit `@else@:'\
  9026. entirely, in which case `@else@:\thinspace\<empty>' is implied just before
  9027. the closing `^@fi@'. For example, plain \MF's @mode\_setup@ routine
  9028. includes the conditional~command
  9029. \begindisplay
  9030. @if@ unknown "mag": \ $"mag":=1$; \ @fi@
  9031. \enddisplay
  9032. whose effect is to set "mag" equal to 1 if it hasn't already received
  9033. a value; in this case there's only one alternative.
  9034. \exercise Would it be wrong to put the `;' after the `@fi@' in the example
  9035. just given?
  9036. \answer Then \MF's ``stomach'' would see `;' if "mag" is known, but there
  9037. would be no change if "mag" is unknown. An extra semicolon is harmless,
  9038. since \MF\ statements can be \<empty>. But it's wise to get in the habit
  9039. of putting `;' before @fi@, because it saves a wee bit of time and because
  9040. `;' definitely belongs before ^@endfor@.
  9041. \danger The informal rules just stated can, of course, be expressed more
  9042. formally as rules of syntax:
  9043. \beginsyntax
  9044. <condition>\is[if]<boolean expression>[:]<conditional text><alternatives>[fi]
  9045. <alternatives>\is<empty>
  9046.  \alt[else][:]<conditional text>
  9047.  \alt[elseif]<boolean expression>[:]<conditional text><alternatives>
  9048. \endsyntax
  9049. Every conditional construction begins with `^@if@\kern1pt' and ends with
  9050. `@fi@'.  The conditional texts are any sequences of tokens that are
  9051. balanced with respect to `@if@\kern1pt' and~`@fi@'; furthermore,
  9052. `@elseif@\kern1pt' and `@else@' can occur in a conditional text only when
  9053. enclosed by `@if@\kern1pt' and~`@fi@'.
  9054. \danger Each `@if@\kern1pt' and `@elseif@\kern1pt' must be followed by a
  9055. \<boolean expression>, i.e., by an expression whose value is either
  9056. `@true@' or `@false@'. ^{Boolean expressions} are named after George
  9057. ^{Boole}, the founder of algebraic approaches to logic. Chapter~7 points
  9058. out that variables can be of type ^@boolean@, and numerous examples of
  9059. boolean expressions appear in Chapter~8. It's time now to be more
  9060. systematic, so that we will know the facts about boolean expressions just
  9061. as we have become well-versed in numeric expressions, pair expressions,
  9062. picture expressions, path expressions, transform expressions, and pen
  9063. expressions. Here are the relevant syntax rules:
  9064. \beginsyntax
  9065. <boolean primary>\is<boolean variable>
  9066.  \alt[true]\alt[false]
  9067.  \alt[(]<boolean expression>[)]
  9068.  \alt[begingroup]<statement list><boolean expression>[endgroup]
  9069.  \alt[known]<primary>\alt[unknown]<primary>
  9070.  \alt<type><primary>\alt[cycle]<primary>
  9071.  \alt[odd]<numeric primary>
  9072.  \alt[not]<boolean primary>
  9073. <boolean secondary>\is<boolean primary>
  9074.  \alt<boolean secondary>[and]<boolean primary>
  9075. <boolean tertiary>\is<boolean secondary>
  9076.  \alt<boolean tertiary>[or]<boolean secondary>
  9077. <boolean expression>\is<boolean tertiary>
  9078.  \alt<numeric expression><relation><numeric tertiary>
  9079.  \alt<pair expression><relation><pair tertiary>
  9080.  \alt<transform expression><relation><transform tertiary>
  9081.  \alt<boolean expression><relation><boolean tertiary>
  9082.  \alt<string expression><relation><string tertiary>
  9083. <relation>\is[\char'74]\alt[\char'74=]\alt[>]\alt[>=]\alt[=]\alt[\char'74>]
  9084. \endsyntax
  9085. Most of these operations were already explained in Chapter~8, so it's only
  9086. necessary to mention the more subtle points now. A ^\<primary> of any
  9087. type can be tested to see whether it has a specific type, and whether it
  9088. has a known or unknown value based on the equations so far. In these tests,
  9089. a ^\<future pen primary> is considered to be of type ^@pen@. The test
  9090. `cycle~$p$' is true if and only if $p$~is a cyclic path. The `odd' function
  9091. first rounds its argument to an integer, then tests to see if the integer
  9092. is odd.  The `not' function changes true to false and vice versa. The `and'
  9093. function yields true only if both arguments are true; the `or' function
  9094. yields true unless both arguments are false. Relations on pairs, transforms,
  9095. or strings are decided by the first unequal component from left to right.
  9096. \ (A ^{transform} is considered to be a 6-tuple as in Chapter~15.) \
  9097. \dangerexercise What do you think: Is @false@ $>$ @true@?
  9098. \answer No; that would be shocking.
  9099. \dangerexercise Could `(odd $n$) and not (odd $-n$)' possibly be true?
  9100. \answer Yes, if and only if $n-{1\over2}$ is an even integer. \ (Because
  9101. ambiguous values are rounded up.)
  9102. \dangerexercise Could `(cycle $p$) and not (known $p$)' possibly be true?
  9103. \answer No.
  9104. \dangerexercise Define an `even' macro such that `even~$n$' is true if
  9105. and only if round$(n)$ is an even integer. \ [{\sl Hint:\/} There's a
  9106. slick answer.]
  9107. \answer @def@ even $=$ not odd @enddef@.
  9108. \ddanger Boolean expressions beginning with a ^\<type> should not come
  9109. at the very beginning of a statement, because \MF\ will think that
  9110. a ^\<declaration> is coming up instead of an \<expression>. Thus, for
  9111. example, if $b$~is a boolean variable, the equation `$@path@\,p=b$'
  9112. should be rewritten either as `$b=@path@\,p$' or as `$(@path@\,p)=b$'.
  9113. \ddanger A boolean expression like `$x=y$' that involves the ^{equality}
  9114. relation looks very much like an ^{equation}. \MF\ will consider `$=$'
  9115. to be a \<relation> unless the expression to its left occurs at the
  9116. very beginning of a ^\<statement> or the very beginning of a ^\<right-hand
  9117. side>. If you want to change an equation into a relation,
  9118. just insert parentheses, as in `$(x=y)=b$' or `$b=(x=y)$'.
  9119. \ddanger After a ^\<path join>, the token `^{cycle}' is not considered
  9120. to be the beginning of a \<boolean primary>. \ (Cf.\ Chapter~14.)
  9121. \ddanger The boolean expression `^@path@ $((0,0))$' is false, even
  9122. though `$((0,0))$' meets Chapter~14's syntax rules for
  9123. \<path primary>, via (\<path expression>) and
  9124. (\<path subexpression>) and
  9125. (\<pair tertiary>). A ^{pair expression} is not considered to be
  9126. of type @path@ unless the path interpretation is mandatory.
  9127. \ddangerexercise Evaluate `length $((3,4))$' and `length $((3,4)\{0,0\})$'
  9128. and `length reverse~$(3,4)$'.
  9129. \answer The first is~5, because the pair is not considered to be a path.
  9130. The second and third are~0, because the pair is forced to become a path.
  9131. OK, that covers all there is to be said about conditions. What about
  9132. loops? It's easiest to explain loops by giving the syntax first:
  9133. \beginsyntax
  9134. <loop>\is<loop header>:<loop text>[endfor]
  9135. <loop header>\is[for]<symbolic token><is><for list>
  9136.  \alt[for]<symbolic token><is><progression>
  9137.  \alt[forsuffixes]<symbolic token><is><suffix list>
  9138.  \alt[forever]
  9139. <is>\is[=]\alt[:=]
  9140. <for list>\is<expression>\alt<empty>
  9141.  \alt<for list>[,]<expression>\alt<for list>[,]<empty>
  9142. <suffix list>\is<suffix>
  9143.  \alt<suffix list>[,]<suffix>
  9144. <progression>\is<initial value>[step]<step size>[until]<limit value>
  9145. <initial value>\is<numeric expression>
  9146. <step size>\is<numeric expression>
  9147. <limit value>\is<numeric expression>
  9148. <exit clause>\is[exitif]<boolean expression>[;]
  9149. \endsyntax
  9150. As in macro definitions, `$=$' and `$:=$' are interchangeable here.
  9151. This syntax shows that loops can be of four kinds, which we might
  9152. indicate schematically as follows:
  9153. \begindisplay
  9154. @for@ $x=\epsilon_1,\epsilon_2,\epsilon_3$: text($x$) @endfor@\cr
  9155. \noalign{\vskip 1pt plus 1pt}
  9156. @for@ $x=\nu_1$ @step@ $\nu_2$ @until@ $\nu_3$: text($x$) @endfor@\cr
  9157. \noalign{\vskip 1pt plus 1pt}
  9158. @forsuffixes@ $s=\sigma_1,\sigma_2,\sigma_3$: text($s$) @endfor@\cr
  9159. \noalign{\vskip 1pt plus 1pt}
  9160. @forever@: text @endfor@\cr
  9161. \enddisplay
  9162. The first case expands to
  9163. `text($\epsilon_1$) text($\epsilon_2$) text($\epsilon_3$)'; the
  9164. $\epsilon$'s here are expressions of any type, not necessarily ``known,''
  9165. and they are evaluated and put into ^{capsules} before being substituted
  9166. for~$x$. The $\epsilon$'s might also be empty, in which case
  9167. text($\epsilon$) is omitted.
  9168. The second case is more complicated, and it will be explained carefully
  9169. below; simple cases like `1~@step@~2 @until@~7' are equivalent to
  9170. short lists like `$1,3,5,7$'. The third case expands to
  9171. `text($\sigma_1$) text($\sigma_2$) text($\sigma_3$)'; the $\sigma$'s here
  9172. are arbitrary suffixes (possibly empty), in which subscripts will have been
  9173. evaluated and changed to numeric tokens before being substituted for~$x$.
  9174. The final case expands into the sequence `text~text~text~$\ldots$',
  9175. ad~infinitum; there's an escape from this (and from the other three kinds
  9176. of loop) if an \<exit clause> appears in the text, as explained below.
  9177. Notice that if the loop text is a single statement that's supposed to
  9178. be repeated several times, you should put a `^{;}' just before the
  9179. @endfor@, not just after it; \MF's loops do not insert ^{semicolons}
  9180. automatically, because they are intended to be used in the midst of
  9181. expressions as well as with statements that are being iterated.
  9182. Plain \MF\ defines `^@upto@' as an abbreviation for `@step@~1~@until@',
  9183. and `^@downto@' as an abbreviation for `@step@~$-1$~@until@'. Therefore
  9184. you can say, e.g., `\thinspace@for@ $x=1$ @upto@~9:\thinspace' instead of
  9185. `\thinspace@for@ $x=1,2,3,4,5,6,7,8,9$:\thinspace'.
  9186. \danger When you say `@for@ $x=\nu_1$ @step@ $\nu_2$ @until@~$\nu_3$',
  9187. \MF\ evaluates the three numeric expressions, which must have known values.
  9188. Then it reads the loop text. If $\nu_2>0$ and $\nu_1>\nu_3$, or if
  9189. $\nu_2<0$ and $\nu_1<\nu_3$, the loop is not performed at all. Otherwise
  9190. text($\nu_1$) is performed, $\nu_1$ is replaced by $\nu_1+\nu_2$, and
  9191. the same process is repeated with the new value of $\nu_1$.
  9192. \dangerexercise Read the rules in the previous paragraph carefully, then
  9193. explain for what values of~$x$ the loop is performed if you say
  9194. (a)~`\thinspace@for@~$x=1$ @step@~2 @until@~0'\thinspace. \
  9195. (b)~`\thinspace@for@~$x=1$ @step@~$-2$ @until@~0\thinspace'. \
  9196. (c)~`\thinspace@for@~$x=1$ @step@~0 @until@~0\thinspace'. \
  9197. (d)~`\thinspace@for@~$x=0$ @step@~.1 @until@~1\thinspace'.
  9198. \answer (a) The loop text is never executed. \
  9199. (b)~It's executed only once, for $x=1$. \
  9200. (c)~It's executed infinitely often, for $x=1,1,1,\ldots\,$. \
  9201. (d)~Since ten times \MF's internal representation of
  9202. .1 is slightly larger than 1, the answer
  9203. is not what you probably expect! The loop text is executed for
  9204. $x=0$,~0.1, 0.20001, 0.30002, 0.40002, 0.50003, 0.60004, 0.70004, 0.80005,
  9205. and 0.90005 only. \ (If you want the values $(0,.1,.2,\ldots,1)$, say
  9206. `\thinspace@for@ $"xx"=0$ @upto@~10: $x:="xx"/10$; \<text> @endfor@' instead.)
  9207. \danger A \<loop text> is rather like the \<replacement text> of a macro.
  9208. It is any sequence of tokens that is balanced with respect to
  9209. un^{quote}d appearances of @for@/@forsuffixes@/@forever@ and @endfor@
  9210. delimiters. \MF\ reads the entire loop text quickly and stores it away
  9211. before trying to perform it or to expand macros within it. All occurrences
  9212. of the controlled \<symbolic token> in the loop text are changed to
  9213. special internal parameter tokens that mean ``insert an argument here,''
  9214. where the argument is of type @expr@ in the case of @for@, of
  9215. type @suffix@ in the case of @forsuffixes@. This rule implies, in
  9216. particular, that the symbolic token has no connection with similarly
  9217. named variables elsewhere in the program.
  9218. \dangerexercise What values are shown by the following program?
  9219. \begintt
  9220. n=0; for n=1: m=n; endfor show m,n; end.
  9221. \endtt
  9222. \answer $m=1$, $n=0$.
  9223. \danger The ^"flex" routine described in Chapter~14 provides an interesting
  9224. example of how loops can be used inside of macros inside of expressions:
  9225. \begindisplay
  9226. @pair@ $"z\_"\,[\,]$, $"dz\_"$; \ @numeric@ "n\_"\thinspace;
  9227.  &\% private variables\cr
  9228. @def@ "flex"(@text@ $t$) $=$&\% $t$ is a list of pairs\cr
  9229. \quad^"hide"$\bigl(\,"n\_":=0$;\cr
  9230. \qquad @for@ $z=t$: $"z\_"\,[{\rm incr}\,"n\_"]:=z$; @endfor@\cr
  9231. \qquad $"dz\_":="z\_"\,["n\_"]-"z\_"\,[1]\,\bigr)$\cr
  9232. \quad $"z\_"\,[1]$ @for@ $k=2$ @upto@ $"n\_"-1$:
  9233.  $\ldots"z\_"\,[k]\{"dz\_"\}$ @endfor@\hidewidth\cr
  9234. \qquad $\ldots"z\_"\,["n\_"]$ @enddef@;\cr
  9235. \enddisplay
  9236. The first loop stores the given pairs temporarily in an array, and it also
  9237. counts how many there are; this calculation is ``hidden.'' Then
  9238. the actual flex-path is contributed to the program with the help of
  9239. a second loop. \ (Appendix~B uses the convention that symbolic tokens
  9240. ending in `^{\_}' should not appear in a user's program; this often
  9241. makes it unnecessary to `^@save@' tokens.)
  9242. \danger When \MF\ encounters the construction `^@exitif@ \<boolean
  9243. expression>;', it evaluates the boolean expression. If the
  9244. expression is true, the (innermost) loop being iterated is terminated
  9245. abruptly. Otherwise, nothing special happens.
  9246. \dangerexercise Define an `^@exitunless@' macro such that
  9247. `@exitunless@ \<boolean expression>;' will exit the current loop
  9248. if the boolean expression is false.
  9249. \answer @def@ @exitunless@ @expr@ $b$ $=$ @exitif@ not $b$ @enddef@.
  9250. \ (The simpler alternative `@def@ @exitunless@ $=$ @exitif@ not
  9251. @enddef@\kern1pt' wouldn't work, since `not' applies only to the following
  9252. \<primary>.)
  9253. \ddangerexercise Write a \MF\ program that sets $p[k]$ to the $k$th
  9254. ^{prime number}, for $1\le k\le30$. Thus, $p[1]$ should be~2,
  9255. $p[2]=3$, etc.
  9256. \answer |numeric p[]; boolean n_is_prime; p[1]=2; k:=1;|\parbreak
  9257. |for n=3 step 2 until infinity:|\parbreak
  9258. | n_is_prime:=true;|\parbreak
  9259. | for j=2 upto k: if n mod p[j]=0: n_is_prime:=false; fi|\parbreak
  9260. |  exitif n/p[j]<p[j]; endfor|\parbreak
  9261. | if n_is_prime: p[incr k]:=n; exitif k=30; fi|\parbreak
  9262. | endfor fi|\parbreak
  9263. ^^@show@^^@str@
  9264. |show for k=1 upto 30: str p[k]&"="&decimal p[k], endfor "done" end.|
  9265. \ddangerexercise When you run \MF\ on the file `|expr.mf|' of
  9266. Chapter~8, you get into a `^@forever@' loop that can be stopped
  9267. if you type, e.g., `|0|~|end|'. But what can you type to get out
  9268. of the loop without ending the run? \ (The goal is to make
  9269. \MF\ type~`|*|', without incurring any error messages.)
  9270. \answer `|0; exitif true;|'.
  9271. \endchapter
  9272. If? thou Protector of this damned Strumpet,
  9273. Talk'st thou to me of Ifs: thou art a Traytor,
  9274. Off with his Head.
  9275. \author WILLIAM ^{SHAKESPEARE},  {\sl Richard the Third\/} (1593)
  9276. \bigskip
  9277. % When ye pray,
  9278. Use not vain repetitions.
  9279. \author {\sl ^{Matthew} 6\thinspace:\thinspace7\/} (c.~70 A.D.)
  9280. \eject
  9281. \beginchapter Chapter 20. More\\About\\Macros
  9282. Chapter 18 gave the basic facts about macro definitions, but it didn't
  9283. tell the whole story. It's time now for the Ultimate Truth to be revealed.
  9284. \ninepoint
  9285. \danger But this whole chapter consists of ``dangerous bend'' paragraphs,
  9286. since the subject matter will be appreciated best by people who have
  9287. worked with \MF\ for a little while.
  9288. We shall discuss the following topics:\enddanger
  9289. \smallskip
  9290. \item\bull Definitions that begin with `@vardef@\kern1pt'; these embed macros
  9291. into the variables of a program and extend the unary operators of
  9292. \MF\ expressions.
  9293. \item\bull Definitions that begin with `@primarydef@\kern.3pt',
  9294. `@secondarydef@\kern.3pt', or `@tertiarydef@\kern.3pt'; these extend the
  9295. binary operators of \MF\ expressions.
  9296. \item\bull Other primitives of \MF\ that expand into sequences of tokens
  9297. in a macro-like way, including `@input@' and `@scantokens@'.
  9298. \item\bull Rules that explain when tokens are subject to expansion
  9299. and when they aren't.
  9300. \danger First let's consider the \<vardef heading> that was left
  9301. undefined in Chapter~18. The ordinary macros discussed in that chapter
  9302. begin with
  9303. \begindisplay
  9304. @def@ \<symbolic token>\<parameter heading>
  9305. \enddisplay
  9306. and then comes `$=$', etc. You can also begin a definition by saying
  9307. \begindisplay
  9308. ^@vardef@ \<declared variable>\<parameter heading>
  9309. \enddisplay
  9310. instead; in this case the ^\<declared variable> might consist of
  9311. several tokens, and you are essentially defining a variable whose
  9312. ``value'' is of type ``macro.'' For example, suppose you decide to say
  9313. \begindisplay
  9314. @pair@ $a.p$; \ @pen@ $a.q$; \ @path@ $a.r$; \
  9315. @vardef@ $a.s=\ldots$ @enddef@;
  9316. \enddisplay
  9317. then $a.p$, $a.q$, and $a.r$ will be variables of types @pair@, @pen@,
  9318. and @path@, but $a.s$ will expand into a sequence of tokens. \
  9319. (The language {\eightrm^{SIMULA67}} demonstrated that it is advantageous
  9320. to include procedures as parts of variable data structures; \MF\ does an
  9321. analogous thing with macros.)
  9322. \danger After a definition like `@def@ $t=\ldots$', the token $t$ becomes
  9323. a ``^{spark}''; i.e., you can't use it in a suffix. But after
  9324. `@vardef@ $t=\ldots$', the token~$t$ remains a ``^{tag},'' because
  9325. macro expansion will take place only when $t$~is the first token in
  9326. a variable name. Some of the definitions in Appendix~B are vardefs
  9327. instead of defs for just that reason; for example,
  9328. \begindisplay
  9329. @vardef@ dir @primary@ $d$ $=$ "right" rotated $d$ @enddef@
  9330. \enddisplay
  9331. allows a user to have variable names like `|p5dir|'.
  9332. \danger A variable is syntactically a primary expression, and \MF\ would
  9333. get unnecessarily confused if the replacement texts of vardef macros
  9334. were very different from primary expressions. Therefore, the
  9335. tokens `^@begingroup@'
  9336. and `^@endgroup@' are automatically inserted at the beginning and end
  9337. of every vardef replacement text. If you say `^@showvariable@~$a$'
  9338. just after making the declarations and definition above, the machine
  9339. will reply as follows:
  9340. \begintt
  9341. a.p=pair
  9342. a.q=unknown pen
  9343. a.r=unknown path
  9344. a.s=macro:->begingroup...endgroup
  9345. \endtt
  9346. \danger The `^{incr}' macro of Appendix B increases its argument by~1
  9347. and produces the increased value as its result. The inserted `@begingroup@'
  9348. and `@endgroup@' come in handy here:
  9349. \begindisplay
  9350. @vardef@ incr @suffix@ \$ $=$ $\$:=\$+1$; \ \$ @enddef@.
  9351. \enddisplay
  9352. Notice that the argument is a ^@suffix@, not an @expr@, because
  9353. every variable name is a special case of a ^\<suffix>, and because
  9354. an ^@expr@ parameter should never appear to the left ^^{:=} of~`$:=$'.
  9355. Incidentally, according to the rules for ^{undelimited suffix parameters}
  9356. in Chapter~18, you're allowed to say either `incr~$v$' or `incr$(v)$' when
  9357. applying incr to~$v$.
  9358. \danger There's another kind of vardef, in which the variable name being
  9359. defined can have any additional suffix when it is used; this suffix is
  9360. treated as an argument to the macro. In this case you write
  9361. \begindisplay
  9362. @vardef@ \<declared variable>|@#| \<parameter heading>
  9363. \enddisplay
  9364. ^^{at sharp} and you can use |@#| in the replacement text (where it
  9365. behaves like any other @suffix@ parameter). For example, Appendix~B says
  9366. \begindisplay
  9367. @vardef@ $z$|@#| $=$ $(x$|@#|$,y$|@#|) @enddef@;
  9368. \enddisplay
  9369. this is the magic definition that makes `$z_{3r}$' equivalent to
  9370. `$(x_{3r},y_{3r})$', etc. In fact, we now know that `|z3r|' actually
  9371. expands into eleven tokens:
  9372. \begintt
  9373. begingroup (x3r, y3r) endgroup
  9374. \endtt
  9375. \ddangerexercise True or false: After `|vardef| |a@#| |suffix| |b| |=|
  9376. $\ldots$~|enddef|', the suffix argument~|b| will always be empty.
  9377. \answer False; consider `|a1(2)|'.
  9378. \ddanger Plain \MF\ includes a ^"solve" macro that uses ^{binary search}
  9379. to find numerical solutions to ^{nonlinear equations}, which are too
  9380. difficult to resolve in the ordinary way. ^^{equations, nonlinear}
  9381. To use "solve", you first define a macro $f$ such that $f(x)$ is either
  9382. @true@ or @false@; then you say
  9383. \begindisplay
  9384. "solve" $f("true\_x","false\_x")$
  9385. \enddisplay
  9386. where "true\_x" and "false\_x" are values such that $f("true\_x")=@true@$
  9387. and $f("false\_x")=@false@$. The resulting value~$x$ will be at the cutting
  9388. edge between truth and falsity, in the sense that $x$~will be within a
  9389. given ^"tolerance" of values for which $f$ yields both outcomes.
  9390. \begindisplay
  9391. @vardef@ "solve"|@#|(@expr@ $"true\_x","false\_x"$) $=$\cr
  9392. \quad $"tx\_":="true\_x"$; \ $"fx\_":="false\_x"$;\cr
  9393. \quad^@forever@: $"x\_":=.5["tx\_","fx\_"]$; \
  9394.  ^@exitif@ abs$("tx\_"-"fx\_")\le"tolerance"$;\cr
  9395. \quad @if@ |@#|$("x\_"):\ "tx\_" @else@:\ "fx\_" @fi@ $:="x\_"; @endfor@;\cr
  9396. \quad "x\_" @enddef@;\cr
  9397. \enddisplay
  9398. \ddanger For example, the "solve" routine makes it possible to solve the
  9399. following interesting problem posed by Richard ^{Southall}: Given
  9400. points $z_1$,~$z_2$, $z_3$,~$z_4$ such that $x_1<x_2<x_3<x_4$ and
  9401. $y_1<y_2=y_3>y_4$, find the point~$z$ between $z_2$ and~$z_3$ such that
  9402. \MF\ will choose to travel "right" at~$z$ in the path
  9403. \begindisplay
  9404. $z_1\,\{z_2-z_1\}\to z\to\{z_4-z_3\}\,z_4$.
  9405. \enddisplay
  9406. If we try $z=z_2$, \MF\ will choose a direction at $z$ that has a positive
  9407. (upward) $y$-component; but at $z=z_3$, \MF's chosen direction will have a
  9408. negative (downward) $y$-component. Somewhere in between is a ``^{nice}''
  9409. value of~$z$ for which the curve will not rise above the line $y=y_2$.
  9410. What is this~$z$?
  9411. \displayfig 20a (115\apspix)
  9412. Chapter 14 gives equations from which $z$ could be computed, in principle,
  9413. but those equations involve trigonometry in a complicated fashion.
  9414. It's nice to know that we can find~$z$ rather easily in spite of those
  9415. complexities:
  9416. \begindisplay
  9417. @vardef@ "upward"(@expr@ $x$) $=$\cr
  9418. \quad ypart direction 1 of $\bigl(z_1\{z_2-z_1\}
  9419.  \to(x,y_2)\to\{z_4-z_3\}z_4\bigr)>0$ @enddef@;\cr
  9420. $z=\bigl("solve"\,"upward"(x_2,x_3),y_2\bigr)$.\cr
  9421. \enddisplay
  9422. \ddangerexercise It might happen in unusual cases that $"upward"(x)$
  9423. is @false@ for all $x_2\le x\le x_3$, hence "solve" is being invoked
  9424. under invalid assumptions. What result does it give~then?
  9425. \answer A value very close to $z_2$.
  9426. \ddangerexercise Use "solve" to find $\root3\of{10}$, and compare
  9427. the answer to the ^{cube root} obtained in the normal way.
  9428. \answer |vardef lo_cube(expr x)=x*x*x<10 enddef;|\parbreak
  9429. |show solve lo_cube(0,10), 10**1/3; end.|\par\nobreak\medskip\noindent
  9430. ^^{**} With the default ^"tolerance" of 0.1,
  9431. this will show the respective values |2.14844| and |2.1544|.
  9432. A more general routine could also be written, with `10' as a parameter:
  9433. \begintt
  9434. vardef lo_cube[](expr x)=x*x*x<@ enddef;
  9435. show solve lo_cube10(0,10);
  9436. \endtt
  9437. if we ask for minimum tolerance ($"tolerance":="epsilon"$), the
  9438. result is |2.15445|; the true value is $\approx 2.15443469$.
  9439. \ddanger The syntax for \<declared variable> in Chapter~7 allows for
  9440. ^{collective subscripts} as well as tags in the name of the variable
  9441. being declared. Thus, you can say
  9442. \begindisplay
  9443. @vardef@ $a[\,]b[\,]=\ldots$ @enddef@;
  9444. \enddisplay
  9445. what does this mean? Well, it means that all variables like |a1b2|
  9446. are macros with a common replacement text. Every vardef has two
  9447. ^^{at} ^^{sharp at}
  9448. implicit suffix parameters, `|#@|' and~`|@|', which can be used in
  9449. the replacement text to discover what subscripts have actually been
  9450. used. Parameter~`|@|' is the final token of the variable name
  9451. (`|2|' in this example); parameter `|#@|' is everything preceding
  9452. the final token (in this case `|a1b|'). These notations are supposed to
  9453. be memorable because `|@|' is where you're ``at,'' while `|#@|' is
  9454. everything before and `|@#|' is everything after.
  9455. \ddangerexercise After `|vardef| |p[]dir=(#@dx,#@dy)| |enddef|', what's
  9456. the expansion of `|p5dir|'\thinspace?
  9457. \answer |begingroup(p5dx,p5dy)endgroup|.
  9458. \ddangerexercise Explain how it's possible to retrieve the first subscript
  9459. in the replacement text of |vardef|~|a[]b[]| (thereby obtaining,
  9460. for example, `|1|' instead of `|a1b|').
  9461. \answer Say `|first#@|' after defining `|vardef| |first.a[]@#=@| |enddef|'.
  9462. \ (There are other solutions, e.g., using substrings of ^@str@~|#@|,
  9463. but this one is perhaps the most instructive.)
  9464. \ddangerexercise Say `^|showvariable| |incr,z|' to \MF\ and explain
  9465. ^^{incr} ^^{z} the machine's reply.
  9466. \answer The machine answers thus:
  9467. \begintt
  9468. incr=macro:<suffix>->
  9469.    begingroup(SUFFIX2):=(SUFFIX2)+1;(SUFFIX2)endgroup
  9470. z@#=macro:->begingroup(x(SUFFIX2),y(SUFFIX2))endgroup
  9471. \endtt
  9472. Parameters to a macro are numbered sequentially, starting with zero,
  9473. and classified as either ^|(EXPR|$_n$|)|, ^|(SUFFIX|$_n$|)|, or
  9474. ^|(TEXT|$_n$|)|. In a vardef, |(SUFFIX0)| and |(SUFFIX1)| are always
  9475. reserved for the implicit parameters |#@| and~|@|; |(SUFFIX2)| will
  9476. be |@#|, if it is used in the parameter heading, otherwise it will be the
  9477. ^^{at sharp} ^^{at} ^^{sharp at} first explicit parameter, if
  9478. it happens to be a suffix parameter.
  9479. \ddanger A vardef wipes out all type declarations and macro definitions
  9480. for variables whose name begins with the newly defined macro variable name.
  9481. For example, `|vardef|~|a|' causes variables like |a.p|
  9482. and |a1b2| to disappear silently; `|vardef|~|a.s|' wipes out
  9483. |a.s.p|, etc. Moreover, after `|vardef|~|a|' is
  9484. in effect, you are not allowed to say `|pair|~|a.p|' or `|vardef|~|a[]|',
  9485. since such variables would be inaccessible.
  9486. \ddanger The syntax for \<definition> in Chapter 18 was incomplete,
  9487. because $\langle$vardef heading$\rangle$ and \<leveldef heading> were
  9488. omitted. Here are the missing rules:
  9489. \beginsyntax
  9490. <vardef heading>\is[vardef]<declared variable><parameter heading>
  9491.  \alt[vardef]<declared variable>[\char'100\#]<parameter heading>
  9492. <leveldef heading>\is<leveldef><parameter><symbolic token><parameter>
  9493. <leveldef>\is[primarydef]\alt[secondarydef]\alt[tertiarydef]
  9494. <parameter>\is<symbolic token>
  9495. \endsyntax
  9496. The new things here are @primarydef@, @secondarydef@, and @tertiarydef@,
  9497. which permit you to extend \MF's repertoire of binary operators. For example,
  9498. the `dotprod' operator is defined as follows in Appendix~B:
  9499. \begindisplay
  9500. @primarydef@ $w$ dotprod $z$ $=$\cr
  9501. \quad $({\rm xpart}\,w\ast{\rm xpart}\,z\;+\;
  9502.  {\rm ypart}\,w\ast{\rm ypart}\,z)$ @enddef@.\cr
  9503. \enddisplay
  9504. \MF's syntax for expressions has effectively gained a new rule
  9505. \beginsyntax
  9506. <numeric secondary>\is<pair secondary>[dotprod]<pair primary>
  9507. \endsyntax
  9508. in addition to the other forms of \<numeric secondary>, because of this
  9509. primarydef.
  9510. \ddanger The names `@primarydef@\kern1pt', `@secondarydef@\kern1pt',
  9511. and `@tertiarydef@\kern1pt' may
  9512. seem off by one, because they define operators at one level higher up:
  9513. A primarydef defines a binary operator that forms a secondary expression
  9514. from a secondary and a primary; such operators are at the same level
  9515. as `$\ast$' and `rotated'.
  9516. A secondarydef defines a binary operator that forms a tertiary expression
  9517. from a tertiary and a secondary; such operators are at the same level
  9518. as~`$+$'~and~`or'.
  9519. A tertiarydef defines a binary operator that forms an expression
  9520. from an expression and a tertiary; such operators are at the same level
  9521. as~`$<$'~and~`\&'.
  9522. \ddanger Plain \MF's `^{intersectionpoint}' macro is defined by a
  9523. @secondarydef@ because it is analogous to `^{intersectiontimes}', which
  9524. occurs at the same level (namely the secondary~$\rightarrow$~tertiary level).
  9525. \begindisplay
  9526. @secondarydef@ $p$ intersectionpoint $q$ $=$\cr
  9527. \quad @begingroup@ ^@save@ $"x\_","y\_"$; \
  9528.  $("x\_","y\_")=p$ intersectiontimes $q$;\cr
  9529. \quad @if@ $"x\_"<0$: ^@errmessage@(|"The paths don't intersect"|);
  9530.  \ $(0,0)$\cr
  9531. \quad @else@: .5[point "x\_" of $p$,
  9532.  point "y\_" of $q$] @fi@ @endgroup@ @enddef@;\cr
  9533. \enddisplay
  9534. Notice that ^@begingroup@ and ^@endgroup@ are necessary here; they aren't
  9535. inserted automatically as they would have been in a @vardef@.
  9536. \ddangerexercise Define a `^{transum}' macro operation that yields
  9537. the ^{sum} of two ^{transforms}. \ (If $t_3=t_1$~transum~$t_2$, then
  9538. $z$~transformed~$t_3=z$~transformed~$t_1+z$~transformed~$t_2$,
  9539. for~all~pairs~$z$.)
  9540. \answer |secondarydef t transum tt =|\parbreak
  9541. | begingroup save T; transform T;|\parbreak
  9542. | for z=origin,up,right:|^^"origin"\parbreak
  9543. |  z transformed t + z transformed tt = z transformed T; endfor|\parbreak
  9544. |  T endgroup enddef.|
  9545. \ddanger \looseness=-1
  9546. Now we've covered all the types of \<definition>, and it's time to
  9547. take stock and think about the total picture. \MF's ^{mastication} process
  9548. converts an input file into a long sequence of tokens, as explained in
  9549. Chapter~6, and its digestive processes work strictly on those tokens.
  9550. When a symbolic token is about to be digested, \MF\ looks up the token's
  9551. current meaning, and in certain cases \MF\ will expand that token into
  9552. a sequence of other tokens before continuing; this ``^{expansion process}''
  9553. applies to macros and to @if@ and~@for@, as well as to certain other
  9554. special primitives that we shall consider momentarily. Expansion
  9555. continues until an unexpandable token is found; then the ^{digestion process}
  9556. can continue. Sometimes, however, the expansion is not carried out; for
  9557. example, after \MF\ has digested a @def@ token, it stops all expansion until
  9558. just after it reaches the corresponding @enddef@. A complete list of
  9559. all occasions when tokens are not expanded appears later in this chapter.
  9560. \ddanger Let's consider all the tokens that cause expansion to occur,
  9561. whenever expansion hasn't been inhibited:\enddanger
  9562. \nobreak\medskip
  9563. \textindent\bull Macros. When a macro is expanded, \MF\ first reads and
  9564. evaluates the arguments (if any), as already explained.
  9565. \ (Expansion continues while @expr@ and @suffix@ arguments are
  9566. being evaluated, but it is suppressed within @text@ arguments.) \
  9567. Then \MF\ replaces the macro and its arguments by the replacement text.
  9568. \smallbreak
  9569. \textindent\bull ^{Conditions}. When `^@if@\kern1pt' is expanded, \MF\
  9570. reads and evaluates the boolean expression, then skips ahead, if necessary,
  9571. until coming to either `^@fi@' or a condition that's true; then it will
  9572. continue to read the next token. When `^@elseif@\kern1pt' or `^@else@'
  9573. or `@fi@' is expanded, a conditional text has just ended, so \MF\
  9574. skips to the closing `@fi@' and the expansion is empty.
  9575. \smallbreak
  9576. \textindent\bull ^{Loops}. When `^@for@' or `^@forsuffixes@' or
  9577. `^@forever@' is expanded, \MF\ reads the specifications up to the colon,
  9578. then reads the loop text (without expansion) up to the @endfor@.
  9579. Finally it rereads the loop text repeatedly, with expansion. When
  9580. `^@exitif@\kern1pt' is expanded, \MF\ evaluates the following boolean
  9581. expression and throws away the semicolon; if the expression proves
  9582. to be true, the current loop is terminated.
  9583. \smallbreak
  9584. \textindent\bull ^@scantokens@ \<string primary>. When `@scantokens@'
  9585. is expanded, \MF\ evaluates the following primary expression, which
  9586. should be of type @string@. This string is converted to tokens by the
  9587. rules of Chapter~6, as if
  9588. it had been input from a file containing just one line of text.
  9589. \smallbreak
  9590. \textindent\bull ^@input@ ^\<filename>. When `@input@' is expanded,
  9591. the expansion is null, but \MF\ prepares to read from the specified
  9592. file before looking at any more tokens from its current source.
  9593. A \<filename> is subject to special restrictions explained on the
  9594. next page.
  9595. \smallbreak
  9596. \textindent\bull ^@endinput@. When `@endinput@' is expanded, the
  9597. expansion is null. But the next time \MF\ gets to the end of an
  9598. @input@ line, it will stop reading from the file containing that line.
  9599. \smallbreak
  9600. \textindent\bull ^@expandafter@. When `@expandafter@' is expanded,
  9601. \MF\ first reads one more token, without expanding it; let's
  9602. call this token~$t$. Then \MF\ reads the token that comes after~$t$
  9603. (and possibly more tokens, if that token takes an argument),
  9604. replacing it by its expansion. Finally, \MF\ puts~$t$ back in front
  9605. of that expansion.
  9606. \nobreak\smallskip
  9607. \textindent\bull ^^{backslash} |\|. When `|\|' is expanded, the
  9608. expansion is null, i.e., empty.
  9609. \ddanger The syntax for \<filename> is not standard in \MF\!, because
  9610. different operating systems have different conventions. You should
  9611. ask your local system wizards for details on just how they have
  9612. decided to implement ^{file names}. The situation is complicated by
  9613. the fact that \MF's process of converting to tokens is irreversible;
  9614. for example, `|x01|' and `|x1.0|' both yield identical sequences
  9615. of tokens. Therefore \MF\ doesn't even try to convert a file name
  9616. to tokens; an ^|input| operation must appear only in a text file, not
  9617. in a list of tokens like the replacement text of a macro! \ (You can get
  9618. around this restriction by saying
  9619. \begindisplay
  9620. ^@scantokens@ |"input foo"|
  9621. \enddisplay
  9622. or, more generally,
  9623. \begindisplay
  9624. ^@scantokens@ (|"input "| \& "fname")
  9625. \enddisplay
  9626. if "fname" is a string variable containing the \<filename> you want to
  9627. input.) \ Although file names have nonstandard syntax, a sequence of six
  9628. or fewer ordinary letters and/or digits followed by a space should be a
  9629. file name that works in essentially the same way on all installations of
  9630. \MF\!\null. Uppercase letters are considered to be distinct from their
  9631. lowercase counterparts, on many systems.
  9632. \ddanger Here now is the promised list of all cases when expandable
  9633. tokens are not expanded. Some of the situations involve primitives
  9634. that haven't been discussed yet, but we'll get to them eventually.
  9635. Expansion is suppressed at the following times:\enddanger
  9636. \nobreak\medskip\item\bull
  9637. When tokens are being deleted during error recovery (see Chapter~5).
  9638. \smallskip\item\bull
  9639. When tokens are being skipped because conditional text is being ignored.
  9640. \smallskip\item\bull
  9641. When \MF\ is reading the definition of a macro.
  9642. \smallskip\item\bull
  9643. When \MF\ is reading a loop text, or the symbolic token that
  9644. immediately follows @for@ or @forsuffixes@.
  9645. \smallskip\item\bull
  9646. When \MF\ is reading the @text@ argument of a macro.
  9647. \smallskip\item\bull
  9648. When \MF\ is reading the initial symbolic token of a \<declared variable>
  9649. in a type declaration.
  9650. \smallskip\item\bull
  9651. When \MF\ is reading the symbolic tokens to be defined by ^@delimiters@,
  9652. ^@inner@, ^@let@, ^@newinternal@, or ^@outer@.
  9653. \smallskip\item\bull
  9654. When \MF\ is reading the symbolic tokens to be shown by ^@showtoken@
  9655. or ^@showvariable@.
  9656. \smallskip\item\bull
  9657. When \MF\ is reading the token after ^@expandafter@, ^@everyjob@,
  9658. or the `$=$' following @let@.
  9659. \medskip\noindent
  9660. The expansion process is not suppressed while reading the suffix that
  9661. follows the initial token of a \<declared variable>, not even in a
  9662. \<vardef heading>.
  9663. \endchapter
  9664. % quam oppressis, qui novas res moliebantur, ...
  9665. The two lieutenants,
  9666. Fonteius Capito in Germany,
  9667. % in Germania, Fonteio Capitone;
  9668. and Claudius Macro in Africa,
  9669. % in Africa, Clodio Macro, legatis.
  9670. who opposed his advancement,
  9671. were put down.
  9672. \author ^{SUETONIUS}, %
  9673.   {\sl Sergius Sulpicius Galba\/} (c.\thinspace125 A.D.) % chapter 11
  9674. % from the translation by Alexander Thomson
  9675. % (he says Macer, not Macro, but other translators call this man Macro)
  9676. \bigskip
  9677. By introducing macro instructions in the source language,
  9678. the designer can bring about the same ease of programming
  9679. as could be achieved by giving the computer
  9680. a more powerful operation list than it really has.
  9681. But naturally, one does not get the same advantages
  9682. in terms of economy of memory space and computer time
  9683. as would be obtained if the more powerful instructions
  9684. were really built into the machine.
  9685. \author O. ^{DOPPING},  {\sl Computers \& Data Processing\/} (1970) % ch19 p312
  9686. \eject
  9687. \beginchapter Chapter 21. Random\\Numbers
  9688. \newcount\n \n=93 \def\nextn{\global\advance\n1 \rand\char\n}%
  9689. \def\threenextn{\nextn&\nextn&\nextn}%
  9690. It's fun to play games with
  9691. {\nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn}
  9692. by writing programs that incorporate
  9693. an element of ^{chance}. You can generate unpredictable shapes, and
  9694. you can add patternless perturbations to break up the rigid symmetry that
  9695. is usually associated with mathematical constructions.
  9696.  Musicians who use computers to
  9697. synthesize their compositions have found that ^{music} has more ``life'' if
  9698. its rhythms are slightly irregular and offbeat; perfect 1--2--3--4 pulses
  9699. sound pretty dull by contrast. The same phenomenon might prove to
  9700. be true in typography.
  9701. \MF\ allows you to introduce controlled indeterminacy in two ways:
  9702. (1)~`^{uniformdeviate}~$t$' gives a number~$u$ that's randomly distributed
  9703. between 0 and~$t$; \ (2)~`^{normaldeviate}' gives a ^{random number}~$x$
  9704. that has the so-called normal distribution with mean zero and variance one.
  9705. \danger More precisely, if $t>0$ and $u=\null$uniformdeviate~$t$, we will
  9706. have $0\le u<t$, and for each fraction $0\le p\le1$ we will have
  9707. $0\le u<pt$ with approximate probability~$p$. If $t<0$, the results are
  9708. similar but negated, with $0\ge u>t$. Finally if $t=0$, we always have
  9709. $u=0$; this is the only case where $u=t$ is possible.
  9710. \danger A normaldeviate, $x$, will be positive about half the time and
  9711. negative about half the time. Its distribution is ``^{bell-shaped}'' in
  9712. the sense that a particular value $x$ occurs with probability roughly
  9713. proportional to $e^{-x^2/2}$; the graph of this function looks something
  9714. like a bell. The probability is about 68\% that $\vert x\vert<1$,
  9715. about 95\% that $\vert x\vert<2$, and about 99.7\% that $\vert x\vert<3$.
  9716. It's a pretty safe bet that $\vert x\vert<4$.
  9717. Instead of relying on mathematical formulas to explain this random
  9718. behavior, we can actually see the results graphically by letting \MF\
  9719. draw some ``^{scatter plots}.'' Consider the following program, which
  9720. draws a $10\pt\times10\pt$ square and puts 100 little dots inside it:
  9721. \begindisplay
  9722. @beginchar@$\,(@incr@ "code",10"pt"\0,10"pt"\0,0)$;\cr
  9723. @pickup@ @pencircle@ scaled .3"pt"; \ @draw@ "unitsquare" scaled $w$;\cr
  9724. @pickup@ @pencircle@ scaled 1"pt";\cr
  9725. @for@ $k=1$ @upto@ 100:\cr
  9726. \quad @drawdot@(uniformdeviate $w,\,$uniformdeviate $w$);
  9727.  \ @endfor@ @endchar@.\cr
  9728. \enddisplay
  9729. The resulting ``characters,'' if we repeat the experiment ten times,
  9730. \n=-1 look like~this:
  9731. \begindisplay
  9732. \threenextn&\threenextn&\threenextn&\nextn\rm\quad.
  9733. \enddisplay
  9734. And if we replace `uniformdeviate $w$' by `$.5w+w/6\ast\null$normaldeviate',
  9735. we get
  9736. \begindisplay
  9737. \threenextn&\threenextn&\threenextn&\nextn\rm\quad.
  9738. \enddisplay
  9739. Finally, if we say `@drawdot@(uniformdeviate $w,\,.5w+w/6\ast\null
  9740. $normaldeviate)' the results are a mixture of the other two cases:
  9741. \begindisplay
  9742. \threenextn&\threenextn&\threenextn&\nextn\rm\quad.
  9743. \enddisplay
  9744. \exercise Consider the program fragment `@if@ uniformdeviate$\,1\kern-1pt<
  9745. \kern-1pt1/3$:\
  9746. "case\_a" @else@:~"case\_b"~@fi@'\kern-.2pt. True or false:
  9747. "case\_b" will occur about three times as often as "case\_a".
  9748. \answer False; about twice as often (2/3 versus 1/3).
  9749. \exercise \MF's uniformdeviate operator usually doesn't give you an integer.
  9750. Explain how to generate random integers between 1 and~$n$, in such a way
  9751. that each value will be about equally likely.
  9752. \answer |1+floor uniformdeviate n|.
  9753. \exercise What does the formula `(uniformdeviate 1)[$z_1,z_2$]' represent?
  9754. \answer A random point on the straight line segment from $z_1$ to $z_2$.
  9755. \ (The point $z_1$ itself will occur with probability about 1/65536;
  9756. but point $z_2$ will never occur.)
  9757. \exercise Guess what the following program will produce:
  9758. \begintt
  9759. beginchar(incr code,100pt#,10pt#,0);
  9760. for n:=0 upto 99:
  9761.  fill unitsquare xscaled 1pt yscaled uniformdeviate h
  9762.   shifted (n*pt,0); endfor endchar.
  9763. \endtt
  9764. \answer A random ``^{skyline}'' texture, $100\pt$ wide $\times$ $10\pt$ tall:
  9765. {\rand\char127} The density decreases uniformly as you go up in altitude.
  9766. \dangerexercise And what does this puzzle program draw?
  9767. \begintt
  9768. beginchar(incr code,24pt#,10pt#,0);
  9769. numeric count[];
  9770. pickup pencircle scaled 1pt;
  9771. for n:=1 upto 100:
  9772.  x:=.5w+w/6*normaldeviate;
  9773.  y:=floor(x/pt);
  9774.  if unknown count[y]: count[y]:=-1; fi
  9775.  drawdot(x,pt*incr count[y]); endfor endchar.
  9776. \endtt
  9777. \answer A more-or-less bell-shaped ^{histogram}: {\rand\char126}
  9778. \danger Let's try now to put more ``life'' in the \MF\ ^{logo}, by
  9779. asking Lady Luck to add small perturbations to each of the key points.
  9780. First we define "noise",
  9781. \begindisplay
  9782. @vardef@ "noise" $=$ normaldeviate$\null\ast"craziness"$ @enddef@;
  9783. \enddisplay
  9784. the ^"craziness" parameter will control the degree of haphazard variation.
  9785. \rightfig 21a ({240\apspix} x {216\apspix}) ^-20pt
  9786. Then we can write the following program for the logo's `{\manual n}':
  9787. \begindisplay
  9788. @beginlogochar@\thinspace(|"N"|$,15)$;\cr
  9789. $x_1="leftstemloc"+"noise"$;\cr
  9790. $x_2="leftstemloc"+"noise"$;\cr
  9791. $w-x_4="leftstemloc"+"noise"$;\cr
  9792. $w-x_5="leftstemloc"+"noise"$;\cr
  9793. $"bot"\,y_1="noise"-"o"$;\cr
  9794. $"top"\,y_2=h+o+"noise"$;\cr
  9795. $y_3=y_4+"ygap"+"noise"$;\cr
  9796. $"bot"\,y_4="noise"-"o"$;\cr
  9797. $"top"\,y_5=h+o+"noise"$;\cr
  9798. $z_3="whatever"[z_4,z_5]$;\cr
  9799. @draw@ $z_1\dashto z_2\dashto z_3$; \
  9800. @draw@ $z_4\dashto z_5$; \ @labels@$(1,2,3,4,5)$; \ @endchar@.
  9801. \enddisplay
  9802. The illustration here was drawn with $"craziness"=0$, so there was no noise.
  9803. \danger Three trials of the $9\pt$ `{\manual n}' with $"craziness"=.1"pt"$
  9804. gave the following results:
  9805. \displayfig 21b\&c\&d (195\apspix)
  9806. And here's what happens if you do similar things to all the
  9807. letters of \MF\!, with "craziness" decreasing from $.45"pt"$ to zero in
  9808. steps of $.05"pt"$:
  9809. \begindisplay \global\advance\n by 8
  9810. % we haven't room for craziness .5!
  9811. %\nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9812. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9813. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9814. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9815. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9816. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9817. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9818. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9819. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9820. \nextn\nextn\nextn\kern-.23333pt\nextn\nextn\kern-.55555pt\nextn\nextn\nextn\cr
  9821. {\manual METAFONT}\cr
  9822. \enddisplay
  9823. \danger Every time you run a program that refers to random numbers,
  9824. you'll get different results, because \MF\ uses the date and time of day
  9825. to change its generator. This unpredictable behavior
  9826. is normally what you want, but it can be troublesome if your
  9827. program draws a lovely shape that you'd like to see again.
  9828. Or perhaps one of your runs will uncover a program bug; you won't be able to
  9829. diagnose the problem, because it probably won't recur!
  9830. The solution is to say
  9831. \begindisplay
  9832. ^@randomseed@ $:=$ \<numeric expression>
  9833. \enddisplay
  9834. and to remember the value of that numeric expression. \ (The value
  9835. will automatically be recorded in the transcript file of your run.) \
  9836. You will get the same sequence of uniform and normal deviates on
  9837. any two runs that begin with the same @randomseed@, because \MF's
  9838. numbers are only ``pseudo-random.''
  9839. \endchapter
  9840. % En musiker, som jag k\"ande, roade sig med
  9841. A musician whom I knew amused himself
  9842. % att st\"amma sitt piano hur som helst utan rim och reson.
  9843. by tuning his piano arbitrarily, without any rhyme or reason.
  9844. % D\"arefter spelade han Beethovens Sonate path\'etique utantill.
  9845. Afterwards he played ^{Beethoven}'s\/ {\rm Sonate Path\'etique} by heart.
  9846. % Det var en otrolig fr\"ojd att h\"ora ett gammlt stycke leva upp igen.
  9847. It was an unbelievable delight to hear an old piece come back to life.
  9848. % Jag hade h\"ort denna sonat spelas under tjugo \aa r, st\"andigt
  9849. ^^{beauty} I had heard this sonata for twenty years,
  9850. % utan hopp att se den utvecklas; fixerad, of\"orm\"ogen att n\aa\ l\"angre.
  9851. never dreaming that it was capable of being developed further.
  9852. \author AUGUST ^{STRINDBERG}, {\sl Chance in Artistic Creation} (1894)
  9853. % The original was in French, but I was unable to locate anything
  9854. % but the above Swedish translation, from Modern Museet catalog 28 (1962)
  9855. % Nye Konstriktningar! eller Slumpen i det konstn\"arliga skapandet
  9856. % [New Directions in Art! or, Chance in Artistic Creation]
  9857. \bigskip
  9858. [Education] must lead us from chance and arbitrariness
  9859. to rational clarity and intellectual order.
  9860. \author L. ^{MIES VAN DER ROHE},  {\sl Inaugural Address\/} (1938)
  9861. \eject
  9862. \beginchapter Chapter 22. Strings
  9863. \MF\ is not a word processor, but a \MF\ programmer can process words and
  9864. other short strings of symbols in rudimentary ways. Strings can help
  9865. explain what a program is doing; for example, the |io.mf| file of
  9866. Chapter~5 mentions |"The|~|letter|~|O"| as a title that should appear
  9867. on proofsheets, and it also says |"O"| in order to identify the
  9868. position of a character in the output font.
  9869. Chapter 6 points out that a \<string token> is any sequence of
  9870. characters enclosed in double-quote (|"|) marks, except that you're
  9871. not allowed to use the double-quote character itself in this way.
  9872. If you need that character, plain \MF\ provides it in a string of
  9873. length~1 called ^"ditto". Thus
  9874. \begintt
  9875. "A string expression can contain a `" & ditto & "' mark"
  9876. \endtt
  9877. even though a \<string token> cannot.
  9878. A string expression can be used all by itself as a statement, just as
  9879. if it were an equation or declaration or command. Such a statement is called
  9880. a ^\<title>, provided that it is immediately followed by a~`|;|'.
  9881. If ^"tracingtitles"$\null>0$ when a title is encountered, \MF\
  9882. will type the title on the user's terminal. If ^"proofing"$\null>0$
  9883. when a title is encountered, \MF\ will copy the title into the output
  9884. file, so that it can be put onto proofsheets by postprocessors such
  9885. as the ^|GFtoDVI| program described in Appendix~H.
  9886. \danger Appendix H explains how to specify the strings that are used as
  9887. ^{labels} for the key points on proofsheets.
  9888. \ddanger Here's the full syntax for string expressions. All of the
  9889. activity except for ^{concatenation} (`\&') ^^{ampersand} takes
  9890. place at the primary level:
  9891. \beginsyntax
  9892. <string primary>\is<string token>
  9893.  \alt<string variable>
  9894.  \alt[(]<string expression>[)]
  9895.  \alt[begingroup]<statement list><string expression>[endgroup]
  9896.  \alt[jobname]
  9897.  \alt[readstring]
  9898.  \alt[str]<suffix>
  9899.  \alt[char]<numeric primary>
  9900.  \alt[decimal]<numeric primary>
  9901.  \alt[substring]<pair primary>[of]<string primary>
  9902. <string secondary>\is<string primary>
  9903. <string tertiary>\is<string secondary>
  9904. <string expression>\is<string tertiary>
  9905.  \alt<string expression>[\&]<string tertiary>
  9906. \endsyntax
  9907. The new features here are |jobname|, |readstring|, |str|, |char|,
  9908. |decimal|, and |substring|; we shall consider each of them in turn.
  9909. \ddanger The name of your job (\kern1pt@jobname@) is the name of the first
  9910. file you input, provided that the first line of instructions to \MF\
  9911. (the `^|**|' line or ^{command line}) causes input of some file.
  9912. Otherwise the job name is ^|mfput|, as in Experiment~1 of Chapter~5.
  9913. \ddanger When you say `^@readstring@', \MF\ stops and waits for the user
  9914. to type a line at the terminal. The value of @readstring@ is the contents
  9915. of this line, with trailing spaces eliminated.
  9916. \ (You probably should use the @message@ command first, to give the
  9917. user a clue about what to type; for example, see the |expr.mf| file
  9918. of Chapter~8, which gets its input expressions via @readstring@.
  9919. The ^@stop@ macro of Appendix~B makes use of the fact that @readstring@
  9920. halts the computer; it doesn't actually look at the string.)
  9921. \ddanger An arbitrary ^\<suffix> is converted to a string by ^@str@,
  9922. using the method by which \MF\ displays suffix arguments in
  9923. diagnostic typeouts. Negative subscripts are enclosed in
  9924. square brackets; spaces or dots are inserted between tokens whose
  9925. characters belong to the same class (according to the table in
  9926. Chapter~6). For example, if $n=1$ then `@str@~$x[n]a$' is |"x1a"|;
  9927. `@str@~$x\,n\,a$' is |"x.n.a"|.
  9928. \ddanger The result of `^@char@~$n$' is a string of length~1,
  9929. representing the character whose ^{ASCII} code is~$n$.
  9930. \ (Appendix~C explains this code.) \ The value of~$n$ is first
  9931. rounded to the nearest integer, then multiples of~256 are
  9932. added or subtracted if necessary until $0\le n<256$; this
  9933. defines @char@~$n$ in all cases.
  9934. \ddanger The ^{decimal representation} of a known numeric value~$x$
  9935. is available in string form as `@decimal@~$x$'. If $x$ is negative,
  9936. the first character of this string will be~`|-|'. If $x$ is not
  9937. an integer, a decimal point will be included, followed by as
  9938. many digits as are necessary to characterize the value. \ (These
  9939. conventions are the same as those illustrated in the example
  9940. outputs of Chapter~8.)
  9941. \ddanger The rules for ^{substring} are like the rules for ^{subpath}
  9942. in Chapter~14. \MF\ thinks of a string as if its characters were
  9943. written in the squares of a piece of ^{graph paper}, between
  9944. coordinates $x=0$ and $x=n$, where $n$~is the length of the string.
  9945. In simple cases, substring$\,(a,b)$
  9946. then refers to the characters between $x=a$ and~$x=b$. The
  9947. rules for the general case are slightly more involved: If $b<a$,
  9948. the result will be the ^{reverse} of substring$\,(b,a)$.
  9949. Otherwise $a$ and~$b$ are replaced respectively by
  9950. $\max\bigl(0,\min(n,\round a)\bigr)$ and
  9951. $\max\bigl(0,\min(n,\round b)\bigr)$; this leads to the simple
  9952. case $0\le a\le b\le n$ described above, when the resulting
  9953. string has length $b-a$.
  9954. \ddanger Strings can be converted into numbers, although Chapter~8
  9955. didn't mention this fact in its syntax for \<numeric primary>. The
  9956. primitive operations are
  9957. \begindisplay
  9958. {\tt ASCII}\thinspace\<string primary>\alt
  9959. \thinspace{\tt oct}\thinspace\<string primary>\alt
  9960. \thinspace{\tt hex}\thinspace\<string primary>
  9961. \enddisplay
  9962. where `^{ASCII}' returns the ASCII code of the first character of the
  9963. string, `^{oct}' computes an integer from a string representing
  9964. ^{octal notation} (radix~8), and `^{hex}' computes an integer from
  9965. a string representing ^{hexadecimal notation} (radix~16). For example,
  9966. \begindisplay
  9967. ASCII |"100"| $=$ 49;\qquad oct |"100"| $=$ 64;\qquad hex |"100"| $=$ 256.
  9968. \enddisplay
  9969. Several exceptional conditions need to be mentioned:
  9970. (1)~ASCII~|""|~$=-1$; otherwise ASCII yields an integer between 0 and~255.
  9971. \ (2)~The characters in the string argument to `oct' must all be
  9972. digits in the range |0|--|7|.
  9973. \ (3)~The characters in the string argument to `hex' must all be
  9974. digits in the range |0|--|9|, |A|--|F|, or |a|--|f|.
  9975. \ (4)~The number that results from `oct' or `hex' must be less than 4096.
  9976. Thus, `oct~|"7777"|' and `hex~|"FFF"|' are the maximum legal values.
  9977. \ddangerexercise Under what circumstances is (a) ASCII @char@ $n=n$?
  9978. \ (b)~@char@~ASCII~$s=s$?
  9979. \answer (a) Iff $n$ is an integer between 0 and 255.
  9980. (b) Iff $s$ is a string of length~1.
  9981. \ddangerexercise Why are there primitive operations to convert from
  9982. strings to numbers assuming octal notation and hexadecimal notation,
  9983. but not assuming decimal notation?
  9984. \answer Whoever says that there's no such primitive operation has
  9985. forgotten about @scantokens@.
  9986. \ddangerexercise Write an "octal" macro that converts a nonnegative
  9987. integer to an octal string.
  9988. \answer |vardef octal primary n =|\parbreak
  9989. | save m,s; m:=abs round n; string s; s=decimal(m mod 8);|\parbreak
  9990. | forever: m:=m div 8; exitif m=0;|\parbreak
  9991. |  s:=decimal(m mod 8) & s; endfor|\parbreak
  9992. | s enddef;|\par\nobreak\medskip\noindent
  9993. `|str[m mod 8]|' could also be used instead of `|decimal(m mod 8)|'.
  9994. \ddanger A ^\<message command> allows you to communicate directly
  9995. or indirectly with the user. It has the general syntax
  9996. \beginsyntax
  9997. <message command>\is<message op><string expression>
  9998. <message op>\is[message]\alt[errmessage]\alt[errhelp]
  9999. \endsyntax
  10000. If you say `@message@~$s$', the characters of $s$ will be typed on the
  10001. terminal, at the beginning of a new line; `@errmessage@~$s$' is
  10002. similar, but the string will be preceded by |"! "| and followed
  10003. by~|"."|, followed by lines of context as in \MF's normal error messages.
  10004. If the user asks for ^{help} after an @errmessage@ error,
  10005. the most recent @errhelp@ string will be typed (unless it was empty).
  10006. \ddanger \MF\ doesn't allow you to have an array of different
  10007. macros $m[i]$; but you can have an array of strings that have
  10008. macro-like behavior, via ^@scantokens@. The ^@mode\_def@ construction
  10009. of Appendix~B exploits this idea.
  10010. \endchapter
  10011. Many other useful Practises
  10012. mecanicks perform by this Theo.
  10013. as the finding the length of strings.
  10014. \author WILLIAM ^{ALINGHAM},  {\sl Geometry Epitomized\/} (1695)
  10015.  % p51 acc to OED; but British Library doesn't have this edition!
  10016.  % they have 1701 `An epitome of geometry', as does Yale
  10017. \bigskip
  10018. Forgive me, if my trembling Pen displays
  10019. What never yet was sung in mortal Lays.
  10020. But how shall I attempt such arduous String?
  10021. \author JAMES ^{THOMSON},  {\sl The Castle of Indolence\/} (1748)
  10022.  % canto 1 verse 31
  10023. \eject
  10024. \beginchapter Chapter 23. Online\\Displays
  10025. How do you get pictures to appear on your screen? Plain \MF\ provides
  10026. the `^@showit@' command, which displays the ^"currentpicture".
  10027. Furthermore you can ask for `^@screenchars@'; this automatically
  10028. does a @showit@ at the time of each ^@endchar@. And you can see all
  10029. the action by asking for `^@screenstrokes@'; this automatically
  10030. does a @showit@ after every @draw@ or @fill@.
  10031. \ddanger The above-described features of plain \MF\ are implemented
  10032. from low-level primitive commands, by macros that appear in Appendix~B\null.
  10033. At the lowest level, \MF\ obeys commands such as `@display@
  10034. "currentpicture" @inwindow@~1'; there's also an `@openwindow@'
  10035. command that defines a correspondence between \MF\ coordinates and
  10036. screen coordinates. The syntax is
  10037. \beginsyntax
  10038. <display command>\is[display]<picture variable>[inwindow]<window>
  10039. <window>\is<numeric expression>
  10040. <openwindow command>\is[openwindow]<window><window spec>
  10041. <window spec>\is<screen place>[at]<pair expression>
  10042. <screen place>\is[from]<screen coordinates>[to]<screen coordinates>
  10043. <screen coordinates>\is<pair expression>
  10044. \endsyntax
  10045. A \<window> is an integer between 0 and 15, inclusive; it represents
  10046. one of sixteen ``windows'' or ``portholes'' that \MF\ provides
  10047. between its pictures and the outside world. The \<window> mentioned
  10048. in a @display@ command must previously have been ``opened'' by
  10049. an @openwindow@ command.
  10050. \ddanger \MF's windows should not be confused with the so-called
  10051. windows provided by many modern operating systems. If you have
  10052. such a system, you'll probably find that all of \MF's pictorial
  10053. output appears in one operating-system window, and all of its
  10054. terminal I/O appears in another, and you might be running other
  10055. jobs (like the system editor) in another. \MF's windows are not so
  10056. fancy as this; they are just internal subwindows of one big
  10057. picture window.
  10058. \ddanger The command `@openwindow@ $k$ @from@ $(r_0,c_0)$ @to@ $(r_1,c_1)$
  10059. @at@~$(x,y)$' associates a rectangular area of the user's screen
  10060. (or of the user's big picture window) with pixels in \MF's coordinate
  10061. system. All of the numbers in this command (namely $k$, $r_0$,~$c_0$,
  10062. $r_1$,~$c_1$, $x$, and~$y$) are rounded to the nearest integer if they
  10063. aren't integers already. Furthermore $r_0$ is replaced by
  10064. $\max\bigl(0,\min("maxr",r_0)\bigr)$ and $r_1$ is replaced by
  10065. $\max\bigl(r_0,\min("maxr",r_1)\bigr)$, where "maxr" is the maximum
  10066. number of rows on the screen; similar adjustments are made to $c_0$
  10067. and~$c_1$. The two $(r,c)$ values are row and column
  10068. numbers on the screen; the topmost row is conventionally taken to be
  10069. row zero, and the leftmost column is taken to be column zero.
  10070. \ (These conventions for screen coordinates are quite different from
  10071. the normal ^{Cartesian} coordinate system used everywhere else
  10072. in \MF\!, but somehow they seem appropriate when applied to screens.) \
  10073. Point~$(x,y)$ of \MF's raster will be equated to the upper left
  10074. corner of the rectangle, i.e., to the upper left corner of the pixel
  10075. in screen column~$c_0$ of screen row~$r_0$. The window itself
  10076. occupies $r_1-r_0$ rows and $c_1-c_0$ columns. It follows that
  10077. the pixel in column~$c_1$ of row~$r_1$ is not in the window itself,
  10078. but it is the screen pixel diagonally just below and to the right of the
  10079. lower right corner of the window.
  10080. \ddangerexercise What are the \MF\ coordinates of the boundary of
  10081. such a window?
  10082. \answer Point $(x,y)$ is the upper left corner, ${(x+c_1-c_0,y)}$ is the
  10083. upper right corner, ${(x,y-r_1+r_0)}$ is the lower left corner, and
  10084. ${(x+c_1-c_0,y-r_1+r_0)}$ is the lower right corner. \ (Pixels
  10085. outside this rectangle will not be displayed.)
  10086. \danger If you run \MF\ on a system that doesn't support general
  10087. bitmap displays, the @display@ and @openwindow@ commands will do
  10088. nothing. You'll have to look at hardcopy output, off\/line.
  10089. \ (But your \MF\ might run a bit faster.)
  10090. \ddanger The syntax for @display@ insists that you display a
  10091. \<picture variable>, not a \<picture expression>; thus, you
  10092. can't `@display@ ^@nullpicture@'. Plain \MF\ defines a special
  10093. variable ^"blankpicture" that's entirely blank, just so that
  10094. you can easily display nothing whenever you like.
  10095. \ddanger A window may be opened any number of times, hence moved
  10096. to different locations on the screen. Opening a window blanks the
  10097. corresponding screen rectangle as if you had displayed "blankpicture".
  10098. \ddanger The effect of overlapping windows is undefined, because \MF\
  10099. does not always repaint pixels that have remained unchanged between
  10100. displays.
  10101. \ddanger Changes to a picture do not change the displays that were
  10102. generated from it, until you give another display command explicitly.
  10103. Thus, the images emblazoned on your screen might not exist any longer
  10104. in \MF's picture memory.
  10105. \ddanger Plain \MF\ has an `@openit@' macro that opens
  10106. ^"currentwindow"; this variable "currentwindow" is always zero
  10107. unless you change it yourself. The @showit@ macro displays
  10108. "currentpicture" in "currentwindow"; and it's also designed
  10109. to call @openit@---but only the very first time @showit@ is invoked.
  10110. This means that the screen normally won't be touched until the moment you
  10111. first try to display something.
  10112. \ddanger Appendix E explains how to manage a more elaborate scheme
  10113. in which six windows can be used to show how ^{meta-characters} vary
  10114. under six different font-parameter settings. The author ^^{Knuth}
  10115. used such a six-window system when developing the Computer Modern
  10116. typefaces; here is a typical example of what appeared on his
  10117. ^^{a} terminal when the letter~`a' was being refined:
  10118. \displayfig 23 (68mm)
  10119. \ddangerexercise The @openit@ macro in Appendix~B specifies $(-50,300)$
  10120. as the upper left corner point of the window used for showing
  10121. all the pictures. This might clip off the bottom of a large character,
  10122. if your screen is limited to, say, 360 rows. How could you change
  10123. @openit@ so that the character images will be raised 20 rows higher
  10124. than they would be in the standard setting?
  10125. \answer Redefine @openit@ so that it puts the top left at $(-50,280)$.
  10126. \ddangerexercise Design a `^@new\_window@' routine that allocates
  10127. windows 1, 2, \dots,~15. If the user says `|new_window $(u,v)|',
  10128. where |$|~is any suffix and |u,v| are pairs of coordinates for
  10129. two opposite corners of a rectangle, your macro should map that
  10130. rectangle to the next available screen rectangle and open it as
  10131. window number |window$|. The allocation should be left to right,
  10132. top to bottom; assume that the screen is an infinite rectangle,
  10133. ^"screen\_cols" wide.
  10134. \answer (This routine is due to John ^{Hobby}.)
  10135. \begintt
  10136. newinternal n_windows;    % the number of windows allocated so far
  10137. newinternal screen_bot;   % the first untouched screen row
  10138. pair screen_corner;       % the upper left corner of next window
  10139. def wipescreen =          % do this to initialize or reinitialize
  10140.  for i:=1 upto n_windows: display blankpicture inwindow i; endfor
  10141.  n_windows := screen_bot := 0; screen_corner := origin enddef;
  10142. wipescreen;
  10143. vardef new_window@#(expr u,v) = save r,c,up_lft; pair up_lft;
  10144.  if n_windows=15: errmessage "No more windows left"
  10145.  else: window@# := incr n_windows;
  10146.  up_lft = (min(xpart u,xpart v), max(ypart u, ypart v));
  10147.  (r,c) = (u+v-2up_lft) rotated 90;
  10148.  if ypart screen_corner + c > screen_cols:
  10149.   screen_corner:=(screen_bot,0); fi
  10150.  openwindow window@# from screen_corner
  10151.   to screen_corner+(r,c) at up_lft;
  10152.  screen_bot := max(screen_bot,xpart screen_corner + r);
  10153.  screen_corner := screen_corner + (0,c) fi; enddef;
  10154. \endtt
  10155. \endchapter
  10156. Editing will be done on-line with a display scope and keyboard.
  10157. \author RICHARD L. ^{VENEZKY}, in {\sl American Documentation\/} (1968)
  10158.  % p72; ``Storage, Retrieval, and Editing of Information for a Dictionary''
  10159. \bigskip
  10160. In future I might be obliged to turn for material to the tube.
  10161. \author IGOR ^{STRAVINSKY},  in {\sl Harper's\/} (1970) % April, p112
  10162.  % that year he wrote a regular column called Performing Arts
  10163. \eject
  10164. \beginchapter Chapter 24. Discreteness\\and Discretion
  10165. Pixel patterns are indistinguishable from continuous curves, when the
  10166. pixels are small enough. After all, the human eye is composed of
  10167. discrete receptors, and visible light has a finite wavelength.
  10168. Our hypothetical ^"luxo" printer of Chapter~11, with its resolution
  10169. of 2000 pixels per inch, would surely be able to produce printed
  10170. pages of high quality, if it existed; the physical properties of ink
  10171. would smooth out all the tiny bumps, obliterating all the evidence that
  10172. the letterforms had been digitized.  However, it will always be less
  10173. expensive to work with devices of lower resolution, and we want the output
  10174. of \MF\ to look as good as possible on the machines that we can afford to
  10175. buy. The purpose of this chapter is to discuss the principles of
  10176. ``discreet ^{rounding},'' i.e., to consider the tasteful application of
  10177. mathematical techniques by which \MF\ can be made to produce satisfactory
  10178. shapes even when the resolution is rather coarse.
  10179. The technical material in this chapter is entirely marked with danger
  10180. signs, since careful rounding tends to make \MF\ programs more complex; a
  10181. novice user will not wish to worry about such details.  On the other hand,
  10182. an expert \MF er will take pains to round things properly even when
  10183. preparing high-resolution fonts, since the subtle refinements we are about
  10184. to discuss will often lead to significantly better letterforms.
  10185. We should realize before we begin that it would be a mistake to
  10186. set our hopes too high. Mechanically generated letters that are untouched
  10187. by human hands and unseen by human eyes can never be expected to compete
  10188. with alphabets that are carefully crafted to look best on a particular
  10189. device. There's no substitute for actually looking at the letters
  10190. and changing their pixels until the result looks right. Therefore our
  10191. goal should not be to make ^{hand-tuning} obsolete; it should rather be
  10192. to make hand-tuning tolerable. Let us try to create meta-designs so
  10193. that we would never want to change more than a few pixels per character,
  10194. say half a dozen, regardless of the resolution. At low resolutions, six
  10195. pixels will of course be a significant percentage of the whole, and at higher
  10196. resolutions six well-considered pixel changes can still lead to worthwhile
  10197. improvements. The point is that if our design comes close enough, a
  10198. person with a good bitmap-editing program will be able to optimize an
  10199. entire font in less than an hour. This is an attainable goal, if rounding
  10200. is done judiciously.
  10201. \danger \MF\ tries to adjust curves automatically, so that they are
  10202. well adapted to the ^{raster}, if the internal quantities ^"autorounding"
  10203. and/or ^"smoothing" have positive values. \ (Plain \MF\ sets
  10204. $"autorounding":=2$ and $"smoothing":=1$, so you generally get these
  10205. features unless you turn them off yourself.) \ But all the examples in
  10206. this chapter will be generated with $"autorounding":="smoothing":=0$
  10207. unless otherwise mentioned, because this will keep \MF's automatic
  10208. mechanisms from interfering with our experiments. We shall discuss the
  10209. pros and cons of automatic rounding after we have explored the general
  10210. problem in more detail.
  10211. \danger The first thing we need to understand about rounding is \MF's
  10212. procedure for ^{digitizing} a path. A path of length~$n$ can be regarded
  10213. as a trajectory~$z(t)$ that is traced out as $t$~varies from 0 to~$n$.  In
  10214. these terms, the corresponding digitized path is most easily described by
  10215. the formula `round~$z(t)$' for $0\le t\le n$; each $z(t)$ is rounded to
  10216. the nearest point with integer coordinates.  For example, if a path goes
  10217. through point~$(3.1,5.7)$, its digitization will go through point~$(3,6)$.
  10218. The digitized trajectory makes discrete jumps at certain values of $t$,
  10219. when round~$z(t)$ hops from one point to another; the two points will be
  10220. one pixel apart, and we can imagine that the digitized path traverses the
  10221. horizontal or vertical edge between them when it jumps.
  10222. \danger When an ordinary region is being filled, this rule for
  10223. digitizing paths boils down to a simple criterion that's easy to
  10224. visualize: {\sl A pixel belongs to the digitized region if and only if
  10225. its center point lies inside the original undigitized path.} For example,
  10226. two versions of Chapter~5's Ionian `{\manual\IOO}' are shown here
  10227. at a resolution of 200 pixels per inch, using the characteristics
  10228. of ^"lowres" mode in Appendix~B:
  10229. \displayfig 24a\&b (190\apspix)
  10230. The heavy broken lines are digitized paths, and the pixels inside these
  10231. ragged boundaries are those whose centers lie in the shaded regions.
  10232. \danger The `{\manual\IOO}' on the left has digitized well; but the
  10233. one on the right has problems, because it was based on curves that
  10234. were generated without taking the raster into account. The difference
  10235. between these two letters is entirely due to line~8 of the program
  10236. in Chapter~5, which says
  10237. \begindisplay
  10238. "curve\_sidebar" $=$ round $1/18"em"$;
  10239. \enddisplay
  10240. this equation determines the position of the leftmost and rightmost
  10241. edges of the `{\manual\IOO}' before digitization, and it leads to
  10242. the nice digitized form in the left-hand example. Without the word
  10243. `^{round}', we get the inferior right-hand example, which was
  10244. obtained by exactly the same \MF\ program except that "curve\_sidebar"
  10245. was set to $1/18"em"$ exactly. One little token---which changed an exact
  10246. calculation to an approximate, rounded calculation---made all the difference!
  10247. \danger Curves that are placed in arbitrary positions on
  10248. a raster can lead to digital disasters, even though the curves themselves
  10249. aren't bad. For example, suppose we take the right-hand example above
  10250. and shift it just 0.05 and 0.10 pixels to the right:
  10251. \displayfig 24c\&d (190\apspix)
  10252. The first shift of 0.05 pixels causes a tiny ^{pimple} to appear
  10253. at the right edge; after another small shift the pimple has grown into a
  10254. mole, and the left edge has become too ^{flat}. \looseness=-1
  10255. \danger A designer who is asked to make a digital `O' that is 22 pixels
  10256. wide will certainly have pixels in mind when making the design. Therefore
  10257. it's not surprising that our program to generate a digital~`O' should
  10258. pay attention to actual pixel positions by rounding "curve\_sidebar" as
  10259. in this example. We have distorted the infinite-resolution curve
  10260. slightly so that it will digitize well, before digitizing it.
  10261. \danger A path $z(t)$ will digitize well if the digitization process doesn't
  10262. change it too much; thus, we want $z(t)$ to be essentially the same as
  10263. round$\,z(t)$, at all the important places. But what places are ``important''?
  10264. Experience shows that the most critical points are those where the path
  10265. travels horizontally or vertically, i.e., where it runs parallel to
  10266. the raster lines. It's best to arrange things so that a curve becomes
  10267. parallel to the raster lines just when it touches or nearly touches those
  10268. lines; then it will appear to have the right curvature after digitization.
  10269. The worst case occurs when a curve becomes parallel to the raster just
  10270. when it's halfway between raster lines; then it gets a pimple or a flat spot.
  10271. \ddanger Diagonal slopes, where a curve has a $\pm45^\circ$ tangent angle,
  10272. are also potential sources of unwanted pimples and flats. Similarly, at
  10273. higher resolutions it is sometimes possible to detect small glitches
  10274. when a curve travels with slopes of $\pm1/2$ or $\pm2/1$. Rational
  10275. slopes $m/n$ where $m$ and~$n$ are small integers turn out to be
  10276. somewhat dangerous.  But diagonals are of secondary importance; horizontal
  10277. and vertical slopes lead to more severe problems.
  10278. \danger These considerations suggest a simple general principle for adapting
  10279. the outlines of shapes to be digitized:  {\sl If you know that the outline
  10280. will have a vertical tangent at some point, round the $x$~coordinate to an
  10281. integer and leave the $y$~coordinate unchanged.  If you know that the
  10282. outline will have a horizontal tangent at some point, round the
  10283. $y$~coordinate to an integer and leave the $x$~coordinate unchanged.}
  10284. \ddanger Incidentally, the horizontal tangent points in our `{\manual\IOO}'
  10285. examples were taken care~of by the fact that `^@define\_corrected\_pixels@'
  10286. makes the ^{overshoot} parameter~$o$ nearly an integer, together with
  10287. the fact that ^@beginchar@ makes $h$ an integer. If the $y$~coordinates
  10288. had not been rounded at the horizontal tangent points,
  10289. our bad examples would have looked even worse.
  10290. \danger Before we go further into the study of rounding, we had better
  10291. face up to a technicality that's sometimes important: We said that the
  10292. pixels of a digitized region are those whose centers lie inside the
  10293. undigitized region; but this rule is vague about what happens when the
  10294. centers happen to fall precisely on the undigitized boundary. Similarly,
  10295. when we said that round$\,z(t)$ jumps from one point to an adjacent point,
  10296. we ignored the fact that a curve such as $z(t)=(t,t)$ actually
  10297. jumps from $(0,0)$ to $(1,1)$ when it is rounded as $t$ passes 1/2;
  10298. those points are not adjacent.
  10299. \MF\ skirts both of these problems in an interesting way:
  10300. It shifts all of its paths to the
  10301. right by an infinitesimal amount~$\delta$, and it also shifts them
  10302. upward by an even smaller
  10303. infinitesimal amount~$\delta\epsilon$, so that no path actually
  10304. touches a pixel center. Here $\delta$ and~$\epsilon$ are positive numbers
  10305. that are chosen to be so small that their actual values don't matter.
  10306. For example, the path $z(t)=(t,t)$ becomes $(t+\delta,t+\delta\epsilon)$,
  10307. which jumps from $(0,0)$ to $(1,0)$ to $(1,1)$ because it momentarily
  10308. rounds to $(1,0)$ when $t=1/2-2\delta\epsilon$.
  10309. \danger Points of the form $(m+1/2,n+1/2)$, where $m$ and $n$ are integers,
  10310. lie in the centers of their pixels. They are called ``ambiguous'' points
  10311. because we can't round them to the nearest integer neighbor without
  10312. deciding which of four adjacent points is to be considered the nearest.
  10313. If we imagine taking a curved outline and shifting it slowly to the
  10314. right, the digitized image makes abrupt transitions when the outline
  10315. passes over an ^{ambiguous point}. When a path comes near an ambiguous
  10316. point, the path is farthest away from its digitization. Thus the
  10317. ambiguous points are points of instability, and digitizing works best
  10318. when paths don't get too close to them.
  10319. \danger Let's consider now what happens when we ^@draw@ with a pen,
  10320. instead of filling an outline. It may seem that the simplest possible @draw@
  10321. command would be something like this:
  10322. \begindisplay
  10323. @pickup@ @pencircle@; \ @draw@ $(0,0)\to(10,0)$;
  10324. \enddisplay
  10325. what could be easier? But a closer look shows that this is actually
  10326. about the worst case that could be imagined! A circular pen of
  10327. diameter~1 that goes from $(0,0)$ to $(10,0)$ has upper and lower
  10328. boundaries that go from $(0,\pm1/2)$ to $(10,\pm1/2)$,
  10329. and both of these boundaries run smack through lots of
  10330. ambiguous points. \MF\ has to decide whether to fill the row of pixels
  10331. with $0\le y\le1$ or the lower row with $-1\le y\le0$, neither of which is
  10332. centered on the given line. According to the rule stated earlier, \MF\
  10333. shifts the path very slightly to the right and very, very slightly up;
  10334. thus the pixels actually filled are bounded by
  10335. $(0,0)\dashto(10,0)\dashto(10,1)\dashto(0,1)\dashto\cycle$.
  10336. \dangerexercise Continuing this example, what pixels would have been
  10337. filled if the path had been `$(0,0)\to(10,-"epsilon")$'\thinspace?
  10338. \answer The entire path now has negative $y$~coordinates except at
  10339. point~$(0,0)$, so the outline of the filled region is
  10340.  $(0,-1)\dashto(10,-1)\dashto(10,0)\dashto(0,0)\dashto(0,1)
  10341. \dashto\cycle$. \ $\bigl($Notice that the
  10342. digitized outline actually goes up to $(0,1)$ before coming straight down
  10343. again. This fills no pixels, but \MF\ correctly puts ``cancelling'' edges
  10344. from $(0,0)$ to $(0,1)$ and back to $(0,0)$ into its edge structure, because the
  10345. point $(0,.5)$ is on the boundary and rounds to $(0,1).\bigr)$
  10346. \danger In general when we @draw@ with a fixed pen, good digitizations
  10347. depend on where the edges of the pen happen to fall, not on the
  10348. path followed by the pen's center. Thus, for example, if the path we're
  10349. drawing has a vertical tangent at point~$z_1$, we don't necessarily
  10350. want $x_1$~to be an integer; we want "lft"$\,x_1$ and "rt"$\,x_1$
  10351. to be integers. If there's a horizontal tangent at~$z_2$, we want
  10352. "top"$\,y_2$ and "bot"$\,y_2$ to be integers. The pens created by
  10353. ^@pencircle@ always have the property that $("lft"\,x)-("rt"\,x)$
  10354. and $("top"\,y)-("bot"\,y)$ are integers; hence both edges will
  10355. be in good or bad positions simultaneously.
  10356. \danger Suppose that we want $x_1$ to be approximately equal to~$\alpha$,
  10357. and we also want it to be at a good place for vertical tangents with respect
  10358. to the pen that has currently been picked up. One way to define $x_1$ is to say
  10359. \begindisplay
  10360. $"lft"\,x_1=\round("lft"\,\alpha)$;
  10361. \enddisplay
  10362. this does the right thing, because it makes "lft"$\,x_1$ an integer and
  10363. it also makes $x_1\approx\alpha$. Similarly, to make~$y_2\approx\beta$
  10364. good for horizontal tangents, we can say
  10365. \begindisplay
  10366. $"top"\,y_2=\round("top"\,\beta)$.
  10367. \enddisplay
  10368. Such operations occur frequently in practice, so plain \MF\ provides
  10369. ^^"good.x"  ^^"good.y" ^^{gumdrop} convenient abbreviations: We can say simply
  10370. \begindisplay
  10371. $x_1="good.x"\,\alpha$; \ $y_2="good.y"\,\beta$
  10372. \enddisplay
  10373. instead of using indirect equations for $"lft"\,x_1$ and $"top"\,y_2$.
  10374. \danger Let's look one last time at the letters of the \MF\ logo, in
  10375. order to make them round properly. Chapter~11 describes a file ^|logo.mf|
  10376. that draws the seven characters, but we can improve the results by
  10377. making pixel-oriented refinements. In the first place, we can replace
  10378. the command
  10379. \begindisplay
  10380. @define\_pixels@($s,u,"xgap","ygap","leftstemloc","barheight"$)
  10381. \enddisplay
  10382. by something better: Looking at the uses of these ad hoc dimensions,
  10383. we see that ^"xgap" and ^"ygap" ought to be integers; ^"leftstemloc"
  10384. should be a "good.x" value for "logo\_pen"; and ^"barheight" should
  10385. be a "good.y" value. Therefore we say
  10386. \begindisplay
  10387. ^@define\_pixels@$(s,u)$;\cr
  10388. ^@define\_whole\_pixels@$("xgap","ygap")$;\cr
  10389. ^@define\_good\_x\_pixels@$("leftstemloc")$;\cr
  10390. ^@define\_good\_y\_pixels@$("barheight")$;\cr
  10391. \enddisplay
  10392. these commands, provided by plain \MF\!, will do the right thing.
  10393. \ (The "logo\_pen" should be picked up before the last two commands are
  10394. given.) \ These few changes, and a change to the `{\manual m}', suffice to
  10395. fix all the letters except `\kern1pt{\manual j}\kern1pt'.
  10396. \dangerexercise The program for \MF's `{\manual m}' ^^{O}
  10397. appears in Chapter~18. What changes would you suggest to make
  10398. it digitize well?
  10399. \answer The horizontal tangents are already taken care of by the equations
  10400. $"top"\,y_1=h+o$ and $"bot"\,y4=-o$, so nothing needs to be done there.
  10401. We should, however, say
  10402. \begindisplay
  10403. $x_2=w-x_3="good.x"(1.5u+s)$
  10404. \enddisplay
  10405. so that vertical tangents will occur in good places. Since $w$~is an
  10406. integer, and since the "logo\_pen" has left-right symmetry,
  10407. $w-x_3$ will be good if and only if $x_3$ is.
  10408. \danger The `\kern1pt{\manual j}\kern1pt' ^^{T} presents a new problem,
  10409. because we want it to be symmetric between left and right. If the pen
  10410. breadth is odd, we want the character width~$w$ to be odd, so that there
  10411. will be as many pixels to the left of the stem as there are to the right.
  10412. If the pen breadth is even, we want $w$ to be even. Therefore we have a
  10413. 50-50 chance of being unhappy with the value of~$w$ that is computed by
  10414. ^@beginchar@.
  10415. \dangerexercise Prove that the value of $w$ is satisfactory for
  10416. `\kern1pt{\manual j}\kern1pt' with respect to the "logo\_pen" if and
  10417. only if $.5w$ is a good $x$~value for vertical strokes.
  10418. \answer Let $b$ be the pen breadth. Then $.5w$ is a good $x$ value if and only
  10419. if $"lft"\,.5w$ is an integer; but $"lft"\,.5w=.5w-.5b$, and this is an
  10420. integer if and only if $w-b$ is even.
  10421. \danger If $w$ is not a good value, we want to replace it by either
  10422. $w+1$ or~$w-1$, whichever is closer to the device-independent width
  10423. from which $w$ was rounded. For example, if $w$ was rounded to 22 from
  10424. the ideal width~21.7, we want to change it to 21 rather than~23.
  10425. Plain \MF's ^@change\_width@ routine does this. Hence we have the
  10426. following program for `\kern1pt{\manual j}\kern1pt', in place of the
  10427. \rightfig 4b ({208\apspix} x {216\apspix}) ^-18pt
  10428. simpler version found in exercise 11.\metaT:
  10429. \begindisplay
  10430. @beginlogochar@(|"T"|$,13)$;\cr
  10431. @if@ $.5w<>"good.x"\,.5w$: @change\_width@; @fi@\cr
  10432. $"lft"\,x_1=-"eps"$;\cr
  10433. $x_2=w-x_1$;\cr
  10434. $x_3=x_4=.5w$;\cr
  10435. $y_1=y_2=y_3$; \ $"top"\,y_1=h$; \ $"bot"\,y_4=-o$;\cr
  10436. @draw@ $z_1\dashto z_2$; \ @draw@ $z_3\dashto z_4$;\cr
  10437. @labels@$(1,2,3,4)$; \ @endchar@.\cr
  10438. \enddisplay
  10439. \decreasehsize 44mm
  10440. Chapter 4 said that `\kern1pt{\manual j}\kern1pt' was the simplest of the
  10441. seven logo letters, but it has turned out to be the trickiest.
  10442. \restorehsize
  10443. \ddanger This program has one unexplained feature. Why was $"lft"\,x_1$
  10444. set to $-"eps"$ instead of zero? The answer requires an understanding
  10445. of the pen polygons discussed in Chapter~16. The edges of those polygons
  10446. are highly likely to pass through ambiguous points when the center of
  10447. the pen has integer or half-integer coordinates. \MF\ shifts paths slightly
  10448. to the right and up, in order to resolve ambiguities; therefore if
  10449. ambiguous points occur at the left and right edges of the
  10450. `\kern1pt{\manual j}\kern1pt', some pixels will be lost at the left but
  10451. gained at the right. The constant ^"eps" is 0.00049, which is small but
  10452. positive enough that \MF\ will surely notice it.  Subtracting "eps"
  10453. from~$x_1$ and adding "eps" to~$x_2$ avoids ambiguous edge points and
  10454. keeps the result symmetric.
  10455. \ddanger Since the ^{overshoot} `$o$' is always "eps" more than an
  10456. integer, it is unnecessary to do anything similar at point~$z_4$;
  10457. the equation `$"bot"\,y_4=-o$' is sufficient.
  10458. \ddanger Point $z_3$ in the middle of the `{\manual h}' ^^{M} is in
  10459. a satisfactory position because $"bot"\,y_3="ygap"-"o"$.
  10460. If $"bot"\,y_3$ were exactly an integer, the~{\manual h} would often turn
  10461. out to be unsymmetric, because of ambiguous points on the boundary
  10462. at~$z_3$.
  10463. \ddangerexercise True or false: If "currentpen" is @pencircle@ xscaled "px"
  10464. yscaled~"py", the command `@draw@ $(-"epsilon",0)\to(+"epsilon",0)$'
  10465. will produce an image that has both left-right and top-bottom symmetry.
  10466. \ (Assume that "autorounding"="smoothing"=0.)
  10467. \answer There are no ambiguous points on the outlines of this stroke,
  10468. except perhaps on the top and bottom edges; the latter can occur only if
  10469. $\round"py"$ is odd. Hence there is always left-right symmetry, but
  10470. top-bottom symmetry might fail because of a missing row at the bottom
  10471. (e.g., when $"px"="py"=3$). In a case like the `\kern1pt{\manual j}\kern1pt'
  10472. we do have both symmetries, because $y_1$ and $x_4$ are in good positions.
  10473. \ddangerexercise The polygon for `^@pencircle@ scaled 3' is an octagon
  10474. whose vertices are at the points $(\pm0.5,\pm1.5)$ and $(\pm1.5,\pm0.5)$.
  10475. Prove that if you `^@draw@~$(x,y)$' with this pen, the result never has
  10476. both top-bottom and left-right symmetry.
  10477. \answer No matter where you place the octagon so that it isn't touching
  10478. any ambiguous points, exactly seven ambiguous points are inside it; hence
  10479. every one-point ^@draw@ fills exactly seven pixels. \ (In fact,
  10480. you always get one of the patterns
  10481. $\vcenter{\vbox{\offinterlineskip\manual
  10482.     \hbox{\kern\Blankpix RR}\hbox{RRR}\hbox{\kern\Blankpix RR}\kern1pt}}$,
  10483. $\vcenter{\vbox{\offinterlineskip\manual
  10484.     \hbox{\kern\Blankpix R}\hbox{RRR}\hbox{RRR}\kern1pt}}$,
  10485. $\vcenter{\vbox{\offinterlineskip\manual
  10486.     \hbox{RR}\hbox{RRR}\hbox{RR}\kern1pt}}$, or
  10487. $\vcenter{\vbox{\offinterlineskip\manual
  10488.     \hbox{RRR}\hbox{RRR}\hbox{\kern\Blankpix R}\kern1pt}}$.)
  10489. \ddanger Rounding can also help to position points at which we don't
  10490. have horizontal or vertical tangents. For example, consider the
  10491. ``^{sharp sign}'' or ``^{hash mark}'' character that's drawn by the
  10492. \rightfig 24e ({300\apspix} x {320\apspix}) ^-60pt
  10493. following program:
  10494. \begindisplay
  10495. $u\0:={10\over18}"pt"\0$; \ @define\_pixels@$(u)$;\cr
  10496. @beginchar@$\,(0,15u\0,{250\over36}"pt"\0,{70\over36}"pt"\0)$;\cr
  10497. @pickup@ @pencircle@\cr
  10498. \qquad scaled $(.4"pt"+"blacker")$;\cr
  10499. $"lft"\,x_1=\round u-"eps"$;\cr
  10500. $x_3=x_1$;\cr
  10501. $x_2=x_4=w-x_1$;\cr
  10502. $y_1=y_2="good.y"(.5[-d,h]+"pt")$;\cr
  10503. $y_3=y_4=h-d-y_1$;\cr
  10504. @draw@ $z_1\dashto z_2$; \ @draw@ $z_3\dashto z_4$;\cr
  10505. $"lft"\,x_6=\round 3u$;\cr
  10506. $x_7=w-x_6$;\cr
  10507. $x_8="good.x"\,.5w$;\cr
  10508. $x_5-x_6=x_7-x_8$;\cr
  10509. $"top"\,y_5="top"\,y_7=h+"eps"$;\cr
  10510. $"bot"\,y_6="bot"\,y_8=-d-"eps"$;\cr
  10511. @draw@ $z_5\dashto z_6$; \ @draw@ $z_7\dashto z_8$;\cr
  10512. @labels@(^@range@ 1 ^@thru@ 8);\cr
  10513. @endchar@.\cr
  10514. \enddisplay
  10515. If we digitize this character according to ^"lowres" mode at 200
  10516. pixels per inch, we get the following results:
  10517. \begindisplay
  10518. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10519. SSSSSSSSSSSRSSSSSRSSSSS\cr
  10520. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10521. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10522. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10523. SSSSSSSSSSRRSSSRRSSSSSS\cr
  10524. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10525. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10526. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10527. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10528. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10529. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10530. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10531. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10532. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10533. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10534. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10535. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10536. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10537. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10538. SSSSSSRRSSSRRSSSSSSSSSS\cr
  10539. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10540. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10541. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10542. SSSSSRSSSSSRSSSSSSSSSSS\cr
  10543. }}\qquad
  10544. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10545. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10546. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10547. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10548. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10549. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10550. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10551. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10552. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10553. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10554. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10555. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10556. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10557. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10558. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10559. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10560. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10561. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10562. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10563. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10564. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10565. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10566. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10567. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10568. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10569. }}\qquad
  10570. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10571. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10572. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10573. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10574. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10575. SSSSSSSSSSRRSSSSRRSSSSS\cr
  10576. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10577. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10578. SSSSSSSSSRRSSSSRRSSSSSS\cr
  10579. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10580. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10581. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10582. SSSSSSSSRRSSSSRRSSSSSSS\cr
  10583. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10584. SSSSSSSRRSSSSRRSSSSSSSS\cr
  10585. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10586. SSRRRRRRRRRRRRRRRRRRRSS\cr
  10587. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10588. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10589. SSSSSSRRSSSSRRSSSSSSSSS\cr
  10590. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10591. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10592. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10593. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10594. SSSSSRRSSSSRRSSSSSSSSSS\cr
  10595. \enddisplay
  10596. The left-hand example was obtained by omitting the `round' and `"good.x"'
  10597. instructions in the equations for $x_6$ and~$x_8$. This meant that points
  10598. $z_6$ and $z_8$ fell into different, possibly unlucky, raster positions,
  10599. so the two diagonal strokes digitized differently even though they
  10600. came from essentially identical undigitized lines. The middle example
  10601. was produced by the given program without changes. And the right-hand
  10602. example was produced by drawing the diagonals in a more complicated way:
  10603. The commands `@draw@~$z_5\dashto z_6$; @draw@~$z_7\dashto z_8$;' were
  10604. replaced by
  10605. \begindisplay
  10606. $y_{15}=y_1$; \ $z_{15}="whatever"[z_5,z_6]$; \
  10607.  $y_{36}=y_3$; \ $z_{36}="whatever"[z_5,z_6]$;\cr
  10608. $y_{27}=y_2$; \ $z_{27}="whatever"[z_7,z_8]$; \
  10609.  $y_{48}=y_4$; \ $z_{48}="whatever"[z_7,z_8]$;\cr
  10610. \noalign{\smallskip}
  10611. @draw@ $z_5\dashto("good.x"(x_{15}+.5),y_1)\dashto("good.x"(x_{15}-.5),y_1)$\cr
  10612. \qquad\qquad$\dashto("good.x"(x_{36}+.5),y_3)\dashto("good.x"(x_{36}-.5),y_3)
  10613.  \dashto z_6$;\cr
  10614. @draw@ $z_7\dashto("good.x"(x_{27}+.5),y_2)\dashto("good.x"(x_{27}-.5),y_2)$\cr
  10615. \qquad\qquad$\dashto("good.x"(x_{48}+.5),y_4)\dashto("good.x"(x_{48}-.5),y_4)
  10616.  \dashto z_8$;\cr
  10617. \enddisplay
  10618. The idea here was to control the goodness of the points where the
  10619. diagonals intersect the horizontal bar lines, and to hide one of the
  10620. ``^{jaggies}'' inside each bar line. If we do the same three experiments
  10621. but triple the resolution, we get similar results but the differences are
  10622. not quite so obvious:
  10623. \begindisplay
  10624. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10625. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQ\cr
  10626. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10627. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10628. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10629. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQ\cr
  10630. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10631. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10632. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10633. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQ\cr
  10634. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10635. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10636. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQ\cr
  10637. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10638. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10639. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10640. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQ\cr
  10641. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10642. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10643. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10644. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQ\cr
  10645. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10646. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10647. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10648. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10649. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQ\cr
  10650. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQ\cr
  10651. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10652. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10653. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10654. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10655. QQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQ\cr
  10656. QQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10657. QQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10658. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10659. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10660. QQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10661. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10662. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10663. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10664. QQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10665. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10666. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10667. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10668. QQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10669. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10670. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10671. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10672. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10673. QQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10674. QQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10675. QQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10676. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10677. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10678. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10679. QQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10680. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10681. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10682. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10683. QQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10684. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10685. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10686. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10687. QQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10688. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10689. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10690. QQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10691. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10692. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10693. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10694. QQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10695. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10696. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10697. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10698. QQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10699. }}\qquad
  10700. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10701. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQ\cr
  10702. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10703. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10704. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQ\cr
  10705. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10706. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10707. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10708. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQ\cr
  10709. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10710. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10711. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10712. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQ\cr
  10713. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10714. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10715. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10716. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQ\cr
  10717. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10718. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10719. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10720. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQ\cr
  10721. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10722. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10723. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10724. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10725. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQ\cr
  10726. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQ\cr
  10727. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10728. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10729. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10730. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10731. QQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQ\cr
  10732. QQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQ\cr
  10733. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10734. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10735. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10736. QQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10737. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10738. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10739. QQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10740. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10741. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10742. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10743. QQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10744. QQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10745. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10746. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10747. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10748. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10749. QQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10750. QQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10751. QQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10752. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10753. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10754. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10755. QQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10756. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10757. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10758. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10759. QQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10760. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10761. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10762. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10763. QQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10764. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10765. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10766. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10767. QQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10768. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10769. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10770. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10771. QQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10772. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10773. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10774. QQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10775. }}\qquad
  10776. \vbox{\manual\offinterlineskip\halign{#\hfil\cr
  10777. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQ\cr
  10778. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10779. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10780. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQ\cr
  10781. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQ\cr
  10782. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10783. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10784. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQ\cr
  10785. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQ\cr
  10786. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10787. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10788. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQ\cr
  10789. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQ\cr
  10790. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10791. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10792. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10793. QQQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQ\cr
  10794. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQ\cr
  10795. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10796. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10797. QQQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQ\cr
  10798. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQ\cr
  10799. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10800. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10801. QQQQQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10802. QQQQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQ\cr
  10803. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10804. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10805. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10806. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10807. QQQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQ\cr
  10808. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10809. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10810. QQQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10811. QQQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQ\cr
  10812. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10813. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10814. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10815. QQQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10816. QQQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10817. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10818. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10819. QQQQQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10820. QQQQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10821. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10822. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10823. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  10824. QQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  10825. QQQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10826. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10827. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10828. QQQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10829. QQQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10830. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10831. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10832. QQQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10833. QQQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10834. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10835. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10836. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10837. QQQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10838. QQQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10839. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10840. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10841. QQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10842. QQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10843. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10844. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10845. QQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10846. QQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10847. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10848. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10849. QQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10850. QQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  10851. \enddisplay
  10852. \danger When letters are drawn by filling outlines, the left and right
  10853. outlines are digitized independently; therefore corresponding outlines
  10854. should usually be offset from each other by an integer amount whenever
  10855. possible. For example, suppose that the letter~`^{n}' is being drawn
  10856. with commands like
  10857. \begindisplay
  10858. $\penpos2("stem",0)$; \ $\penpos4("stem",0)$
  10859. \enddisplay
  10860. to specify the stroke widths at the base of the two ^{stems}.
  10861. We will therefore have $x_{2r}-x_{2l}=x_{4r}-x_{4l}="stem"$. If
  10862. "stem" is not an integer, say $"stem"=2.7$, we might have
  10863. $x_{2l}=2.1$, $x_{2r}=4.8$, $x_{4l}=9.6$, $x_{4r}=12.3$;
  10864. then $x_{2r}-x_{2l}$ will digitize to $5-2=3$, so the left stem
  10865. will be three pixels wide, but the right stem will be only
  10866. $12-10=2$ pixels wide. We could get around this problem by
  10867. insisting that either $x_{2l}$ or~$x_{2r}$ be an integer,
  10868. and that either $x_{4l}$ or~$x_{4r}$ be an integer; then both stems
  10869. would be three pixels wide. But other quantities calculated from "stem"
  10870. (e.g., the breadth of diagonal strokes) would then be based on a
  10871. value of~2.7 instead of the stem width~3 that an observer of the
  10872. font actually perceives. Therefore it is best to make "stem" an integer.
  10873. The proper way to do this is generally to say
  10874. \begindisplay
  10875. ^@define\_whole\_blacker\_pixels@("stem");
  10876. \enddisplay
  10877. this command computes "stem" from $"stem"\0$ by the formula
  10878. \begindisplay
  10879. $"stem":=max\bigl(1,\,\round("stem"\0\ast"hppp"+"blacker")\bigr)$.
  10880. \enddisplay
  10881. (Notice that this rounding operation is not allowed to reduce "stem"
  10882. to zero at low resolutions.)
  10883. \danger Even when the "stem" width is an integer in the `n' example,
  10884. we probably want to arrange things so that $x_{2l}$, $x_{2r}$, $x_{4l}$,
  10885. and~$x_{4r}$ are integers, because this will give the least distortion
  10886. under digitization. Suppose, however, that it's most convenient to define
  10887. the pen position at the center of the stroke instead of at the edge; i.e.,
  10888. the program would say just `$x_2=\alpha$' if rounding were not taken into
  10889. account. How should $x_2$ be defined, when we want $x_{2l}$ to be an
  10890. integer? We could say
  10891. \begindisplay
  10892. $x_2=\alpha$; \ $x_{2l}:=\round x_{2l}$; \ $x_{2r}:=\round x_{2r}$; \
  10893. $x_2:=.5[x_{2l},x_{2r}]$
  10894. \enddisplay
  10895. but that's too complicated; moreover, it will fail if any other
  10896. variables depend on $x_2$, $x_{2l}$, or $x_{2r}$, because such
  10897. dependencies are forgotten when new values are assigned.
  10898. In the case of fixed pens we solved this problem by saying
  10899. `$x_2="good.x"\,\alpha$'; but the "good.x" function doesn't know
  10900. about "stem". One solution is to say
  10901. \begindisplay
  10902. $x_{2l}=\round(\alpha-.5"stem")$,
  10903. \enddisplay
  10904. or equivalently, `$x_{2r}=\round(\alpha+.5"stem")$'. This does the
  10905. job all right, but it isn't completely satisfying. It requires
  10906. knowledge of the breadth that was specified in the $\penpos2$ command,
  10907. and it works only when the penpos angle is~0. If the penpos command
  10908. is changed, the corresponding equation for rounding must be
  10909. changed too. There's another solution that's more general and more
  10910. attractive once you get used to it:
  10911. \begindisplay
  10912. $x_{2l}=\round\bigl(x_{2l}-(x_2-\alpha)\bigr)$.
  10913. \enddisplay
  10914. Why does this work? The argument to `^{round}' must be a known value,
  10915. but both $x_{2l}$ and~$x_2$ are unknown. Fortunately, their difference
  10916. $x_{2l}-x_2$ is known, because of the $\penpos2$ command. The
  10917. rounding operation makes $x_2\approx\alpha$ because it makes $x_{2l}$
  10918. approximately equal to the value of $x_{2l}$ minus the difference
  10919. between $x_2$ and~$\alpha$.
  10920. \ddangerexercise The generality of this technique can be appreciated
  10921. by considering the following more difficult problem that the author
  10922. faced while designing a~`^{w}': Suppose you want $x_1-x_2$ to be
  10923. an integer and $x_3\approx x_4$, and suppose that $x_2$, $x_3-x_1$,
  10924. and~$x_4+x_1$ are known; but $x_1$ is unknown, hence $x_3$ and~$x_4$
  10925. are also unknown. According to our general idea, we want to specify an
  10926. equation of the form `$x_1-x_2=\round(x_1-x_2+f)$', where $x_1-x_2+f$
  10927. is known and $f$~is a formula that should be approximately zero.
  10928. In this case $x_3-x_4$ is approximately zero, and $(x_3-x_1)-(x_4+x_1)$
  10929. is known; what value of~$f$ should we choose?
  10930. \answer $f=.5(x_4-x_3)$; the desired equation is
  10931. `$x_1-x_2=\round\bigl(x_1-x_2+.5(x_4-x_3)\bigr)$'.
  10932. \ddanger In many fonts, such as the one you are now reading,
  10933. curved lines swell out so that the thick parts of~`^{o}' are actually
  10934. a bit broader than the stems of~`n'. Therefore the ^{Computer Modern}
  10935. font routines discussed in Appendix~E have two parameters,
  10936. $"stem"\0$ and $"curve"\0$, to govern the stroke thickness.
  10937. For example, the font ^|cmr9| used in the present paragraph has
  10938. $"stem"\0=2/3"pt"\0$ and $"curve"\0=7/9"pt"\0$. Both of these should
  10939. be integers, hence the ^@font\_setup@ macro in Appendix~E
  10940. dutifully says
  10941. \begindisplay
  10942. @define\_whole\_blacker\_pixels@$("stem","curve")$.
  10943. \enddisplay
  10944. Although this looks good on paper, it can cause problems at certain
  10945. low resolutions, because the rounding operation might make ^"stem" and
  10946. ^"curve" rather different from each other even though $"stem"\0$ and
  10947. $"curve"\0$ are fairly close. For example, the resolution might be
  10948. just at the value where |cmr9|'s "stem" turns out to be only~2
  10949. but "curve" is~3. Curves shouldn't be that much darker than stems;
  10950. they would look too splotchy. Therefore plain \MF\
  10951. has a `^@lowres\_fix@' subroutine, and Appendix~E says
  10952. \begindisplay
  10953. @lowres\_fix@("stem","curve") 1.2
  10954. \enddisplay
  10955. after "stem" and "curve" have been defined as above. In this particular
  10956. case @lowres\_fix@ will reset $"curve":="stem"$ if it turns out that the
  10957. ratio $"curve"/"stem"$ is greater than 1.2 times the ratio
  10958. $"curve"\0/"stem"\0$. Since $"curve"\0/"stem"\0=7/6$ in the case of |cmr9|,
  10959. this means that the ratio $"curve"/"stem"$ after rounding is allowed
  10960. to be at most~1.4; if $"curve"=3$ and $"stem"=2$, the "curve" parameter
  10961. will be lowered to~2. In general the command
  10962. \begindisplay
  10963. @lowres\_fix@($d_1,d_2,\ldots,d_n$) $r$
  10964. \enddisplay
  10965. will set $d_n:=\cdots d_2:=d_1$ if $\max(d_1,d_2,\ldots,d_n)/\!
  10966. \min(d_1,d_2,\ldots,d_n)$ is greater than
  10967. $r\cdot\max(d_1\0,d_2\0,\ldots,d_n\0)/\!\min(d_1\0,d_2\0,\ldots,d_n\0)$.
  10968. \ddangerexercise
  10969. \parshape 12
  10970. 3pc 201pt
  10971. 3pc 201pt
  10972. 0pc 237pt
  10973. 0pc 237pt
  10974. 0pc 237pt
  10975. 0pc 237pt
  10976. 0pc 237pt
  10977. 0pc 237pt
  10978. 0pc 237pt
  10979. 0pc 237pt
  10980. 0pc 237pt
  10981. 0pc 29pc
  10982. \rightfig 4e ({180\apspix} x {225\apspix}) ^15pt
  10983. Good digitization can also require attention to the shapes of the
  10984. digitized angles where straight lines meet. The purpose of
  10985. the present exercise is to illustrate the relevant ideas by
  10986. studying the `\kern1pt{\manual\char'170}' symbol, for which a program
  10987. appears in Chapter~4. If that program is used without change to produce
  10988. low-resolution ^{triangle}s, the results might turn out to be unsatisfactory
  10989. because, for example, the point of the triangle at the right
  10990. might digitize into a snubnosed or asymmetric shape.
  10991. If $y_3$ is an integer, the triangle will be top-bottom symmetric, but
  10992. the right-hand tip will be two pixels tall and this will look too blunt.
  10993. Therefore we should choose~$y_3$ to be an integer plus~1/2.
  10994. Given this value of~$y_3$, what will be the shape of the rightmost
  10995. four columns of the digitized tip, as $x_3$ varies?
  10996. \answer Let $x_3=n+{1\over2}+\theta$, where $n$ is an integer and
  10997. $0\le\theta<1$. By drawing lines of slope~$30^\circ$ from the pixel
  10998. centers, we find that there are three cases for the rightmost four
  10999. columns:
  11000. \begindisplay
  11001. Case A,
  11002. $\vcenter{\vbox{\offinterlineskip\manual
  11003.     \hbox{RR}\hbox{RRRR}\hbox{RR}\kern1pt}}$;\qquad
  11004. Case B,
  11005. $\vcenter{\vbox{\offinterlineskip\manual
  11006.     \hbox{R}\hbox{RR}\hbox{RRRR}\hbox{RR}\hbox{R}\kern1pt}}$;\qquad
  11007. Case C,
  11008. $\vcenter{\vbox{\offinterlineskip\manual
  11009.     \hbox{R}\hbox{RRR}\hbox{RRRR}\hbox{RRR}\hbox{R}\kern1pt}}$.
  11010. \enddisplay
  11011. Case A occurs for $0\le\theta<2\sqrt3-3$; Case B occurs for
  11012. $2\sqrt3-3\le\theta<\sqrt3-1$; Case~C occurs for
  11013. $\sqrt3-1\le\theta<1$. The tip in Case~A looks a bit too sharp,
  11014. and Case~C looks too blunt, so Case~B seems best. This case occurs
  11015. when $x_3$ is near an integer, so it's OK to let $x_3$ be an integer.
  11016. \ddangerexercise Continuing the previous exercise, assume that $x_1$
  11017. is an integer. What value of~$y_1$ will make the upper tip of the
  11018. triangle look like
  11019. `\thinspace$\vcenter{\vbox{\offinterlineskip\manual
  11020.     \hbox{R}\hbox{RR}\hbox{RRRR}\kern1pt}}$' after digitization?
  11021. \answer Let $y_1=n+\theta$. If $\theta$ lies between
  11022. ${1\over2}\sqrt3-{1\over2}$ and ${1\over6}\sqrt3+{1\over2}$,
  11023. the top row after digitization will contain two black pixels.
  11024. If $\theta$ lies between ${1\over6}\sqrt3+{1\over2}$ and
  11025. ${5\over6}\sqrt3-{1\over2}$, we get the desired shape. Otherwise
  11026. we get `\thinspace$\vcenter{\vbox{\offinterlineskip\manual
  11027.     \hbox{R}\hbox{RRR}\hbox{RRRR}\kern1pt}}$'.
  11028. \ddangerexercise Concluding the previous exercise, modify the
  11029. program of Chapter 4 so that the upper tip and
  11030. the upper part of the right tip both digitize to the shape
  11031. `\thinspace$\vcenter{\vbox{\offinterlineskip\manual
  11032.     \hbox{R}\hbox{RR}\hbox{RRRR}\kern1pt}}$'.
  11033. \answer (We choose $\theta={1\over2}\sqrt3$ in the previous exercise, since
  11034. ^^{floor} this is the midpoint of the desirable interval.) The equations
  11035. are changed to
  11036. \begindisplay
  11037. $x_1=x_2=w-x_3=\round s$;\cr
  11038. $y_3=.5+{\rm floor}\,.5h$;\cr
  11039. $z_1-z_2=(z_3-z_2)$ rotated 60;\cr
  11040. $y_1:=.5\rmsqrt3+\round(y_1-.5\rmsqrt3)$;\cr
  11041. $y_2:=h-y_1$;\cr
  11042. \enddisplay
  11043. and then we @fill@ $z_1\dashto z_2\dashto z_3\dashto\cycle$ as before.
  11044. \ddanger So far in this chapter we've assumed that pixels are square. But
  11045. sometimes ^^{nonsquare} we need to prepare output for devices with
  11046. general rectangular pixels, and this adds an extra dimension of
  11047. complexity to rounding. Plain \MF\ sets things up so that
  11048. ^"currenttransform" multiplies all $y$~coordinates by
  11049. ^"aspect\_ratio", when paths are filled or drawn, or when pens are
  11050. picked up. Furthermore the ^"top" and ^"bot" functions divide the
  11051. amount of offset by "aspect\_ratio". This means that \MF\ programs
  11052. can still be written as if pixels were square;
  11053. the normal `angle' and `direction' functions, etc., can be used.
  11054. But the good places for rounding horizontal tangents are not at
  11055. integer values of~$y$ in general, they are actually at values that
  11056. will become integers after multiplication by the aspect ratio.
  11057. \ddanger The ^"vround" function rounds its argument to the nearest
  11058. $y$~coordinate that corresponds to a pixel boundary in the
  11059. general case. Thus if $"aspect\_ratio"=1$, "vround" simply rounds
  11060. to the nearest integer, just like `round'; but if, say,
  11061. $"aspect\_ratio"=4/3$, then "vround" will round to the nearest
  11062. multiple of~$3/4$. Plain \MF\ uses "vround" instead of `round'
  11063. when it computes an ^{overshoot} correction, and also when ^@beginchar@
  11064. computes the values of ^"h" and~^"d". The ^"good.y" function produces
  11065. a good $y$~value that takes "aspect\_ratio" properly into account.
  11066. \ddangerexercise Without looking at Appendix B\null, try to guess how
  11067. the "vround" and "good.y" macros are defined.
  11068. \answer @vardef@ "vround" @primary@ $v$ $=$\parbreak
  11069. \qquad floor$(v\ast"aspect\_ratio"+.5)/"aspect\_ratio"$ @enddef@;\parbreak
  11070. @vardef@ "good.y" @primary@ $y$ $=$\parbreak
  11071. \qquad "vround"$(y+"pen\_top")-"pen\_top"$ @enddef@.
  11072. \ddangerexercise What are the ``ambiguous points'' when pixels
  11073. are not square?
  11074. \answer $\bigl(m+1/2,(n+1/2)/"aspect\_ratio"\bigr)$. These are the points
  11075. that "currenttransform" maps into pixel centers.
  11076. \ddanger The \MF\ ^{logo} as we have described it so far will round
  11077. properly with respect to arbitrary aspect ratios if we make only
  11078. a few more refinements. The value of "ygap" should be vrounded
  11079. instead of rounded, so we initialize it by saying
  11080. \begindisplay
  11081. ^@define\_whole\_vertical\_pixels@("ygap").
  11082. \enddisplay
  11083. Furthermore we should say
  11084. \begindisplay
  11085. $"ho"\0:="o"\0$; \ ^@define\_horizontal\_corrected\_pixels@("ho");
  11086. \enddisplay
  11087. and "ho" should replace ^"o" in the equations for $x_4$ in the programs
  11088. for `{\manual i}' and~`{\manual l}'. ^^{E} ^^{F}
  11089. Everything else should work satisfactorily as it stands.
  11090. \ddanger Appendix B includes macros ^"good.top", ^"good.bot", ^"good.lft",
  11091. and ^"good.rt" that take pairs as arguments. If you say, for example,
  11092. `$z_3="good.top"(\alpha,\beta)$' it means that $z_3$ will be near
  11093. $(\alpha,\beta)$ and that when $z_3$ is modified by ^"currenttransform"
  11094. the top point of ^"currentpen" placed at the transformed point will
  11095. be in a good raster position.
  11096. \danger \MF's `^"autorounding"' feature tries to adjust curves to the
  11097. raster for you, but it is a mixed blessing. Here's how it works:
  11098. If the internal quantity "autorounding" is positive, the $x$~coordinates
  11099. of all paths that are filled or drawn are rounded to good raster positions
  11100. wherever there's a vertical tangent; and the $y$~coordinates
  11101. are rounded to good raster positions wherever there's a horizontal
  11102. tangent. The rest of the curve is distorted appropriately, as if
  11103. the raster were stretching or shrinking slightly. If $"autorounding">1$,
  11104. you get even more changes: paths are perturbed slightly at $\pm45^\circ$
  11105. tangent directions, so that second-order ^{pimples} and flat spots don't
  11106. appear there.
  11107. \danger For example, if we return to the Ionian `{\manual\IOO}' with
  11108. which we began this chapter, let's suppose that "curve\_sidebar" was left
  11109. unrounded. We saw that the result was bad when "autorounding" was~0;
  11110. when $"autorounding"=1$ and~2 we get this:
  11111. \displayfig 24f\&g (190\apspix)
  11112. The stroke has gotten a lot thinner at the sides, by comparison with
  11113. the original design (which, incidentally, can be seen in the illustrations
  11114. below).  Although autorounding has produced a fairly recognizable O~shape,
  11115. the character of the original has been lost, especially in the case
  11116. $"autorounding"=2$; indeed, the inner outline has been brought towards the
  11117. center, in the upper left and lower right sectors, and this has made the
  11118. digitized inner boundary perfectly symmetric!
  11119. \ddanger There's an internal quantity called ^"granularity", normally
  11120. equal to~1, which affects autorounding by effectively scaling~up
  11121. the raster size. If, for example, $"granularity"=4$, the autorounded
  11122. $x$~coordinates and $y$~coordinates will become multiples of~4 instead
  11123. of simply integers. The illustrations above were produced by
  11124. setting $"granularity"=10$ and $"mag"=10$; this made the
  11125. effects of autorounding visible. The granularity should always be an integer.
  11126. \ddanger Besides "autorounding", there's a `smoothing' feature
  11127. that becomes active when ^"smoothing"$\null>0$. The basic idea is
  11128. to try to make the edges of a curve follow a regular progression
  11129. instead of wobbling. A complete discussion of the smoothing algorithm
  11130. is beyond the scope of this manual, but an example should make the
  11131. general idea clear: Let's use the letters $R$ and~$D$ to stand for
  11132. single-pixel steps to the right and down, respectively. If a digitized
  11133. path goes `"RDDRDRDDD"', say, the number of downward steps per
  11134. rightward step is first decreasing, then increasing; the "smoothing"
  11135. process changes this to `"RDDRDDRDD"'. If smoothing is applied to the
  11136. Ionian `{\manual\IOO}' shapes above, nothing happens; but if we go back
  11137. to the original obtained with $"autorounding"=0$, we get a few changes:
  11138. \displayfig 24b\&h (190\apspix)
  11139. Three pixels have been added by "smoothing" in the right-hand illustration;
  11140. e.g., a pattern "RDRDDDDRDD" has become "RDDRDDDRDD".
  11141. \danger If you do your own rounding, it turns out that autorounding
  11142. and smoothing usually change very few pixels, if any; thus your
  11143. safest strategy is probably to turn them off in such cases. If you
  11144. define your strokes by outlines, autorounding and smoothing
  11145. apply independently to the left and right edges, so they may
  11146. hurt as often as they help; again, they should probably be turned off.
  11147. But if you are drawing with fixed pens, autorounding generally
  11148. works well and saves a lot of fuss. If the pens are circles or
  11149. nearly circles, smoothing is also helpful; but if the pens are
  11150. more ``calligraphic,'' they are supposed to produce nonsmooth
  11151. edges occasionally, so you had better set $"smoothing":=0$.
  11152. \ddanger If you ``^{slant}'' a font by modifying "currenttransform"
  11153. as described in Chapter~15, positions of horizontal tangency will
  11154. remain the same. But positions of vertical tangency will change
  11155. drastically, and they will probably not fall in known parts
  11156. of your design. This means, for example, that autorounding will be
  11157. helpful in a slanted pen-generated font like the
  11158. `{\manual 89:;<=>:}\kern2pt' logo. However, the author ^^{Knuth}
  11159. found that the outline-generated letters of ^{Computer Modern}
  11160. {\it^{italic}\/} came out better with $"autorounding"=0$, because
  11161. autorounding tended to make some characters too dark and others too light.
  11162. \ninepoint
  11163. \ddanger The effect of autorounding can be studied numerically
  11164. if you set ^"tracingspecs" to a positive value; this displays \MF's
  11165. internal calculations as it finds horizontal, vertical, and diagonal
  11166. tangent points. \ (\MF\ prepares to digitize paths by first
  11167. subdividing each B\'ezier segment into pieces that travel in only one
  11168. ``^{octant}'' direction.) \ For example, if $"autorounding"=0$
  11169. and $"tracingspecs"=1$, and if "curve\_sidebar" is left unrounded,
  11170. the file |io.log| will contain the following information about the
  11171. outer curve of the `{\manual\IOO}':
  11172. \beginlines
  11173. |Path at line 15, before subdivision into octants:|
  11174. |(1.53745,9.05344)..controls (1.53745,4.0051) and (5.75407,-0.0005)|
  11175. | ..(10.85146,-0.0005)..controls (16.2217,-0.0005) and (20.46255,4.51297)|
  11176. | ..(20.46255,9.94656)..controls (20.46255,14.99715) and (16.23842,19.0005)|
  11177. | ..(11.13652,19.0005)..controls (5.77066,19.0005) and (1.53745,14.48491)|
  11178. | ..cycle|
  11179. \smallskip
  11180. |Cycle spec at line 15, after subdivision:|
  11181. |(1.53745,9.05344) % beginning in octant `SSE'|
  11182. |   ..controls (1.53745,6.58784) and (2.54324,4.37099)|
  11183. | ..(4.16621,2.74802) % segment 0|
  11184. |% entering octant `ESE'|
  11185. |   ..controls (5.8663,1.04793) and (8.24362,-0.0005)|
  11186. | ..(10.85146,-0.0005) % segment 0|
  11187. |% entering octant `ENE'|
  11188. \endlines
  11189. $\ldots$ and so on; there are lots more numbers! What does this all mean?
  11190. ^^|ENE|^^|ESE|^^|SSE|^^{compass directions}
  11191. Well, the first segment of the curve, from $(1.53745,9.05344)$ to
  11192. $(10.85146,-0.0005)$,
  11193. has been subdivided into two parts at the place where the slope is $-1$.
  11194. The first of these parts travels basically `South by South East' and
  11195. the second travels `East by South East'. The other three segments are
  11196. subdivided in a similar way (not shown here).  If you try the same
  11197. experiment but with $"autorounding"=1$, some rather different numbers
  11198. emerge: \looseness=-1
  11199. \goodbreak
  11200. \beginlines
  11201. |Cycle spec at line 15, after subdivision and autorounding:|
  11202. |(2,9.05347) % beginning in octant `SSE'|
  11203. |   ..controls (2,6.50525) and (3.02194,4.2227)|
  11204. | ..(4.65768,2.58696) % segment 0|
  11205. |% entering octant `ESE'|
  11206. |   ..controls (6.26239,0.98225) and (8.45784,0)|
  11207. | ..(10.85872,0) % segment 0|
  11208. |% entering octant `ENE'|
  11209. \endlines
  11210. Point $(1.53745,9.05344)$, where there was a vertical tangent, has been
  11211. rounded to $(2,9.05347)$; point $(10.85146,-.00005)$, where there was
  11212. a horizontal tangent, has been rounded to $(10.85872,0)$; the intermediate
  11213. control points have been adjusted accordingly. \ (Rounding of $x$~coordinates
  11214. has been done separately from $y$~coordinates.) \ Finally, with
  11215. $"autorounding"=2$, additional adjustments are made so that the
  11216. $45^\circ$ transition point will occur at what \MF\ thinks is a good spot:
  11217. \beginlines
  11218. |Cycle spec at line 15, after subdivision and double autorounding:|
  11219. |(2,9.05347) % beginning in octant `SSE'|
  11220. |   ..controls (2,6.67609) and (3.07103,4.42897)|
  11221. | ..(4.78535,2.71465) % segment 0|
  11222. |% entering octant `ESE'|
  11223. |   ..controls (6.46927,1.03073) and (8.62747,0)|
  11224. | ..(10.85872,0) % segment 0|
  11225. |% entering octant `ENE'|
  11226. \endlines
  11227. (Notice that $4.78535+2.71465=7.50000$; when the slope
  11228. is~$-1$ at a transition point $(x,y)$, the curve stays as far away as
  11229. possible from ambiguous points near the transition if $x+y+.5$ is an integer.)
  11230. \endchapter
  11231. \rightline{\vbox{\offinterlineskip\manual\halign{#\hfil\cr
  11232. SRRRRRRRRRSSSSSSSSSSSRRRRRRSSSSSSSRRRRRRRRRSSSSSSS\cr
  11233. SSRRRSSSSSRRSSSSSSSRRSSSSSSRRSSSSSSRRRSSSSRRSSSSSS\cr
  11234. SSSRRSSSSSSRRSSSSSRRSSSSSSSSRRSSSSSSRRSSSSSRRSSSSS\cr
  11235. SSSRRSSSSSSRRSSSSRRSSSSSSSSSSRRSSSSSRRSSSSSRRSSSSS\cr
  11236. SSSRRSSSSSSRRSSSRRSSSSSSSSSSSSRRSSSSRRSSSSSRRSSSSS\cr
  11237. SSSRRSSSSSSRRSSSRRSSSSSSSSSSSSRRSSSSRRSSSSSRRSSSSS\cr
  11238. SSSRRSSSSSSRRSSRRSSSSSSSSSSSSSSRRSSSRRSSSSSRRSSSSS\cr
  11239. SSSRRSSSSSRRSSSRRSSSSSSSSSSSSSSRRSSSRRSSSSRRSSSSSS\cr
  11240. SSSRRSSRRRRSSSSRRSSSSSSSSSSSSSSRRSSSRRRRRRSSSSSSSS\cr
  11241. SSSRRSSSSSSSSSSRRSSSSSSSSSSSSSSRRSSSRRSSRRRSSSSSSS\cr
  11242. SSSRRSSSSSSSSSSRRSSSSSSSSSSSSSSRRSSSRRSSSRRRSSSSSS\cr
  11243. SSSRRSSSSSSSSSSRRSSSSSSSSSSSSSSRRSSSRRSSSSRRRSSSSS\cr
  11244. SSSRRSSSSSSSSSSSRRSSSSSSSSSSSSRRSSSSRRSSSSSRRRSSSS\cr
  11245. SSSRRSSSSSSSSSSSRRSSSSSSSSSSSSRRSSSSRRSSSSSSRRSSSS\cr
  11246. SSSRRSSSSSSSSSSSSRRSSSSSSSSSSRRSSSSSRRSSSSSSRRRSSS\cr
  11247. SSSRRSSSSSSSSSSSSSRRSSSSSSSSRRSSSSSSRRSSSSSSSRRRSS\cr
  11248. SSRRRRSSSSSSSSSSSSSRRSSSSSSRRSSSSSSRRRRSSSSSSSRRRS\cr
  11249. SRRRRRRSSSSSSSSSSSSSSRRRRRRSSSSSSSRRRRRRSSSSSSSRRR\cr
  11250. \kern23\Blankpix RRR\cr
  11251. \kern24\Blankpix RRR\cr
  11252. \kern25\Blankpix RRR\cr
  11253. \kern26\Blankpix RRRR\cr
  11254. \author PIERRE ^{LE B\'E}, {\sl B\'ele Pr\'erie\/} (1601)
  11255.   % (an extract from his third alphabet)
  11256. \bigskip
  11257. \bigskip
  11258. \rightline{\vbox{\offinterlineskip\manual\halign{#\hfil\cr
  11259. QQQQQPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQ\cr
  11260. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQ\cr
  11261. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQ\cr
  11262. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQ\cr
  11263. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQ\cr
  11264. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  11265. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  11266. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQ\cr
  11267. QQQQQPPPPPPPPPPQQQQQQQQQQPPPPPPPPPPPPPPQQQQ\cr
  11268. QQQQQPPPPPPPPPPQQQQQQQQQQQQPPPPPPPPPPPPPQQQ\cr
  11269. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPPQQQ\cr
  11270. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQ\cr
  11271. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPPQQ\cr
  11272. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPPQQ\cr
  11273. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11274. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11275. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11276. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11277. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11278. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQ\cr
  11279. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPPQQ\cr
  11280. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11281. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQ\cr
  11282. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQ\cr
  11283. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPQQQQ\cr
  11284. QQQQQPPPPPPPPPPQQQQQQQQQQQPPPPPPPPPPPPPQQQQ\cr
  11285. QQQQQPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPPPQQQQQ\cr
  11286. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQ\cr
  11287. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQ\cr
  11288. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQ\cr
  11289. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQ\cr
  11290. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQ\cr
  11291. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQ\cr
  11292. QQQQQPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQ\cr
  11293. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11294. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11295. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11296. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11297. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11298. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11299. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11300. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11301. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11302. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11303. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11304. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11305. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11306. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11307. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11308. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11309. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11310. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11311. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQQQQQQQ\cr
  11312. }\kern7\blankpix}\vbox{\offinterlineskip\manual\halign{#\hfil\cr
  11313. \kern19\blankpix  PPPPPPPPPP\cr
  11314. QQQQQQQQQQQQQQQQPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQ\cr
  11315. QQQQQQQQQQQQQQPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQ\cr
  11316. QQQQQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQ\cr
  11317. QQQQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQ\cr
  11318. QQQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQ\cr
  11319. QQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQ\cr
  11320. QQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQ\cr
  11321. QQQQQQQPPPPPPPPPPPPPPQQQQQQPPPPPPPPPPPPPPQQQQQQQ\cr
  11322. QQQQQQQPPPPPPPPPPPPQQQQQQQQQQPPPPPPPPPPPPQQQQQQQ\cr
  11323. QQQQQQPPPPPPPPPPPPQQQQQQQQQQQQPPPPPPPPPPPPQQQQQQ\cr
  11324. QQQQQQPPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQQQQ\cr
  11325. QQQQQPPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQQQ\cr
  11326. QQQQQPPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPPQQQQQ\cr
  11327. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQQ\cr
  11328. QQQQPPPPPPPPPPPQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQQ\cr
  11329. QQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11330. QQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11331. QQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11332. QQQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11333. QQQPPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPPQQQ\cr
  11334. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11335. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11336. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11337. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11338. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11339. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11340. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11341. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11342. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11343. QQQPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQQPPPPPPPPPPQQQ\cr
  11344. QQQPPPPPPPPPPQQQQQQQQQQQQPQQQQQQQQQPPPPPPPPPPQQQ\cr
  11345. QQQPPPPPPPPPPQQQQQQQQQQQPPQQQQQQQQQPPPPPPPPPPQQQ\cr
  11346. QQQPPPPPPPPPPQQQQQQQQQQPPPPQQQQQQQQPPPPPPPPPPQQQ\cr
  11347. QQQPPPPPPPPPPPQQQQQQQQPPPPPPQQQQQQQPPPPPPPPPQQQQ\cr
  11348. QQQQPPPPPPPPPPQQQQQQQPPPPPPPPQQQQQQPPPPPPPPPQQQQ\cr
  11349. QQQQPPPPPPPPPPQQQQQQPPPPPPPPPQQQQQQPPPPPPPPPQQQQ\cr
  11350. QQQQPPPPPPPPPPQQQQQPPPPPPPPPPPQQQQQPPPPPPPPQQQQQ\cr
  11351. QQQQPPPPPPPPPPQQQQQQQPPPPPPPPPPQQQQPPPPPPPPQQQQQ\cr
  11352. QQQQPPPPPPPPPPPQQQQQQQPPPPPPPPPPQQQPPPPPPPPQQQQQ\cr
  11353. QQQQQPPPPPPPPPPQQQQQQQQPPPPPPPPPQQQPPPPPPPQQQQQQ\cr
  11354. QQQQQPPPPPPPPPPPQQQQQQQQPPPPPPPPQQQPPPPPPPQQQQQQ\cr
  11355. QQQQQPPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPPPPPPQQQQQQ\cr
  11356. QQQQQQPPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPPPPQQQQQQQ\cr
  11357. QQQQQQPPPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPPQQQQQQQQ\cr
  11358. QQQQQQQPPPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPQQQQQQQQ\cr
  11359. QQQQQQQPPPPPPPPPPPPPPQQQQQQQQPPPPPPPPPPQQQQQQQQQ\cr
  11360. QQQQQQQQPPPPPPPPPPPPPPPQQQQQQPPPPPPPPPQQQQQQQQQQ\cr
  11361. QQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQ\cr
  11362. QQQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQ\cr
  11363. QQQQQQQQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQ\cr
  11364. QQQQQQQQQQQQPPPPPPPPPPPPPPPPPPPPQQPPPPPPPPQQQQQQ\cr
  11365. QQQQQQQQQQQQQQPPPPPPPPPPPPPPPPPPQQPPPPPPPPPQQQQQ\cr
  11366. QQQQQQQQQQQQQQQQPPPPPPPPPPPPPPQQQQPPPPPPPPPPQQQQ\cr
  11367. \kern19\blankpix PPPPPPP\kern9\blankpix PPPPPPPPPPP\cr
  11368. \kern36\blankpix PPPPPPPPP\cr
  11369. \kern37\blankpix PPPPPPP\cr
  11370. \kern37\blankpix PPPPPP\cr
  11371. \kern38\blankpix PPPP\cr
  11372. \kern39\blankpix PP\cr
  11373. \kern39\blankpix P\cr
  11374. }}\vbox{\offinterlineskip\manual\halign{#\hfil\cr
  11375. QQQQQPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQQ\cr
  11376. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQ\cr
  11377. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQ\cr
  11378. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQ\cr
  11379. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQ\cr
  11380. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQ\cr
  11381. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQ\cr
  11382. QQQQQPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPPPPQQQQQQ\cr
  11383. QQQQQPPPPPPPPPPQQQQQQQQQQQPPPPPPPPPPPPPQQQQQ\cr
  11384. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPQQQQQ\cr
  11385. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPQQQQQ\cr
  11386. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQQ\cr
  11387. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQQ\cr
  11388. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11389. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11390. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11391. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11392. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11393. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPQQQQ\cr
  11394. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPQQQQQ\cr
  11395. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPQQQQQ\cr
  11396. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPQQQQQQ\cr
  11397. QQQQQPPPPPPPPPPQQQQQQQQQQQQPPPPPPPPPPPQQQQQQ\cr
  11398. QQQQQPPPPPPPPPPQQQQQQQQQQPPPPPPPPPPPPQQQQQQQ\cr
  11399. QQQQQPPPPPPPPPPQQQQQQQQPPPPPPPPPPPPPQQQQQQQQ\cr
  11400. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQ\cr
  11401. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQ\cr
  11402. QQQQQPPPPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQ\cr
  11403. QQQQQPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQ\cr
  11404. QQQQQPPPPPPPPPPPPPPPPPPPPPPPQQQQQQQQQQQQQQQQ\cr
  11405. QQQQQPPPPPPPPPPPPPPPQPPPPPPPPPQQQQQQQQQQQQQQ\cr
  11406. QQQQQPPPPPPPPPPQQQQQQPPPPPPPPPPQQQQQQQQQQQQQ\cr
  11407. QQQQQPPPPPPPPPPQQQQQQPPPPPPPPPPPQQQQQQQQQQQQ\cr
  11408. QQQQQPPPPPPPPPPQQQQQQQPPPPPPPPPPQQQQQQQQQQQQ\cr
  11409. QQQQQPPPPPPPPPPQQQQQQQPPPPPPPPPPPQQQQQQQQQQQ\cr
  11410. QQQQQPPPPPPPPPPQQQQQQQQPPPPPPPPPPQQQQQQQQQQQ\cr
  11411. QQQQQPPPPPPPPPPQQQQQQQQPPPPPPPPPPPQQQQQQQQQQ\cr
  11412. QQQQQPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPQQQQQQQQQ\cr
  11413. QQQQQPPPPPPPPPPQQQQQQQQQPPPPPPPPPPPQQQQQQQQQ\cr
  11414. QQQQQPPPPPPPPPPQQQQQQQQQQPPPPPPPPPPPQQQQQQQQ\cr
  11415. QQQQQPPPPPPPPPPQQQQQQQQQQPPPPPPPPPPPQQQQQQQQ\cr
  11416. QQQQQPPPPPPPPPPQQQQQQQQQQQPPPPPPPPPPPQQQQQQQ\cr
  11417. QQQQQPPPPPPPPPPQQQQQQQQQQQPPPPPPPPPPPQQQQQQQ\cr
  11418. QQQQQPPPPPPPPPPQQQQQQQQQQQQPPPPPPPPPPPQQQQQQ\cr
  11419. QQQQQPPPPPPPPPPQQQQQQQQQQQQPPPPPPPPPPPQQQQQQ\cr
  11420. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPQQQQQ\cr
  11421. QQQQQPPPPPPPPPPQQQQQQQQQQQQQPPPPPPPPPPPQQQQQ\cr
  11422. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQQ\cr
  11423. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQPPPPPPPPPPPQQQQ\cr
  11424. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPPQQQ\cr
  11425. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQPPPPPPPPPPPPQQ\cr
  11426. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPPPQ\cr
  11427. QQQQQPPPPPPPPPPQQQQQQQQQQQQQQQQPPPPPPPPPPPPQ\cr
  11428. }\kern7\blankpix}}
  11429. \author MATTHEW ^{CARTER},  {\sl Bell Centennial\/} (1978)
  11430.   % from the 6pt `name and number' font as he digitized it by hand
  11431.   % reference: Type & Technology Manuscript No.1, Cooper Union (1982)
  11432. \eject
  11433. \beginChapter Chapter 25. Summary of\\Expressions
  11434. We've seen that \MF\ can handle a wide variety of algebraic ^{expressions};
  11435. now it's time to consolidate what we have learned. The purpose of this
  11436. chapter and the one that follows is to present a precise and concise
  11437. summary of everything that \MF\ knows how to do.
  11438. We shall be concerned here solely with \MF's {\sl^{primitive}\/} operations,
  11439. rather than with the higher-level features of the plain \MF\ base that
  11440. comprise the bulk of typical programs. Therefore novice users should put
  11441. off reading Chapters 25 and~26 until they feel a need to know what
  11442. goes on at the more mundane levels inside the computer. Appendix~B contains
  11443. a summary of the features of plain \MF\!, together with a ready-reference guide
  11444. to the things that most people want to know about \MF\ usage.
  11445. \ninepoint\medskip
  11446. The remainder of this chapter is set in small type, like that of the
  11447. present paragraph, since it is analogous to material that is marked
  11448. ``doubly dangerous'' in other chapters. Instead of using dangerous
  11449. bend signs repeatedly, let us simply agree that Chapters 25 and~26 are
  11450. dangerous by definition.
  11451. Chapter 8 introduced the general idea of expressions and the four-fold
  11452. ``primary, secondary, tertiary, expression'' ^{hierarchy} on which
  11453. their syntax is based. \MF's variables can have any of eight types:
  11454. @boolean@, @numeric@, @pair@, @path@, @pen@, @picture@, @string@,
  11455. and @transform@. Its expressions can actually have nine different
  11456. types, although the ninth one---``^{vacuous}''---is not particularly
  11457. interesting since it has only one possible value. Here is the overall
  11458. syntax:
  11459. \beginsyntax
  11460. <primary>\is<boolean primary>\alt<numeric primary>
  11461.  \alt<pair primary>\alt<path primary>
  11462.  \alt<pen primary>\alt<future pen primary>
  11463.  \alt<picture primary>\alt<string primary>
  11464.  \alt<transform primary>\alt<vacuous primary>\endgraf\medskip
  11465. <secondary>\is<boolean secondary>\alt<numeric secondary>
  11466.  \alt<pair secondary>\alt<path secondary>
  11467.  \alt<pen secondary>\alt<future pen secondary>
  11468.  \alt<picture secondary>\alt<string secondary>
  11469.  \alt<transform secondary>\alt<vacuous secondary>\endgraf\medskip
  11470. <tertiary>\is<boolean tertiary>\alt<numeric tertiary>
  11471.  \alt<pair tertiary>\alt<path tertiary>
  11472.  \alt<pen tertiary>\alt<picture tertiary>
  11473.  \alt<string tertiary>\alt<transform tertiary>
  11474.  \alt<vacuous tertiary>\endgraf\medskip
  11475. <expression>\is<boolean expression>\alt<numeric expression>
  11476.  \alt<pair expression>\alt<path expression>
  11477.  \alt<pen expression>\alt<picture expression>
  11478.  \alt<string expression>\alt<transform expression>
  11479.  \alt<vacuous expression>
  11480. \endsyntax
  11481. We shall discuss the different types of expressions in alphabetic order;
  11482. thus, if you are dying to know what a ``vacuous'' expression is,
  11483. you should skip to the end of the chapter. \looseness=-1
  11484. \medbreak
  11485. \textindent\bull
  11486. Boolean expressions were discussed in Chapter 19. The full syntax has
  11487. one more operation, `charexists', that was not mentioned there:
  11488. \beginsyntax
  11489. <boolean primary>\is<boolean variable>\alt<boolean argument>
  11490.  \alt[true]\alt[false]
  11491.  \alt[(]<boolean expression>[)]
  11492.  \alt[begingroup]<statement list><boolean expression>[endgroup]
  11493.  \alt[known]<primary>\alt[unknown]<primary>
  11494.  \alt<type><primary>\alt[cycle]<primary>
  11495.  \alt[odd]<numeric primary>
  11496.  \alt[charexists]<numeric primary>
  11497.  \alt[not]<boolean primary>
  11498. <boolean secondary>\is<boolean primary>
  11499.  \alt<boolean secondary>[and]<boolean primary>
  11500. <boolean tertiary>\is<boolean secondary>
  11501.  \alt<boolean tertiary>[or]<boolean secondary>
  11502. <boolean expression>\is<boolean tertiary>
  11503.  \alt<numeric expression><relation><numeric tertiary>
  11504.  \alt<pair expression><relation><pair tertiary>
  11505.  \alt<transform expression><relation><transform tertiary>
  11506.  \alt<boolean expression><relation><boolean tertiary>
  11507.  \alt<string expression><relation><string tertiary>
  11508. <relation>\is[\char'74]\alt[\char'74=]\alt[>]\alt[>=]\alt[=]\alt[\char'74>]
  11509. \endsyntax
  11510. The expression `charexists $x$' is true if and only if a ^@shipout@
  11511. command has previously been done with ^"charcode"$\null=x$. \ (The value
  11512. of~$x$ is first rounded to an integer, and reduced to the range
  11513. $0\le x<256$ by adding or subtracting multiples of~256.)
  11514. In these rules, tokens like `|true|' that appear in typewriter type stand for
  11515. any ^{tokens} whose current meaning is the same as the meaning of `|true|'
  11516. when \MF\ starts from scratch; the particular token `|true|'---whose
  11517. meaning may indeed change as a program runs---is not really involved.
  11518. The special tokens `|(|' and~`|)|' in these rules do not refer to
  11519. ^{parentheses}; they refer to any matching pair of ^{delimiters} defined
  11520. by a ^@delimiters@ command.
  11521. A \<boolean variable> denotes a ^\<variable> whose type is @boolean@; a
  11522. $\langle$numeric variable$\rangle$ is a \<variable> whose type is
  11523. @numeric@; and so~on.  The syntax for \<variable> was discussed in
  11524. Chapter~7. A \<boolean argument> is an ^@expr@ ^{argument} to a macro,
  11525. where the value of the expression is of type @boolean@;
  11526. @expr@ arguments are put into special ``^{capsule}''
  11527. tokens as explained in Chapter~18.
  11528. \medbreak
  11529. \textindent\bull
  11530. Numeric expressions have the richest syntax of all, because they form the
  11531. nucleus of the entire \MF\ language:
  11532. \beginsyntax
  11533. <numeric atom>\is<numeric variable>\alt<numeric argument>
  11534.  \alt<numeric token atom>
  11535.  \alt<internal quantity>
  11536.  \alt[normaldeviate]
  11537.  \alt[(]<numeric expression>[)]
  11538.  \alt[begingroup]<statement list><numeric expression>[endgroup]
  11539. <numeric token atom>\is<numeric token>[/]<numeric token>
  11540.  \alt<numeric token not followed by `{\tt/}$\langle$numeric token$\rangle$'>
  11541. <numeric primary>\is<numeric atom>
  11542.  \alt<numeric atom>[\char'133]<numeric expression>%
  11543.    [,]<numeric expression>[\char'135]
  11544.  \alt[length]<numeric primary>\alt[length]<pair primary>
  11545.  \alt[length]<path primary>\alt[length]<string primary>
  11546.  \alt[ASCII]<string primary>\alt[oct]<string primary>\alt[hex]<string primary>
  11547.  \alt<pair part><pair primary>\alt<transform part><transform primary>
  11548.  \alt[angle]<pair primary>
  11549.  \alt[turningnumber]<path primary>\alt[totalweight]<picture primary>
  11550.  \alt<numeric operator><numeric primary>
  11551.  \alt[directiontime]<pair expression>[of]<path primary>
  11552. <pair part>\is[xpart]\alt[ypart]
  11553. <transform part>\is<pair part>\alt[xxpart]\alt[xypart]\alt[yxpart]\alt[yypart]
  11554. <numeric operator>\is[sqrt]\alt[sind]\alt[cosd]\alt[mlog]\alt[mexp]
  11555.  \alt[floor]\alt[uniformdeviate]\alt<scalar multiplication operator>
  11556. <scalar multiplication operator>\is<plus or minus>
  11557.  \alt<numeric token atom not followed by {\tt+} or {\tt-} or a numeric token>
  11558. <numeric secondary>\is<numeric primary>
  11559.  \alt<numeric secondary><times or over><numeric primary>
  11560. <times or over>\is[*]\alt[/]
  11561. <numeric tertiary>\is<numeric secondary>
  11562.  \alt<numeric tertiary><plus or minus><numeric secondary>
  11563.  \alt<numeric tertiary><Pythagorean plus or minus><numeric secondary>
  11564. <plus or minus>\is[+]\alt[-]
  11565. <Pythagorean plus or minus>\is[++]\alt[+-+]
  11566. <numeric expression>\is<numeric tertiary>
  11567. \endsyntax
  11568. Each of the operations mentioned in this syntax has already been explained
  11569. somewhere in this book; Appendix~I tells where.
  11570. \medbreak
  11571. This is a good time to list all of the internal quantities that are
  11572. initially present in \MF:
  11573. \begindisplay
  11574. ^"tracingtitles"&show titles online when they appear\cr
  11575. ^"tracingequations"\hidewidth&show each variable when it becomes known\cr
  11576. ^"tracingcapsules"\hidewidth&show capsules as well as variables\cr
  11577. ^"tracingchoices"&show the control points chosen for paths\cr
  11578. ^"tracingspecs"&show subdivision of paths into octants before digitizing\cr
  11579. ^"tracingpens"&show vertices of pens as they are made from future pens\cr
  11580. ^"tracingcommands"\hidewidth
  11581.  &show commands and operations before they're performed\cr
  11582. ^"tracingrestores"&show when a symbol or internal quantity is restored\cr
  11583. ^"tracingmacros"&show macros before they are expanded\cr
  11584. ^"tracingedges"&show digitized edges as they are computed\cr
  11585. ^"tracingoutput"&show digitized edges as they are output\cr
  11586. ^"tracingonline"&show long diagnostics on the terminal and in the log\cr
  11587. ^"tracingstats"&log the memory usage at end of job\cr
  11588. ^"pausing"&show lines on the terminal before they are read\cr
  11589. ^"showstopping"&stop after each @show@ command\cr
  11590. ^"fontmaking"&produce font metric output\cr
  11591. ^"proofing"&produce proof mode output\cr
  11592. ^"turningcheck"&reorient clockwise paths, flag strange ones\cr
  11593. ^"warningcheck"&advise when a variable value gets large\cr
  11594. ^"smoothing"&remove certain glitches from digitized curves\cr
  11595. ^"autorounding"&move paths to ``good'' tangent points\cr
  11596. ^"granularity"&the pixel size for "autorounding"\cr
  11597. ^"fillin"&the extra darkness of diagonals (to be counteracted)\cr
  11598. ^"year"&the current year (e.g., 1986)\cr
  11599. ^"month"&the current month (e.g, 3 $\equiv$ March)\cr
  11600. ^"day"&the current day of the month\cr
  11601. ^"time"&the number of minutes past midnight when job started\cr
  11602. ^"charcode"&the number of the next character to be output\cr
  11603. ^"charext"&the extension code of the next character to be output\cr
  11604. ^"charwd"&the width of the next character to be output, in points\cr
  11605. ^"charht"&the height of the next character to be output, in points\cr
  11606. ^"chardp"&the depth of the next character to be output, in points\cr
  11607. ^"charic"&the italic correction of the next character, in points\cr
  11608. ^"chardx"&the device's $x$ movement for the next character, in pixels\cr
  11609. ^"chardy"&the device's $y$ movement for the next character, in pixels\cr
  11610. ^"designsize"&the approximate size of the current typeface, in points\cr
  11611. ^"hppp"&the number of horizontal pixels per point\cr
  11612. ^"vppp"&the number of vertical pixels per point\cr
  11613. ^"xoffset"&the horizontal displacement of shipped-out characters\cr
  11614. ^"yoffset"&the vertical displacement of shipped-out characters\cr
  11615. ^"boundarychar"&the right boundary character for ligatures and kerns\cr
  11616. \enddisplay
  11617. All of these quantities are numeric. They are initially zero at the
  11618. start of a job, except for "year", "month", "day", and "time", which
  11619. are initialized to the time the run began; furthermore, "boundarychar" is
  11620. initially~$-1$. A "granularity" of zero is equivalent to $"granularity"=1$.
  11621. A preloaded base file like plain \MF\ will usually give nonzero values to
  11622. several other internal quantities on this list.
  11623. \medbreak
  11624. \textindent\bull
  11625. Now we come to expressions of type @pair@, which are the second most
  11626. important elements of \MF\ programs:
  11627. \beginsyntax
  11628. <pair primary>\is<pair variable>\alt<pair argument>
  11629.  \alt[(]<numeric expression>[,]<numeric expression>[)]
  11630.  \alt[(]<pair expression>[)]
  11631.  \alt[begingroup]<statement list><pair expression>[endgroup]
  11632.  \alt<numeric atom>[\char'133]<pair expression>[,]<pair expression>[\char'135]
  11633.  \alt<scalar multiplication operator><pair primary>
  11634.  \alt[point]<numeric expression>[of]<path primary>
  11635.  \alt[precontrol]<numeric expression>[of]<path primary>
  11636.  \alt[postcontrol]<numeric expression>[of]<path primary>
  11637.  \alt[penoffset]<pair expression>[of]<pen primary>
  11638.  \alt[penoffset]<pair expression>[of]<future pen primary>
  11639. <pair secondary>\is<pair primary>
  11640.  \alt<pair secondary><times or over><numeric primary>
  11641.  \alt<numeric secondary>[*]<pair primary>
  11642.  \alt<pair secondary><transformer>
  11643. <transformer>\is[rotated]<numeric primary>
  11644.  \alt[scaled]<numeric primary>
  11645.  \alt[shifted]<pair primary>
  11646.  \alt[slanted]<numeric primary>
  11647.  \alt[transformed]<transform primary>
  11648.  \alt[xscaled]<numeric primary>
  11649.  \alt[yscaled]<numeric primary>
  11650.  \alt[zscaled]<pair primary>
  11651. <pair tertiary>\is<pair secondary>
  11652.  \alt<pair tertiary><plus or minus><pair secondary>
  11653.  \alt<path tertiary>[intersectiontimes]<path secondary>
  11654. <pair expression>\is<pair tertiary>
  11655. \endsyntax
  11656. A pair is a special case of a path (namely, it's a path of length zero);
  11657. Chapter 19 explains that \MF\ doesn't change the type from pair to path
  11658. unless there is no other way to meet the syntax rules.
  11659. \medbreak
  11660. \textindent\bull
  11661. Speaking of paths, they come next in our survey:
  11662. \beginsyntax
  11663. <path primary>\is<path variable>\alt<path argument>
  11664.  \alt[(]<path expression>[)]
  11665.  \alt[begingroup]<statement list><path expression>[endgroup]
  11666.  \alt[makepath]<pen primary>
  11667.  \alt[makepath]<future pen primary>
  11668.  \alt[reverse]<path primary>
  11669.  \alt[subpath]<pair expression>[of]<path primary>
  11670. <path secondary>\is<path primary>\alt<path secondary><transformer>
  11671. <path tertiary>\is<path secondary>
  11672. <path subexpression>\is<path tertiary>\alt<pair tertiary>
  11673.  \alt<path expression><path join><path tertiary>
  11674. <path join>\is<direction specifier><basic path join><direction specifier>
  11675. <direction specifier>\is<empty>
  11676.  \alt[\char'173][curl]<numeric expression>[\char'175]
  11677.  \alt[\char'173]<pair expression>[\char'175]
  11678.  \alt[\char'173]<numeric expression>[,]<numeric expression>[\char'175]
  11679. <basic path join>\is[\&]
  11680.  \alt[..]
  11681.  \alt[..]<tension>[..]
  11682.  \alt[..]<controls>[..]
  11683. <tension>\is[tension]<tension amount>
  11684.  \alt[tension]<tension amount>[and]<tension amount>
  11685. <tension amount>\is<numeric primary>
  11686.  \alt[atleast]<numeric primary>
  11687. <controls>\is[controls]<pair primary>
  11688.  \alt[controls]<pair primary>[and]<pair primary>
  11689. <path expression>\is<path subexpression>
  11690.  \alt<path subexpression><direction specifier>
  11691.  \alt<path subexpression><path join>[cycle]
  11692. \endsyntax
  11693. Chapter 14 tells all about path creation.
  11694. \medbreak
  11695. \textindent\bull
  11696. Pens and future pens coexist as follows:
  11697. \beginsyntax
  11698. <pen primary>\is<pen variable>\alt<pen argument>
  11699.  \alt[nullpen]
  11700.  \alt[(]<pen expression>[)]
  11701.  \alt[begingroup]<statement list><pen expression>[endgroup]
  11702. <future pen primary>\is[pencircle]
  11703.  \alt[makepen]<path primary>
  11704. <pen secondary>\is<pen primary>
  11705. <future pen secondary>\is<future pen primary>
  11706.  \alt<future pen secondary><transformer>
  11707.  \alt<pen secondary><transformer>
  11708. <pen tertiary>\is<pen secondary>
  11709.  \alt<future pen secondary>
  11710. <pen expression>\is<pen tertiary>
  11711. \endsyntax
  11712. See Chapter 16 for a thorough discussion of pen usage.
  11713. \medbreak
  11714. \textindent\bull
  11715. Pictures can be null, added, or subtracted:
  11716. \beginsyntax
  11717. <picture primary>\is<picture variable>\alt<picture argument>
  11718.  \alt[nullpicture]
  11719.  \alt[(]<picture expression>[)]
  11720.  \alt[begingroup]<statement list><picture expression>[endgroup]
  11721.  \alt<plus or minus><picture primary>
  11722. <picture secondary>\is<picture primary>
  11723.  \alt<picture secondary><transformer>
  11724. <picture tertiary>\is<picture secondary>
  11725.  \alt<picture tertiary><plus or minus><picture secondary>
  11726. <picture expression>\is<picture tertiary>
  11727. \endsyntax
  11728. Chapter 13 is the definitive reference for picture operations.
  11729. \medbreak
  11730. \textindent\bull
  11731. Strings are still fresh in our minds from Chapter 22, but we should
  11732. repeat the syntax again for completeness here.
  11733. \beginsyntax
  11734. <string primary>\is<string variable>\alt<string argument>
  11735.  \alt<string token>
  11736.  \alt[jobname]
  11737.  \alt[readstring]
  11738.  \alt[(]<string expression>[)]
  11739.  \alt[begingroup]<statement list><string expression>[endgroup]
  11740.  \alt[str]<suffix>
  11741.  \alt[char]<numeric primary>
  11742.  \alt[decimal]<numeric primary>
  11743.  \alt[substring]<pair primary>[of]<string primary>
  11744. <string secondary>\is<string primary>
  11745. <string tertiary>\is<string secondary>
  11746. <string expression>\is<string tertiary>
  11747.  \alt<string expression>[\&]<string tertiary>
  11748. \endsyntax
  11749. There's nothing more to say about strings.
  11750. \medbreak
  11751. \textindent\bull
  11752. Chapter 15 explains transforms, but gives no formal syntax. The rules are:
  11753. \beginsyntax
  11754. <transform primary>\is<transform variable>\alt<transform argument>
  11755.  \alt[(]<transform expression>[)]
  11756.  \alt[begingroup]<statement list><transform expression>[endgroup]
  11757. <transform secondary>\is<transform primary>
  11758.  \alt<transform secondary><transformer>
  11759. <transform tertiary>\is<transform secondary>
  11760. <transform expression>\is<transform tertiary>
  11761. \endsyntax
  11762. Note that ^"identity" doesn't appear here; it is a variable defined
  11763. in Appendix~B\null, not a primitive of the language.
  11764. \medbreak
  11765. \textindent\bull
  11766. Finally, we come to the new kind of expression, which wasn't mentioned
  11767. in previous chapters because it is so trivial.
  11768. \beginsyntax
  11769. <vacuous primary>\is<vacuous argument>
  11770.  \alt<compound>
  11771.  \alt[(]<vacuous expression>[)]
  11772.  \alt[begingroup]<statement list><vacuous expression>[endgroup]
  11773. <vacuous secondary>\is<vacuous primary>
  11774. <vacuous tertiary>\is<vacuous secondary>
  11775. <vacuous expression>\is<vacuous tertiary>
  11776. \endsyntax
  11777. A \<compound> is defined in Chapter 26.
  11778. \ddangerexercise Construct minimal examples of each of the
  11779. nine types of expression (boolean, numeric, \dots,~vacuous).
  11780. You should use only ``^{sparks}'' in your constructions, not \<tag>
  11781. tokens or capsules; in particular, variables are not permitted
  11782. (otherwise this exercise would be too easy). Your expressions should
  11783. be as short as possible in the sense of {\sl fewest tokens\/}; the number
  11784. of keystrokes needed to type them is irrelevant.
  11785. \answer By looking at the syntax rules, we find, for example,
  11786. \begindisplay
  11787. \<boolean expression>&|true|\cr
  11788. \<numeric expression>&|0|\cr
  11789. \<pair expression>&|(0,0)|\cr
  11790. \<path expression>&|makepath pencircle|\cr
  11791. \<pen expression>&|nullpen|\cr
  11792. \<picture expression>&|nullpicture|\cr
  11793. \<string expression>&|""|\cr
  11794. \<transform expression>&Impossible!\cr
  11795. \<vacuous expression>&|begingroup endgroup|\cr
  11796. \enddisplay
  11797. Every \<transform expression> includes either a variable or a capsule.
  11798. Incidentally, there are some amusing alternative 5-token solutions for
  11799. \<pair expression>:
  11800. \begintt
  11801. postcontrol 0 of makepath nullpen
  11802. makepath pencircle intersectiontimes makepath nullpen
  11803. \endtt
  11804. \endchapter
  11805. This is of you very well remembred,
  11806. and well and sommaryly rehersed.
  11807. \author THOMAS ^{MORE}, {\sl A Dialogue Concernynge Heresyes\/} (1529)
  11808.  % Bk 2, Ch 1
  11809.  % p178 ll C7--8 in 1557 edition, where the spelling is slightly different
  11810. \bigskip
  11811. Below the tomato blobs was a band of white with vertical black stripes,
  11812. to which he could assign no meaning whatever,
  11813. till some one else came by, murmuring:
  11814. ``What expression he gets with his foreground!''
  11815. .\thinspace.\thinspace. %
  11816. Ah, they were all Expressionists now, he had heard, on the Continent.
  11817. So it was coming here too, was it?
  11818. \author JOHN ^{GALSWORTHY},  {\sl To Let\/} (1921) % Chapter 1, p13
  11819. \eject
  11820. \beginchapter Chapter 26. Summary of\\the Language
  11821. The grand tour of \MF's syntax that was begun in the previous chapter
  11822. is concluded in this one, so that a complete reference guide is
  11823. available for people who need to know the details.
  11824. \ (Another summary appears in Appendix~B.)
  11825. \ninepoint\medskip
  11826. \MF\ actually has a few features that didn't seem to be worth mentioning
  11827. in earlier chapters, so they will be introduced here as part of our
  11828. exhaustive survey. If there is any disagreement between something that
  11829. was said previously and something that will be said below, the facts
  11830. in the present chapter should be regarded as better approximations
  11831. to the ^{truth}.
  11832. We shall study \MF's digestive processes, i.e., what \MF\ does in
  11833. response to the tokens that arrive in its ``stomach.''
  11834. ^^{anatomy of METAFONT}
  11835. Chapter~6 describes the process by which input files are converted to
  11836. lists of tokens in \MF's ``mouth,'' and Chapters 18--20 explain how
  11837. expandable tokens are converted to unexpandable ones in \MF's ``gullet''
  11838. by a process similar to regurgitation. In particular, conditions and
  11839. loops are handled by the expansion mechanism, and we need not
  11840. discuss them further. When unexpandable tokens
  11841. finally reach \MF's gastro-intestinal tract, the real activities
  11842. begin; expressions are evaluated, equations are solved, variables are
  11843. declared, and commands are executed. In this chapter we shall discuss the
  11844. primitive operations that actually draw pictures and produce output.
  11845. Let's start by looking at the full syntax for \<program> and for
  11846. \<statement>:
  11847. \beginsyntax
  11848. <program>\is<statement list>[end]\alt<statement list>[dump]
  11849. <statement list>\is<empty>\alt<statement>[;]<statement list>
  11850. <statement>\is<empty>\alt<title>
  11851.  \alt<equation>\alt<assignment>
  11852.  \alt<declaration>\alt<definition>
  11853.  \alt<compound>\alt<command>
  11854. <title>\is<string expression>
  11855. <compound>\is[begingroup]<statement list><non-title statement>[endgroup]
  11856. <command>\is<save command>
  11857.  \alt<interim command>
  11858.  \alt<newinternal command>
  11859.  \alt<randomseed command>
  11860.  \alt<let command>
  11861.  \alt<delimiters command>
  11862.  \alt<protection command>
  11863.  \alt<everyjob command>
  11864.  \alt<show command>
  11865.  \alt<message command>
  11866.  \alt<mode command>
  11867.  \alt<picture command>
  11868.  \alt<display command>
  11869.  \alt<openwindow command>
  11870.  \alt<shipout command>
  11871.  \alt<special command>
  11872.  \alt<font metric command>
  11873. \endsyntax
  11874. The \<empty> statement does nothing, but it is very handy because you can
  11875. always feel safe when you put extra semicolons between statements.
  11876. A \<title> does almost nothing, but it provides useful documentation
  11877. as explained in Chapter~22.
  11878. The syntax of \<equation> and \<assignment> can be found in Chapter~10;
  11879. \<declaration> is in Chapter~7; \<definition> is in Chapters 18 and~20.
  11880. We shall concentrate in this chapter on the various types of {\sl
  11881. ^{commands}}, especially on those that haven't been mentioned before.
  11882. \beginsyntax
  11883. <save command>\is[save]<symbolic token list>
  11884. <symbolic token list>\is<symbolic token>
  11885.  \alt<symbolic token list>[,]<symbolic token>
  11886. <interim command>\is\kern-1.5pt[interim]%
  11887.  <internal quantity>[:=]<right-hand side>\kern-1pt
  11888. \endsyntax
  11889. The @save@ and @interim@ commands cause values to be restored at the end
  11890. of the current group, as discussed in Chapter~17.
  11891. \beginsyntax
  11892. <newinternal command>\is[newinternal]<symbolic token list>
  11893. \endsyntax
  11894. Each of the symbolic tokens specified in a @newinternal@ command will
  11895. henceforth behave exactly as an \<internal quantity>, initially zero.
  11896. Thus, they can be used in @interim@ commands; they are ^{tags} but not
  11897. ^{external tags} (see Chapter~7). Since \MF\ can access internal
  11898. quantities quickly, you can use them to gain efficiency.
  11899. \beginsyntax
  11900. <randomseed command>\is[randomseed][:=]<numeric expression>
  11901. \endsyntax
  11902. The @randomseed@ command specifies a ``seed'' value that defines
  11903. the pseudo-random numbers to be delivered by
  11904. `uniformdeviate' and `normaldeviate' (cf.~Chapter~21).
  11905. The default value, if you don't specify your own seed, is
  11906. ^^"day" ^^"time" $"day"+"time"\ast"epsilon"$.
  11907. \beginsyntax
  11908. <let command>\is[let]<symbolic token><is><symbolic token>
  11909. <is>\is[=]\alt[:=]
  11910. \endsyntax
  11911. The @let@ command changes the current meaning of the left-hand token
  11912. to the current meaning of the right-hand token. For example,
  11913. after `@let@ $"diamonds"=@forever@$', the token "diamonds" will
  11914. introduce loops. If the left-hand token was the first token of
  11915. any variable names, those variables all disappear. If the right-hand
  11916. token was the first token in any variable names, those variables
  11917. remain unchanged, and the left-hand token becomes
  11918. an unknown, independent variable. \ (The purpose of @let@ is to redefine
  11919. primitive meanings or macro meanings, not to equate variables in any way.)
  11920. \ If the right-hand symbol is one of a pair of matching delimiters,
  11921. the subsequent behavior of the left-hand symbol is undefined.
  11922. For example, it's a bad idea to say `@let@~$[\,[=($;~@let@~$]\,]=)$'.
  11923. \beginsyntax
  11924. <delimiters command>\is[delimiters]<symbolic token><symbolic token>
  11925. \endsyntax
  11926. The @delimiters@ command gives new meanings to the two symbolic tokens;
  11927. henceforth they will match each other (and only each other). For example,
  11928. Appendix~B says `@delimiters@~()'; without this command, parentheses
  11929. would be ordinary symbolic tokens. Any distinct symbolic tokens can be
  11930. defined to act as delimiters, and many different pairs of delimiters
  11931. can be in use simultaneously.
  11932. \beginsyntax
  11933. <protection command>\is[outer]<symbolic token list>
  11934.  \alt[inner]<symbolic token list>
  11935. \endsyntax
  11936. A ``^{forbidden}'' stamp is added to or removed from symbolic tokens
  11937. by an @outer@ or @inner@ command, without changing the essential meanings
  11938. of those tokens. A token that has been called @outer@ should not appear
  11939. when \MF\ is skipping over tokens at high speed; the program will stop
  11940. and insert an appropriate delimiter, if an @outer@ token is sensed in
  11941. the wrong place, since such tokens are supposed to occur only at
  11942. ``quiet'' times. \ (Unquiet times occur when \MF\ is skipping tokens
  11943. because of a false ^{condition}, or because it is reading the ^{replacement
  11944. text} of a macro or the ^{loop text} of a loop, or because it is scanning
  11945. the ^{text argument} to a macro, or because it is ^{flushing} erroneous
  11946. tokens that were found at the end of a statement.) \ Without such
  11947. protection, a missing right delimiter could cause \MF\ to eat up your
  11948. whole program before any error was detected; @outer@ tokens keep such
  11949. errors localized.  An @inner@ command undoes the effect of @outer@; so
  11950. does `@let@', and so does any other command or definition that changes the
  11951. meaning of a symbolic token.  All tokens are initially @inner@.
  11952. \beginsyntax
  11953. <everyjob command>\is[everyjob]<symbolic token>
  11954. \endsyntax
  11955. The command `@everyjob@$\,S$' tells \MF\ that token $S$ should be inserted
  11956. first, just before the input file is read, when a job starts. \ (This
  11957. is meaningful only in a base file that will be loaded or preloaded
  11958. at the beginning of a run; it is analogous to \TeX's |\everyjob| command.)
  11959. \beginsyntax
  11960. <show command>\is[show]<expression list>
  11961.  \alt[showvariable]<symbolic token list>
  11962.  \alt[showtoken]<symbolic token list>
  11963.  \alt[showdependencies]
  11964.  \alt[showstats]
  11965. \endsyntax
  11966. A simple @show@ command displays the value of each expression, in turn.
  11967. Paths, pens, and pictures are shown only in the transcript file, unless
  11968. ^"tracingonline" is positive. The @showvariable@ command gives the
  11969. structure of all variables that begin with a given external tag,
  11970. together with their values in an abbreviated form; this allows you to see
  11971. which of its subscripts and attributes have occurred. For example, if you're
  11972. using plain \MF\ conventions, `@showvariable@~$x,y$' will show all
  11973. coordinates that have been defined since the last @beginchar@. The @showtoken@
  11974. command gives the current meaning of a token, so that you can tell whether
  11975. it is primitive or not, @outer@ or not. (If @showvariable@ is applied to
  11976. a spark instead of a tag, it gives the same information as @showtoken@.)
  11977. \ Every unknown numeric variable that's currently dependent is shown by
  11978. @showdependencies@ (except that unknown capsules are shown only
  11979. when ^"tracingcapsules" is positive). And finally, @showstats@ gives
  11980. information about \MF's current memory usage.
  11981. Each of these commands will stop and say `|!|~^|OK.|', if the internal
  11982. quantity "showstopping" has a positive value; this gives you a chance
  11983. to enter more @show@ commands ^{interactive}ly, while you're trying to
  11984. debug a program.
  11985. \beginsyntax
  11986. <message command>\is<message op><string expression>
  11987. <message op>\is[message]\alt[errmessage]\alt[errhelp]
  11988. \endsyntax
  11989. Communication with the user is possible via @message@, @errmessage@,
  11990. and @errhelp@, as discussed in Chapter~22.
  11991. \beginsyntax
  11992. <mode command>\is[batchmode]\alt[nonstopmode]
  11993.  \alt[scrollmode]\alt[errorstopmode]
  11994. \endsyntax
  11995. The four ``mode commands'' control the amount of interaction during error
  11996. recovery, just as in~\TeX. A job starts in @errorstopmode@, and you can
  11997. also resurrect this mode by ^{interrupting} \MF; @scrollmode@,
  11998. @nonstopmode@, and @batchmode@ are the modes you get into by hitting
  11999. `|S|', `|R|', or `|Q|', respectively, in response to error messages
  12000. (cf.~Chapter~5).
  12001. \beginsyntax
  12002. <picture command>\is<addto command>\alt<cull command>
  12003. <addto command>\is[addto]<picture variable>[also]<picture expression>
  12004.  \alt[addto]<picture variable>[contour]<path expression><with list>
  12005.  \alt[addto]<picture variable>[doublepath]<path expression><with list>
  12006. <with list>\is<empty>\alt<with list><with clause>
  12007. <with clause>\is[withpen]<pen expression>%
  12008.  \alt[withweight]<numeric expression>\kern-3.5pt
  12009. <cull command>\is[cull]<picture variable><keep or drop><pair expression>
  12010.  \alt<cull command>[withweight]<numeric expression>
  12011. <keep or drop>\is[keeping]\alt[dropping]
  12012. \endsyntax
  12013. The @addto@ and @cull@ commands are the principal means of making
  12014. changes to pictures; they are discussed fully in Chapter~13.
  12015. \beginsyntax
  12016. <display command>\is[display]<picture variable>[inwindow]<window>
  12017. <window>\is<numeric expression>
  12018. <openwindow command>\is[openwindow]<window><window spec>
  12019. <window spec>\is<screen place>[at]<pair expression>
  12020. <screen place>\is[from]<screen coordinates>[to]<screen coordinates>
  12021. <screen coordinates>\is<pair expression>
  12022. \endsyntax
  12023. Chapter~23 explains how to display stuff on your screen via @display@
  12024. and @openwindow@\kern-1pt.
  12025. \beginsyntax
  12026. <shipout command>\is[shipout]<picture expression>
  12027. \endsyntax
  12028. You may have wondered how \MF\ actually gets pictorial information into
  12029. a font. Here at last is the answer: `@shipout@~$v$' puts the pixels of
  12030. positive weight, as defined by the picture expression~$v$, into a ^{generic
  12031. font} output file, where they will be the bitmap image associated with
  12032. character number $"charcode"\bmod256+"charext"\ast256$. The pixels of~$v$
  12033. are shifted by $("xoffset","yoffset")$ as they are shipped out.
  12034. \ (However, no output is done if ^"proofing"$\null<0$. The values of
  12035. ^"xoffset", ^"yoffset", ^"charcode", and ^"charext" are first rounded to
  12036. integers, if necessary.) \ This command also saves the values of
  12037. ^"charwd", ^"charht", ^"chardp", ^"charic", ^"chardx", and "chardy"; they
  12038. will be associated with the current "charcode" when ^{font metric
  12039. information} is produced. \ (See Appendices F and~G for the basic
  12040. principles of font metric information and generic font files.)
  12041. \beginsyntax
  12042. <special command>\is[special]<string expression>
  12043.  \alt[numspecial]<numeric expression>
  12044. \endsyntax
  12045. The @special@ and @numspecial@ commands send alphabetic and numeric
  12046. information
  12047. to the generic font output file, if "proofing" is nonnegative.
  12048. For example, the labels on proofsheets are specified in this
  12049. way by macros of plain \MF\!\null. Appendices G and~H provide further details.
  12050. \medbreak
  12051. We have now discussed every kind of command but one; and the remaining
  12052. one is even more special than the \<special command>, so we had better
  12053. defer its discussion to an appendix. Appendix~F will complete the syntax
  12054. by defining \<font metric command>. For now, we merely need to know that
  12055. font metric commands specify fussy font facts; examples are the kerning and
  12056. `@font\_normal\_space@' statements in the \MF\ logo program of Chapter~11.
  12057. \medbreak
  12058. And there's one more loose end to tie up, going back to the very
  12059. first syntax rule in this chapter: The token `^@dump@' can be
  12060. substituted for `^@end@', if a special version of \MF\ called
  12061. `^|INIMF|' is being used. This writes a file containing the macros
  12062. defined so far, together with the current values of variables and
  12063. the current meanings of symbolic tokens, so
  12064. that they can be loaded as a base file. \ (It is analogous to
  12065. \TeX's |\dump| command.) \ Base files are discussed at the end of
  12066. Appendix~B.
  12067. \ddangerexercise Run \MF\ with the input ^^@outer@ ^^@delimiters@ ^^@showtoken@
  12068. \begintt
  12069. \newinternal a;
  12070. let b=a; outer a,b,c;
  12071. let c=b; delimiters a::;
  12072. showtoken a,b,c; end
  12073. \endtt
  12074. and explain the computer's responses.
  12075. \answer The responses are
  12076. \begintt
  12077. > a=left delimiter that matches ::
  12078. > b=(outer) a
  12079. > c=a
  12080. \endtt
  12081. because: $a$ has been redefined from internal quantity to delimiter;
  12082. $b$~is still an internal quantity (named~$a$), and it has been stamped
  12083. @outer@; $c$~denotes the same internal quantity, but it hasn't got outerness.
  12084. \endchapter
  12085. Our life is frittered away by detail.
  12086. An honest man has hardly need
  12087. to count more than his ten fingers,
  12088. or in extreme cases he may add his ten toes,
  12089. and lump the rest. Simplicity, simplicity, simplicity!
  12090. I say, let your affairs be as two or three,
  12091. and not a hundred or a thousand .\thinspace.\thinspace.
  12092. Simplify, simplify.
  12093. \author HENRY DAVID ^{THOREAU},  {\sl Walden\/} (1854) % 1st ed, ch2, graf15
  12094. \bigskip
  12095. The awesome memory of thy ever attentive computer
  12096. accepts all words as ^{truth}.
  12097. Think, therefore, in analytical, modular steps,
  12098. for the truth or untruth spoken through thy fingertips
  12099. will be acted upon unerringly.
  12100. \author HERMANN ^{ZAPF}, {\sl The Ten Commandments of %
  12101.  Photo\kern1pt-\kern-1ptTypesetting\/} (1982) % 2nd Commandment
  12102. \eject
  12103. \beginchapter Chapter 27. Recovery\\from\\Errors
  12104. OK, everything you need to know about \MF\ has been explained---unless you
  12105. happen to be fallible. If you don't plan to make any errors, don't bother to
  12106. read this chapter. Otherwise you might find it helpful to make use of some
  12107. of the ways that \MF\ tries to pinpoint bugs in your programs.
  12108. In the trial runs you did when reading Chapter 5, you learned the general
  12109. form of ^{error messages}, and you also learned the various ways in which
  12110. you can respond to \MF's complaints. With practice, you will be able to
  12111. correct most errors ``online,'' as soon as \MF\ has detected them, by
  12112. inserting and deleting a few things. On the other hand, some errors are
  12113. more devastating than others; one error might cause some other perfectly
  12114. valid construction to be loused~up. Furthermore, \MF\ doesn't always
  12115. diagnose your errors correctly, since the number of ways to misunderstand
  12116. the rules is vast; \MF\ is a rather simple-minded computer program that
  12117. doesn't readily comprehend the human point of view. In fact, there will be times
  12118. when you and \MF\ disagree about something that you feel makes perfectly
  12119. good sense. This chapter tries to help avoid a breakdown in communication
  12120. by explaining how to learn \MF's reasons for its actions.
  12121. Ideally you'll be in a mellow mood when you approach \MF\!, and you will
  12122. regard any error
  12123. messages as amusing puzzles---``Why did the machine do
  12124. that?''---rather than as personal insults.
  12125. \MF\ knows how to issue more than a hundred different sorts of error messages,
  12126. and you probably never will encounter all of them, because some types of
  12127. mistakes are very hard to make.
  12128. Let's go back to the `^|badio.mf|' example file of Chapter~5, since it
  12129. has more to teach us. If you have a better memory than the author, you'll
  12130. recall that the first error message was
  12131. \begintt
  12132. >> mode.setup
  12133. ! Isolated expression.
  12134. <to be read again>
  12135.                    ;
  12136. l.1 mode setup;
  12137.                 % an intentional error!
  12138. \endtt
  12139. In Chapter 5 we just charged ahead at this point, but it would be more
  12140. ^^{!} ^^{to be read again}
  12141. normal for a mature \MF er to think ``Shucks, I meant to type
  12142. `|mode_setup|', but I forgot the underscore. Luckily this didn't cause
  12143. any harm; \MF\ just found an ^{isolated expression}, `"mode.setup"', which
  12144. it will ignore. So let me now insert the correct command, `@mode\_setup@'.''
  12145. Good thinking; so you type `|I| |mode_setup|', right? Wrong~$\ldots$~sorry.
  12146. Lots of error messages occur before \MF\ has read a ^{semicolon} in
  12147. preparation for another ^{statement}; the important clue in this case
  12148. comes from the two lines
  12149. \begintt
  12150. <to be read again>
  12151.                    ;
  12152. \endtt
  12153. which tell us that the semicolon is still pending. So the correct
  12154. response would have been to type `|I;|~|mode_setup|' instead. Without
  12155. the semicolon, you get what appears at first to be a horrible mess:
  12156. \begintt
  12157. ! Extra tokens will be flushed.
  12158. <to be read again>
  12159.                    warningcheck
  12160. mode_setup->warningcheck
  12161.                         :=0;if.unknown.mode:mode=proof;fi...
  12162. <insert>  mode_setup
  12163. |quad
  12164. <to be read again>
  12165.                    ;
  12166. l.1 mode setup;
  12167.                 % an intentional error!
  12168. \endtt
  12169. But relax, there's a simple way out. The help message says
  12170. ^^|Extra tokens will be flushed| ^^{flushing}
  12171. `Please insert a ^{semicolon} now in front of anything that you
  12172. don't want me to delete'; all you have to do is type `|I;|' and
  12173. the net effect will be the same as if you had correctly inserted a semicolon
  12174. before |mode_setup| in the first place.
  12175. The moral of this story is: {\sl When you insert a new statement during
  12176. error recovery, you frequently need to put a semicolon just ahead of~it.}
  12177. But if you forget, \MF\ gives you another chance.
  12178. After proceeding through |badio| with the interactions suggested in
  12179. ^^|Undefined coordinate| ^^{misspelling} ^^{typographic errors}
  12180. Chap\-ter~5, we will come again to the error
  12181. \begintt
  12182. >> 0.08682thinn+144
  12183. ! Undefined x coordinate has been replaced by 0.
  12184. \endtt
  12185. (This is where the erroneous `|thinn|' was detected.) \ The help message for
  12186. this error has some curious advice:
  12187. \begintt
  12188. (Chapter 27 of The METAFONTbook explains that
  12189. you might want to type `I ???' now.)
  12190. \endtt
  12191. Chapter 27? That's us! What happens if we do type `|I ???|' now? We get
  12192. \begintt
  12193. x4l=0.08682thinn+144
  12194. y4=-0.4924thinn+259.0005
  12195. x4r=-0.08682thinn+144
  12196. y4r=-0.9848thinn+259.0005
  12197. ! OK.
  12198. \endtt
  12199. It is now abundantly clear that `|thin|' was misspelled. Plain \MF\
  12200. defines `^|???|' to be a macro that shows all of the current
  12201. dependencies between numeric variables and stops with `^|OK|';
  12202. this is useful because a badly typed variable name might have become a
  12203. ^{dependent variable} instead of an ^{independent variable}, in which
  12204. case it would be revealed by `|???|' but not by the error message.
  12205. One more example of online error correction should suffice to make
  12206. the general strategy clear. Suppose you accidentally type square brackets
  12207. instead of parentheses; the computer will scream:
  12208. \begintt
  12209. ! A primary expression can't begin with `['.
  12210. <inserted text>
  12211.                 0
  12212. <to be read again>
  12213.                    [
  12214. <*> show round[
  12215.                1 + sqrt43];
  12216. \endtt
  12217. (By coincidence, the help message for this particular error also refers to
  12218. Chapter~27.) \ When \MF\ needs to see an expression, because of the tokens
  12219. it has already digested, it will try to insert `|0|' in order to keep going.
  12220. In this case we can see that zero isn't what we intended; so we type
  12221. `|7|' to delete the next seven tokens, and the computer comes back with
  12222. \begintt
  12223. <*> show round[1 + sqrt43]
  12224.                           ;
  12225. \endtt
  12226. Now `|I (1 + sqrt43)|' will insert the correct formula, and the program will
  12227. be able to continue happily as if there were no mistake.
  12228. \exercise Why was `|7|' the right number of tokens to delete?
  12229. \answer We want to delete
  12230. \begindisplay
  12231. \ttok{0}\quad\ttok{[}\quad\ttok{1}\quad\ttok{+}\quad\ttok{sqrt}\quad
  12232. \ttok{43}\quad\ttok{]}
  12233. \enddisplay
  12234. from the sequence of tokens that \MF\ is about to read next, in order to
  12235. get rid of the right bracket, which we can see is going to be just as
  12236. erroneous as the left bracket was. However, there is another way to
  12237. proceed (and indeed, this alternative would be preferable to counting
  12238. tokens, if the bracketed expression were longer): We could simply
  12239. ^^{delimiter} ^^|Missing token has been inserted|
  12240. delete 2~tokens, then `|I(|'. This would produce another error stop,
  12241. \begintt
  12242. ! Missing `)' has been inserted.
  12243. <to be read again>
  12244.                    ]
  12245. <*> show round[1 + sqrt43]
  12246.                           ;
  12247. I found no right delimiter to match a left one. So I've
  12248. put one in, behind the scenes; this may fix the problem.
  12249. \endtt
  12250. after which it's easy to delete the `|]|' and continue successfully.
  12251. \dangerexercise If the user hadn't deleted or inserted anything, but had
  12252. just plunged ahead, \MF\ would have come up with another error:
  12253. \begintt
  12254. ! Extra tokens will be flushed.
  12255. <to be read again>
  12256.                    [
  12257. <to be read again>
  12258.                    (7.55743)
  12259. <to be read again>
  12260.                    ]
  12261. <*> show round[1 + sqrt43]
  12262.                           ;
  12263. \endtt
  12264. Explain what happened. What should be done next?
  12265. \answer \MF\ looked ahead, to see if the expression being evaluated
  12266. was going to be something like `|round 0[1+sqrt43,x]|'. But when it
  12267. found no comma, it put back several tokens so that they could be
  12268. read again. \ (The subexpression |1+sqrt43| had already been evaluated,
  12269. so a ``^{capsule}'' for its value, 7.55743, was inserted among the
  12270. tokens to be reread.) \ The expression ended with `0', and `round~0' was
  12271. shown. Then \MF\ found extra tokens following the @show@ command; a
  12272. semicolon should have come next. To continue, the user should just plunge
  12273. ahead recklessly once again, letting \MF\ delete those unwanted tokens.
  12274. It's wise to remember that the first error in your program may well spawn
  12275. spurious ``errors'' later on, because anomalous commands can inflict
  12276. serious injury on \MF's ability to cope with the subsequent material.
  12277. But most of the time you will find that a single run through the
  12278. machine will locate all of the places in which your input conflicts
  12279. with \MF's rules.
  12280. \danger Sometimes an error is so bad that \MF\ is forced to quit
  12281. prematurely. For example, if you are running in ^@batchmode@ or
  12282. ^@nonstopmode@, \MF\ makes an ``^{emergency stop}'' if it needs
  12283. input from the terminal; this happens when a necessary file can't
  12284. be opened, or when no ^@end@ was found in the input.
  12285. Here are some of the messages you might get just before
  12286. \MF\ gives up the ghost: \enddanger
  12287. {\ninepoint
  12288. \def\fatal#1. {\medbreak{\tt#1.}\par\nobreak\smallskip\noindent\ignorespaces}
  12289. \fatal
  12290. Fatal base file error; I'm stymied.
  12291. ^^|Fatal base file error|
  12292. This means that the preloaded base you have specified cannot be used,
  12293. because it was prepared for a different version of \MF\!.
  12294. \fatal
  12295. That makes 100 errors; please try again.
  12296. \MF\ has scrolled past 100 errors since the last statement ended, so
  12297. it's probably in an~endless ^{loop}. ^^{infinite loop}
  12298. \fatal
  12299. I can't go on meeting you like this.
  12300. ^^|I can't go on|
  12301. A previous error has gotten \MF\ out of whack. Fix it and try again.
  12302. \fatal
  12303. This can't happen.
  12304. ^^|This can't happen|
  12305. Something is wrong with the \MF\ you are using. Complain fiercely.
  12306. \goodbreak}
  12307. \danger There's also a dreadful message that \MF\ issues only with
  12308. great reluctance. But it can happen:
  12309. \begintt
  12310. METAFONT capacity exceeded, sorry.
  12311. \endtt
  12312. ^^|METAFONT capacity exceeded|
  12313. This, alas, means that you have tried to stretch \MF\ too far. The
  12314. message will tell you what part of \MF's memory has become overloaded;
  12315. one of the following eighteen things will be mentioned:
  12316. \begindisplay
  12317. |number of strings|\qquad(strings and names of symbolic tokens and files)\cr
  12318. |pool size|\qquad(the characters in such strings)\cr
  12319. |main memory size|\qquad(pairs, paths, pens, pictures, token lists,
  12320.   transforms, etc.)\cr
  12321. |hash size|\qquad(symbolic token names)\cr
  12322. |input stack size|\qquad(simultaneous input sources)\cr
  12323. |number of internals|\qquad(internal quantities)\cr
  12324. |rounding table size|\qquad(transitions between octants in cycles)\cr
  12325. |parameter stack size|\qquad(macro parameters)\cr
  12326. |buffer size|\qquad(characters in lines being read from files)\cr
  12327. |text input levels|\qquad(@input@ files and error insertions)\cr
  12328. |path size|\qquad(key points per path)\cr
  12329. |move table size|\qquad(rows of picture being simultaneously accessed)\cr
  12330. |pen polygon size|\qquad(pen offsets per octant)\cr
  12331. |ligtable size|\qquad(accumulated @ligtable@ instructions)\cr
  12332. |kern|\qquad(distinct kern amounts)\cr
  12333. |extensible|\qquad(built-up characters)\cr
  12334. |headerbyte|\qquad(largest @headerbyte@ address)\cr
  12335. |fontdimen|\qquad(largest @fontdimen@ address)\cr
  12336. \enddisplay
  12337. The current amount of memory available will also be shown.
  12338. \danger If you have a job that doesn't overflow \MF's capacity, yet
  12339. you want to see just how closely you have approached the limits,
  12340. just set ^"tracingstats" to a positive value before the end of your
  12341. job. The log file will then conclude with a report on your actual
  12342. usage of the first nine things named above (i.e., the number of strings,
  12343. \dots, the buffer size), in that order. ^^{stack positions}
  12344. Furthermore, the @showstats@ command can be used to discover the current
  12345. string memory and main ^{memory usage} at any time during a run.
  12346. The main memory statistics are broken into two
  12347. parts; `|490&5950|' means, for example, that 490 words are being used
  12348. for ``large'' things like pens, capsules, and
  12349. transforms, while 5950 words are being used for ``small'' things like
  12350. tokens and edges.
  12351. \danger What can be done if \MF's capacity is exceeded? All of the
  12352. above-listed components of the capacity can be increased, except the memory
  12353. for kerns and extensible characters, provided
  12354. that your computer is large enough; in fact, the space necessary to
  12355. increase one component can usually be obtained by decreasing some
  12356. other component, without increasing the total size of \MF\!\null.
  12357. If you have an especially important application, you may be able
  12358. to convince your local system people to provide you with a special
  12359. \MF\ whose capacities have been hand-tailored to your needs.
  12360. But before taking such a drastic step, be sure that you are using
  12361. \MF\ properly. If you have specified a gigantic picture that has
  12362. lots of transitions between black and white pixels, you should
  12363. change your approach, because \MF\ has to remember every change between
  12364. adjacent pixel values in every currently accessible picture.
  12365. If you keep saving different pens, you might be wasting memory as
  12366. discussed in Chapter~16. If you have built up an enormous macro library,
  12367. you should realize that \MF\ has to remember all of the replacement texts
  12368. that you define; therefore if memory space is in short supply, you should
  12369. load only the macros that you need.
  12370. \danger Some erroneous \MF\ programs will overflow any finite
  12371. memory capacity. For example, after `|def recurse=(recurse)enddef|', the
  12372. ^^{recursion} use of |recurse| will immediately bomb out:
  12373. \begintt
  12374. ! METAFONT capacity exceeded, sorry [input stack size=30].
  12375. recurse->(recurse
  12376.                  )
  12377. recurse->(recurse
  12378.                  )
  12379. recurse->(recurse
  12380.                  )
  12381. \endtt
  12382. The same sort of error will obviously occur no matter how much you increase
  12383. \MF's input stack size.
  12384. \danger Most implementations of \MF\ allow you to ^{interrupt} the program
  12385. in some way. This makes it possible to diagnose the causes of ^{infinite
  12386. loops}, if the machine doesn't stop because of memory limitations.
  12387. \MF\ switches to ^@errorstopmode@ when interrupted; hence
  12388. you have a chance to insert commands into the input: You can abort the
  12389. run, or you can ^@show@ or change the current contents of variables,
  12390. etc. In such cases you will probably want to ``^{hide}'' your diagnostic
  12391. commands, for example by typing
  12392. \begintt
  12393. I hide(showstopping:=1; alpha:=2; show x)
  12394. \endtt
  12395. so that you don't mess up the expression \MF\ is currently evaluating.
  12396. Interruption can also give you a feeling for where \MF\ is spending most
  12397. of its time, if you happen to be using an inefficient macro, since random
  12398. interrupts will tend to occur in whatever place \MF\ visits most often.
  12399. \danger \MF's second most frustrating error messages are its occasional
  12400. claims that you have ``^{strange}'' paths. Sometimes a glance at your
  12401. output will make it clear that you did indeed specify a path that
  12402. crossed over itself, something like a figure-8; but sometimes a path
  12403. that looks fine to you will be rejected by the computer. In such
  12404. cases you need to decipher \MF's octant codes, which look scary at
  12405. first although they turn out to be helpful when you get used to them.
  12406. For example, let's reconsider |branch4| of ^{El Palo Alto}, from
  12407. the program in Chapter~14:
  12408. \begintt
  12409. branch4=
  12410.  flex((0,509),(-14,492),(-32,481))
  12411.  &flex((-32,481),(-42,455),(-62,430))
  12412.  &flex((-62,430),(-20,450),(42,448))
  12413.  &flex((42,448),(38,465),(4,493),(0,509))
  12414.  &cycle;
  12415. \endtt
  12416. If the number |450| in the third ^{flex} had been |452| instead,
  12417. \MF\ would have stopped and told you this:
  12418. \begintt
  12419. > 0 SSW WSW 1 2 SSW 3 WSW 4 (WNW NNW) NNE ENE 5 ESE 6 (ENE)
  12420.  NNE NNW 7 WNW NNW 8 NNE 0 (NNW WNW WSW)
  12421. ! Strange path (turning number is zero).
  12422. <to be read again>
  12423.                    ;
  12424. <for(4)> ...]shifted(150,50)scaled(w/300);
  12425.                                            ENDFOR
  12426. p.4,l.94 endfor
  12427.                 endchar;
  12428. \endtt
  12429. The `|for(4)|' in the fifth-last line implies that |branch4| is
  12430. at fault, because it says that the ^@for@ loop index is~4;
  12431. but the ^{octant} codes like `^|SSW|' are your only clues about why
  12432. |branch4| is considered strange. \ (A simpler example appeared
  12433. in Chapter~13, which you might want to review now.) \
  12434. ^^{compass directions} ^^|SSE|^^|ESE|^^|WSW|^^|WNW|^^|NNE|^^|NNW|^^|ENE|
  12435. You probably also have a proofmode diagram:
  12436. \displayfig 27a (34mm)
  12437. Starting at time~0, and at the point $(0,509)$, the path goes South by
  12438. Southwest, then West by Southwest until time~2 (the end of the first flex).
  12439. Then it goes |SSW| again, and |WSW| again (that's the second flex).
  12440. But at time~4, the path makes a sharp turn through the directions
  12441. |WNW| and |NNW|, {\sl without moving\/} (because these octant codes are in
  12442. parentheses). Aha! That's where the path was supposed to turn
  12443. ^{counterclockwise}, through |SSW| and~|SSE| and~|ESE|; \MF\ turned clockwise
  12444. because it was the shortest way to go. The path actually makes a little
  12445. loop at time~4, between the end of the second flex and the beginning of
  12446. the third.  Therefore its turning number is indeed zero, and the path is
  12447. strange by definition.
  12448. \dangerexercise At what point do the second and third flexes cross,
  12449. in this example?
  12450. \answer The little program
  12451. \begintt
  12452. path p,q; p=flex((-32,481),(-42,455),(-62,430));
  12453. q=flex((-62,430),(-20,452),(42,448));
  12454. show p intersectiontimes q, p intersectionpoint q,
  12455.  angle -direction 2 of p, angle direction 0 of q; end
  12456. \endtt
  12457. gives the following results:
  12458. \begintt
  12459. >> (1.88403,0.07692)
  12460. >> (-59.32149,432.59523)
  12461. >> 43.14589
  12462. >> 45.47263
  12463. \endtt
  12464. (Actually, the paths would also cross if |452| were |451|, but
  12465. it's such a close call that \MF\ doesn't call the path strange;
  12466. \MF\ prefers to turn ^{counterclockwise} when the amount of turn
  12467. is close enough to $180^\circ$, even if it's slightly more.)
  12468. \danger There are three main ways to avoid problems with strange paths.
  12469. One is to stay away from paths that turn so abruptly. Or you can displace the
  12470. paths by "epsilon", as in the serif example at the end of Chapter~16.
  12471. \ (Displacing by ^"eps" would be even safer.) \ Or you can discipline
  12472. yourself to fill all cycles counterclockwise, so that you can set
  12473. ^"turningcheck"$\null:=0$; this means that \MF\ won't check for
  12474. strange paths, but that's OK because tiny little loops won't hurt anything
  12475. if you are filling cycles in the correct direction.
  12476. \ddanger Sometimes the octant codes of a strange path are shown backwards,
  12477. because the system may have tried to reverse the path to get rid of
  12478. its strangeness.
  12479. Sooner or later---hopefully sooner---you'll get \MF\ to process your
  12480. whole file without stopping once to complain. But maybe the output
  12481. still won't be right; the mere fact that \MF\ didn't stop doesn't mean
  12482. that you can avoid looking at proofsheets. At this stage it's usually easy to
  12483. see how to fix typographic errors by correcting the input; hardcopy proofs
  12484. such as those discussed in Appendix~H usually clear up obvious mistakes,
  12485. especially if you have remembered to label the key points in your constructions.
  12486. But your output may contain seemingly inexplicable errors.
  12487. If you can't find out what went wrong, try the old trick of simplifying
  12488. your program: Remove all the things that do work, until you obtain
  12489. the shortest possible input file that fails in the same way as the
  12490. original. The shorter the file, the easier it will be for you or somebody
  12491. else to pinpoint the problem.
  12492. \danger One of the important tricks for shortening a buggy program is to
  12493. assign a positive value to ^"tracingspecs", because this will put all the
  12494. key points and control points of a problematic path into your log file. \
  12495. (See the example at the end of Chapter~24, ``before subdivision.'') \ If
  12496. something is wrong with the treatment of some path, you can copy the
  12497. path's description from the log file and use it directly in \MF\ input,
  12498. thereby avoiding all the complexity of equations that might have been
  12499. involved in that path's original creation.
  12500. \danger We've just talked about "tracingstats" and "tracingspecs";
  12501. \MF\ is able to produce lots of other kinds of tracing. For example,
  12502. Chapter~22 discusses ^"tracingtitles",
  12503. Chapter~18 discusses ^"tracingmacros", Chapter~17 discusses
  12504. ^"tracingrestores", and Chapter~9 discusses ^"tracingequations".
  12505. You can also invoke ^"tracingchoices", which shows all paths before and
  12506. after their ^{control points} are chosen according to the rules
  12507. in Chapter~14; or ^"tracingpens", which shows the pen polygons that
  12508. arise when a future pen becomes a full-fledged @pen@; or ^"tracingoutput",
  12509. which shows every picture that's shipped out, using edge-transitions
  12510. to represent the pixel values as illustrated in Chapter~13. Each of
  12511. these types of tracing is enabled by assigning a positive value to the
  12512. corresponding internal quantity; for example, you can simply set
  12513. $"tracingpens":=1$ (or~^@interim@ $"tracingpens":=1$)
  12514. if you want the data about pens.
  12515. \danger If ^"tracingcommands"$\null=1$, \MF\ shows every ^{command}
  12516. just before it is carried out. If $"tracingcommands"=2$, \MF\ also shows
  12517. every ^{ex\-pand\-able token} just before it is expanded (except that
  12518. macros are separate, they're traced only when $"tracingmacros">0$). And if
  12519. $"tracingcommands"=3$, \MF\ also shows every ^{algebraic} ^{operation}
  12520. just before it is evaluated. Thus you can get ``stream of
  12521. consciousness'' information about everything \MF\ is doing.
  12522. \begingroup\ninepoint
  12523. \danger ^{Digitized output} can be monitored by setting ^"tracingedges"%
  12524. $\null=1$. For example, if we ask \MF\ to draw the Ionian `{\manual\IOO}'
  12525. of Chapter~5 at a resolution of 100~pixels per inch (^"lowres" mode
  12526. with ^"mag"$\null=.5$), "tracingedges" will report as follows:\enddanger
  12527. \beginlines
  12528. |Tracing edges at line 15: (weight 1)|
  12529. |(1,5)(1,2)(2,2)(2,1)(3,1)(3,0)(8,0)(8,1)(9,1)(9,2)(10,2)(10,8)(9,8)|
  12530. |(9,9)(8,9)(8,10)(3,10)(3,9)(2,9)(2,8)(1,8)(1,5).|
  12531. \smallskip
  12532. |Tracing edges at line 15: (weight -1)|
  12533. |(3,5)(3,2)(4,2)(4,1)(7,1)(7,2)(8,2)(8,8)(7,8)(7,9)(4,9)(4,8)(3,8)(3,5).|
  12534. \endlines
  12535. By following these edges (and negating their weights on the inner boundary)
  12536. we find that the character at this low resolution is symmetric:
  12537. \begindisplay
  12538. \vbox{\offinterlineskip\manual\halign{#\hfil\cr
  12539. SSSRRRRRSSS\cr
  12540. SSRRSSSRRSS\cr
  12541. SRRSSSSSRRS\cr
  12542. SRRSSSSSRRS\cr
  12543. SRRSSSSSRRS\cr
  12544. SRRSSSSSRRS\cr
  12545. SRRSSSSSRRS\cr
  12546. SRRSSSSSRRS\cr
  12547. SSRRSSSRRSS\cr
  12548. SSSRRRRRSSS\cr}}
  12549. \enddisplay
  12550. \endgroup
  12551. \ddanger Further information about digitization comes out when
  12552. $"tracingedges">1$, if fixed pens are used to ^@draw@ or ^@filldraw@ a
  12553. shape. In this case detailed information is presented about the activity
  12554. in each ^{octant} direction; straight line ``^{transition}'' edges are
  12555. also reported whenever \MF\ changes from one ^{penoffset} to another.
  12556. \ddanger The "tracing"$\ldots$ commands put all of their output into your log
  12557. file, unless the ^"tracingonline" parameter is positive; in the latter
  12558. case, all diagnostic information goes to the terminal as well as to the
  12559. log file.  Plain \MF\ has a ^@tracingall@ macro that turns on the
  12560. maximum amount of tracing of all kinds. It not only sets~up
  12561. "tracingcommands", "tracingedges", "tracingspecs", and so on,
  12562. it also sets $"tracingonline":=1$, and it sets ^"showstopping"$\null:=1$ so
  12563. that you can do interactive debugging via ^@show@ commands. This is the works.
  12564. There's also ^@loggingall@, which is like @tracingall@ except that it
  12565. doesn't touch "tracingonline" or "showstopping". You can say ^@interact@
  12566. if you want just $"tracingonline":="showstopping":=1$. Finally, there's
  12567. ^@tracingnone@, which shuts off every form of tracing after you've had enough.
  12568. \ddanger Some production versions of \MF\ have been streamlined for
  12569. speed. These implementations don't look at the value of ^"tracingstats",
  12570. nor do you get extra information when $"tracingedges">1$,
  12571. because \MF\ runs faster when it doesn't have
  12572. to maintain statistics or keep tabs on whether tracing is required.
  12573. If you want all of \MF's diagnostic tools, you should be sure to
  12574. use the right version.
  12575. \ddanger If you set ^"pausing"$\null:=1$, \MF\ will give you a chance to edit
  12576. each line of input as it is read from the file. In this way you can
  12577. make temporary patches (e.g., you can insert @show@$\ldots$ commands)
  12578. while troubleshooting, without changing the actual contents
  12579. of the file, and you can keep \MF\ running at human speed.
  12580. Final hint: When working on a large font, it's best to prepare
  12581. only a few characters at a time. Set up a ``{test}'' file and a ``{master}''
  12582. file, and do your work in the test file. \ (Appendix~E suggests a
  12583. convenient way to prepare control files that supply parameters to individual
  12584. test characters as well as to the whole font.) \
  12585. After the characters come out looking right, you can append them to the
  12586. master file; and you can run the master file through \MF\ occasionally,
  12587. in order to see how the font is shaping up. Characters can always be
  12588. moved back to the test file if you have to fix some unexpected problems.
  12589. \ddangerexercise Final exercise: Find all of the ^{lies} in this
  12590. manual, and all of the ^{jokes}.
  12591. \answer If this exercise isn't just a joke, the title of this
  12592. appendix is a lie. \ (When you've solved this exercise you might also
  12593. try to find all the lies and/or jokes that are the same in both
  12594. this book and {\sl The \TeX book}.)
  12595. \line{Final exhortation: G{\sc O} {\sc FORTH} now and create
  12596. {\sl masterpieces of digital typography!\/}}
  12597. \endchapter
  12598. % Advierto tambien que en quanto \^a los rumbos del camino
  12599. With respect to the directions of the route
  12600. % puedo haver tenido alguna equivocacion.
  12601. I may have made some errors.
  12602. \author FRAY PEDRO ^{FONT}, {\sl Diary\/} (1776)
  12603.  % opening remarks
  12604. \bigskip
  12605. The road to wisdom? Well, it's plain
  12606. and simple to express:
  12607. \tabskip\centering\halign to\hsize{#\hfil\tabskip=0pt\cr%
  12608.   Err\cr%
  12609.   and err\cr%
  12610.   and err again\cr%
  12611.   but less\cr%
  12612.   and less\cr%
  12613.   and less.\cr}%
  12614. \author PIET ^{HEIN}, {\sl Grooks\/} (1966) % p34
  12615. \eject
  12616. \beginchapter Appendix A. Answers to\\All the\\Exercises
  12617. The preface to this manual points out the wisdom of trying to figure out
  12618. each exercise before you look up the answer here. But these answers are intended
  12619. to be read, since they occasionally provide additional information that
  12620. you are best equipped to understand when you have just worked on a problem.
  12621. \immediate\closeout\ans % this makes the answers file ready
  12622. \ninepoint
  12623. \input answers
  12624. \endchapter
  12625. Looke into this Businesse thorowly,
  12626. And call these foule Offendors to their Answeres.
  12627. \author WILLIAM ^{SHAKESPEARE}, %
  12628.  {\sl Second Part of Henry the Sixth\/} (1594) % Act 2 Sc 1 ll 198--199
  12629. \bigskip
  12630. If you can't solve a problem,
  12631. you can always look up the answer.
  12632. But please, try first to solve it by yourself;
  12633. then you'll learn more and you'll learn faster.
  12634. \author DONALD E. ^{KNUTH}, {\sl The %
  12635.  {\manual \char`\\]\char`\^\char`\_efg\char`\^}\kern1ptbook\/} (1986)
  12636. \eject
  12637. \beginchapter Appendix B. Basic\\Operations
  12638. This appendix defines the macros of the plain \MF\ base. Let's begin
  12639. ^^{table, useful}
  12640. with an informal ^{inventory} of all the features that are available.
  12641. \def\bb{$\,\left\{\vcenter\bgroup\halign\bgroup\hfil##\hfil\cr}
  12642. \def\ee{\crcr\egroup\egroup\right\}\,$}
  12643. \def\\{\hfil\break}
  12644. \begingroup\lineskip=3pt plus .5pt
  12645. \medbreak\textindent\bull {\it ^{Boolean} things:\/} \
  12646. |true|, |false|; \ \ \bb|known|\cr|unknown|\cr|cycle|\ee\<expression>;\\
  12647. \lower2pt\vbox to 7pt{}%
  12648. \smash{\raise3pt\hbox{{\tt odd} \<numeric>; \ \ {\tt charexists} \<numeric>;}}\\
  12649. \bb|boolean|\cr|numeric|\cr|pair|\cr|path|\cr
  12650. |pen|\cr|picture|\cr|string|\cr|transform|\ee\<expression>; \
  12651. \bb|boolean|\cr|numeric|\cr|pair|\cr|string|\cr|transform|\ee
  12652.  \bb|<|\cr|<=|\cr|=|\cr|<>|\cr|>=|\cr|>|\ee
  12653.  \bb|boolean|\cr|numeric|\cr|pair|\cr|string|\cr|transform|\ee;\\
  12654. \raise3pt\hbox{\strut}%
  12655. |not| \<boolean>; \ \<boolean> |and| \<boolean>; \ \<boolean> |or| \<boolean>.
  12656. \medbreak\textindent\bull {\it ^{Numeric} things:\/} \
  12657. |tracingtitles|, \dots, |yoffset| (see Chapter~25);\\
  12658. |eps|, |epsilon|, |infinity|; \ |tolerance|, |join_radius|, |displaying|; \
  12659. \<constant>;\\
  12660. \bb|sqrt|\cr|sind|\cr|cosd|\cr|mlog|\cr|mexp|\ee\<numeric>; \
  12661. \bb|floor|\cr|round|\cr|hround|\cr|vround|\cr|ceiling|\ee\<numeric>; \
  12662. \bb|lft|\cr|rt|\cr|top|\cr|bot|\cr|good.x|\cr|good.y|\ee\<numeric>;\\
  12663. \bb|xpart|\cr|ypart|\ee\bb\<pair>\cr\<transform>\ee; \
  12664. \bb|xxpart|\cr|xypart|\cr|yxpart|\cr|yypart|\ee\<transform>; \
  12665. \bb|ASCII|\cr|oct|\cr|hex|\ee\<string>;\\
  12666. |normaldeviate|; \ |uniformdeviate| \<numeric>; \ |whatever|;\\
  12667. \lower6pt\null
  12668. |angle| \<pair>; \ |turningnumber| \<cycle>; \ |totalweight| \<picture>;\\
  12669. \bb|+|\cr\noalign{\kern-2pt}|-|\cr\noalign{\kern-2pt}\<constant>\ee\<numeric>; \
  12670. \bb|incr|\cr|decr|\ee\<variable>; \
  12671. |byte|\bb\<numeric>\cr\<string>\ee;\\
  12672. \<numeric>\bb|+|\cr|-|\ee\<numeric>; \
  12673. \<numeric>\bb|++|\cr|+-+|\ee\<numeric>;\\
  12674. \vbox to24pt{}%
  12675. \smash{\<numeric>\bb\tt*\cr\tt/\cr\tt**\ee\<numeric>}; \
  12676. \<numeric>\bb|mod|\cr|div|\ee\<numeric>;\\
  12677. \<pair> |dotprod| \<pair>; \
  12678. \bb|max|\cr|min|\ee|(|\<numerics>|)|; \
  12679. \bb|abs|\cr|length|\ee\bb\<numeric>\cr\<pair>\cr\<path>\cr\<string>\ee;\\
  12680. \<numeric>|[|\<numeric>|,|\<numeric>|]|; \
  12681. |solve|\<function>|(|\<numeric>|,|\<numeric>|)|;\\
  12682. |directiontime| \<pair> |of| \<path>.
  12683. \medbreak\textindent\bull {\it ^{Pair} things:\/} \
  12684. |left|, |right|, |up|, |down|, |origin|; \
  12685. |(|\<numeric>|,|\<numeric>|)|;\\
  12686. |z|\<suffix>; \ |dir| \<numeric>; \ |unitvector| \<pair>; \ |round| \<pair>;\\
  12687. \bb|lft|\cr|rt|\cr|top|\cr|bot|\ee\<pair>; \
  12688. \bb|good.lft|\cr|good.rt|\cr|good.top|\cr|good.bot|\ee\<pair>; \
  12689. \bb|point|\cr|precontrol|\cr|postcontrol|\cr|direction|\ee%
  12690.  \<numeric> |of| \<path>;\\
  12691. \bb|+|\cr\noalign{\kern-2pt}|-|\cr\noalign{\kern-2pt}\<constant>\ee\<pair>; \
  12692. \<pair>\bb|+|\cr|-|\ee\<pair>; \
  12693. \<numeric>|[|\<pair>|,|\<pair>|]|;\\
  12694. \<numeric>|*|\<pair>; \
  12695. \<pair>\bb|*|\cr|/|\ee\<numeric>; \
  12696. \<pair>\<transformer>;\\
  12697. \<path>\bb|intersectionpoint|\cr|intersectiontimes|\ee\<path>; \
  12698. \bb|max|\cr|min|\ee|(|\<pairs>|)|;\\
  12699. \raise3pt\hbox{\strut}%
  12700. |penoffset| \<pair> |of| \<pen>; \
  12701. |directionpoint| \<pair> |of| \<path>.
  12702. \medbreak\textindent\bull {\it ^{Path} things:\/} \
  12703. |quartercircle|, |halfcircle|, |fullcircle|;\\
  12704. |unitsquare|; \
  12705. |flex(|\<pairs>|)|; \
  12706. |makepath| \<pen>;\\
  12707. |superellipse(|\<pair>|,|\<pair>|,|\<pair>|,|\<pair>|,|\<numeric>|)|;\\
  12708. |reverse| \<path>; \
  12709. |counterclockwise| \<path>; \
  12710. |tensepath| \<path>;\\
  12711. \<path>\<transformer>; \
  12712. |interpath(|\<numeric>|,|\<path>|,|\<path>|)|;\\
  12713. \bb\<pair>\cr\<path>\ee
  12714. \bb|{|\<pair>|}|\cr|{|\<curl>|}|\cr\<empty>\ee
  12715. \bb\strut|..|\cr|...|\cr|..|\<tension>|..|\cr|..|\<controls>|..|\cr
  12716.  |--|\cr|---|\cr|&|\cr|softjoin|\ee
  12717. \bb|{|\<pair>|}|\cr|{|\<curl>|}|\cr\<empty>\ee
  12718. \bb\<pair>\cr\<path>\cr|cycle|\ee;\\
  12719. |subpath| \<pair> |of| \<path>.
  12720. \medbreak\textindent\bull {\it ^{Pen} things:\/} \
  12721. |pencircle|, |pensquare|, |penrazor|, |penspeck|;\\
  12722. |nullpen|; \ |currentpen|; \
  12723. |makepen| \<path>; \
  12724. \<pen>\<transformer>.
  12725. \medbreak\textindent\bull {\it ^{Picture} things:\/} \
  12726. |nullpicture|, |blankpicture|; \ |unitpixel|;\\
  12727. |currentpicture|; \
  12728. \bb|+|\cr|-|\ee\<picture>; \
  12729. \<picture>\bb|+|\cr|-|\ee\<picture>;\\
  12730. \<picture>\<transformer>.
  12731. \medbreak\textindent\bull {\it ^{String} things:\/} \
  12732. |"constant"|; \ |ditto|; \ |jobname|; \ |readstring|;\\
  12733. |str|\<suffix>; \
  12734. |decimal| \<numeric>; \
  12735. |char| \<numeric>;\\
  12736. \<string> |&| \<string>; \
  12737. \bb|max|\cr|min|\ee|(|\<strings>|)|; \
  12738. |substring| \<pair> |of| \<string>.
  12739. \medbreak\textindent\bull {\it ^{Transform} things:\/} \
  12740. |identity|; \ |currenttransform|;\\
  12741. |inverse| \<transform>; \
  12742. \<transform>\<transformer>.
  12743. \advance\lineskip by 4pt
  12744. \advance\medskipamount by 4pt
  12745. \medbreak\textindent\bull {\it ^{Transformers}:\/} \
  12746. |transformed| \<transform>;\\
  12747. \bb|rotated|\cr|slanted|\ee\<numeric>; \
  12748. \bb|scaled|\cr|xscaled|\cr|yscaled|\ee\<numeric>; \
  12749. \bb|shifted|\cr|zscaled|\ee\<pair>;\\
  12750. |reflectedabout(|\<pair>|,|\<pair>|)|; \
  12751. |rotatedaround(|\<pair>|,|\<numeric>|)|.
  12752. \medbreak\textindent\bull {\it ^{Conditions}:\/}\\
  12753. |if| \<boolean>|: |\<text> \bb|elseif|\<boolean>|: |\<text>\ee$^{\ge0}$%
  12754. \bb|else:| \<text>\cr\<empty>\ee|fi|.
  12755. \smallbreak\textindent\bull {\it ^{Loops}:\/} \ |forever:|\<text> |endfor|;\\
  12756. |for| $\nu$ \bb|=|\cr|:=|\ee
  12757. \bb\<numeric> |upto| \<numeric>\cr
  12758.  \<numeric> |downto| \<numeric>\cr
  12759.  \<numeric>\thinspace|step|\thinspace
  12760.   \<numeric>\thinspace|until|\thinspace\<numeric>\ee
  12761. |:| \<text$(\nu)$> |endfor|;\\
  12762. |for| $\epsilon$ \bb|=|\cr|:=|\ee
  12763.  \<expressions>|:| \<text$(\epsilon)$> |endfor|;\\
  12764. |forsuffixes| $\sigma$ \bb|=|\cr|:=|\ee
  12765.  \<suffixes>|:| \<text$(\sigma)$> |endfor|;\\
  12766. |exitif| \<boolean>|;| ; \quad
  12767. |exitunless| \<boolean>|;| .
  12768. \medbreak\textindent\bull {\it ^{Diagnostic things}:\/} \
  12769. |???|; \ |interact|; \
  12770. |hide(|\<statements>|)|;\\
  12771. |loggingall|, |tracingall|, |tracingnone|.
  12772. \textindent\bull {\it ^{Starting a job}:\/} \
  12773. |\mode=|\<modename>; \ |mag=|\bb\<numeric>\cr|magstep|\<numeric>\ee;\\
  12774. |screenchars|; \ |screenstrokes|; \ |imagerules|; \ |gfcorners|; \
  12775. |nodisplays|;\\
  12776. |notransforms|; \ |input| \<filename>.
  12777. \medbreak\textindent\bull {\it ^{Conversion to pixel units}:\/} \
  12778. |mode_setup|; \ |fix_units|;\\
  12779. |pixels_per_inch|, |blacker|, |fillin|, |o_correction|;\\
  12780. |mm#|, |cm#|, |pt#|, |pc#|, |dd#|, |cc#|, |bp#|, |in#|;\\
  12781. |mm|, |cm|, |pt|, |pc|, |dd|, |cc|, |bp|, |in|;\\
  12782. |mode_def|; \ |extra_setup|;\\
  12783. \bb|define_pixels|\cr
  12784. |define_whole_pixels|\cr
  12785. |define_whole_vertical_pixels|\cr
  12786. |define_good_x_pixels|\cr
  12787. |define_good_y_pixels|\cr
  12788. |define_blacker_pixels|\cr
  12789. |define_whole_blacker_pixels|\cr
  12790. |define_whole_vertical_blacker_pixels|\cr
  12791. |define_corrected_pixels|\cr
  12792. |define_horizontal_corrected_pixels|\ee|(|\<names>|)|.
  12793. \advance\lineskip by-4pt
  12794. \advance\medskipamount by-4pt
  12795. \medbreak\textindent\bull {\it Character and font administration:\/}\\
  12796. |beginchar(|\<code>|,|\<width$\0$>|,|\<height$\0$>|,|\<depth$\0$>|)|; \ \
  12797. |extra_beginchar|;\\
  12798. |italcorr| \<numeric$\0$>; \ |change_width|; \ |endchar|; \ \
  12799. |extra_endchar|;\\
  12800. \bb|font_size|\cr|font_slant|\cr|font_normal_space|\cr
  12801.  |font_normal_stretch|\cr|font_normal_shrink|\cr|font_x_height|\cr
  12802.  |font_quad|\cr|font_extra_space|\ee
  12803. \bb|=|\cr\noalign{\kern-2pt}|:=|\cr\noalign{\kern-2pt}\<empty>\ee
  12804. \<numeric$\0$>; \
  12805. \bb|ligtable|\<ligs/kerns>\cr|charlist|\<codes>\cr|extensible|\<codes>\cr
  12806.  |fontdimen|\<info>\cr|headerbytes|\<info>\ee;\\
  12807. \bb|font_identifier|\cr|font_coding_scheme|\ee
  12808. \smash{\bb\tt=\cr\noalign{\kern-2pt}\tt:=\cr\noalign{\kern-2pt}\<empty>\ee}%
  12809. \<string>.
  12810. \medbreak\textindent\bull {\it ^{Drawing}:\/} \
  12811. |penpos|\<suffix>|(|\<length>|,|\<angle>|)|; \
  12812. |penstroke| \<path($e$)>;\\
  12813. |pickup|\bb\<pen>\cr\<saved pen number>\ee; \
  12814. \<pen number>|:=savepen|; \ |clear_pen_memory|;\\
  12815. \lower6pt\null|pen_lft|, |pen_rt|, |pen_top|, |pen_bot|;\\
  12816. \bb|fill|\cr|unfill|\cr|filldraw|\cr|unfilldraw|\ee\<cycle>; \
  12817. \bb|draw|\cr|undraw|\cr|cutdraw|\ee\<path>; \
  12818. \bb|drawdot|\cr|undrawdot|\ee\<pair>;\\
  12819. \vbox to 10pt{}|erase| \<picture command>; \
  12820. |cutoff(|\<pair>|,|\<angle>|)|;\\
  12821. |addto| \<picture variable> |also| \<picture>;\\
  12822. |addto| \<picture variable>\bb|contour| \<cycle>\cr|doublepath| \<path>\ee
  12823.  $\hbox{\bb|withpen|\<pen>\cr|withweight|\<numeric>\ee}^
  12824.  {\smash{\lower3pt\hbox{$\scriptstyle\ge0$}}}\!$;\\
  12825. |cull| \<picture variable>\bb|keeping|\cr|dropping|\ee\<pair>%
  12826.  \bb|withweight|\<numeric>\cr\<empty>\ee.
  12827. \medbreak\textindent\bull {\it ^{Screen display}:\/} \
  12828. |currentwindow|; \
  12829. |screen_rows|, |screen_cols|;\\
  12830. |openwindow| \<numeric> |from| \<screen pair> |to| \<screen pair>
  12831.  |at| \<pair>;\\
  12832. |display| \<picture variable> |inwindow| \<numeric>.
  12833. \advance\lineskip by 4pt
  12834. \advance\medskipamount by 2pt
  12835. \medbreak\textindent\bull {\it ^{Statements}:\/} \
  12836. \<empty>; \ \<string>; \ |begingroup| \<statements> |endgroup|;\\
  12837. \bb\<boolean>\cr\<numeric>\cr\<pair>\cr\<path>\cr
  12838.  \<pen>\cr\<picture>\cr\<string>\cr\<transform>\ee
  12839. $\hbox{\bb\bb|=|\cr|:=|\ee
  12840.  \bb\<boolean>\cr\<numeric>\cr\<pair>\cr\<path>\cr
  12841.   \<pen>\cr\<picture>\cr\<string>\cr\<transform>\ee\ee}^
  12842.  {\smash{\lower6pt\hbox{$\scriptstyle\ge1$}}}\!\!$; \qquad
  12843. \bb|boolean|\cr|numeric|\cr|pair|\cr|path|\cr
  12844. |pen|\cr|picture|\cr|string|\cr\thinspace|transform|\thinspace\ee\<names>;\\
  12845. |save| \<names>; \
  12846. |interim| \<internal> |:=| \<numeric>; \
  12847. |let| \<name>\bb|=|\cr|:=|\ee\<name>;\\
  12848. \bb|def|\cr|vardef|\ee\<name>\<parameters>\bb|=|\cr|:=|\ee
  12849.  \<text>\thinspace|enddef|;\\
  12850. \vbox to24pt{}\bb|primarydef|\cr|secondarydef|\cr|tertiarydef|\ee
  12851.   \ $\alpha$ \<name> $\beta$ \bb|=|\cr|:=|\ee
  12852.  \<text$(\alpha,\beta)$>\thinspace|enddef|;\\
  12853. \strut|showit|; \ |shipit|; \ |cullit|; \ |openit|; \
  12854. |clearit|; \ |clearxy|; \ |clearpen|;\\
  12855. |stop| \<string>; \
  12856. |show| \<expressions>; \
  12857. \bb|message|\cr|errmessage|\cr|errhelp|\ee\<string>;\\
  12858. \bb|showvariable|\cr|showtoken|\ee\<names>; \
  12859. \bb|showdependencies|\cr|showstats|\ee;\\
  12860. \strut see also Chapter 26 for some more exotic commands.
  12861. \advance\lineskip by -1pt
  12862. \advance\medskipamount by 1pt
  12863. \medbreak\textindent\bull {\it ^{Proofsheet} information:\/}\\
  12864. \bb|labels|\cr|penlabels|\ee
  12865.  \bb|top|\cr|lft|\cr|rt|\cr|bot|\cr\<empty>\ee
  12866.  \bb|nodot|\cr\<empty>\ee
  12867.  |(|\<suffixes>|)|;\\
  12868. |makelabel|\bb|top|\cr|lft|\cr|rt|\cr|bot|\cr\<empty>\ee
  12869.  \bb|nodot|\cr\<empty>\ee
  12870.  |(|\<string>|,|\<pair>|)|; \
  12871. \bb|titlefont|\cr|labelfont|\cr|grayfont|\cr|slantfont|\ee \<name>;\\
  12872. \bb|proofrule|\cr|screenrule|\ee|(|\<pair>|,|\<pair>|)|; \
  12873. |makegrid(|\<pairs>|)(|\<pairs>|)|;\\
  12874. |proofrulethickness| \<numeric>; \ |proofoffset| \<pair>.
  12875. \medbreak\textindent\bull {\it Hacks:\/} \ |gobble|, |gobbled|; \
  12876. |capsule_def|; \ |numtok|.
  12877. \medbreak
  12878. \endgroup % end of special \lineskip
  12879. \ninepoint
  12880. \danger The remainder of this appendix contains an edited transcript
  12881. of the ``plain ^{base file},'' which is a set of macros that come with
  12882. normal implementations of \MF\!\null. These macros serve three basic purposes:
  12883. \ (1)~They make \MF\ usable, because \MF's primitive capabilities
  12884. operate at a very low level. A~``virgin'' \MF\ system that has no
  12885. macros is like a newborn baby that has an immense amount to learn about
  12886. the real world; but it is capable of learning fast. \ (2)~The plain
  12887. \MF\ macros provide a basis for more elaborate and powerful bases
  12888. tailored to individual tastes and applications. You can do a lot with
  12889. plain \MF\!, but pretty soon you'll want to do even more. \ (3)~The macros
  12890. also serve to illustrate how additional bases can be designed. \enddanger
  12891. Somewhere in your computer system you should be able to find a file called
  12892. ^|plain.mf| that contains what has been preloaded into the
  12893. running \MF\ system that you use. That file should match the
  12894. code discussed below, except that it might do some things in an
  12895. equivalent but slightly more efficient manner.
  12896. When we come to macros whose use has not yet been explained---for
  12897. example, somehow |softjoin| and |stop| never made it
  12898. into Chapters 1 through~27---we shall consider them from a user's
  12899. viewpoint. But most of the comments that follow are addressed to a
  12900. potential base-file designer.
  12901. A special program called ^|INIMF| is used to install \MF; |INIMF| is
  12902. just like \MF\ except that it is able to `^@dump@' a base file
  12903. suitable for preloading. This operation requires additional program
  12904. space, so |INIMF| generally has less memory available
  12905. than you would expect to find in a production version of \MF\!.
  12906. \subsection Getting started. A base file has to have a ^@delimiters@
  12907. command near the beginning, since |INIMF| doesn't have any delimiters
  12908. built~in.  The first few lines usually also give the base file a name and
  12909. version number as shown here.
  12910. \beginlines
  12911. |% This is the plain METAFONT base that's described in The METAFONTbook.|
  12912. |% N.B.: Please change "base_version" whenever this file is modified!|
  12913. |% And don't modify the file under any circumstances.|
  12914. |string base_name, base_version; base_name="plain"; base_version="2.7";|
  12915. \smallskip
  12916. ^|message|| "Preloading the plain base, version " & base_version;|
  12917. \smallskip
  12918. |delimiters (); % this makes parentheses behave like parentheses|
  12919. \endlines
  12920. Next we define some of the simplest macros, which provide ``syntactic sugar''
  12921. for commonly occurring idioms. ^^{blash blash}
  12922. For example, `@stop@ |"hello"|' displays `|hello|' on the terminal and waits
  12923. until \<return> is typed.
  12924. \beginlines
  12925. |def |^|upto|| = step 1 until enddef;  def |^|downto|| = step -1 until enddef;|
  12926. |def |^|exitunless|| expr c = exitif not c enddef;|
  12927. |let |^|relax|| = \;               % ignore the word `relax', as in TeX|
  12928. |let \\ = \;                  % double relaxation is like single|
  12929. |def |^|]]|| = ] ] enddef;         % right brackets should be loners|
  12930. |def |^|--|| = {curl 1}..{curl 1} enddef;|
  12931. |def |^|---|| = .. tension infinity .. enddef;|
  12932. |def |^|...|| = .. tension atleast 1 .. enddef;|
  12933. \smallskip
  12934. |def |^|gobble|| primary g = enddef;|
  12935. |primarydef g |^|gobbled|| gg = enddef;|
  12936. |def |^|hide||(text t) = exitif numeric begingroup t; endgroup; enddef;|
  12937. |def |^|???|| = hide(interim showstopping:=1; showdependencies) enddef;|
  12938. |def |^|stop|| expr s = message s; gobble readstring enddef;|
  12939. \endlines
  12940. (Chapter 20 points out that `|\|' is an expandable token that expands
  12941. into nothing. Plain \MF\ allows also `|\\|', because there's a
  12942. formatting program called ^|MFT| that uses~|\\| to insert extra spacing
  12943. in a ^{pretty-printed} listing.) \ The ``clever'' code for @hide@
  12944. is based on the fact that a ^{vacuous} expression is not numeric;
  12945. hence no loop is exited, ^^@exitif@ and the computer doesn't mind the
  12946. fact that we may not be in a loop at all.
  12947. The values of ^{internal quantities} are next on the agenda:
  12948. \beginlines
  12949. ^|smoothing||:=1; |^|autorounding||:=2;  % this adjusts curves to the raster|
  12950. ^|turningcheck||:=2;                % this will warn about a "strange path"|
  12951. ^|granularity||:=1;                 % this says that pixels are pixels|
  12952. \smallskip
  12953. |def |^|interact|| =                  % prepares to make "show" commands stop|
  12954. | hide(showstopping:=1; tracingonline:=1) enddef;|
  12955. |def |^|loggingall|| =                % puts tracing info into the log|
  12956. | tracingcommands:=3; tracingedges:=2; tracingtitles:=1;|
  12957. | tracingequations:=1; tracingcapsules:=1; tracingspecs:=1;|
  12958. | tracingpens:=1; tracingchoices:=1; tracingstats:=1;|
  12959. | tracingoutput:=1; tracingmacros:=1; tracingrestores:=1;|
  12960. | enddef;|
  12961. |def |^|tracingall|| =                % turns on every form of tracing|
  12962. | tracingonline:=1; showstopping:=1; loggingall enddef;|
  12963. |def |^|tracingnone|| =               % turns off every form of tracing|
  12964. | tracingcommands:=0; tracingonline:=0; showstopping:=0;|
  12965. | tracingedges:=0; tracingtitles:=0; tracingequations:=0;|
  12966. | tracingcapsules:=0; tracingspecs:=0; tracingpens:=0;|
  12967. | tracingchoices:=0; tracingstats:=0; tracingoutput:=0;|
  12968. | tracingmacros:=0; tracingrestores:=0; enddef;|
  12969. \endlines
  12970. The user can say @interact@ in the midst of a statement; but
  12971. @loggingall@, @tracingall@, and @tracingnone@ should come
  12972. between statements. \ (You don't need a ^{semicolon} after them,
  12973. because they come equipped with their own closing `|;|'.)
  12974. \subsection Math routines. The second major part of |plain.mf|
  12975. contains the definitions of basic constants and mathematical
  12976. macros that extend the primitive capabilities of \MF's expressions.
  12977. \beginlines
  12978. |% numeric constants|
  12979. |newinternal eps,epsilon,infinity;|
  12980. ^|eps|| := .00049;                  % this is a pretty small positive number|
  12981. ^|epsilon|| := 1/256/256;           % but this is the smallest|
  12982. ^|infinity|| := 4095.99998;         % and this is the largest|
  12983. \smallbreak
  12984. |% pair constants|
  12985. |pair right,left,up,down,origin;|
  12986. ^|origin||=(0,0); |^|up||=-|^|down||=(0,1); |^|right||=-|^|left||=(1,0);|
  12987. \smallbreak
  12988. |% path constants|
  12989. |path quartercircle,halfcircle,fullcircle,unitsquare;|
  12990. ^|quartercircle||=(right{up}..(right+up)/sqrt2..up{left}) scaled .5;|
  12991. ^|halfcircle||=quartercircle & quartercircle rotated 90;|
  12992. ^|fullcircle||=halfcircle & halfcircle rotated 180 & cycle;|
  12993. ^|unitsquare||=(0,0)--(1,0)--(1,1)--(0,1)--cycle;|
  12994. \smallbreak
  12995. |% transform constants|
  12996. |transform identity;|
  12997. |for z=origin,right,up: z transformed |^|identity|| = z; endfor|
  12998. \smallbreak
  12999. |% picture constants|
  13000. |picture blankpicture,unitpixel;|
  13001. ^|blankpicture||=nullpicture;       % `display blankpicture...'|
  13002. ^|unitpixel||=nullpicture; addto unitpixel contour unitsquare;|
  13003. \smallbreak
  13004. |% string constants|
  13005. |string ditto; |^|ditto|| = char 34;  % ASCII double-quote mark|
  13006. \smallbreak
  13007. |% pen constants|
  13008. |def capsule_def(suffix s) primary u = def s = u enddef enddef;|
  13009. |capsule_def(pensquare) makepen(unitsquare shifted -(.5,.5));|
  13010. |capsule_def(penrazor) makepen((-.5,0)--(.5,0)--cycle);|
  13011. |pen penspeck; penspeck=pensquare scaled eps;|
  13012. \endlines
  13013. The ^@pensquare@ and ^@penrazor@ constants are defined here in a
  13014. surprisingly roundabout way, just so that they can be ^{future pens}
  13015. instead of pens. \MF\ can transform a future pen much faster than a
  13016. pen, since pens have a complex internal data structure, so this
  13017. trick saves time. But how does it work? Well, a variable cannot
  13018. be a future pen, but a ^{capsule} can; hence @pensquare@ and @penrazor@
  13019. are defined, via ^@capsule\_def@, to be macros that expand into single capsules.
  13020. Incidentally, ^@penspeck@ is an extremely tiny little pen that is used by the
  13021. @drawdot@ macro. Since it is not intended to be transformed,
  13022. we are better off making it a pen; then it's immediately ready for use.
  13023. Now that the basic constants have been defined, we turn to
  13024. mathematical operations. There's one operation that has no arguments:
  13025. \beginlines
  13026. |% nullary operators|
  13027. |vardef |^|whatever|| = save ?; ? enddef;|
  13028. \endlines
  13029. The reasoning behind this is discussed in exercise 17.\Xwhat.
  13030. Operations that take one argument are introduced next.
  13031. \beginlines
  13032. |% unary operators|
  13033. |let |^|abs|| = length;|
  13034. \smallskip
  13035. |vardef |^|round|| primary u =|
  13036. | if numeric u: floor(u+.5)|
  13037. | elseif pair u: (hround xpart u, vround ypart u)|
  13038. | else: u fi enddef;|
  13039. \smallskip
  13040. |vardef |^|hround|| primary x = floor(x+.5) enddef;|
  13041. |vardef |^|vround|| primary y = floor(y.o_+.5)_o_ enddef;|
  13042. \smallskip
  13043. |vardef |^|ceiling|| primary x = -floor(-x) enddef;|
  13044. \smallbreak
  13045. |vardef |^|byte|| primary s = if string s: ASCII fi s enddef;|
  13046. \smallbreak
  13047. |vardef |^|dir|| primary d = right rotated d enddef;|
  13048. \smallskip
  13049. |vardef |^|unitvector|| primary z = z/abs z enddef;|
  13050. \smallbreak
  13051. |vardef |^|inverse|| primary T =|
  13052. | transform T_; T_ transformed T = identity; T_ enddef;|
  13053. \smallbreak
  13054. |vardef |^|counterclockwise|| primary c =|
  13055. | if turningcheck>0:|
  13056. |  interim |^|autorounding||:=0;|
  13057. |  if |^|turningnumber|| c <= 0: reverse fi fi c enddef;|
  13058. \smallbreak
  13059. |vardef |^|tensepath|| expr r =|
  13060. | for k=0 upto length r - 1: point k of r --- endfor|
  13061. | if cycle r: cycle else: point infinity of r fi enddef;|
  13062. \endlines
  13063. Notice that the variable `|T_|' was not saved by the "inverse"
  13064. function. The plain base routines gain ^{efficiency} by
  13065. using ``^{private}'' tokens that are assumed to be distinct
  13066. from any of the user's tokens; these private tokens always
  13067. end with the ^{underscore} character,~`|_|'. If ordinary user programs
  13068. never contain such token names, no surprises will occur,
  13069. provided that different macro designers who combine their routines are
  13070. careful that their private names are not in conflict.
  13071. The private tokens `|o_|' and `|_o_|' used in |vround| stand
  13072. for `|*aspect_ratio|' and `|/aspect_ratio|', respectively,
  13073. as we shall see shortly.
  13074. Now we define `mod' and `div', being careful to do this in such a way that
  13075. the identities $a(x\;\hbox{mod}\;y)=(ax)\;\hbox{mod}\;(ay)$ and
  13076. $(ax)\;\hbox{div}\;(ay)=x\;\hbox{div}\;y$ are valid.
  13077. \beginlines
  13078. |% binary operators|
  13079. |primarydef x |^|mod|| y = (x-y*floor(x/y)) enddef;|
  13080. |primarydef x |^|div|| y = floor(x/y) enddef;|
  13081. |primarydef w |^|dotprod|| z = (xpart w * xpart z + ypart w * ypart z) enddef;|
  13082. \endlines
  13083. The `|**|' operator is designed to be most efficient when it's used
  13084. for squaring. A separate `^|takepower|' routine is used for exponents
  13085. other than~2, so that \MF\ doesn't have to skip over lots of tokens
  13086. in the common case. The |takepower| routine is careful to give the
  13087. correct answer in expressions like `|(-2)**(-3)|' and `|0**0|'.
  13088. \beginlines
  13089. |primarydef x |^|**|| y = if y=2: x*x else: takepower y of x fi enddef;|
  13090. |def takepower expr y of x =|
  13091. | if x>0: mexp(y*mlog x)|
  13092. | elseif (x=0) and (y>0): 0|
  13093. | else: 1|
  13094. |  if y=floor y:|
  13095. |   if y>=0: for n=1 upto y: *x endfor|
  13096. |   else: for n=-1 downto y: /x endfor fi|
  13097. |  else: hide(errmessage "Undefined power: " & decimal x&"**"&decimal y)|
  13098. |  fi fi enddef;|
  13099. \endlines
  13100. \MF's primitive path operations have been defined in such a way that the
  13101. following higher-level operations are easy:
  13102. \beginlines
  13103. |vardef |^|direction|| expr t of p =|
  13104. | postcontrol t of p - precontrol t of p enddef;|
  13105. \smallskip
  13106. |vardef |^|directionpoint|| expr z of p =|
  13107. | a_:=|^|directiontime|| z of p;|
  13108. | if a_<0: errmessage("The direction doesn't occur"); fi|
  13109. | point a_ of p enddef;|
  13110. \smallskip
  13111. |secondarydef p |^|intersectionpoint|| q =|
  13112. | begingroup save x_,y_; (x_,y_)=p |^|intersectiontimes|| q;|
  13113. | if x_<0: errmessage("The paths don't intersect"); (0,0)|
  13114. | else: .5[point x_ of p, point y_ of q] fi endgroup|
  13115. |enddef;|
  13116. \weakendlines
  13117. The private token `|a_|' will be declared as an ^{internal quantity}.
  13118. Internal quantities are more ^{efficient} than ordinary numeric variables.
  13119. Plain \MF's `^{softjoin}' operation provides a way to hook paths together
  13120. without the abrupt change of direction implied by~`|&|'. Assuming that
  13121. the final point of~$p$ is the first point of~$q$, the path `$p$~softjoin~$q$'
  13122. begins on~$p$ until coming within "join\_radius" of this common point;
  13123. then it curves over and finishes~$q$ in essentially the same way.
  13124. The internal quantity ^"join\_radius" should be set to the desired
  13125. value before softjoin is applied. \ (This routine is due to N.~N. ^{Billawala}.)
  13126. \beginlines
  13127. |tertiarydef p softjoin q =|
  13128. | begingroup c_:=|^|fullcircle|| scaled 2join_radius shifted point 0 of q;|
  13129. | a_:=ypart(c_ intersectiontimes p); b_:=ypart(c_ intersectiontimes q);|
  13130. | if a_<0:point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi|
  13131. |  ... if b_<0:{direction infinity of q}point infinity of q|
  13132. |   else: subpath(b_,infinity) of q fi endgroup enddef;|
  13133. |newinternal join_radius,a_,b_; path c_;|
  13134. \endlines
  13135. The remaining math operators don't fall into the ordinary patterns; something
  13136. is unusual about each of them. First we have `|incr|' and `|decr|', which apply
  13137. only to variables; they have the side effect of changing the variable's value.
  13138. \beginlines
  13139. % special operators
  13140. |vardef |^|incr|| suffix $ = $:=$+1; $ enddef;|
  13141. |vardef |^|decr|| suffix $ = $:=$-1; $ enddef;|
  13142. \weakendlines
  13143. You can say either `|incr|~|x|' or `|incr|~|(x)|', within
  13144. an expression; but `|incr|~|x|' by itself is not a valid statement.
  13145. To reflect about a line, we compute a ^{transform} on the fly:
  13146. \beginlines
  13147. |def |^|reflectedabout||(expr w,z) =    % reflects about the line w..z|
  13148. | transformed|
  13149. |  begingroup transform T_;|
  13150. |  w transformed T_ = w;  z transformed T_ = z;|
  13151. |  xxpart T_ = -yypart T_; xypart T_ = yxpart T_; % T_ is a reflection|
  13152. |  T_ endgroup enddef;|
  13153. \smallskip
  13154. |def |^|rotatedaround||(expr z, d) =    % rotates d degrees around z|
  13155. | shifted -z rotated d shifted z enddef;|
  13156. |let |^|rotatedabout|| = rotatedaround;   % for roundabout people|
  13157. \endlines
  13158. Now we come to an interesting trick: The user writes something like
  13159. `min$(a,b)$' or `max$(a,b,c,d)$', and
  13160. \MF's notation for macro calls makes it easy to separate the first argument
  13161. from the rest---assuming that at least two arguments are present.
  13162. \beginlines
  13163. |vardef |^|max||(expr u)(text t) = % t is a list of numerics, pairs, or strings|
  13164. | save u_; setu_ u; for uu = t: if uu>u_: u_:=uu; fi endfor|
  13165. | u_ enddef;|
  13166. \smallskip
  13167. |vardef |^|min||(expr u)(text t) = % t is a list of numerics, pairs, or strings|
  13168. | save u_; setu_ u; for uu = t: if uu<u_: u_:=uu; fi endfor|
  13169. | u_ enddef;|
  13170. \smallskip
  13171. |def setu_ primary u =|
  13172. | if pair u: pair u_ elseif string u: string u_ fi;|
  13173. | u_=u enddef;|
  13174. \weakendlines
  13175. ^^"setu\_" Appendix D discusses some variations on this theme.
  13176. The ^|flex| routine defines part of a path whose directions at the
  13177. endpoints will depend on the environment, because this path is not
  13178. enclosed in parentheses.
  13179. \beginlines
  13180. |def flex(text t) =           % t is a list of pairs|
  13181. | hide(n_:=0; for z=t: z_[incr n_]:=z; endfor|
  13182. |  dz_:=z_[n_]-z_1)|
  13183. | z_1 for k=2 upto n_-1: ...z_[k]{dz_} endfor ...z_[n_] enddef;|
  13184. |newinternal n_; pair z_[],dz_;|
  13185. \endlines
  13186. The five parameters to `superellipse' are the right, the top, the left,
  13187. the bottom, and the superness.
  13188. \beginlines
  13189. |def |^|superellipse||(expr r,t,l,b,s)=|
  13190. | r{up}...(s[xpart t,xpart r],s[ypart r,ypart t]){t-r}...|
  13191. | t{left}...(s[xpart t,xpart l],s[ypart l,ypart t]){l-t}...|
  13192. | l{down}...(s[xpart b,xpart l],s[ypart l,ypart b]){b-l}...|
  13193. | b{right}...(s[xpart b,xpart r],s[ypart r,ypart b]){r-b}...cycle enddef;|
  13194. \endlines
  13195. Chapter~14 illustrates the `interpath' routine, which interpolates
  13196. between paths to find a path that would be written `$a[p,q]$' if
  13197. \MF's macro notation were more general.
  13198. \beginlines
  13199. |vardef |^|interpath||(expr a,p,q) =|
  13200. | for t=0 upto length p-1: a[point t of p, point t of q]|
  13201. |  ..controls a[postcontrol t of p, postcontrol t of q]|
  13202. |   and a[precontrol t+1 of p, precontrol t+1 of q] .. endfor|
  13203. | if cycle p: cycle|
  13204. | else: a[point infinity of p, point infinity of q] fi enddef;|
  13205. \endlines
  13206. Finally we come to the "solve" macro, which has already been presented
  13207. in Chapter~20. Appendix~D gives further illustrations of its use.
  13208. \beginlines
  13209. |vardef |^|solve||@#(expr true_x,false_x)= % @#(true_x)=true, @#(false_x)=false|
  13210. | tx_:=true_x; fx_:=false_x;|
  13211. | forever: x_:=.5[tx_,fx_]; exitif abs(tx_-fx_)<=tolerance;|
  13212. | if @#(x_): tx_ else: fx_ fi :=x_; endfor|
  13213. | x_ enddef; % now x_ is near where @# changes from true to false|
  13214. |newinternal |^|tolerance||, tx_,fx_,x_; tolerance:=.1;|
  13215. \finalendlines
  13216. \subsection Conversion to pixels. The next main subdivision of |plain.mf|
  13217. contains macros and constants that help convert dimensions from
  13218. device-independent ``sharped'' or ``true'' units into the pixel units
  13219. corresponding to a particular device. First comes a subroutine that
  13220. computes eight basic units, assuming that the number
  13221. ^^{mm} ^^{cm} ^^{pt} ^^{pc} ^^{dd} ^^{cc} ^^{bp} ^^{in} ^^@fix\_units@
  13222. of ^"pixels\_per\_inch" is known:
  13223. \beginlines
  13224. |def fix_units =   % define the conversion factors, given pixels_per_inch|
  13225. | mm:=pixels_per_inch/25.4;      cm:=pixels_per_inch/2.54;|
  13226. | pt:=pixels_per_inch/72.27;     pc:=pixels_per_inch/6.0225;|
  13227. | dd:=1238/1157pt;               cc:=12dd;|
  13228. | bp:=pixels_per_inch/72;        in:=pixels_per_inch;|
  13229. | hppp:=pt;                      % horizontal pixels per point|
  13230. | vppp:=aspect_ratio*hppp;       % vertical pixels per point|
  13231. | enddef;|
  13232. \endlines
  13233. ^{Sharped units} are actually expressed in terms of points, but a virtuous
  13234. user will not write programs that exploit this fact.
  13235. \beginlines
  13236. |mm#=2.84528;      pt#=1;        dd#=1.07001;      bp#:=1.00375;|
  13237. |cm#=28.45276;     pc#=12;       cc#=12.84010;     in#:=72.27;|
  13238. \endlines
  13239. A particular device is supposed to be modeled by four parameters, called
  13240. ^"pixels\_per\_inch", ^"blacker", ^"o\_correction", and ^"fillin", as discussed
  13241. in Chapter~11. Appropriate
  13242. values will be assigned to these internal quantities by @mode\_setup@.
  13243. \beginlines
  13244. |newinternal pixels_per_inch;       % the given resolution|
  13245. |newinternal blacker, o_correction; % device-oriented corrections|
  13246. \endlines
  13247. (The fourth parameter, "fillin", is already an internal quantity of \MF\!.)
  13248. Here are the ten principal ways to convert from
  13249. ^^{define\_pixels (and nine others)} sharped units to pixels:
  13250. \beginlines
  13251. |def define_pixels(text t) =|
  13252. | forsuffixes $=t: $:=$.#*hppp; endfor enddef;|
  13253. |def define_whole_pixels(text t) =|
  13254. | forsuffixes $=t: $:=hround($.#*hppp); endfor enddef;|
  13255. |def define_whole_vertical_pixels(text t) =|
  13256. | forsuffixes $=t: $:=vround($.#*hppp); endfor enddef;|
  13257. |def define_good_x_pixels(text t) =|
  13258. | forsuffixes $=t: $:=good.x($.#*hppp); endfor enddef;|
  13259. |def define_good_y_pixels(text t) =|
  13260. | forsuffixes $=t: $:=good.y($.#*hppp); endfor enddef;|
  13261. |def define_blacker_pixels(text t) =|
  13262. | forsuffixes $=t: $:=$.#*hppp+blacker; endfor enddef;|
  13263. |def define_whole_blacker_pixels(text t) =|
  13264. | forsuffixes $=t: $:=hround($.#*hppp+blacker);|
  13265. |  if $<=0: $:=1; fi endfor enddef;|
  13266. |def define_whole_vertical_blacker_pixels(text t) =|
  13267. | forsuffixes $=t: $:=vround($.#*hppp+blacker);|
  13268. |  if $<=0: $:=1_o_; fi endfor enddef;|
  13269. |def define_corrected_pixels(text t) =|
  13270. | forsuffixes $=t: $:=vround($.#*hppp*o_correction)+eps; endfor enddef;|
  13271. |def define_horizontal_corrected_pixels(text t) =|
  13272. | forsuffixes $=t: $:=hround($.#*hppp*o_correction)+eps; endfor enddef;|
  13273. \endlines
  13274. Chapter 24 discusses the ^@lowres\_fix@ routine, which helps to correct
  13275. anomalies that may have occurred when sharped dimensions were rounded
  13276. to whole pixels.
  13277. \beginlines
  13278. |def lowres_fix(text t) expr ratio =|
  13279. | begingroup save min,max,first;|
  13280. | forsuffixes $=t:|
  13281. |  if unknown min: min=max=first=$; min#=max#=$.#;|
  13282. |  elseif $.#<min#: min:=$; min#:=$.#;|
  13283. |  elseif $.#>max#: max:=$; max#:=$.#; fi endfor|
  13284. | if max/min>ratio*max#/min#: forsuffixes $=t: $:=first; endfor fi|
  13285. | endgroup enddef;|
  13286. \finalendlines
  13287. \subsection Modes of operation. The standard way to create a font with
  13288. plain \MF\ is to start~up the program by saying
  13289. \begindisplay
  13290. |\mode=|\<mode name>|; mag=|\<magnification>|; input |%
  13291.  \<font file name>
  13292. \enddisplay
  13293. in response to \MF's initial `^|**|'.
  13294. The ^|mag| is omitted if the magnification is~1, and the ^|mode| is omitted
  13295. if |mode=proof|. Additional commands like `|screenchars|' might be
  13296. given before the `^|input|'; we shall discuss them later. If you are
  13297. using another base file, called say the `|super|' base, this whole
  13298. command line should be preceded by `|&super|'. The mode name should have
  13299. been predeclared in your base file, by the |mode_def| routine below.
  13300. If, however, you need a special mode that isn't in the base, you can put
  13301. its commands into a file (e.g., `|specmode.mf|') and invoke it
  13302. by saying
  13303. \begindisplay
  13304. ^|\smode||="specmode"; mag=|$\,\cdots$
  13305. \enddisplay
  13306. instead of giving a predeclared mode name.
  13307. Here is the ^@mode\_setup@ routine,
  13308. which is usually one of the first macros to be called in a \MF\ program:
  13309. \beginlines
  13310. |def mode_setup =|
  13311. | warningcheck:=0;|
  13312. | if unknown mode: mode=proof; fi|
  13313. | numeric aspect_ratio; transform currenttransform;|
  13314. | scantokens if string mode:("input "&mode) else: mode_name[mode] fi;|
  13315. | if unknown mag: mag=1; fi|
  13316. | if unknown aspect_ratio: aspect_ratio=1; fi|
  13317. | displaying:=proofing;|
  13318. | pixels_per_inch:=pixels_per_inch*mag;|
  13319. | if aspect_ratio=1: let o_=\; let _o_=\|
  13320. | else: def o_=*aspect_ratio enddef; def _o_=/aspect_ratio enddef fi;|
  13321. | fix_units;|
  13322. | scantokens extra_setup; % the user's special last-minute adjustments|
  13323. | currenttransform:=|
  13324. |  if unknown currenttransform: identity else: currenttransform fi|
  13325. |   yscaled aspect_ratio;|
  13326. | clearit;|
  13327. | pickup pencircle scaled (.4pt+blacker);|
  13328. | warningcheck:=1; enddef;|
  13329. |def |^|smode|| = string mode; mode enddef;|
  13330. |string extra_setup, mode_name[];|
  13331. |extra_setup="";          % usually there's nothing special to do|
  13332. |newinternal |^|displaying||;  % if positive, endchar will `showit'|
  13333. \endlines
  13334. ^^"extra\_setup" ^^"mode\_name"
  13335. The first `^@scantokens@' in @mode\_setup@ either reads a special
  13336. file or calls a macro that expands into commands defining the mode.
  13337. Notice that "aspect\_ratio" is always cleared to an undefined value
  13338. when these commands are performed; you can't simply give a value to
  13339. "aspect\_ratio" when you set "mode" and~"mag". If the aspect ratio
  13340. isn't assigned a definite value by the mode routine, it will become unity,
  13341. and the `|o_|' and `|_o_|' operations will be omitted from subsequent
  13342. calculations.  Notice also that the mode commands might do something special
  13343. to "mag", since "mag" isn't examined until after the mode routine has
  13344. acted. The "currenttransform" might also be given a special value. \MF's
  13345. ^"warningcheck" is temporarily disabled during these computations, since
  13346. there might be more than 4096 pixels per inch. After @mode\_setup@ is
  13347. finished, the "currentpicture" will be null, the "currenttransform"
  13348. will take the "aspect\_ratio" into account, and the "currentpen" will be a
  13349. circular nib with the standard default thickness of $0.4\pt$. \ (You should
  13350. save this pen if you want to use it in a character, because @beginchar@
  13351. will clear it away.)
  13352. Plain \TeX\ has a convention for magnifying fonts in terms of ``magsteps,''
  13353. where magstep~$m=1.2^m$. A geometric progression of font sizes is
  13354. convenient, because scaling by magstep~$m$ followed by magstep~$n$ is
  13355. ^^{mexp} equivalent to scaling by magstep~$m+n$.
  13356. \beginlines
  13357. |vardef |^|magstep|| primary m = mexp(46.67432m) enddef;|
  13358. \endlines
  13359. When a mode is defined (e.g., `|proof|'), a numeric variable of that
  13360. name is created and assigned a unique number (e.g.,~1). Then an
  13361. ^{underscore} character is appended, and a macro is defined for the
  13362. resulting name (e.g., `|proof_|'). The "mode\_name" array is used to
  13363. convert between number and name (e.g., "mode\_name"$_1=\null$|"proof_"|).
  13364. \beginlines
  13365. |def mode_def suffix $ =|
  13366. | $:=incr number_of_modes;|
  13367. | mode_name[$]:=str$ & "_";|
  13368. | |^|expandafter|| |^|quote|| def scantokens mode_name[$] enddef;|
  13369. |newinternal number_of_modes;|
  13370. \endlines
  13371. (This ^@mode\_def@ strategy was suggested by Bruce ^{Leban}.)
  13372. Three basic modes are now defined, starting with two for proofing:
  13373. \beginlines
  13374. |% proof mode: for initial design of characters|
  13375. |mode_def |^|proof|| =|
  13376. | proofing:=2;                  % yes, we're making full proofs|
  13377. | fontmaking:=0;                % no, we're not making a font|
  13378. | tracingtitles:=1;             % yes, show titles online|
  13379. | pixels_per_inch:=2601.72;     % that's 36 pixels per pt|
  13380. | blacker:=0;                   % no additional blackness|
  13381. | fillin:=0;                    % no compensation for fillin|
  13382. | o_correction:=1;              % no reduction in overshoot|
  13383. | enddef;|
  13384. \smallbreak
  13385. |% smoke mode: for label-free proofs to mount on the wall|
  13386. |mode_def |^|smoke|| =|
  13387. | proof_;                       % same as proof mode, except:|
  13388. | proofing:=1;                  % yes, we're making unlabeled proofs|
  13389. | extra_setup:=extra_setup&"grayfont black"; % with solid black pixels|
  13390. | let makebox=maketicks;        % make the boxes less obtrusive|
  13391. | enddef;|
  13392. \weakendlines
  13393. Notice that "smoke" mode saves a lot of fuss by calling on `|proof_|';
  13394. this is the macro that was defined by the first @mode\_def@.
  13395. A typical mode for font generation appears next. ^^"fontmaking"
  13396. \beginlines
  13397. |% lowres mode: for certain devices that print 200 pixels per inch|
  13398. |mode_def |^|lowres|| =|
  13399. | proofing:=0;                   % no, we're not making proofs|
  13400. | fontmaking:=1;                 % yes, we are making a font|
  13401. | tracingtitles:=0;              % no, don't show titles at all|
  13402. | pixels_per_inch:=200;          % that's pretty low resolution|
  13403. | blacker:=.65;                  % make pens a bit blacker|
  13404. | fillin:=.2;                    % compensate for diagonal fillin|
  13405. | o_correction:=.4;              % but don't overshoot as much|
  13406. | enddef;|
  13407. \smallskip
  13408. |localfont:=lowres;      % the mode most commonly used to make fonts|
  13409. \endlines
  13410. Installations of \MF\ typically have several more predefined modes, and they
  13411. generally set "localfont" to something else. Such alterations should
  13412. not be made in the master file |plain.mf|; they should appear in a separate
  13413. file, as discussed below.
  13414. \subsection Drawing and filling. Now we come to the macros that provide
  13415. an interface between the user and \MF's primitive picture commands.
  13416. ^^"currentpen" ^^"currentpicture" ^^"currenttransform"
  13417. First, some important program variables are introduced:
  13418. \beginlines
  13419. |pen currentpen;|
  13420. |path currentpen_path;|
  13421. |picture currentpicture;|
  13422. |transform currenttransform;|
  13423. |def t_ = transformed currenttransform enddef;|
  13424. \endlines
  13425. The key macros are ^@fill@, ^@draw@, ^@filldraw@, and ^@drawdot@.
  13426. \beginlines
  13427. |def fill expr c = addto_currentpicture contour c.t_ enddef;|
  13428. |def addto_currentpicture = addto currentpicture enddef;|
  13429. |def draw expr p =|
  13430. | addto_currentpicture doublepath p.t_ withpen currentpen enddef;|
  13431. |def filldraw expr c = fill counterclockwise c withpen currentpen enddef;|
  13432. |def drawdot expr z = if unknown currentpen_path: def_pen_path_ fi|
  13433. | addto_currentpicture contour|
  13434. |  currentpen_path shifted (z.t_) withpen penspeck enddef;|
  13435. |def def_pen_path_ =|
  13436. | hide(currentpen_path=tensepath makepath currentpen) enddef;|
  13437. \endlines
  13438. And they have negative counterparts:
  13439. \beginlines
  13440. |def |^|unfill|| expr c = fill c withweight -1 enddef;|
  13441. |def |^|undraw|| expr p = draw p withweight -1 enddef;|
  13442. |def |^|unfilldraw|| expr c = filldraw c withweight -1 enddef;|
  13443. |def |^|undrawdot|| expr z = drawdot z withweight -1 enddef;|
  13444. |def |^|erase|| text t = begingroup interim default_wt_:=-1;|
  13445. | cullit; t withweight -1; cullit; endgroup enddef;|
  13446. |newinternal default_wt_; default_wt_:=1;|
  13447. \endlines
  13448. It's more difficult to cut off the ends of a stroke, but the
  13449. following macros (discussed near the end of Chapter~16) do the job:
  13450. \beginlines
  13451. |def |^|cutdraw|| expr p = % caution: you may need autorounding=0|
  13452. | cutoff(point 0 of p, 180+angle direction 0 of p);|
  13453. | cutoff(point infinity of p, angle direction infinity of p);|
  13454. | draw p enddef;|
  13455. \smallbreak
  13456. |vardef |^|cutoff||(expr z,theta) =|
  13457. | interim autorounding := 0; interim smoothing := 0;|
  13458. | addto pic_ doublepath z.t_ withpen currentpen;|
  13459. | addto pic_ contour|
  13460. |  (cut_ scaled (1+max(pen_lft,pen_rt,pen_top,pen_bot))|
  13461. |   rotated theta shifted z)t_;|
  13462. | cull pic_ keeping (2,2) withweight -default_wt_;|
  13463. | addto currentpicture also pic_;|
  13464. | pic_:=nullpicture enddef;|
  13465. |picture pic_; pic_:=nullpicture;|
  13466. |path cut_; cut_ = ((0,-1)--(1,-1)--(1,1)--(0,1)--cycle) scaled 1.42;|
  13467. \weakendlines
  13468. The use of ^"default\_wt\_" here makes `^@erase@ @cutdraw@' work. The
  13469. private variable "pic\_" is usually kept equal to @nullpicture@ in
  13470. order to conserve memory space.
  13471. Picking up a pen not only sets "currentpen", it also establishes
  13472. the values of ^"pen\_lft", ^"pen\_rt", ^"pen\_top", and ^"pen\_bot",
  13473. which are used by "lft", "rt", "top", and "bot".
  13474. \beginlines
  13475. |def |^|pickup|| secondary q =|
  13476. | if numeric q: numeric_pickup_ else: pen_pickup_ fi q enddef;|
  13477. |def numeric_pickup_ primary q =|
  13478. | if unknown pen_[q]: errmessage "Unknown pen"; clearpen|
  13479. | else: currentpen:=pen_[q];|
  13480. |  pen_lft:=pen_lft_[q];|
  13481. |  pen_rt:=pen_rt_[q];|
  13482. |  pen_top:=pen_top_[q];|
  13483. |  pen_bot:=pen_bot_[q];|
  13484. |  currentpen_path:=pen_path_[q] fi; enddef;|
  13485. |def pen_pickup_ primary q =|
  13486. |  currentpen:=q yscaled aspect_ratio;|
  13487. |  pen_lft:=xpart penoffset down of currentpen;|
  13488. |  pen_rt:=xpart penoffset up of currentpen;|
  13489. |  pen_top:=(ypart penoffset left of currentpen)_o_;|
  13490. |  pen_bot:=(ypart penoffset right of currentpen)_o_;|
  13491. |  path currentpen_path; enddef;|
  13492. |newinternal pen_lft,pen_rt,pen_top,pen_bot,pen_count_;|
  13493. \endlines
  13494. And saving a pen saves all the relevant values for later retrieval.
  13495. \beginlines
  13496. |vardef |^|savepen|| = pen_[incr pen_count_]=currentpen;|
  13497. | pen_lft_[pen_count_]=pen_lft;|
  13498. | pen_rt_[pen_count_]=pen_rt;|
  13499. | pen_top_[pen_count_]=pen_top;|
  13500. | pen_bot_[pen_count_]=pen_bot;|
  13501. | pen_path_[pen_count_]=currentpen_path;|
  13502. | pen_count_ enddef;|
  13503. \smallbreak
  13504. |def |^|clearpen|| = currentpen:=nullpen;|
  13505. | pen_lft:=pen_rt:=pen_top:=pen_bot:=0;|
  13506. | path currentpen_path; enddef;|
  13507. \smallbreak
  13508. |def clear_pen_memory =|^^@clear\_pen\_memory@
  13509. | pen_count_:=0;|
  13510. | numeric pen_lft_[],pen_rt_[],pen_top_[],pen_bot_[];|
  13511. | pen currentpen,pen_[];|
  13512. | path currentpen_path, pen_path_[];|
  13513. | enddef;|
  13514. \endlines
  13515. The four basic pen-edge functions offer no surprises:
  13516. ^^"lft"^^"rt"^^"top"^^"bot"
  13517. \beginlines
  13518. |vardef lft primary x = x + if pair x: (pen_lft,0) else: pen_lft fi enddef;|
  13519. |vardef rt primary x = x + if pair x: (pen_rt,0) else: pen_rt fi enddef;|
  13520. |vardef top primary y = y + if pair y: (0,pen_top) else: pen_top fi enddef;|
  13521. |vardef bot primary y = y + if pair y: (0,pen_bot) else: pen_bot fi enddef;|
  13522. \endlines
  13523. There are six functions that ^{round} to good positions for pen placement.
  13524. \beginlines
  13525. |vardef |^|good.x|| primary x = hround(x+pen_lft)-pen_lft enddef;|
  13526. |vardef |^|good.y|| primary y = vround(y+pen_top)-pen_top enddef;|
  13527. |vardef |^|good.lft|| primary z = save z_; pair z_;|
  13528. |  (z_+(pen_lft,0))t_=round((z+(pen_lft,0))t_); z_ enddef;|
  13529. |vardef |^|good.rt|| primary z = save z_; pair z_;|
  13530. |  (z_+(pen_rt,0))t_=round((z+(pen_rt,0))t_); z_ enddef;|
  13531. |vardef |^|good.top|| primary z = save z_; pair z_;|
  13532. |  (z_+(0,pen_top))t_=round((z+(0,pen_top))t_); z_ enddef;|
  13533. |vardef |^|good.bot|| primary z = save z_; pair z_;|
  13534. |  (z_+(0,pen_bot))t_=round((z+(0,pen_bot))t_); z_ enddef;|
  13535. \endlines
  13536. So much for fixed pens. When pen-like strokes are defined by
  13537. outlines, the ^"penpos" macro is of primary importance.  Since "penpos"
  13538. may be used quite frequently, we might as well write out the $x$ and~$y$
  13539. coordinates explicitly instead of using the (somewhat slower) $z$~convention:
  13540. \beginlines
  13541. |vardef penpos@#(expr b,d) =|
  13542. | (x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d;|
  13543. | x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef;|
  13544. \endlines
  13545. Simulated pen strokes are provided by the convenient ^@penstroke@ command.
  13546. \beginlines
  13547. |def penstroke text t =|
  13548. | forsuffixes e = l,r: path_.e:=t; endfor|
  13549. | if cycle path_.l: cyclestroke_|
  13550. | else: fill path_.l -- reverse path_.r -- cycle fi enddef;|
  13551. |def cyclestroke_ =|
  13552. | begingroup interim turningcheck:=0;|
  13553. | addto pic_ contour path_.l.t_ withweight 1;|
  13554. | addto pic_ contour path_.r.t_ withweight -1;|
  13555. | cull pic_ dropping origin withweight default_wt_;|
  13556. | addto_currentpicture also pic_;|
  13557. | pic_:=nullpicture endgroup enddef;|
  13558. |path path_.l,path_.r;|
  13559. \finalendlines
  13560. \subsection Proof labels and rules. The next main section of |plain.mf|
  13561. is devoted to macros for the annotations on proofsheets. These macros
  13562. are discussed in Appendix~H\null, and they use the ^@special@ and ^@numspecial@
  13563. commands discussed in Appendix~G.
  13564. Labels are generated at the lowest level by @makelabel@\kern1pt:^^"lcode\_"
  13565. \beginlines
  13566. |vardef |^|makelabel||@#(expr s,z) =            % puts string s at point z|
  13567. | if known z: special lcode_@# & s;|
  13568. |  numspecial xpart(z.t_); numspecial ypart(z.t_) fi enddef;|
  13569. \smallskip
  13570. |string lcode_,lcode_.top,lcode_.lft,lcode_.rt,lcode_.bot,|
  13571. |  lcode_.top.nodot,lcode_.lft.nodot,lcode_.rt.nodot,lcode_.bot.nodot;|
  13572. |lcode_.top=" 1"; lcode_.lft=" 2"; lcode_.rt=" 3"; lcode_.bot=" 4";|
  13573. |lcode_=" 0"; % change to " /" to avoid listing in overflow column|
  13574. |lcode_.top.nodot=" 5"; lcode_.lft.nodot=" 6";|
  13575. |lcode_.rt.nodot=" 7"; lcode_.bot.nodot=" 8";|
  13576. \endlines
  13577. Users generally don't invoke @makelabel@ directly, because there's a convenient
  13578. shorthand. For example, `@labels@$(1,2,3)$' expands into
  13579. `@makelabel@\kern1pt(|"1"|$,z_1$); @makelabel@\kern1pt(|"2"|$,z_2$);
  13580. @makelabel@\kern1pt(|"3"|$,z_3$)'.
  13581. \ (But nothing happens if ^"proofing"$\null\le1$.)
  13582. \beginlines
  13583. |vardef |^|labels||@#(text t) =|
  13584. | if proofing>1: forsuffixes $=t: makelabel@#(str$,z$); endfor fi enddef;|
  13585. |vardef |^|penlabels||@#(text t) =|
  13586. | if proofing>1: forsuffixes $$=l,,r: forsuffixes $=t:|
  13587. |  makelabel@#(str$.$$,z$.$$); endfor endfor fi enddef;|
  13588. \endlines
  13589. When there are lots of purely numeric labels, you can say, e.g.,
  13590. \begindisplay
  13591. @labels@(1, @range@ 5 @thru@ 9, @range@ 100 @thru@ 124, 223)
  13592. \enddisplay
  13593. which is equivalent to `@labels@$(1,5,6,7,8,9,100,101,\ldots,124,223)$'.
  13594. Labels are omitted from the proofsheets if the corresponding $z$ value
  13595. isn't known, so it doesn't hurt (much) to include unused subscript numbers
  13596. in a range.
  13597. \beginlines
  13598. |def |^|range|| expr x = numtok[x] enddef;|
  13599. |def |^|numtok|| suffix x=x enddef;|
  13600. |tertiarydef m |^|thru|| n =|
  13601. | m for x=m+1 step 1 until n: , numtok[x] endfor enddef;|
  13602. \weakendlines
  13603. (This @range@ abbreviation will work in any ^@forsuffixes@ list;
  13604. and in a `@for@' list you can even omit the word `@range@'.
  13605. But you might fill~up \MF's main memory if too many values are involved.)
  13606. A straight line will be drawn on the proofsheet by @proofrule@.
  13607. Although @makelabel@ takes the current transform into account,
  13608. @proofrule@ does not. There's also a corresponding routine `@screenrule@'
  13609. that puts a straight line in the current picture, so that design
  13610. guidelines will be visible on your screen:
  13611. \beginlines
  13612. |def |^|proofrule||(expr w,z) =|
  13613. | special "rule"; numspecial xpart w; numspecial ypart w;|
  13614. | numspecial xpart z; numspecial ypart z enddef;|
  13615. |def |^|screenrule||(expr w,z) =|
  13616. | addto currentpicture doublepath w--z withpen rulepen enddef;|
  13617. |pen rulepen; rulepen = pensquare scaled 2;|
  13618. \endlines
  13619. (The ^"rulepen" is two pixels wide, because screen rules are usually
  13620. drawn exactly over raster lines. A two-pixel-wide pen straddles the pixel
  13621. edges so that you can ``see'' the correct line position. If
  13622. a two-pixel-wide line proves to be too dark, you can redefine
  13623. "rulepen" to be simply ^@pensquare@; then \MF\ will draw the
  13624. thinnest possible screen rule, but it will be
  13625. a half-pixel too high and a half-pixel too far to the right.)
  13626. You can produce lots of proof rules with ^@makegrid@, which connects
  13627. an arbitrary list of $x$~coordinates with an arbitrary list
  13628. of $y$~coordinates:
  13629. \beginlines
  13630. |def makegrid(text xlist,ylist) =|
  13631. | xmin_ := min(xlist); xmax_ := max(xlist);|
  13632. | ymin_ := min(ylist); ymax_ := max(ylist);|
  13633. | for x=xlist: proofrule((x,ymin_), (x,ymax_)); endfor|
  13634. | for y=ylist: proofrule((xmin_,y), (xmax_,y)); endfor|
  13635. | enddef;|
  13636. \endlines
  13637. Finally we have a few macros that allow further communication with
  13638. the hardcopy proof-drawing routine of Appendix~H\null. You can change the
  13639. fonts, the thickness of proof rules, and the position of the image
  13640. on its page.
  13641. \beginlines
  13642. |vardef |^|titlefont|| suffix $ = special "titlefont "&str$ enddef;|
  13643. |vardef |^|labelfont|| suffix $ = special "labelfont "&str$ enddef;|
  13644. |vardef |^|grayfont|| suffix $ = special "grayfont "&str$ enddef;|
  13645. |vardef |^|slantfont|| suffix $ = special "slantfont "&str$ enddef;|
  13646. |def |^|proofoffset|| primary z =   % shift proof output by z|
  13647. | special "offset"; numspecial xpart z; numspecial ypart z enddef;|
  13648. |vardef |^|proofrulethickness|| expr x =|
  13649. | special "rulethickness"; numspecial x enddef;|
  13650. \finalendlines
  13651. \subsection Character and font administration.
  13652. After this elaborate preparation, we're finally ready
  13653. to consider the @beginchar@$\,\ldots\,$@endchar@
  13654. framework for the individual characters of a font. Each ^@beginchar@ begins
  13655. a group, which should end at the next ^@endchar@. Then @beginchar@
  13656. stores the given character code and device-independent
  13657. box dimensions in \MF's internal variables ^"charcode", ^"charwd",
  13658. ^"charht", and ^"chardp". Then it computes the device-dependent box
  13659. dimensions ^"w", ^"h", and~^"d". Finally it
  13660. clears the $z$ variables, the current picture, and the
  13661. current pen.
  13662. \beginlines
  13663. |def beginchar(expr c,w_sharp,h_sharp,d_sharp) =|
  13664. | begingroup|
  13665. | charcode:=if known c: byte c else: 0 fi;|
  13666. | charwd:=w_sharp;      charht:=h_sharp;       chardp:=d_sharp;|
  13667. | w:=hround(charwd*hppp); h:=vround(charht*hppp); d:=vround(chardp*hppp);|
  13668. | charic:=0; clearxy; clearit; clearpen; scantokens extra_beginchar;|
  13669. | enddef;|
  13670. \endlines
  13671. The ^{italic correction} is normally zero, unless the user gives an
  13672. `^@italcorr@' command; even then, the correction stays zero unless
  13673. the given value is positive:
  13674. \beginlines
  13675. |def italcorr expr x_sharp = if x_sharp>0: charic:=x_sharp fi enddef;|
  13676. \endlines
  13677. When we want to change the pixel width $w$ from even to odd or vice
  13678. versa, the ^@change\_width@ macro does the right thing.
  13679. \beginlines
  13680. |def change_width =|
  13681. | w:=w if w>charwd*hppp:- else:+ fi 1 enddef;|
  13682. \endlines
  13683. (The user might also decide to change $w$ in some other way.) \ The
  13684. current value of~$w$ at the time of @endchar@ will be the
  13685. ``official'' pixel width of the character, ^"chardx", that is
  13686. shipped to the |gf| output file.
  13687. \beginlines
  13688. |def endchar =|
  13689. | scantokens extra_endchar;|
  13690. | if proofing>0: makebox(proofrule); fi|
  13691. | chardx:=w;    % desired width of the character in pixels|
  13692. | shipit;|
  13693. | if displaying>0: makebox(screenrule); showit; fi|
  13694. | endgroup enddef;|
  13695. \endlines
  13696. Extensions to these routines can be provided by putting commands in the
  13697. string variables ^"extra\_beginchar" and ^"extra\_endchar".
  13698. \beginlines
  13699. |string extra_beginchar, extra_endchar;|
  13700. |extra_beginchar=extra_endchar="";|
  13701. \endlines
  13702. A ``^{bounding box}'' that surrounds the character according to the
  13703. specifications given in @beginchar@ is produced by ^@makebox@, which
  13704. takes into account the possibility that pixels might not be square.
  13705. An extra line is drawn to mark the width of the character with its
  13706. ^{italic correction} included, if this correction is nonzero.
  13707. \beginlines
  13708. |def makebox(text r) =|
  13709. | for y=0,h.o_,-d.o_: r((0,y),(w,y)); endfor % horizontals|
  13710. | for x=0,w:   r((x,-d.o_),(x,h.o_)); endfor % verticals|
  13711. | if charic<>0: r((w+charic*hppp,h.o_),(w+charic*hppp,.5h.o_)); fi|
  13712. | enddef;|
  13713. \endlines
  13714. The ^@maketicks@ routine is an alternative to @makebox@ that draws less
  13715. conspicuous lines. This makes it easier to visualize a character's
  13716. appearance near the edges of its bounding box.
  13717. \beginlines
  13718. |def maketicks(text r) =|
  13719. | for y=0,h.o_,-d.o_: r((0,y),(10,y)); r((w-10,y),(w,y)); endfor|
  13720. | for x=0,w: r((x,10-d.o_),(x,-d.o_)); r((x,h.o_-10),(x,h.o_)); endfor|
  13721. | if charic<>0: r((w+charic*hppp,h.o_-10),(w+charic*hppp,h.o_)); fi|
  13722. | enddef;|
  13723. \endlines
  13724. Overall information about the font as a whole is generally supplied
  13725. ^^@font\_size\_etc@
  13726. by the following commands, which are explained in Appendix~F\null.
  13727. \beginlines
  13728. |def font_size expr x = designsize:=x enddef;|
  13729. |def font_slant expr x = fontdimen 1: x enddef;|
  13730. |def font_normal_space expr x = fontdimen 2: x enddef;|
  13731. |def font_normal_stretch expr x = fontdimen 3: x enddef;|
  13732. |def font_normal_shrink expr x = fontdimen 4: x enddef;|
  13733. |def font_x_height expr x = fontdimen 5: x enddef;|
  13734. |def font_quad expr x = fontdimen 6: x enddef;|
  13735. |def font_extra_space expr x = fontdimen 7: x enddef;|
  13736. \smallskip
  13737. |def font_identifier expr x = font_identifier_:=x enddef;|
  13738. |def font_coding_scheme expr x = font_coding_scheme_:=x enddef;|
  13739. |string font_identifier_, font_coding_scheme_;|
  13740. |font_identifier_=font_coding_scheme_="UNSPECIFIED";|
  13741. \finalendlines
  13742. \bigskip
  13743. \subsection The endgame. What have we left out? A few miscellaneous
  13744. things still need to be handled. First, we almost forgot to define the
  13745. ^"z"~convention for points:
  13746. \beginlines
  13747. |vardef z@#=(x@#,y@#) enddef;|
  13748. \endlines
  13749. Then we need to do something rudimentary about \MF's ``windows.''
  13750. ^^"screen\_rows" ^^"screen\_cols"
  13751. \beginlines
  13752. |newinternal screen_rows, screen_cols, currentwindow;|
  13753. |screen_rows:=400;     % these values should be corrected,|
  13754. |screen_cols:=500;     % by reading in a separate file after plain.mf|
  13755. \smallskip
  13756. |def |^|openit|| = openwindow currentwindow|
  13757. | from origin to (screen_rows,screen_cols) at (-50,300) enddef;|
  13758. |def |^|showit|| = openit; let showit=showit_; showit enddef; % first time only|
  13759. |def showit_ = display currentpicture inwindow currentwindow enddef;|
  13760. \endlines
  13761. Plain \MF\ has several other terse commands like `@openit@' and `@showit@':
  13762. \beginlines
  13763. |def |^|clearxy|| = save x,y enddef;|
  13764. |def |^|clearit|| = currentpicture:=nullpicture enddef;|
  13765. |def |^|shipit|| = shipout currentpicture enddef;|
  13766. |def |^|cullit|| = cull currentpicture dropping (-infinity,0) enddef;|
  13767. \endlines
  13768. \medbreak
  13769. The next several macros are handy things to put on your ^{command line}
  13770. when you are starting a \MF\ job (i.e., just before `|input| \<font file
  13771. name>'):
  13772. \smallskip\item\bull |screenchars|. Say this when you're making a font
  13773. but want the characters to be displayed just before they are shipped out.
  13774. \item\bull |screenstrokes|. Say this when you're in "proof" mode
  13775. and want to see each stroke as it's added to the current picture.
  13776. \item\bull |imagerules|. Say this when you want to include the bounding box
  13777. in the current character, before you begin to draw it.
  13778. \item\bull |gfcorners|. Say this when you expect to make proofsheets
  13779. with large pixels, from a low-resolution font.
  13780. \item\bull |nodisplays|. Say this to save computer time when you don't
  13781. want "proof" mode to display each character automatically.
  13782. \item\bull |notransforms|. Say this to save computer time when you know
  13783. that the current transform is the identity.
  13784. \beginlines
  13785. |def |^|screenchars|| =     % endchar should `showit'|
  13786. | extra_endchar:=extra_endchar&"showit;" enddef;|
  13787. \smallskip
  13788. |def |^|screenstrokes|| =   % every stroke should `showit'|
  13789. | def addto_currentpicture text t=|
  13790. |  addto currentpicture t; showit enddef; enddef;|
  13791. \smallbreak
  13792. |def |^|imagerules|| =      % a box should be part of the character image|
  13793. | extra_beginchar:=extra_beginchar & "makebox(screenrule);" enddef;|
  13794. \smallbreak
  13795. |def |^|gfcorners|| =       % `maketicks' should send rules to the gf file|
  13796. | extra_setup:=extra_setup & "let makebox=maketicks;proofing:=1;" enddef;|
  13797. \smallbreak
  13798. |def |^|nodisplays|| =      % endchar shouldn't `showit'|
  13799. | extra_setup:=extra_setup & "displaying:=0;" enddef;|
  13800. \smallskip
  13801. |def |^|notransforms|| =    % currenttransform should not be used|
  13802. | let t_ = \ enddef;|
  13803. \endlines
  13804. We make `^@bye@' synonymous with `^@end@', just in case \TeX\ users expect
  13805. \MF\ programs to end like \TeX\ documents do.
  13806. \beginlines
  13807. |let bye = end; outer end,bye;|
  13808. \endlines
  13809. And finally, we provide the default environment that a user gets when
  13810. ^^@clear\_pen\_memory@ ^^@mode\_setup@
  13811. simple experiments like those at the beginning of Chapter~5 are desired.
  13812. \beginlines
  13813. |clear_pen_memory;     % initialize the `savepen' mechanism|
  13814. |mode_setup;           % establish proof mode as the default|
  13815. |numeric |^|mode||,|^|mag||;     % but leave mode and mag undefined|
  13816. \weakendlines
  13817. Whew! That's the end of the |plain.mf| file.
  13818. \subsection Adapting to local conditions. In order to make plain \MF\
  13819. programs interchangeable between different computers, everybody should use
  13820. the same |plain.mf| base. But there are some things that clearly should
  13821. be customized at each installation:
  13822. \smallskip\item\bull Additional modes should be defined, so that fonts
  13823. can be made for whatever output devices are of interest.
  13824. \item\bull The proper ^"localfont" mode should be established.
  13825. \item\bull The correct numbers should be assigned to
  13826. ^"screen\_rows" and ^"screen\_cols".
  13827. \smallbreak
  13828. \noindent
  13829. Here's an example of a supplementary file `|local.mf|'
  13830. that would be appropriate for a computer center with the
  13831. hypothetical "cheapo" and "luxo" printers described in Chapter~11.
  13832. We assume that "cheapo" mode is to be identical to "lowres" mode,
  13833. except that the "cheapo" fonts should be generated with a {\sl negative\/}
  13834. value of ^"fillin" (because "cheapo" tends to make diagonal lines lighter
  13835. than normal, not heavier). The terminal screens are assumed to be
  13836. 768 pixels wide and 512 pixels high.
  13837. \beginlines
  13838. |% A file to be loaded after "plain.mf".|
  13839. |base_version:=base_version&"/drofnats";|
  13840. \smallskip
  13841. |screen_rows:=512; screen_cols:=768;|
  13842. \smallskip
  13843. |mode_def cheapo =        % cheapo mode: to generate fonts for cheapo|
  13844. | lowres_;                       % do as in lowres mode, except:|
  13845. | fillin:=-.1;                   % compensate for lighter diagonals|
  13846. | enddef;|
  13847. \smallskip
  13848. |mode_def luxo =          % luxo mode: to generate fonts for luxo|
  13849. | proofing:=0;                   % no, we're not making proofs|
  13850. | fontmaking:=1;                 % yes, we are making a font|
  13851. | tracingtitles:=1;              % yes, show titles online|
  13852. | pixels_per_inch:=2000;         % almost 30 pixels per pt|
  13853. | blacker:=.2;                   % make pens a teeny bit blacker|
  13854. | fillin:=.1;                    % but compensate for heavy diagonals|
  13855. | o_correction:=1;               % and keep the full overshoot|
  13856. | enddef;|
  13857. \smallskip
  13858. |localfont:=cheapo;|
  13859. \weakendlines
  13860. The macro `^@bye@' might also be redefined, as suggested at the close
  13861. of Appendix~F.
  13862. To prepare a preloaded base file at this installation, a suitably
  13863. privileged person should run ^|INIMF| in the following way:
  13864. \begintt
  13865. This is METAFONT, Version 2.0 (INIMF)  8 NOV 1989 10:09
  13866. **plain
  13867. (plain.mf
  13868. Preloading the plain base, version 2.0)
  13869. *input local
  13870. (local.mf)
  13871. *dump
  13872. Beginning to dump on file plain.base
  13873. \endtt
  13874. ^^{dump}(The stuff after `|**|' or `|*|' is typed by the user; everything
  13875. else is typed by the system. A few more messages actually come out.)
  13876. Notice that |local.mf| does not include any new macros or features that a
  13877. programmer could use in a special way. Therefore it doesn't make plain
  13878. \MF\ incompatible with implementations at other computing centers.
  13879. Changes and/or extensions to the |plain.mf| macros should never be made,
  13880. unless the resulting base file is clearly distinguished from the standard
  13881. plain base. But new, differently named bases are welcome.
  13882. For example, the author prepared a special base for the
  13883. ^{Computer Modern} fonts, so that they could be generated without first
  13884. reading the same 700 lines of macro definitions each time. To load
  13885. this base at high speed, he can type `|&cm|' after \MF's initial
  13886. `|**|'. ^^{asterisk} ^^{ampersand} (Or, on some machines, he has a special
  13887. version called `|cmmf|' in which the new base is already present.)
  13888. \endchapter
  13889. None but the Base, in baseness doth delight.
  13890. \author MICHAEL ^{DRAYTON},  {\sl Robert, Duke of Normandy\/} (1605)
  13891.  % line 262; quite different in the 1596 version
  13892. \bigskip
  13893. So far all was plain sailing, as the saying is;
  13894. but Mr.\thinspace Till knew that his main difficulties were yet to come.
  13895. \author FRANCIS E. ^{PAGET},  {\sl Milford Malvoisin\/} (1842) % p209
  13896.  % in the 22nd paragraph of Chapter 9
  13897. \eject
  13898. \beginchapter Appendix C. Character\\Codes
  13899. Different computers tend to have different ways of representing the
  13900. characters in files of text, but \MF\ gives the same results on
  13901. all machines, because it converts everything to a standard internal
  13902. code when it reads a file. \MF\ also converts back from its internal
  13903. representation to the appropriate external code, when it writes
  13904. a file of text; therefore most users need not be aware of the fact
  13905. that the ^{codes} have actually switched back and forth inside the machine.
  13906. The purpose of this appendix is to define \MF's internal code,
  13907. which has the same characteristics on all implementations of \MF\!\null.
  13908. The existence of such a code is important, because it
  13909. makes \MF\ programs portable.
  13910. \MF's scheme is based on the American Standard Code for
  13911. Information Interchange, known popularly as ``^{ASCII}.'' There are
  13912. 128 codes, numbered 0~to~127; we conventionally express the numbers
  13913. in ^{oct}al notation, from |oct"000"| to |oct"177"|, or in
  13914. ^{hex}adecimal notation, from |hex"00"| to |hex"7F"|. Thus, the value of
  13915. |ASCII"b"| is normally called |oct"142"| or |hex"62"|, not 98. In the
  13916. ^{ASCII} scheme, codes |oct"000"| through |oct"037"| and
  13917. code |oct"177"| are~assigned to special functions; for example,
  13918. code |oct"007"| is called |BEL|, and it means ``Ring the bell.''
  13919. The other 95 codes are assigned to visible symbols and to the
  13920. blank space character. Here is a
  13921. chart that shows ASCII codes in such a way that octal and hexadecimal
  13922. equivalents can easily be read off:
  13923. \beginchart{\global\count255='41\postdisplaypenalty=0\tentt
  13924.   \def\chartstrut{\lower4.3pt\vbox to13.6pt{}}}
  13925. &\oct{00x}&&NUL&&SOH&&STX&&ETX&&EOT&&ENQ&&ACK&&BEL&&\oddline0
  13926. &\oct{01x}&&BS&&HT&&LF&&VT&&FF&&CR&&SO&&SI&\evenline
  13927. &\oct{02x}&&DLE&&DC1&&DC2&&DC3&&DC4&&NAK&&SYN&&ETB&&\oddline1
  13928. &\oct{03x}&&CAN&&EM&&SUB&&ESC&&FS&&GS&&RS&&US&\evenline
  13929. &\oct{04x}&& &&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline2
  13930. &\oct{05x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline
  13931. &\oct{06x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline3
  13932. &\oct{07x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline
  13933. &\oct{10x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline4
  13934. &\oct{11x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline
  13935. &\oct{12x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline5
  13936. &\oct{13x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline
  13937. &\oct{14x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline6
  13938. &\oct{15x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&\evenline
  13939. &\oct{16x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\oddline7
  13940. &\oct{17x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&DEL&\evenline
  13941. \endchart
  13942. Ever since ASCII was established in the early 1960s, people have had
  13943. different ideas about what to do with positions |oct"000"| thru |oct"037"| and
  13944. |oct"177"|, because most of the functions assigned to those codes are
  13945. appropriate only for special purposes like file transmission, not for
  13946. applications to printing or to interactive computing.
  13947. Manufacturers soon started producing line printers that were capable of
  13948. generating 128 characters, 33~of~which were tailored to the special needs
  13949. of particular customers; part of the advantage of a standard code was
  13950. therefore lost.
  13951. An extended ASCII code intended for text editing and interactive computing
  13952.  was developed at several universities about 1965, and
  13953. for many years there have been terminals in use at Stanford, MIT,
  13954. Carnegie-Mellon, and elsewhere that have 120 or~121 symbols, not just~95.
  13955. For example, the author ^^{Knuth} developed \MF\ on a keyboard that
  13956. includes the symbols `{\tentex\char'32}', `{\tentex\char'34}',
  13957. `{\tentex\char'35}', and `{\tentex\char'30}', which are easier to use than
  13958. the character pairs `{\tentex^{<>}}', `{\tentex^{<=}}', `{\tentex^{>=}}',
  13959. and `{\tentex^{:=}}'.  The full character set looks like this:
  13960. \beginchart{\tentex\postdisplaypenalty=0}
  13961. \normalchart
  13962. \endchart
  13963. \MF\ can also be configured to accept any or all of the character codes
  13964. 128--255.
  13965. However, \MF\ programs that make use of anything in addition to the 95
  13966. standard ASCII characters cannot be expected to run on other systems, so
  13967. the use of extended character sets is discouraged.
  13968. A possible middle ground has been suggested, based on the fact that
  13969. it's easy to write a
  13970. program that converts extended-character files into standard files by
  13971. substituting `|<>|' for `{\tentex\char'32}', etc. In the author's
  13972. implementation at Stanford, the symbols
  13973. `{\tentex\char'32}', `{\tentex\char'34}', `{\tentex\char'35}',
  13974. and `{\tentex\char'30}' are considered to be in the same class as
  13975. `{\tentex<}', `{\tentex=}', `{\tentex:}', and `{\tentex>}' when tokens are
  13976. formed (see Chapter~6). Tokens like `{\tentex\char'32=}'
  13977. and `{\tentex<\char'35}' are therefore distinct, although
  13978. they both become `{\tentex<>=}' after
  13979. conversion. As long as such tokens are avoided,
  13980. the author's programs can easily be expurgated into a
  13981. portable form for general distribution. \ (Another feasible approach would
  13982. have been to convert nonstandard codes to character pairs during \MF's
  13983. input process; that would have been slightly less efficient.)
  13984. Computers with non-ASCII character sets should specify a correspondence
  13985. between 95 distinct characters and the standard ASCII codes |oct"040"|
  13986. thru |oct"176"|.  \MF\ programs written on any such machines will be
  13987. completely interchangeable with each other.
  13988. \endchapter
  13989. If any shall suggest, that some of the Enquiries here insisted upon
  13990. (as particularly those about the Letters of the Alphabet)
  13991. do seem too minute and trivial, for any prudent Man
  13992. to bestow his serious thoughts and time about.
  13993. Such Persons may know, that the discovery
  13994. of the true nature and Cause of any the most minute thing,
  13995. doth promote real Knowledge,
  13996. and therefore cannot be unfit for any Mans endeauours,
  13997. who is willing to contribute to the advancement of Learning.
  13998. \author JOHN ^{WILKINS},  {\sl Towards a Real Character\/} (1668)
  13999.  % preface to the reader
  14000. \bigskip
  14001. Clearly even the simple A.B.C.~is a thing of mystery.
  14002. Like all codes, it should not be trifled with,
  14003. but it is to be feared that in modern times
  14004. it has not always been respected.
  14005. \author STANLEY ^{MORISON},  {\sl On Type Faces\/} (1923)
  14006.  % from the introduction, near the beginning
  14007. \eject
  14008. \beginchapter Appendix D. Dirty Tricks
  14009. Any powerful computer language can be used in ways that go considerably
  14010. beyond what the language designer originally had in mind, especially
  14011. when macro expansion is possible. Sometimes the unexpected constructions
  14012. are just amusing; sometimes they are disgustingly arcane. But
  14013. sometimes they turn out to be quite useful, and they graduate from ``tricks''
  14014. to the status of ``techniques.'' \ (For example, several of the macros
  14015. now in Appendix~B started out as suggestions for Appendix~D\null.) \
  14016. In any case, gurus of a language always like to explore its limits.
  14017. The depths of \MF\ have hardly been plumbed, but this appendix probably
  14018. reached a new low at the time it was written.
  14019. Acknowledgment: More than half of the ideas in this appendix are due to
  14020. John ^{Hobby}, who has been a tireless and inspiring co-worker during the
  14021. entire development of the new \MF\ system.
  14022. \advance\medskipamount by -.5pt
  14023. \advance\abovedisplayskip by -.5pt
  14024. \advance\belowdisplayskip by -.5pt
  14025. \ninepoint\medskip
  14026. \setbox0=\hbox spread-7\fontdimen4\font % that removes all the shrinkability
  14027.  {\strut Please don't read this material until you've had}
  14028. \setbox1=\hbox to\wd0{\strut plenty of experience with plain \MF\!.}
  14029. \line{\leaders\hbox{\dbend\kern2pt}\hfil\vtop{\box0\box1}}
  14030. \nointerlineskip
  14031. \noindent\strut After you have read and understood the secrets below, you'll
  14032. know all sorts of devious combinations of \MF\ commands,
  14033. and you will often be tempted to write inscrutable macros. Always remember,
  14034. however, that there's usually a simpler and better way to do something
  14035. than the first way that pops into your head. You may not have to
  14036. resort to any subterfuge at all, since \MF\ is able to do lots of things
  14037. in a straightforward way. Try for simple solutions first.
  14038. \subsection Macro madness. If you need to write complicated ^{macros}, you'll
  14039. need to be familiar with the fine points in Chapter~20. \MF's symbolic tokens
  14040. are divided into two main categories, ``expandable'' and ``unexpandable'';
  14041. the former category includes all macros and @if@$\,\ldots\,$@fi@ tests and
  14042. @for@$\,\ldots\,$@endfor@ loops, as well as special operations like @input@,
  14043. while the latter category includes the primitive operators and commands
  14044. listed in Chapters 25 and~26. The expansion of expandable tokens takes place
  14045. in \MF's ``^{mouth},'' but primitive statements (including equations,
  14046. declarations, and the various types of commands) are done in \MF's
  14047. ``^{stomach}.'' There's a communication between the two, since the stomach
  14048. evaluates expressions that are needed as arguments to the mouth's macros;
  14049. any statement can be embedded in a group expression, so arbitrarily
  14050. complicated things can be done as part of the ^{expansion} process.
  14051. Let's begin by considering a toy problem that is treated at the beginning
  14052. of Appendix~D in {\sl The \TeX book}, in case some readers are interested in
  14053. comparing \TeX\ to \MF\!\null. Given a numeric variable $n\ge0$, we wish to
  14054. define a macro |asts| whose replacement text consists of precisely
  14055. $n$~asterisks. This task is somewhat tricky because expansion is suppressed
  14056. when a replacement text is being read; we want to use a ^@for@ loop, but
  14057. loops are special cases of expansion. In other words,
  14058. \begintt
  14059. def asts = for x=1 upto n: * endfor enddef
  14060. \endtt
  14061. defines |asts| to be a macro with a @for@ loop in its replacement text;
  14062. \advance\belowdisplayskip by -1.5pt
  14063. in practice, |asts| would behave as if it contained $n$ asterisks (using
  14064. possibly different values of~$n$), but
  14065. we have not solved the stated problem. The alternative
  14066. \begintt
  14067. def makedef primary n =
  14068.  def asts = for x=1 upto n: * endfor enddef enddef;
  14069. makedef n
  14070. \endtt
  14071. ``freezes'' the present value of $n$; but this doesn't solve the problem either.
  14072. \advance\medskipamount by .5pt
  14073. \advance\abovedisplayskip by .5pt
  14074. \advance\belowdisplayskip by 2pt
  14075. \goodbreak
  14076. One solution is to build up the definition by adding one asterisk at a time,
  14077. using ^@expandafter@ as follows:
  14078. \begintt
  14079. def asts = enddef;
  14080. for x=1 upto n:
  14081.  expandafter def expandafter asts expandafter = asts * enddef;
  14082. endfor.
  14083. \endtt
  14084. The three expandafters provide a ``finger'' into the replacement text,
  14085. before @def@ suppresses expansion; without them the replacement text
  14086. would turn out to be `|asts|~|*|', causing infinite recursion.
  14087. This solution involves a running time proportional to $n^2$, so the
  14088. reader might wonder why a simpler approach like
  14089. \begintt
  14090. expandafter def expandafter asts expandafter =
  14091.  for x = 1 upto n: * endfor enddef
  14092. \endtt
  14093. wasn't suggested? The reason is that this doesn't work, unless $n=0$!
  14094. A @for@ loop isn't entirely expanded by expandafter, only \MF's first
  14095. step in loop expansion is carried out. Namely, the loop text is read,
  14096. and a special ^{inaccessible} token `^|ENDFOR|' is placed at its end.
  14097. Later on when \MF's mouth encounters `|ENDFOR|' (which incidentally is an
  14098. expandable token, but it wasn't listed in Chapter~20), the loop text is
  14099. re-inserted into the input stream, unless of course the loop has finished.
  14100. The special |ENDFOR| is an `^@outer@' token, hence it should not
  14101. appear in replacement texts; \MF\ will therefore stop with a ``^{forbidden
  14102. token}'' error if you try the above with $n\ge1$.
  14103. ^^@inner@ You might try to defeat the outerness by saying
  14104. \begintt
  14105. for x=1: inner endfor;
  14106. \endtt
  14107. but \MF\ won't let you. And even if this had worked, it wouldn't have
  14108. solved the problem; it would simply have put |ENDFOR| into the
  14109. replacement text of |ast|, because expansion is inhibited when the
  14110. replacement text is being read.
  14111. There's another way to solve the problem that seems to have running
  14112. time proportional to~$n$ rather than~$n^2$:
  14113. \begintt
  14114. scantokens("def asts=" for x=1 upto n: & "* " endfor) enddef;
  14115. \endtt
  14116. ^^{*} but actually \MF's string ^{concatenation}
  14117. operation takes time proportional to the length of the strings it
  14118. deals with, so the running time is still order~$n^2$.
  14119. Furthermore, the ^{string} operations in \MF\ are rather primitive,
  14120. because this isn't a major aspect of the language; so it turns out that
  14121. this approach uses order~$n^2$ storage cells in the string pool, although
  14122. they are recycled later. Even if the ^{pool size} were infinite, \MF's
  14123. ``^{buffer size}'' would be exceeded for large~$n$, because ^@scantokens@
  14124. puts the string into the input buffer before scanning it.
  14125. Is there a solution of order $n$? Yes, of course. For example,
  14126. \begintt
  14127. def a=a* enddef;
  14128. for x=0 upto n:
  14129.  if x=n: def a=quote quote def asts = enddef; fi
  14130.  expandafter endfor a enddef;
  14131. showtoken asts.
  14132. \endtt
  14133. (The first `^@quote@' is removed by the @for@, hence one will survive until
  14134. $a$~is redefined. If you don't understand this program, try ^^{debugging tricks}
  14135. running it with $n=3$; insert an isolated expression `|0;|' just before
  14136. the~`|if|', and look at the lines of context that are shown when
  14137. \MF\ gives you four error messages.) \ The only flaw in this method is
  14138. that it uses~up $n$ cells of stack space; \MF's ^{input stack size}
  14139. may have to be increased, if $n$ is bigger than 25~or~so.
  14140. \smallbreak
  14141. The asterisk problem is just a puzzle; let's turn now to a genuine
  14142. application. Suppose we want to define a macro called `"ten"' ^^{Derek}
  14143. whose replacement text is the contents of the parameter file ^|logo10.mf|
  14144. in Chapter~11, up to but {\sl not\/} including the last two lines of
  14145. that file. Those last two lines say
  14146. \begintt
  14147. input logo         % now generate the font
  14148. end                % and stop.
  14149. \endtt
  14150. The "ten" macro will make it possible to set up the 10-point parameters
  14151. repeatedly (perhaps alternating with 9-point parameters in a "nine" macro);
  14152. Appendix~E explains how to create a meta-design tool via such macros.
  14153. One idea would be to try to input the entire file |logo10.mf| as the
  14154. replacement text for "ten". We could nullify the effect of the last three
  14155. unwanted tokens by saying
  14156. \begintt
  14157. save input,logo,end;
  14158. forsuffixes s=input,logo,end: let s=\; endfor
  14159. \endtt
  14160. just before "ten" is used. To get the entire file as a replacement text,
  14161. we can try one of the approaches that worked in the asterisk problem, say
  14162. \begintt
  14163. expandafter def expandafter ten expandafter = input logo10 enddef.
  14164. \endtt
  14165. But this first attempt runs awry if we haven't already redefined `^@end@';
  14166. Appendix~B makes `@end@' an `^@outer@' token, preventing its appearance
  14167. in replacement texts. So we say `^@inner@ @end@'
  14168. and try again, only to discover an unwritten law that somehow never
  14169. came up in Chapters 20 or~26:
  14170. \begintt
  14171. Runaway definition?
  14172. font_size10pt#;ht#:=6pt#;xgap#:=0.6pt#;u#:=4/9pt#;s#:=0;o#:=1/ ETC.
  14173. ! File ended while scanning the definition of ten.
  14174. <inserted text>
  14175.                 enddef
  14176. l.2 ...fter ten expandafter = input logo10
  14177.                                            enddef;
  14178. \endtt
  14179. ^^|Runaway| ^^|File ended...|
  14180. The ^{end of a file} is invisible; but it's treated like an `@outer@'
  14181. token, in the sense that a file should never end when \MF\ is passing
  14182. rapidly over text.
  14183. Therefore this whole approach is doomed to failure. We'll have to find a
  14184. way to stop the replacement text before the file ends.
  14185. OK, we'll redefine `@input@' so that it means `@enddef@\kern1pt', and
  14186. redefine "logo" so that it means `^@endinput@'.
  14187. \begintt
  14188. let INPUT = input; let input = enddef; let logo = endinput;
  14189. expandafter def expandafter ten expandafter = INPUT logo10;
  14190. showtoken ten.
  14191. \endtt
  14192. It works! By the way, the line with three expandafters can be replaced by
  14193. a more elegant construction that uses @scantokens@ as follows:
  14194. \begintt
  14195. scantokens "def ten=" INPUT logo10;
  14196. \endtt
  14197. This does the job because \MF\ always looks ahead and expands the token
  14198. immediately following an expression that is being evaluated. \ (The
  14199. expression in this case is the string |"def|~|ten="|, which is an argument
  14200. to @scantokens@.  The token that immediately follows an expression
  14201. almost always needs to be examined in order to be sure that the expression
  14202. has ended, so \MF\ always examines it.) \ Curiously, the @expandafter@
  14203. alternative causes "ten"'s replacement text to begin with the tokens
  14204. `|font_size10pt#;ht#:=...|', while the @scantokens@ way makes it start
  14205. with `|designsize:=(10);ht#:=...|'. Do you see why? In the second case,
  14206. expansion continued until an unexpandable token (`|designsize|') was
  14207. found, so the |font_size| macro was changed into its replacement text; but
  14208. @expandafter@ just expanded `|INPUT|'.
  14209. Now let's make the problem a bit harder. Suppose we know that `|input|'
  14210. comes at the end of where we want to read, but we don't know that `|logo|'
  14211. will follow. We know that some program file name will be there, but
  14212. it might not be for the logo font. Furthermore, let's assume that `|end|'
  14213. might not be present; therefore we can't simply redefine it to be @enddef@.
  14214. In this case we can make `|input|' into a right ^{delimiter}, and
  14215. read the file as a {\sl delimited ^{text argument}\/}; ^^{argument}
  14216. that will give us enough time to insert other tokens, which will
  14217. terminate the input and flush the unwanted file name. But the construction
  14218. is more complex:
  14219. \begintt
  14220. let INPUT = input; delimiters begintext input;
  14221. def makedef(expr name)(text t) =
  14222.  expandafter def scantokens name = t enddef;
  14223.  endinput flushfilename enddef;
  14224. def flushfilename suffix s = enddef;
  14225. makedef("ten") expandafter begintext INPUT logo10;
  14226. showtoken ten.
  14227. \endtt
  14228. This example merits careful study, perhaps with `^@tracingall@' to
  14229. show exactly how \MF\ proceeds. We have assumed that the unknown file
  14230. name can be parsed as a suffix; this solves the problem that a file cannot
  14231. end inside of a @text@ parameter or a false condition. \ (If we knew that
  14232. `@end@' were present, we could have replaced `|endinput|~|flushfilename|' by
  14233. `|if|~|false:|' and redefined `|end|' to be `|fi|'.)
  14234. Let's turn now to a simpler problem. \MF\ allows you to consider the
  14235. `^{and}' of two Boolean expressions, but it always evaluates both
  14236. expressions. This is problematical in situations like
  14237. \begintt
  14238. if pair x and (x>(0,0)): A else: B fi
  14239. \endtt
  14240. because the expression `|x>(0,0)|' will stop with an error message
  14241. unless $x$ is of type @pair@. The obvious way to avoid this error,
  14242. \begintt
  14243. if pair x:  if x>(0,0): A else: B fi  else: B fi
  14244. \endtt
  14245. is cumbersome and requires |B| to appear twice.  What we want is a
  14246. ``^{conditional and}'' operation in which the second Boolean expression is
  14247. evaluated only if the first one turns out to be true; then we can safely write
  14248. \begintt
  14249. if pair x cand (x>(0,0)): A else: B fi.
  14250. \endtt
  14251. Similarly we might want ``^{conditional or}'' in which the second operand is
  14252. evaluated only if the first is false, for situations like
  14253. \begintt
  14254. if unknown x cor (x<0): A else: B fi.
  14255. \endtt
  14256. Such ^|cand| and ^|cor| macros can be defined as follows:
  14257. \begintt
  14258. def cand(text q) = startif true q else: false fi enddef;
  14259. def cor(text q) = startif true true else: q fi enddef;
  14260. tertiarydef p startif true = if p: enddef;
  14261. \endtt
  14262. the ^{text arguments} are now evaluated only when necessary. We have essentially
  14263. ^^@if@ replaced the original line by
  14264. \begintt
  14265. if if pair x: x<(0,0) else: false fi: A else: B fi.
  14266. \endtt
  14267. This construction has one catch; namely, the right-hand operands of |cand| and
  14268. |cor| must be explicitly enclosed in delimiters. But delimiters are only a
  14269. minor nuisance, because the operands to `and' and `or' usually need them
  14270. anyway. It would be impossible to make |cand| and |cor| obey the normal
  14271. expression ^{hierarchy}; when macros make primary/secondary/tertiary
  14272. distinctions, they evaluate their arguments, and such evaluation is
  14273. precisely what |cand| and |cor| want to avoid.
  14274. If these |cand| and |cor| macros were changed so that they took
  14275. {\sl undelimited\/} text arguments, the text argument wouldn't stop at a colon.
  14276. We could, however, use such modified macros with ^{group delimiters}
  14277. instead. For example, after
  14278. \begintt
  14279. let {{ = begingroup; let }} = endgroup;
  14280. def cand text q = startif true q else: false fi enddef
  14281. \endtt
  14282. we could write things like
  14283. \begintt
  14284. if {{pair x cand x>(0,0)}}: A else: B fi.
  14285. \endtt
  14286. (Not that this buys us anything; it just illustrates a property of
  14287. undelimited text arguments.) \ Group delimiters
  14288. are not valid delimiters of {\sl delimited\/} text arguments.
  14289. Speaking of group delimiters, the gratuitous ^@begingroup@ and ^@endgroup@
  14290. tokens added by ^@vardef@ are usually helpful, but they can be a nuisance.
  14291. For example, suppose we want to write a |zz|~macro such that
  14292. `|zz1..zz2..zz3|' expands into
  14293. \begintt
  14294. z1{dz1}..z2{dz2}..z3{dz3}
  14295. \endtt
  14296. It would be trivial to do this with @def@:
  14297. \begintt
  14298. def zz suffix $ = z${dz$} enddef;
  14299. \endtt
  14300. but this makes |zz| a ``^{spark}.'' Let's suppose that we want to use
  14301. @vardef@, so that |zz| will be usable in suffixes of variable names.
  14302. Additional @begingroup@ and @endgroup@ delimiters will mess up the
  14303. syntax for paths, so we need to get rid of them. Here's one way to
  14304. finesse the problem:
  14305. \begintt
  14306. vardef zz@# =
  14307.  endgroup gobbled true z@#{dz@#} gobble begingroup enddef.
  14308. \endtt
  14309. The ^|gobbled| and ^|gobble| functions of Appendix~B will remove the ^{vacuous
  14310. expressions} `@begingroup@~@endgroup@' at the beginning and end of
  14311. the replacement text.
  14312. (The initial @begingroup@ @endgroup@ won't be gobbled if the vardef is
  14313. being read as a primary instead of as a secondary, tertiary, or
  14314. expression. But in such cases you probably don't mind having @begingroup@
  14315. present.)
  14316. \subsection Fortuitous loops.
  14317. The `^{max}' and `^{min}' macros in Appendix~B make use of the fact
  14318. that commas are like `|)(|' in argument lists. Although the
  14319. definition heading is
  14320. \begintt
  14321. def max(expr x)(text t)
  14322. \endtt
  14323. we can write `max$(a,b,c)$' and this makes $x=a$ and $t=\null$`$b,c$'.
  14324. Of course, a person isn't supposed to say `max$(a)(b)(c)$'.
  14325. Here are two more applications of the idea: We want `^{inorder}$(a,b,c)$'
  14326. to be true if and only if $a\le b\le c$; and we want
  14327. `^@equally\_spaced@$(x_1,x_2,x_3)\,"dx"$' to produce the equations
  14328. `$x_2-x_1=x_3-x_2=dx$'.
  14329. \begintt
  14330. def inorder(expr x)(text t) =
  14331.  ((x for u=t: <= u)
  14332.   and (u endfor gobbled true true)) enddef;
  14333. def equally_spaced(expr x)(text t) expr dx =
  14334.  x for u=t: - u = u endfor gobbled true
  14335.  - dx enddef.
  14336. \endtt
  14337. Isn't this fun? \ (Look closely.)
  14338. There is a problem, however, if we try to use these macros with
  14339. loops in the arguments. Consider the expressions
  14340. \begintt
  14341. inorder(for n=1 upto 10: a[n], endfor infinity),
  14342. inorder(a[1] for n=2 upto 10: ,a[n] endfor),
  14343. inorder(a[1],a[2] for n=3 upto 10: ,a[n] endfor);
  14344. \endtt
  14345. the first two give error messages, but the third one works!
  14346. The reason is that, in the first two cases,
  14347. the @for@ loop begins to be expanded before \MF\ begins to read the
  14348. ^{text argument}, hence ^|ENDFOR| rears its ugly head again.
  14349. We can avoid this problem by rewriting the macros in a more complicated
  14350. way that doesn't try to single out the first argument~$x$:
  14351. \begintt
  14352. def inorder(text t) =
  14353.  expandafter startinorder for u=t:
  14354.   <= u endgroup and begingroup u endfor
  14355.  gobbled true true endgroup) enddef;
  14356. def startinorder text t =
  14357.  (begingroup true enddef;
  14358. def equally_spaced(text t) expr dx =
  14359.  if pair dx: (whatever,whatever) else: whatever fi
  14360.  for u=t: - u = u endfor gobbled true
  14361.  - dx enddef;
  14362. \endtt
  14363. Two separate tricks have been used here: (1)~The `^@endgroup@' within
  14364. `inorder' will stop an undelimited text argument; this gets rid
  14365. of the unwanted `|<=|~|u|' at the beginning. (2)~A throwaway variable,
  14366. `^"whatever"', nullifies an unwanted equation at the beginning of
  14367. `@equally\_spaced@'. With the new definitions,
  14368. all three of the expressions above will be understood,
  14369. and so will things like
  14370. \begintt
  14371. equally_spaced(for n=1 upto 10: x[n], endfor whatever) dx.
  14372. \endtt
  14373. Furthermore the single-argument cases now work:
  14374. `inorder($a$)' will always be true, and
  14375. `@equally\_spaced@($x)\,"dx"$' will produce no new equations.
  14376. If we want to improve ^{max} and ^{min} in the same way, so that a person can
  14377. specify loop arguments like
  14378. \begintt
  14379. max(a[1] for n=2 upto 10: ,a[n] endfor)
  14380. \endtt
  14381. and so that `max($a)=a$' in the case of a single argument, we have to
  14382. work harder, because max and min treat their first argument in quite
  14383. a special way; they need to apply the special macro ^"setu\_", which defines
  14384. the type of the auxiliary variable "u\_". The fastest way to solve this
  14385. problem is probably to use a token whose meaning changes during the
  14386. first time through the loop:
  14387. \begintt
  14388. vardef max(text t) =
  14389.  let switch_ = firstset_;
  14390.  for u=t: switch_ u>u_: u_ := u ;fi endfor
  14391.  u_ enddef;
  14392. vardef min(text t) =
  14393.  let switch_ = firstset_;
  14394.  for u=t: switch_ u<u_: u_ := u ;fi endfor
  14395.  u_ enddef;
  14396. def firstset_ primary u =
  14397.  setu_ u; let switch_ = if; if false: enddef.
  14398. \endtt
  14399. Incidentally, the author's ^^{Knuth} first programs for max and min
  14400. contained an interesting bug.  They started with `@save@ "u\_"', and they
  14401. tried to recognize the first time through the loop by testing if "u\_" was
  14402. unknown.  This failed because "u\_" could be constantly unknown in
  14403. well-defined cases like max$(x,x+1,x+2)$.
  14404. \subsection Types. Our programs for |inorder|, |equally_spaced|, and
  14405. |max| are careful not to make unnecessary assumptions about the type
  14406. of an expression. The `round' and `byte' functions in Appendix~B
  14407. are further examples of macros that change behavior based
  14408. on the types of their @expr@ arguments. Let's look more closely at
  14409. applications of type testing. \looseness=-1
  14410. When the author was developing macros for plain \MF\!, his first
  14411. ``correct'' solution for |max| had the following form:
  14412. \begintt
  14413. vardef max(text t) =
  14414.  save u_; boolean u_;
  14415.  for u=t: if boolean u_: setu_ u
  14416.   elseif u_<u: u_ := u fi; endfor
  14417.  u_ enddef.
  14418. \endtt
  14419. This was interesting because it showed that there was no need to
  14420. set "u\_" to true or false; the simple fact that it was boolean
  14421. was enough to indicate the first time through the loop. \ (A slightly
  14422. different "setu\_" macro was used at that time.)
  14423. We might want to generalize the `^{scaled}' operation of \MF\ so that
  14424. `scaled~$(x,y)$' is shorthand for `^{xscaled}~$x$ ^{yscaled}~$y$'.
  14425. That's pretty easy:
  14426. \begintt
  14427. let SCALED = scaled;
  14428. def scaled primary z =
  14429.  if pair z: xscaled xpart z yscaled ypart z
  14430.  else: SCALED z fi enddef;
  14431. \endtt
  14432. It's better to keep the primitive operation `|SCALED| |z|' here than to replace
  14433. it by the slower variant `|xscaled| |z| |yscaled| |z|'.
  14434. \MF\ allows you to compare booleans, numerics, pairs, strings, and
  14435. transforms for equality; but it doesn't allow the expression
  14436. `$p=q$' where $p$ and~$q$ are paths or pens or pictures. Let's
  14437. write a general ^{equality test} macro ^^{==} such that `$p==q$'
  14438. will be true if and only if $p$ and $q$ are known and equal,
  14439. whatever their type.
  14440. \begintt
  14441. tertiarydef p == q =
  14442.  if unknown p or unknown q: false
  14443.  elseif boolean p and boolean q: p=q
  14444.  elseif numeric p and numeric q: p=q
  14445.  elseif pair p and pair q: p=q
  14446.  elseif string p and string q: p=q
  14447.  elseif transform p and transform q: p=q
  14448.  elseif path p and path q:
  14449.   if (cycle p = cycle q) and (length p = length q)
  14450.    and (point 0 of p = point 0 of q): patheq p of q
  14451.   else: false fi
  14452.  elseif pen p and pen q: (makepath p == makepath q)
  14453.  elseif picture p and picture q: piceq p of q
  14454.  elseif vacuous p and vacuous q: true
  14455.  else: false fi enddef;
  14456. vardef vacuous primary p =
  14457.  not(boolean p or numeric p or pair p or path p
  14458.   or pen p or picture p or string p or transform p) enddef;
  14459. vardef patheq expr p of q =
  14460.  save t; boolean t; t=true;
  14461.  for k=1 upto length p:
  14462.   t := (postcontrol k-1 of p = postcontrol k-1 of q)
  14463.    and (precontrol k of p = precontrol k of q)
  14464.    and (point k of p = point k of q);
  14465.   exitunless t; endfor
  14466.  t enddef;
  14467. vardef piceq expr p of q =
  14468.  save t; picture t;
  14469.  t=p; addto t also -q;
  14470.  cull t dropping origin;
  14471.  (totalweight t=0) enddef;
  14472. \endtt
  14473. If $p$ and $q$ are numeric or pair expressions, we could relax the condition
  14474. that they both be known by saying `@if@ known $p-q$: $p=q$ @else@ @false@ @fi@';
  14475. transforms could be handled similarly by testing each of their six parts.
  14476. But there's no way to tell if booleans, paths, etc., have been equated
  14477. when they're both unknown, without the risk of irrevocably changing the
  14478. values of other variables.
  14479. \subsection ^{Nonlinear equations}. \MF\ has a built-in solution mechanism
  14480. for linear equations, but it balks at nonlinear ones.
  14481. You might be able to solve a set of nonlinear equations yourself by
  14482. means of algebra or calculus, but in difficult cases it is probably
  14483. simplest to use the `^"solve"' macro of plain \MF\!\null. This makes it
  14484. possible to solve $n$~equations in $n$~unknowns, provided that at most
  14485. one of the equations is nonlinear when one of the unknowns is fixed.
  14486. The general technique will be illustrated here in the case $n=3$.
  14487. Let us try to find numbers $a$, $b$, and~$c$ such that
  14488. $$\eqalign{-2a+3b/c&=c-3;\cr
  14489.   ac+2b&=c^3-20;\cr
  14490.   a^3+b^3&=c^2.\cr}$$
  14491. When $c$ is fixed, the first two equations are linear in $a$ and~$b$.
  14492. We make an inequality out of the remaining equation by changing `$=$'
  14493. to~`$<$', then we embed the system in a boolean-valued function:
  14494. \begintt
  14495. vardef f(expr c) = save a,b;
  14496.  -2a + 3b/c = c - 3;
  14497.  a*c + 2b = c*c*c - 20;
  14498.  a*a*a + b*b*b < c*c enddef;
  14499. c = solve f(1,7);
  14500. -2a + 3b/c = c - 3;
  14501. a*c + 2b = c*c*c - 20;
  14502. show a, b, c.
  14503. \endtt
  14504. If we set ^"tolerance"$\null="epsilon"$ (which is the minimum value
  14505. that avoids infinite looping in the "solve" routine), the values
  14506. $a=1$, $b=2$, and $c=3$ are shown (so it is obvious that the example
  14507. was rigged). If "tolerance" has its default value~0.1, we get
  14508. $a=1.05061$, $b=2.1279$, $c=3.01563$; this would probably be close
  14509. enough for practical purposes, assuming that the numbers represent
  14510. pixels. \ (Increasing the tolerance saves time because it
  14511. decreases the number of iterations within "solve"; you have to
  14512. balance time versus necessary accuracy.)
  14513. The only tricky thing about this use of solve was the choice of the
  14514. numbers 1 and~7 in `$f(1,7)$'. In typical applications we'll usually have
  14515. obvious values of the unknown where $f$ will be true and false,
  14516. but a bit of experimentation was necessary for the problem considered
  14517. here. In fact,
  14518. it turns out that $f(-3)$ is~true and $f(-1)$ is false, in this
  14519. particular system; setting $c="solve"\,f(-3,-1)$ leads to
  14520. another solution: $a=7.51442$, $b=-7.48274$, $c=-2.3097$. Furthermore,
  14521. it's interesting to observe that this system has no solution with
  14522. $c$ between $-1$ and~$+1$, even though $f(+1)$ is true and
  14523. $f(-1)$ is false! When $c\rightarrow0$, the quantity $a^3+b^3$
  14524. approaches $-\infty$ when $c$~is negative, $+\infty$ when $c$~is
  14525. positive. An attempt to `"solve" $f(1,-1)$' will divide by zero and
  14526. come up with several arithmetic overflows.
  14527. \hangindent=-42mm \hangafter=-7
  14528. Let's consider now a real application instead of a contrived example.
  14529. \rightfig Da (34mm x 24mm) ^20pt
  14530. We wish to find the vertices of a ^{parallelogram}
  14531. $z_{1l}$,~$z_{1r}$, $z_{0l}$,~$z_{0r}$, such that
  14532. \begindisplay
  14533. $x_{1l}=a$; \ \ $y_{1r}=b$; \ \ $z_{0r}=(c,d)$;\cr
  14534. length$(z_{1r}-z_{1l})$ $=$ length$(z_{0r}-z_{0l})$ $=$ "stem",\cr
  14535. \enddisplay
  14536. and such that the lines $z_{1r}\dashto z_{1l}$ and
  14537. $z_{1r}\dashto z_{0r}$ meet at a given angle~$phi$. We can consider
  14538. the common angle~$\theta$ of $z_{1r}-z_{1l}$ and $z_{0r}-z_{0l}$ to be
  14539. the ``nonlinear'' unknown, so the equations to be solved can be
  14540. written
  14541. \begindisplay
  14542. $\penpos1("stem",\theta)$; \ \ $\penpos0("stem",\theta)$;\cr
  14543. $x_{1l}=a$; \ \ $y_{1r}=b$; \ \ $z_{0r}=(c,d)$;\cr
  14544. angle$(z_{1r}-z_{0r})\,=\,\theta+\phi$.\cr
  14545. \enddisplay
  14546. When $\theta$ has a given value, all but the last of these equations
  14547. are linear; hence we can solve them by turning the crank in our general method:
  14548. \begintt
  14549. vardef f(expr theta) = save x,y;
  14550.  penpos1(stem,theta); penpos0(stem,theta);
  14551.  x1l=a; y1r=b; z0r=(c,d);
  14552.  angle(z1r-z0r)<theta+phi enddef;
  14553. theta=solve f(90,0);
  14554. penpos1(stem,theta); penpos0(stem,theta);
  14555. x1l=a; y1r=b; z0r=(c,d);
  14556. show z1l,z1r,z0l,z0r,theta,angle(z1r-z0r).
  14557. \endtt
  14558. For example, if $a=1$, $b=28$, $c=14$, $d=19$, $"stem"=5$, and $\phi=80$,
  14559. we get
  14560. \begindisplay \def\qquad{\hskip1.5em}
  14561. $(1,23.703)$&$(3.557,28)$&$(11.443,14.703)$&$(14,19)$&59.25&139.25
  14562. \enddisplay
  14563. as answers when $"tolerance"="epsilon"$, and
  14564. \begindisplay \def\qquad{\hskip1.5em}
  14565. $(1,23.702)$&$(3.554,28)$&$(11.446,14.702)$&$(14,19)$&59.28&139.25
  14566. \enddisplay
  14567. when $"tolerance"=0.1$.
  14568. The function $f$ prescribed by the general method
  14569. can often be simplified; for example, in this case we can remove
  14570. redundancies and get just
  14571. \begintt
  14572. vardef f(expr theta) = save x,y;
  14573.  penpos1(stem,theta); x1l=a; y1r=b;
  14574.  angle(z1r-(c,d))<theta+phi enddef.
  14575. \endtt
  14576. The problem just solved can be called the ``^{d} problem,'' because it arose in
  14577. connection with N.~N. ^{Billawala}'s meta-design of a ^{black-letter}
  14578. `{\manual?}', and because it appears in Appendix~D.
  14579. \subsection Nonlinear interpolation.
  14580. Suppose a designer has empirically determined good values of some quantity
  14581. $f(x)$ for several values of~$x$; for example, $f(x)$ might be a
  14582. stroke weight or a serif length or an amount of overshoot, etc. These
  14583. empirical values can be generalized and incorporated into a ^{meta-design}
  14584. if we are able to ^{interpolate} between the original $x$'s, obtaining
  14585. $f(x)$ at intermediate points.
  14586. Suppose the data points are known for $x=x_1<x_2<\cdots<x_n$. We can
  14587. represent $f(x)$ by its graph, which we can assume is well approximated
  14588. by the \MF\ path defined by
  14589. \begindisplay
  14590. $F\,=\,\bigl(x_1,f(x_1)\bigr)\to\bigl(x_2,f(x_2)\bigr)\to
  14591. \<etc.>\to\bigl(x_n,f(x_n)\bigr)$
  14592. \enddisplay
  14593. if $f(x)$ is a reasonable ^{function}. Therefore interpolation can be
  14594. done by using path intersection (!):
  14595. \begintt
  14596. vardef interpolate expr F of x = save t; t =
  14597.  if x < xpart point 0 of F: extrap_error 0
  14598.  elseif x > xpart point infinity of F: extrap_error infinity
  14599.  else: xpart(F intersectiontimes verticalline x) fi;
  14600.  ypart point t of F enddef;
  14601. def extrap_error = hide(errhelp "The extreme value will be used.";
  14602.  errmessage "`interpolate' has been asked to extrapolate";
  14603.  errhelp "") enddef;
  14604. vardef verticalline primary x =
  14605.  (x,-infinity)--(x,infinity) enddef;
  14606. \endtt
  14607. For example, if $f(1)=1$, $f(3)=2$, and $f(15)=4$, this interpolation
  14608. scheme gives `interpolate $(1,1)\to(3,2)\to(15,4)$ of~7' the value 3.37.
  14609. \subsection Drawing with ^{overlays}. Let's leave numerical computations
  14610. now and go back into the realm of pictures. Bruce ^{Leban} has suggested
  14611. an extension of plain \MF's `^@clearit@/^@showit@/^@shipit@' commands
  14612. by which `^@fill@' and `^@draw@' essentially operate on imaginary sheets of
  14613. clear plastic. A new command `^@keepit@' places a fresh sheet of plastic
  14614. on top of whatever has already been drawn, thereby preserving the covered image
  14615. against subsequent erasures.
  14616. We can implement @keepit@ by introducing a new picture variable
  14617. ^"totalpicture", and new boolean variables ^"totalnull", ^"currentnull",
  14618. then defining macros as follows:
  14619. \begintt
  14620. def clearit = currentpicture:=totalpicture:=nullpicture;
  14621.  currentnull:=totalnull:=true; enddef;
  14622. def keepit = cull currentpicture keeping (1,infinity);
  14623.  addto totalpicture also currentpicture;
  14624.  currentpicture:=nullpicture;
  14625.  totalnull:=currentnull; currentnull:=true; enddef;
  14626. def addto_currentpicture =
  14627.  currentnull:=false; addto currentpicture enddef;
  14628. def mergeit (text do) =
  14629.  if totalnull: do currentpicture
  14630.  elseif currentnull: do totalpicture
  14631.  else: begingroup save v; picture v; v:=currentpicture;
  14632.   cull v keeping (1,infinity); addto v also totalpicture;
  14633.   do v endgroup fi enddef;
  14634. def shipit = mergeit(shipout) enddef;
  14635. def showit_ = mergeit(show_) enddef;
  14636. def show_ suffix v = display v inwindow currentwindow enddef;
  14637. \endtt
  14638. The "totalnull" and "currentnull" bookkeeping isn't strictly necessary,
  14639. but it contributes greatly to the efficiency of this scheme if the
  14640. extra generality of @keepit@ is not actually being used.
  14641. The `$v$' computations in @mergeit@ involve copying the accumulated
  14642. picture before displaying it or shipping it out; this takes time,
  14643. and it almost doubles the amount of memory needed, so we try to avoid it
  14644. when possible.
  14645. \subsection Filing pictures. If you want to store a picture in a file
  14646. and read it in to some other \MF\ job, you face two problems:
  14647. (1)~\MF's @shipout@ command implicitly culls the picture, so that only
  14648. binary data is left. Pixel values $>0$ are distinguished from pixel
  14649. values $<=0$, but no other information about those values will survive.
  14650. \ (2)~The result of ^@shipout@ can be used in another \MF\ job only if
  14651. you have an auxiliary program that converts from binary ^|gf| format
  14652. to a \MF\ source program; \MF\ can write |gf| files, but it can't
  14653. read them.
  14654. These problems can be resolved by using \MF's ^{transcript} or ^{log file}
  14655. as the output medium, instead of using the |gf| file. For example, let's
  14656. consider first the use of ^"tracingedges". Suppose we say
  14657. \begindisplay
  14658. "tracingedges" $:=$ 1;\cr
  14659. \<any sequence of @fill@, @draw@, or @filldraw@ commands>\cr
  14660. @message@ |"Tracing edges completed."|; \ $"tracingedges":=0$;\cr
  14661. \enddisplay
  14662. then the log file will contain lines such as the following:
  14663. \beginlines
  14664. |Tracing edges at line 15: (weight 1)|
  14665. |(1,5)(1,2)(2,2)(2,1)(3,1)(3,0)(8,0)(8,1)(9,1)(9,2)(10,2)(10,8)(9,8)|
  14666. |(9,9)(8,9)(8,10)(3,10)(3,9)(2,9)(2,8)(1,8)(1,5).|
  14667. \smallskip
  14668. |Tracing edges at line 15: (weight -1)|
  14669. |(3,5)(3,2)(4,2)(4,1)(7,1)(7,2)(8,2)(8,8)(7,8)(7,9)(4,9)(4,8)(3,8)(3,5).|
  14670. \smallskip
  14671. |Tracing edges at line 18: (weight -1)|
  14672. |(No new edges added.)|
  14673. \smallskip
  14674. |Tracing edges completed.|
  14675. \endlines
  14676. Let us write macros so that these lines are acceptable input to \MF\!.
  14677. \begintt
  14678. def Tracing=begingroup save :,[,],Tracing,edges,at,weight,w;
  14679.  delimiters []; let Tracing = endfill; interim turningcheck := 0;
  14680.  vardef at@#(expr wt) = save (,); w := wt;
  14681.   let ( = lp; let ) = rp; fill[gobble begingroup enddef;
  14682.  let edges = \; let weight = \; let : = \; enddef;
  14683. def lp = [ enddef;
  14684. def rp = ] -- enddef;
  14685. vardef No@# = origin enddef;
  14686. def endfill = cycle] withweight w endgroup; enddef;
  14687. def completed = endgroup; enddef;
  14688. \endtt
  14689. ^^"turningcheck" ^^@save@ ^^@delimiters@
  14690. The precise form of edge-traced output, with its limited vocabulary
  14691. and its restricted use of parentheses and commas, has been exploited here.
  14692. With slight changes to this code, you can get weird effects.
  14693. For example, if the definition of |rp| is changed to `|]..tension 4..|',
  14694. ^^{tension}, and if `|scaled|~|5pt|' is inserted before `|withweight|',
  14695. the image will be an ``^{almost digitized}'' character:
  14696. \displayfig Daa (18.5mm)
  14697. (The bumps at the left here are due to the repeated points `|(1,5)|' and
  14698. `|(3,5)|' in the original data. You can remove them by adding an extra
  14699. pass, first tracing the edges that are output by the {\sl unmodified\/}
  14700. |Tracing| macros.)
  14701. Although the effects of @fill@ and @draw@ can be captured by
  14702. "tracingedges", other operations like ^{culling} are not traced.
  14703. Let us therefore consider the more general picture representation
  14704. that \MF\ produces when ^"tracingoutput" is positive, or when you
  14705. ask it to ^@show@ a picture (see Chapter~13). The macros on the next
  14706. page will recreate a picture from input of the form
  14707. \begintt
  14708. beginpicture
  14709. row 1: 1+ -2- || 0+ 2-
  14710. row 0: || 0+ 2++ 5---
  14711. row -2: 0- -2+ ||
  14712. endpicture
  14713. \endtt
  14714. where the middle three lines have been copied verbatim from a transcript
  14715. file. \ (The task would be easier if the token `|-|' didn't have
  14716. to perform two different functions!)
  14717. \begintt
  14718. let neg_ = -; let colon_ = :;
  14719. def beginpicture =
  14720.  begingroup save row, ||, :, ---, --, +, ++, +++, v, xx, yy, done;
  14721.  picture v; v := nullpicture; interim turningcheck := 0;
  14722.  let --- = mmm_; let -- = mm_;
  14723.  let + = p_; let ++ = pp_; let +++ = ppp_;
  14724.  let row = pic_row; let || = relax; let : = pic_colon; : enddef;
  14725. def pic_row primary y = done; yy := y; enddef;
  14726. def pic_colon primary x =
  14727.  if known x colon_ ; xx := x; pic_edge fi enddef;
  14728. def pic_edge =
  14729.  let - = m_;
  14730.  addto v contour unitsquare xscaled xx shifted(0,yy) enddef;
  14731. def mmm_ = withweight 3; let - = neg_; : enddef;
  14732. def mm_ = withweight 2; let - = neg_; : enddef;
  14733. def m_ = withweight 1; let - = neg_; : enddef;
  14734. def p_ = withweight neg_1; let - = neg_; : enddef;
  14735. def pp_ = withweight neg_2; let - = neg_; : enddef;
  14736. def ppp_ = withweight neg_3; let - = neg_; : enddef;
  14737. transform xy_swap; xy_swap = identity rotated 90 xscaled -1;
  14738. def endpicture = done;
  14739.  v transformed xy_swap transformed xy_swap endgroup enddef;
  14740. \endtt
  14741. The reader will find it instructive to study these macros closely.
  14742. When `|done|' appears, it is an unknown primary, so |pic_colon|
  14743. will not attempt to generate another edge. Each new edge also
  14744. inserts a cancelling edge at $x=0$. The two applications ^^"xy\_swap"
  14745. of |xy_swap| at the end will clear away all redundant edges.  (Double
  14746. swapping is a bit faster than the operation `|rotated-90| |rotated|~|90|'
  14747. that was used for this purpose in Chapter~13.)
  14748. \subsection Fattening a pen. Let's move on to another aspect of
  14749. \MF\ by considering
  14750. an operation on ^{pen} ^{polygons}: Given a @pen@ value~$p$,
  14751. the task is to construct a pen `^@taller@~$p$' that is one pixel
  14752. taller. For example, if $p$ is the ^{diamond} nib
  14753. `$(0.5,0)\dashto(0,0.5)\dashto(-0.5,0)\dashto(0,-0.5)\dashto\cycle$',
  14754. the taller nib will be
  14755. \begindisplay
  14756. $(0.5,0.5)\dashto(0,1)\dashto(-0.5,0.5)\dashto(-0.5,-0.5)\dashto(0,-1)
  14757.  \dashto(0.5,-0.5)\dashto\cycle$;
  14758. \enddisplay
  14759. if $p$ is a tilted ^{penrazor} `$(-x,-y)\dashto(x,y)\dashto\cycle$',
  14760. the taller nib will be
  14761. \begindisplay
  14762. $(-x,-y-0.5)\dashto(x,y-0.5)\dashto(x,y+0.5)\dashto(-x,-y+0.5)\dashto\cycle$,
  14763. \enddisplay
  14764. assuming that $x>0$. The macro itself turns out to be fairly simple, but
  14765. it makes instructive use of ^{path} and pen operations.
  14766. We want to split the pen into two parts, a ``bottom'' half and a ``top''
  14767. half; the bottom half should be shifted down by .5~pixels, and the
  14768. top half should be shifted up. The dividing points between halves occur
  14769. at the leftmost and rightmost vertices of the pen. Hmmm; a potential problem
  14770. arises if there are two or more leftmost or rightmost points; for example,
  14771. what if we try to make `@taller@ @taller@~$p$'? Fortunately \MF\ doesn't
  14772. mind if a pen polygon has three or more consecutive vertices that
  14773. lie on a line, hence we can safely choose {\sl any\/} leftmost
  14774. point and any rightmost point.
  14775. The next question is, ``How should we find leftmost and rightmost
  14776. points?'' We will, of course, use ^@makepath@ to find the set of all
  14777. vertices; so we could simply traverse the path and find the minimum
  14778. and maximum $x$~coordinates. However, it will be faster (and more fun)
  14779. to use either ^{directiontime} or ^{penoffset} for this purpose.
  14780. Let's try directiontime first:
  14781. \begintt
  14782. vardef taller primary p =
  14783.  save r, n, t, T; path r;
  14784.  r = tensepath makepath p; n = length r;
  14785.  t = round directiontime up of r;
  14786.  T = round directiontime down of r;
  14787.  if t>T: t := t-n; fi
  14788.  makepen(subpath(T-n,t) of r shifted .5down
  14789.   --subpath(t,T) of r shifted .5up -- cycle) enddef;
  14790. \endtt
  14791. The result of @makepath@ has control points equal to their adjacent
  14792. vertices, so it could not be used with @directiontime@.
  14793. \ (If any key point is equal to its precontrol or postcontrol,
  14794. the ``^{velocity}'' of the path is zero at that point; @directiontime@
  14795. assumes that all directions occur whenever the velocity drops to zero.) \
  14796. Therefore we have used `^@tensepath@'.
  14797. This almost works, once we realize that the values
  14798. of $t$ and~$T$ sometimes need to be rounded to integers. But it
  14799. fails for pens like @penspeck@ that have points very close together,
  14800. since @tensepath@ is no better than an unadulterated @makepath@ in such cases.
  14801. Furthermore, even if we could define a nice path from~$p$ (for example
  14802. by scaling it up), we would run into problems of
  14803. numerical instability, in cases like @penrazor@ where
  14804. the pen polygon takes a $180^\circ$ turn. Razor-thin pens cannot be recognized
  14805. easily, because they might have more than two vertices; for example,
  14806. rotations of future pens such as
  14807. `@makepen@($"left"\to"origin"\to"right"\to\cycle$)' are problematical.
  14808. We can obtain a more robust result by using penoffset, because
  14809. this operation makes use of the convexity of the polygon. The
  14810. ``fastest'' solution looks like this:
  14811. \begintt
  14812. vardef taller primary p =
  14813.  save q, r, n, t, T; pen q; q = p;
  14814.  path r; r = makepath q; n = length r;
  14815.  t = round xpart(r intersectiontimes penoffset up of q);
  14816.  T = round xpart(r intersectiontimes penoffset down of q);
  14817.  if t>T: t := t-n; fi
  14818.  makepen(subpath(T-n,t) of r shifted .5down
  14819.   --subpath(t,T) of r shifted .5up -- cycle) enddef;
  14820. \endtt
  14821. ^^{intersectiontimes} ^^{subpath}
  14822. (The argument $p$ is copied into $q$, in case it's a ^{future pen};
  14823. this means that the conversion of future pen to pen need be
  14824. done only once instead of three times.)
  14825. \subsection ^{Bernshte{\u\i}n} polynomials. And now, for our last trick,
  14826. let's try to extend \MF's syntax so that it will accept generalized
  14827. ^{mediation} formulas of the form `$t[u_1,\ldots,u_n]$' for all $n\ge2$.
  14828. \ (This notation was introduced for $n=3$ and~4 in Chapter~14, when we were
  14829. considering fractional subpaths.) \ If $n>2$, the identity
  14830. \begindisplay
  14831. $t[\,u_1,\ldots,u_n]\;=\;t\bigl[t[u_1,\ldots,u_{n-1}],t[u_2,\ldots,u_n]\,\bigr]$
  14832. \enddisplay
  14833. defines $t[u_1,\ldots,u_n]$ recursively, and it can be shown that the
  14834. alternative definition
  14835. \begindisplay
  14836. $t[\,u_1,\ldots,u_n]\;=\;t\bigl[t[u_1,u_2],\ldots,t[u_{n-1},u_n]\,\bigr]$
  14837. \enddisplay
  14838. gives the same result. \ (Indeed, we have
  14839. \begindisplay
  14840. $\displaystyle t[u_1,\ldots,u_n]\;=\;\sum_{k=1}^n{n-1\choose k-1}
  14841.  (1-t)^{n-k}t^{k-1}u_k,$
  14842. \enddisplay
  14843. a Bernste{\u\i}n polynomial of order $n-1$.)
  14844. Our problem is to change the meaning of \MF's ^{brackets} so that
  14845. expressions like `$1/2[a,b,c,d]$' will evaluate to `$.125a+.375b+.375c
  14846. +.125d$' in accordance with the formulas just given, but we don't want
  14847. to mess up the other primitive uses of brackets in contexts like
  14848. `|x[n]|' and `|path|~|p[][]a|'. We also want to be able to use
  14849. brackets inside of brackets.
  14850. The reader is challenged to try solving this problem before looking at
  14851. the weird solution that follows. Perhaps there is a simpler way?
  14852. \begintt
  14853. let [[[ = [; let ]]] = ]; let [ = lbrack;
  14854. def lbrack = hide(delimiters []) lookahead [ enddef;
  14855. def lookahead(text t) =
  14856.  hide(let [ = lbrack;
  14857.   for u=t, hide(n_ := 0; let switch_ = first_): switch_ u; endfor)
  14858.  if n_<3: [[[t]]] else: Bernshtein n_ fi enddef;
  14859. def first_ primary u =
  14860.  if numeric u: numeric u_[[[]]]; store_ u
  14861.  elseif pair u: pair u_[[[]]]; store_ u fi;
  14862.  let switch_ = store_ enddef;
  14863. def store_ primary u = u_[[[incr n_]]] := u enddef;
  14864. primarydef t Bernshtein nn =
  14865.  begingroup for n=nn downto 2:
  14866.   for k=1 upto n-1: u_[[[k]]]:=t[[[u_[[[k]]],u_[[[k+1]]] ]]];
  14867.   endfor endfor u_[[[1]]] endgroup enddef;
  14868. \endtt
  14869. The most subtle thing about this code is the way it uses the `empty'
  14870. option of a ^\<for list> to dispense with ^{empty text arguments}.
  14871. Since \MF\ evaluates all the expressions of a ^@for@ loop before
  14872. reading the loop text, and since `|n_|' and `|u_|' are used here
  14873. only when no recursion is taking place, it is unnecessary to ^{save}
  14874. their values even when brackets are nested inside of brackets.
  14875. Of course this trick slows \MF\ down tremendously, whenever brackets
  14876. appear, so it is just of academic interest. But it seems to work
  14877. in all cases except with respect to formulas that involve `^|]]|'
  14878. (two consecutive brackets); the latter token, which plain \MF\ expands
  14879. to `|]|~|]|', is not expanded when |lookahead| reads its ^{text
  14880. argument}, hence the user must remember to insert a space between
  14881. consecutive brackets. \looseness=-1
  14882. \endchapter
  14883. Their tricks an' craft hae put me daft,
  14884. They've taen me in, an' a' that.
  14885. \author ROBERT ^{BURNS},  {\sl The Jolly Beggar\/} (1799) % air 7
  14886. \bigskip
  14887. Ebery house hab him dutty carner.
  14888. \author ^{ANDERSON} and ^{CUNDALL},  {\sl Jamaica Proverbs and Sayings\/} (1927)
  14889.  % #755 in 2nd edition; was not in the first (1910) edition
  14890. \eject
  14891. \beginchapter Appendix E. Examples
  14892. We've seen lots of examples of individual letters or parts of letters;
  14893. let's concentrate now on the problem of getting things all together.
  14894. The next two pages contain the entire contents of an example file
  14895. `|logo.mf|', which generates the letters of the \MF\ ^{logo}. The file
  14896. is short, because only seven letters are involved, and because those letters
  14897. were intentionally done in a style that would be easy for the system they name.
  14898. But the file is complete, and it illustrates in simplified form all
  14899. the essential aspects of larger fonts: Ad~hoc dimensions are
  14900. converted to pixels; subroutines are defined; programs for
  14901. individual letters appear; intercharacter and interword
  14902. spacing conventions are nailed down. Furthermore, the character programs
  14903. are careful to draw letters that will be
  14904. well adapted to the raster, even if pixels on the output device are
  14905. not square. % It's all there, in one short program.
  14906. We've been studying the `\MF' letters off and on since Chapter~4, making
  14907. our examples slightly more complex as more of the language has been
  14908. encountered. Finally we're ready to pull out all the stops and look at the
  14909. real, professional-quality |logo.mf|, which incorporates all the best
  14910. suggestions that have appeared in the text and in answers to the exercises.
  14911. It's easy to generate a font with |logo.mf|, by proceeding as explained
  14912. in Chapter~11. For example, the |logo10| font that produces `\MF' in
  14913. 10-point size can be created for a low-resolution printer by running
  14914. \MF\ with the ^{command line}
  14915. \begintt
  14916. \mode=lowres; input logo10
  14917. \endtt
  14918. where the ^{parameter file} |logo10.mf| appears in that chapter. Furthermore
  14919. the slanted version `{\manual 89:;<=>:}\kern3pt' can be created by
  14920. inputting the parameter file |logosl10.mf|, which says simply
  14921. \begintt
  14922. % 10-point slanted METAFONT logo
  14923. slant := 1/4;
  14924. input logo10
  14925. \endtt
  14926. The ^"slant" parameter affects ^"currenttransform" as explained in
  14927. Chapter~15.
  14928. There isn't a great deal of ``^{meta-ness}'' in the |logo.mf| design,
  14929. because only a few forms of the \MF\ logo are needed. However, some
  14930. interesting variations are possible; for example, if we use the
  14931. parameter files
  14932. \begindisplay \def\qquad{\hskip4em\relax} \advance\belowdisplayskip by 3pt
  14933. |font_size 30pt#;|&|font_size 10pt#;|\cr
  14934. |ht#:=25pt#;|&|ht#:=6pt#;|\cr
  14935. |xgap#:=1.5pt#;|&|xgap#:=2pt#;|\cr
  14936. |u#:=3/9pt#;|&|u#:=4/3pt#;|\cr
  14937. |s#:=1/3pt#;|&|s#:=-2/3pt#;|\cr
  14938. |o#:=2/9pt#;|&|o#:=1/9pt#;|\cr
  14939. |px#:=1pt#;|&|px#:=1/3pt#;|\cr
  14940. |slant:=-1/9;|\cr
  14941. \enddisplay
  14942. we get \kern2pt{\manual BCDGHIJD} and \kern4pt{\manual KLUVWvwU},
  14943. \kern4pt\ respectively.
  14944. \goodbreak\begingroup\obeylines\everypar{\strut}\parindent=0pt
  14945. |% Routines for the METAFONT logo, as found in The METAFONTbook|
  14946. |% (logo10.mf is a typical parameter file)|
  14947. \medskip
  14948. |mode_setup;|
  14949. |if unknown slant: slant:=0 else: currenttransform:=|
  14950. | identity slanted slant yscaled aspect_ratio fi;|
  14951. \medskip
  14952. |ygap#:=(ht#/13.5u#)*xgap#;              % vertical adjustment|
  14953. |ho#:=o#;                                % horizontal overshoot|
  14954. |leftstemloc#:=2.5u#+s#;                 % position of left stem|
  14955. |barheight#:=.45ht#;                     % height of bar lines|
  14956. |py#:=.9px#;                             % vertical pen thickness|
  14957. \medskip
  14958. |define_pixels(s,u);|
  14959. |define_whole_pixels(xgap);|
  14960. |define_whole_vertical_pixels(ygap);|
  14961. |define_blacker_pixels(px,py);|
  14962. |pickup pencircle xscaled px yscaled py;|
  14963. |logo_pen:=savepen;|
  14964. |define_good_x_pixels(leftstemloc);|
  14965. |define_good_y_pixels(barheight);|
  14966. |define_corrected_pixels(o);|
  14967. |define_horizontal_corrected_pixels(ho);|
  14968. \medskip
  14969. |def beginlogochar(expr code, unit_width) =|
  14970. | beginchar(code,unit_width*u#+2s#,ht#,0);|
  14971. | pickup logo_pen enddef;|
  14972. \medskip
  14973. |def super_half(suffix i,j,k) =|
  14974. | draw z.i{0,y.j-y.i}|
  14975. | ... (.8[x.j,x.i],.8[y.i,y.j]){z.j-z.i}|
  14976. | ... z.j{x.k-x.i,0}|
  14977. | ... (.8[x.j,x.k],.8[y.k,y.j]){z.k-z.j}|
  14978. | ... z.k{0,y.k-y.j} enddef;|
  14979. \medskip
  14980. |beginlogochar("M",18);|
  14981. |x1=x2=leftstemloc; x4=x5=w-x1; x3=w-x3;|
  14982. |y1=y5; y2=y4; bot y1=-o;|
  14983. |top y2=h+o; y3=y1+ygap;|
  14984. |draw z1--z2--z3--z4--z5;|
  14985. |labels(1,2,3,4,5); endchar;|
  14986. \medskip
  14987. |beginlogochar("E",14);|
  14988. |x1=x2=x3=leftstemloc;|
  14989. |x4=x6=w-x1+ho; x5=x4-xgap;|
  14990. |y1=y6; y2=y5; y3=y4;|
  14991. |bot y1=0; top y3=h; y2=barheight;|
  14992. \nointerlineskip
  14993. \smash{\vbox{
  14994.   \rightline{\figbox{Eb}{224\apspix}{216\apspix}\vbox} % F
  14995.   \kern12pt
  14996.   \rightline{\figbox{A18a}{240\apspix}{216\apspix}\vbox} % A
  14997.   \kern12pt
  14998.   \rightline{\figbox{Ea}{208\apspix}{216\apspix}\vbox} % T
  14999.   \kern3.5pt}}
  15000. \goodbreak
  15001. \smash{\vtop{\kern0pt\kern6pt
  15002.   \rightline{\figbox{18a}{240\apspix}{216\apspix}\vbox} % O
  15003.   \kern12pt
  15004.   \rightline{\figbox{4c}{288\apspix}{216\apspix}\vbox} % M
  15005.   \kern12pt
  15006.   \rightline{\figbox{11a}{224\apspix}{216\apspix}\vbox} % E
  15007.   \kern12pt
  15008.   \rightline{\figbox{21a}{240\apspix}{216\apspix}\vbox} % N
  15009.   }}\nointerlineskip
  15010. |draw z6--z1--z3--z4; draw z2--z5;|
  15011. |labels(1,2,3,4,5,6); endchar;|
  15012. \medskip
  15013. |beginlogochar("T",13);|
  15014. |italcorr ht#*slant + .5u#;|
  15015. |if .5w<>good.x .5w: change_width; fi|
  15016. |lft x1=-eps; x2=w-x1; x3=x4=.5w;|
  15017. |y1=y2=y3; top y1=h; bot y4=-o;|
  15018. |draw z1--z2; draw z3--z4;|
  15019. |labels(1,2,3,4); endchar;|
  15020. \medskip
  15021. |beginlogochar("A",15);|
  15022. |x1=.5w; x2=x4=leftstemloc; x3=x5=w-x2;|
  15023. |top y1=h+o; y2=y3=barheight;|
  15024. |bot y4=bot y5=-o;|
  15025. |draw z4--z2--z3--z5; super_half(2,1,3);|
  15026. |labels(1,2,3,4,5); endchar;|
  15027. \medskip
  15028. |beginlogochar("F",14);|
  15029. |x1=x2=x3=leftstemloc;|
  15030. |x4=w-x1+ho; x5=x4-xgap;|
  15031. |y2=y5; y3=y4; bot y1=-o;|
  15032. |top y3=h; y2=barheight;|
  15033. |draw z1--z3--z4; draw z2--z5;|
  15034. |labels(1,2,3,4,5); endchar;|
  15035. \medskip
  15036. |beginlogochar("O",15);|
  15037. |x1=x4=.5w; top y1=h+o; bot y4=-o;|
  15038. |x2=w-x3=good.x(1.5u+s); y2=y3=barheight;|
  15039. |super_half(2,1,3); super_half(2,4,3);|
  15040. |labels(1,2,3,4); endchar;|
  15041. \medskip
  15042. |beginlogochar("N",15);|
  15043. |x1=x2=leftstemloc; x3=x4=x5=w-x1;|
  15044. |bot y1=bot y4=-o;|
  15045. |top y2=top y5=h+o; y3=y4+ygap;|
  15046. |draw z1--z2--z3; draw z4--z5;|
  15047. |labels(1,2,3,4,5); endchar;|
  15048. \medskip
  15049. |ligtable "T": "A" kern -.5u#;|
  15050. |ligtable "F": "O" kern -u#;|
  15051. \medskip
  15052. |font_quad:=18u#+2s#;|
  15053. |font_normal_space:=6u#+2s#;|
  15054. |font_normal_stretch:=3u#;|
  15055. |font_normal_shrink:=2u#;|
  15056. |font_identifier:="MFLOGO" if slant<>0: & "SL" fi;|
  15057. |font_coding_scheme:="AEFMNOT only";|
  15058. \endgroup\goodbreak
  15059. Everything in |logo.mf| has already been explained previously in this
  15060. book except for the very last two lines, which define a `^@font\_identifier@'
  15061. and a `^@font\_coding\_scheme@'. These are optional bits of information
  15062. that are discussed in Appendix~F\null. Furthermore an ^{italic correction}
  15063. has been specified for the letter `{\manual T}', since it's the final
  15064. letter of `\kern-1.4pt{\manual 89:;<=>:\/}'.
  15065. \medskip\ninepoint
  15066. The program for a complete typeface will differ from the program for
  15067. this simple logo font primarily in degree; there will be lots more
  15068. parameters, lots more subroutines, lots more characters, lots more
  15069. ligatures and kerns and whatnot. But there will probably also be
  15070. more administrative machinery, designed to facilitate the creation,
  15071. testing, and modification of characters, since a large enterprise
  15072. requires good organization. The remainder of this appendix is
  15073. devoted to an example of how this might be done: We shall discuss
  15074. the additional kinds of routines that the author ^^{Knuth} found
  15075. helpful while he was developing the ^{Computer Modern} family
  15076. of typefaces.
  15077. The complete, unexpurgated programs for Computer Modern appear in {\sl
  15078. Computers \& Typesetting}, Volume~E\null; but since they have evolved
  15079. over a long period of time, they are rather complex. We shall simplify
  15080. the details so that it will be easier to grasp the important issues
  15081. without being distracted by irrelevant technicalities.
  15082. The simple logo fonts discussed above are generated by two types
  15083. of files: There are parameter files like |logo10.mf|, and there is
  15084. a program file |logo.mf|. The Computer Modern fonts, being more
  15085. extensive, are generated by four types of files: There are
  15086. {\sl^{parameter files}\/} like `|cmr10.mf|', which specify the
  15087. ad hoc dimensions for particular sizes and styles of type; there are
  15088. {\sl^{driver files}\/} like `|roman.mf|', which serve as chief
  15089. executives of the font-generation process; there are
  15090. {\sl^{program files}\/} like `|punct.mf|', which contain programs
  15091. for individual characters; and there's a {\sl^{base file}\/} called
  15092. `|cmbase.mf|', which contains the subroutines and other macros used
  15093. throughout the system.
  15094. Our logo example could have been cast in this more general mold by moving
  15095. the character programs into a program file `|METAFON.mf|', and by moving
  15096. most of the opening material into a base file `|logobase.mf|'
  15097. that looks like this:
  15098. \beginlines
  15099. |% Base file for the METAFONT logo|
  15100. |logobase:=1;           % when logobase is known, this file has been input|
  15101. \smallskip
  15102. |def font_setup =|
  15103. | if unknown slant: slant:=0 else: currenttransform:=|
  15104. %|  identity slanted slant yscaled aspect_ratio fi;|
  15105. \qquad\smash{\vdots}\qquad\vbox to10pt{}%
  15106.  \raise1pt\hbox{(the previous code is unchanged)}
  15107. | define_corrected_pixels(o);|
  15108. | define_horizontal_corrected_pixels(ho); enddef;|
  15109. \endlines
  15110. followed by the definitions of |beginlogochar| and |super_half|.
  15111. Then we're left with a driver file |logo.mf| that looks like this:
  15112. \beginlines
  15113. |% Driver file for the METAFONT logo|
  15114. |if unknown logobase: input logobase fi|
  15115. \smallskip
  15116. |mode_setup; font_setup;                  % establish pixel-oriented units|
  15117. |input METAFON                            % generate the characters|
  15118. \smallskip
  15119. |ligtable "T": "A" kern -.5u#;|
  15120. \weakendlines
  15121. and so on, concluding as before.
  15122. In general, a parameter file calls on a driver file, which calls on
  15123. one or more program files; the base file contains predefined macros
  15124. shared by all. There may be several driver files, each using a
  15125. different combination of program files; for example, Computer Modern
  15126. has `|roman.mf|' and `|italic.mf|', % a little white lie, multiplied below
  15127. both of which call on |punct.mf| to generate punctuation marks,
  15128. although they use different program files to generate the lowercase
  15129. alphabets. Characters are partitioned into program files so that
  15130. they can be shared by different drivers.
  15131. Parameter files in Computer Modern don't quite follow the conventions
  15132. of\/ |logo10.mf|. Here, for example, are the
  15133. opening and closing lines of ^|cmr10.mf|:
  15134. \beginlines
  15135. |% Computer Modern Roman 10 point|
  15136. |if unknown cmbase: input cmbase fi|
  15137. \smallskip
  15138. |font_identifier "CMR"; font_size 10pt#;|
  15139. \smallskip
  15140. |u#:=20/36pt#;                % unit width|
  15141. |serif_fit:=0pt#;             % extra sidebar near serifs|
  15142. |letter_fit:=0pt#;            % extra space added to all sidebars|
  15143. \vskip-3pt
  15144. \qquad\vdots
  15145. |serifs:=true;                % should serifs and bulbs be attached?|
  15146. |monospace:=false;            % should all characters have the same width?|
  15147. \smallskip
  15148. |generate roman               % switch to the driver file|
  15149. \endlines
  15150. The main differences are: \ (1) There's special code at the beginning, to
  15151. make sure that |cmbase.mf| has been loaded. The base file includes
  15152. several things that are needed right away; for example, |cmbase| declares
  15153. the variables `"serifs"' and `^"monospace"' to be of type @boolean@,
  15154. so that boolean-valued parameter assignments like `$"serifs":=@true@$'
  15155. will be legal. \ (2)~The @font\_identifier@ is defined in the parameter file,
  15156. not in the driver file. \ (3)~The last line says `^@generate@' instead of
  15157. `@input@'; the base file defines @generate@ to be the same as @input@,
  15158. but other meanings are assigned by utility routines that we'll study later.
  15159. \ (4)~The final `^@end@' is no longer present in the parameter file.
  15160. The |roman.mf| driver looks like this (vastly simplified):
  15161. ^^@font\_slant@ ^^@font\_quad@ ^^@font\_normal\_space@
  15162. ^^@font\_normal\_stretch@ ^^@font\_normal\_shrink@
  15163. \beginlines
  15164. |% The Computer Modern Roman family of fonts|
  15165. \smallskip
  15166. |mode_setup; font_setup;|
  15167. \smallskip
  15168. |input romanu;                         % upper case (majuscules)|
  15169. |input romanl;                         % lower case (minuscules)|
  15170. |input romand;                         % numerals|
  15171. |input punct;                          % punctuation marks|
  15172. \smallskip
  15173. |font_slant slant;|
  15174. |if monospace: font_quad 18u#;|
  15175. | font_normal_space 9u#;               % no stretching or shrinking|
  15176. |else: font_quad 18u#+4letter_fit#;|
  15177. | font_normal_space 6u#+2letter_fit#;  % interword spacing|
  15178. | font_normal_stretch 3u#;             % with ``glue''|
  15179. | font_normal_shrink 2u#;|
  15180. | input romlig;                        % f ligatures|
  15181. | |^|ligtable|| "f": "i" =: oct"014", "f" =: oct"013", "l" =: oct"015",|
  15182. |            "'" kern u#, "?" kern u#, "!" kern u#;|
  15183. | ligtable oct"013": "i" =: oct"016", "l" =: oct"016",   % ffi and ffl|
  15184. |            "'" kern u#, "?" kern u#, "!" kern u#;|
  15185. | ligtable "-": "-" =: oct"173";                         % en dash|
  15186. | ligtable oct"173": "-" =: oct"174";                    % em dash|
  15187. | ligtable "`": "`" =: oct"134";                         % open quotes|
  15188. | ligtable "'": "'" =: oct"042",                         % close quotes|
  15189. |            "?" kern 2u#, "!" kern 2u#;|
  15190. |fi; |^|bye.|
  15191. \endlines
  15192. In a ^{monospaced} font like ^|cmtt10|, all characters will be exactly
  15193. $9u\0$ wide. Both |cmr10| and~|cmtt10| use the |roman| driver, but
  15194. |roman| omits the ligatures and changes the interword spacing
  15195. when it is producing monospaced fonts.
  15196. The program files of Computer Modern have slightly different conventions
  15197. from those of plain \MF\!\null. Here, for example, are the ^^{.} ^^{em dash}
  15198. programs for two of the simplest ^{punctuation marks}:
  15199. \beginlines
  15200. |cmchar "Period";|
  15201. |numeric dot_diam#; dot_diam# = if monospace: 5/4 fi dot_size#;|
  15202. |define_whole_blacker_pixels(dot_diam);|
  15203. |beginchar(".",5u#,dot_diam#,0);|
  15204. |adjust_fit(0,0); pickup fine.nib;|
  15205. |pos1(dot_diam,0); pos2(dot_diam,90);|
  15206. |x1l=good.x(x1l+.5w-x1); bot y2l=0; z1=z2; dot(1,2);              % dot|
  15207. |penlabels(1,2); endchar;|
  15208. \medskip
  15209. \leftline{\hskip3pc\figbox{Ec\&Ed}{3in}{360\apspix}\vbox}
  15210. \smallskip
  15211. |iff not monospace: cmchar "Em dash";|
  15212. |beginchar(oct"174",18u#,x_height#,0);|
  15213. |italcorr .61803x_height#*slant + .5u#;|
  15214. |adjust_fit(letter_fit#,letter_fit#);|
  15215. |pickup crisp.nib; pos1(vair,90); pos2(vair,90);|
  15216. |y1r=y2r=good.y(y1r+.61803h-y1); lft x1=-eps; rt x2=w+eps;|
  15217. |filldraw stroke z1e--z2e;                                   % crossbar|
  15218. |penlabels(1,2); endchar;|
  15219. \endlines
  15220. The new structural features in these programs are: (1)~`^@cmchar@',
  15221. which appears at the very beginning of each character program;
  15222. (2)~`^@iff@~\<boolean expression>:', which precedes @cmchar@ if
  15223. the character is to be generated only when the boolean expression
  15224. is true; (3)~`^@adjust\_fit@', which can change the amount of white space
  15225. at the character's left and/or right; (4)~pens called `"fine.nib"' and
  15226. `"crisp.nib"'; (5)~new macros `"pos"', `"dot"', and `"stroke"',
  15227. discussed further below.
  15228. The base file |cmbase.mf| begins as follows:
  15229. \beginlines
  15230. |% The base file for Computer Modern (a supplement to plain.mf)|
  15231. \smallskip
  15232. |cmbase:=1;              % when cmbase is known, this file has been input|
  15233. \smallskip
  15234. |let cmchar = relax;     % `cmchar' should precede each character|
  15235. |let generate = input;   % `generate' should follow the parameters|
  15236. \smallskip
  15237. |newinternal slant, superness,| $\cdots$ |  % purely numeric parameters|
  15238. |boolean serifs, monospace,| $\cdots$ |     % boolean parameters|
  15239. \endlines
  15240. These few lines are straightforward enough. Although |cmchar| is defined
  15241. to be the same as ^|relax|, which does nothing, the definition of
  15242. |cmchar| will be changed by certain utility programs below; this will
  15243. prove to be a convenience when characters are designed, tested, and maintained.
  15244. The next few lines of |cmbase| are trickier. They implement the `@iff@\kern1pt'
  15245. feature, which bypasses unwanted characters at high speed.
  15246. \beginlines
  15247. |let semi_ = ;; let colon_ = :; let endchar_ = endchar;|
  15248. |def iff expr b =|
  15249. | if b: let next_ = use_it else: let next_ = lose_it fi;|
  15250. | next_ enddef;|
  15251. |def use_it = let : = restore_colon; enddef;|
  15252. |def restore_colon = let : = colon_; enddef;|
  15253. |def lose_it = let endchar = fi; inner cmchar; let ; = fix_ semi_|
  15254. | if false enddef;|
  15255. |def fix_ = let ; = semi_; let endchar = endchar_; outer cmchar; enddef;|
  15256. |def always_iff = let : = endgroup; killboolean enddef;|
  15257. |def killboolean text t = use_it enddef;|
  15258. |outer cmchar;|
  15259. \weakendlines
  15260. ^^@always\_if@ ^^@inner@ ^^@outer@
  15261. (The |lose_it| routine assumes that every character program will end
  15262. with `|endchar;|'.)
  15263. The most interesting part of |cmbase| is probably the way it allows the
  15264. ``^{side\-bearings}'' of each character to be fine-tuned. The amount of
  15265. space at the left and right edges of the character's ``^{bounding box}''
  15266. can be adjusted without actually shifting the picture, and without
  15267. changing the width that was specified in @beginchar@. Here's how it works:
  15268. After a @beginchar@ command and an optional @italcorr@, each Computer
  15269. Modern character program is supposed to say
  15270. \begindisplay
  15271. @adjust\_fit@(\<left sidebearing adjustment>,\thinspace
  15272.   \<right sidebearing adjustment>);
  15273. \enddisplay
  15274. sidebearing adjustments are given in true, ``sharped'' units.
  15275. The ^@adjust\_fit@ routine essentially adds extra space at the left
  15276. and right, corresponding to the sidebearing adjustments. An ad-hoc
  15277. dimension called ``^"letter\_fit"$\0$'' is also added to all sidebearings,
  15278. behind the scenes.
  15279. Our example program for the |"."|\ says simply `@adjust\_fit@$(0,0)$';
  15280. this means that only "letter\_fit" is added. The program for em-dash
  15281. says `@adjust\_fit@$("letter\_fit"\0,\allowbreak"letter\_fit"\0)$', hence
  15282. the sidebearings are increased by 2"letter\_fit" at each side.
  15283. The total character width of the em-dash comes to $18u\0+
  15284. 4"letter\_fit"\0$ (which is indeed one em, the value of ^@font\_quad@
  15285. specified in the |roman| driver file).
  15286. The program for lowercase `^{b}' in file |romanl.mf| says
  15287. `@adjust\_fit@$("serif\_fit"\0,0)$'; this adds the ^"serif\_fit"
  15288. parameter at the left, to compensate for the possible appearance
  15289. of a serif at the left of this character. The "serif\_fit" is
  15290. zero in |cmr10|, but it has a negative value in a ^{sans-serif} font,
  15291. and a positive value when serifs are extralong.
  15292. The nice thing about @adjust\_fit@ is that it's an ``add-on''
  15293. specification that doesn't affect the rest of the character design.
  15294. The program can still be written as if 0~were the left edge and
  15295. $w$~were the right edge; afterwards the fit can be adjusted without
  15296. changing the program or the shapes.
  15297. There are two versions of @adjust\_fit@, one for normal fonts
  15298. and one for ^{mono\-space} fonts. Both of them are slightly complicated
  15299. by something called ^"shrink\_fit", which will be explained later;
  15300. for the moment, let's just imagine that $"shrink\_fit"=0$. Here is the
  15301. routine for the normal case:
  15302. \beginlines
  15303. |def normal_adjust_fit(expr left_adjustment,right_adjustment) =|
  15304. | l := -hround(left_adjustment*hppp)-letter_fit;|
  15305. | interim xoffset := -l;|
  15306. | charwd := charwd+2letter_fit#+left_adjustment+right_adjustment;|
  15307. | r := l+hround(charwd*hppp)-shrink_fit;|
  15308. | w := r-hround(right_adjustment*hppp)-letter_fit;|
  15309. | enddef;|
  15310. \endlines
  15311. Variables ^"l" and ^"r" are set to the actual pixel boundaries of the
  15312. character; thus, plain \MF's bounding box has $0\le x\le w$, but
  15313. Computer Modern's has $l\le x\le r$. ^{Rounding} has been done
  15314. very carefully so that the sidebearings will have consistent
  15315. relationships across an entire font. Notice that ^"w"~has been
  15316. recalculated; this means that @adjust\_fit@ can affect the digitization,
  15317. but---we hope---in a beneficial way.
  15318. In a monospaced font, the @adjust\_fit@ routine changes the
  15319. unit-width parameter, ^"u", so that the total width after adjustment
  15320. comes out to be constant. Similar adjustments are made to parameters
  15321. like ^"jut", the nominal serif length. The width of all characters
  15322. in a monospaced font will be $"mono\_charwd"\0$ in true units,
  15323. ^"mono\_charwd" in pixels. The italic correction of all
  15324. characters will be $"mono\_charic"\0$.
  15325. \beginlines
  15326. |def mono_adjust_fit(expr left_adjustment,right_adjustment) =|
  15327. | numeric expansion_factor; mono_charwd# = 2letter_fit#|
  15328. |   + expansion_factor*(charwd+left_adjustment+right_adjustment);|
  15329. | forsuffixes $=u,jut,| $\cdots$ |:|
  15330. |   $ := $.#*expansion_factor*hppp; endfor|
  15331. | l := -hround(left_adjustment*expansion_factor*hppp)-letter_fit;|
  15332. | interim xoffset := -l;|
  15333. | r := l+mono_charwd-shrink_fit;|
  15334. | w := r-hround(right_adjustment*expansion_factor*hppp)-letter_fit;|
  15335. | charwd := mono_charwd#; charic := mono_charic#;|
  15336. | enddef;|
  15337. \weakendlines
  15338. It took the author ^^{Knuth} umpteen trials to get this routine right.
  15339. The ^"xoffset" calculations in @adjust\_fit@ are enough to shift the
  15340. character by the proper amount when it's being ^{shipped out}. We just
  15341. have to take care of getting the correct character width in pixels,
  15342. and |cmbase| does this by setting
  15343. ^^"extra\_endchar"
  15344. \beginlines
  15345. |extra_endchar := extra_endchar&"r:=r+shrink_fit;w:=r-l;";|
  15346. \endlines
  15347. No other changes to plain \MF's ^@endchar@ routine are needed; but we do
  15348. need to redefine ^|makebox| and ^|maketicks|, in order to show the
  15349. adjusted bounding box. It's convenient to change |makebox| so that it also
  15350. slants the box, in a slanted font, and so that it draws vertical lines
  15351. one unit apart as aids to the designer; several more horizontal lines
  15352. are also drawn:
  15353. \beginlines
  15354. |def makebox(text rule) =|
  15355. | for y=0,asc_height,body_height,x_height,bar_height,|
  15356. |     -desc_depth,-body_depth: rule((l,y)t_,(r,y)t_); endfor % horizontals|
  15357. | for x=l,r: rule((x,-body_depth)t_,(x,body_height)t_); endfor % verticals|
  15358. | for x=u*(1+floor(l/u)) step u until r-1:|
  15359. |  rule((x,-body_depth)t_,(x,body_height)t_); endfor      % more verticals|
  15360. | if charic<>0:|
  15361. |  rule((r+charic*pt,h.o_),(r+charic*pt,.5h.o_)); fi   % italic correction|
  15362. | enddef;|
  15363. \smallskip
  15364. |def maketicks(text rule) =|
  15365. | for y=0,h.o_,-d.o_:|
  15366. |  rule((l,y),(l+10,y)); rule((r-10,y),(r,y)); endfor        % horizontals|
  15367. | for x=l,r: rule((x,10-d.o_),(x,-d.o_));|
  15368. |            rule((x,h.o_-10),(x,h.o_)); endfor                % verticals|
  15369. | if charic<>0:|
  15370. |  rule((r+charic*pt,h.o_-10),(r+charic*pt,h.o_)); fi  % italic correction|
  15371. | enddef;|
  15372. \weakendlines
  15373. (Examples of the new |makebox| routine appear in the illustrations for
  15374. period and em-dash earlier in this appendix, and also in Chapter~23.)
  15375. \smallskip
  15376. Plain \MF's ^@change\_width@ routine must also be generalized:
  15377. \beginlines
  15378. |def change_width = if not monospace:           % change width by +1 or -1|
  15379. | if r+shrink_fit-l = floor(charwd*hppp): w := w+1; r := r+1;|
  15380. | else: w := w-1; r := r-1; fi fi enddef;|
  15381. \endlines
  15382. The Computer Modern ^@font\_setup@ routine is invoked at the beginning of
  15383. each driver file. This is what converts sharped units to pixels;
  15384. @font\_setup@ also computes additional quantities that are important to the
  15385. font as a whole. It's a long macro, but here are its important features:
  15386. \beginlines
  15387. |def font_setup =|
  15388. | define_pixels(u,jut,| $\cdots$ |);|
  15389. | define_whole_pixels(letter_fit,fine,crisp,| $\cdots$ |);|
  15390. | define_whole_vertical_pixels(body_height,cap_height,| $\cdots$ |);|
  15391. | define_whole_blacker_pixels(hair,stem,curve,| $\cdots$ |);|
  15392. | define_whole_vertical_blacker_pixels(vair,slab,| $\cdots$ |);|
  15393. | define_corrected_pixels(o,| $\cdots$ |);|
  15394. \smallbreak
  15395. | if monospace: mono_charwd# := 9u#; define_whole_pixels(mono_charwd);|
  15396. |  mono_charic# := max(0,body_height#*slant);|
  15397. |  let adjust_fit = mono_adjust_fit;|
  15398. | else: let adjust_fit = normal_adjust_fit; fi|
  15399. | lowres_fix(stem,curve) 1.2;|
  15400. ^^@lowres\_fix@ \smallbreak
  15401. | |\<Initialize pen nibs, see below>
  15402. \smallbreak
  15403. | |^|currenttransform||:=identity slanted slant|
  15404. |  yscaled aspect_ratio scaled |^|granularity||;|
  15405. | shrink_fit := 1+hround(2letter_fit#*hppp)-2letter_fit;|
  15406. | if not string mode: if mode <= smoke: shrink_fit := 0; fi fi|
  15407. | enddef;|
  15408. \endlines
  15409. If $"letter\_fit"\0=0$, the `^"shrink\_fit"' is set to~1; otherwise
  15410. "shrink\_fit" is 0, 1, or~2, depending on how "letter\_fit" has
  15411. rounded to an integer. This amount is essentially subtracted from~^"w"
  15412. before each character in the font has been drawn. Experience shows that
  15413. this trick greatly improves the readability of fonts at ^{medium}
  15414. and ^{low resolutions}.
  15415. Many of the Computer Modern characters are drawn with ^@filldraw@, which
  15416. is a mixture of outline-filling and fixed-pen drawing. Several macros
  15417. are included in |cmbase| to facilitate filldrawing, especially
  15418. `^"pos"' and `^"stroke"':
  15419. \beginlines
  15420. |vardef pos@#(expr b,d) =|
  15421. | (x@#r-x@#l,y@#r-y@#l)=(b-currentbreadth,0) rotated d;|
  15422. | x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef;|
  15423. \smallbreak
  15424. |vardef stroke text t =|
  15425. | forsuffixes e=l,r: path_.e:=t; endfor|
  15426. | path_.l -- reverse path_.r -- cycle enddef;|
  15427. \endlines
  15428. Thus "pos" is like ^"penpos", except that it subtracts ^"currentbreadth"
  15429. from the overall breadth. \ (Cf.~the program for left parentheses in
  15430. Chapter~12.) \ The "stroke" routine is a simplified alternative to
  15431. @penstroke@, such that @penstroke@ is equivalent to `@fill@~"stroke"'
  15432. if the specified path isn't a cycle.
  15433. The value of "currentbreadth" is maintained by redefining plain \MF's
  15434. `^"numeric\_pickup\_"' macro so that it includes the new line
  15435. \beginlines
  15436. |  if known breadth_[q]: currentbreadth:=breadth_[q]; fi|
  15437. \endlines
  15438. The ^@clear\_pen\_memory@ macro is redefined so that its second line now says
  15439. \beginlines
  15440. | numeric pen_lft_[],pen_rt_[],pen_top_[],pen_bot_[],breadth_[];|
  15441. \endlines
  15442. relevant entries of the "breadth\_" array will be defined by @font\_setup@,
  15443. as we'll see soon.
  15444. The example programs for period and em-dash say `@pickup@ "fine.nib"' and
  15445. `@pickup@ "crisp.nib"'. These nibs are initialized by @font\_setup@ in
  15446. the following way:
  15447. \beginlines
  15448. | clear_pen_memory;|
  15449. | forsuffixes $ = fine,crisp,| $\cdots$ |:|
  15450. |  $.breadth := $;|
  15451. |  pickup if $=0: nullpen else: pencircle scaled $; $ := $-eps fi;|
  15452. |  $.nib := |^|savepen||; breadth_[$.nib] := $;|
  15453. |  forsuffixes $$ = lft,rt,top,bot: shiftdef($.$$,$$ 0); endfor endfor|
  15454. \weakendlines
  15455. If, for example, we have $"fine"=4$, this code sets $"fine.breadth":=4$,
  15456. $"fine.nib":=1$, $"fine":=4-"eps"$, and $"breadth\_"[4]:=4-"eps"$.
  15457. \ (A small amount~^"eps" has been subtracted so that "pos" will
  15458. usually find $b-"currentbreadth">0$.) \ Furthermore, four subroutines
  15459. ^"fine.lft", "fine.rt", "fine.top", and "fine.bot" are defined, so
  15460. that it's easy to refer to the edges of "fine.nib" when it has not been
  15461. picked up. These four subroutines are created by a slightly
  15462. tricky ^|shiftdef| macro:
  15463. \beginlines
  15464. |def shiftdef(suffix $)(expr delta) =|
  15465. | vardef $ primary x = x+delta enddef enddef;|
  15466. \endlines
  15467. OK, we've just about covered everything in |cmbase| that handles the
  15468. extra administrative complexity inherent in a large-scale design.
  15469. The rest of the base file simply contains subroutines like
  15470. ^"serif" and ^"dot", for recurring features of the characters themselves.
  15471. Such subroutines needn't be shown here.
  15472. To make a binary file called ^|cm.base|, there's a trivial file `|cm.mf|':
  15473. \beginlines
  15474. |% This file creates `cm.base', assuming that plain.base is preloaded|
  15475. |input cmbase; |^|dump.|
  15476. \endlines
  15477. \medbreak
  15478. Besides parameter files, driver files, program files, and the base file,
  15479. the Computer Modern routines also include a number of {\sl^{utility files}\/}
  15480. that provide a convenient environment for designing new characters and
  15481. improving old ones. We'll conclude this appendix by studying the contents
  15482. of those utility files.
  15483. Let's suppose, for example, that test proofs have revealed problems
  15484. with the characters `k' and `S', so we want to fix them. Instead of
  15485. working with the font as a whole, we can copy the programs for those two
  15486. characters (and only those two) into a temporary file called `^|test.mf|'.
  15487. Then we can run \MF\ on the file `^|rtest.mf|', which says the following:
  15488. \beginlines
  15489. |% try all characters on `test.mf' using the parameters of cmr10|
  15490. |if unknown cmbase: input cmbase fi|
  15491. |mode_setup;|
  15492. \smallskip
  15493. |def generate suffix t = enddef;|
  15494. |input cmr10; font_setup;|
  15495. \smallbreak
  15496. |let echar = endchar;|
  15497. |def endchar = echar; stop "done with char "&decimal charcode&". " enddef;|
  15498. |let iff = always_iff;|
  15499. \smallskip
  15500. |input test; bye|
  15501. \endlines
  15502. This will produce proofs of `k' and `S', using the |cmr10| parameters.
  15503. Notice the simple trick by which |rtest| is able to stay in charge
  15504. after inputting |cmr10|, without letting the |roman| driver come into
  15505. action: `|generate|' is redefined so that it becomes innocuous.
  15506. Furthermore |rtest| changes ^|endchar| so that \MF\ will ^{stop} and
  15507. display each character before moving~on to the next. The `^|iff|'
  15508. convention is changed to `|always_iff|', so that every test character will
  15509. ^^@always\_iff@ be tested even if the boolean expression is undefined;
  15510. this makes it easier to copy from program files
  15511. into the test file and back again, since the |iff| indications do not
  15512. have to be touched.
  15513. If you invoke \MF\ with `|\mode=lowres;| |input| |rtest|', you'll generate
  15514. a low-resolution font called |rtest| with the parameters of |cmr10|,
  15515. but containing only the characters in the test file. If you leave out
  15516. the mode, you get proof mode as usual.
  15517. There are similar pseudo-drivers |ttest.mf| (for |cmtt10| instead of |cmr10|),
  15518. |btest.mf| (for |cmbx10|), etc.; these make it possible to try the
  15519. test characters with many different parameter settings. There's also
  15520. |ztest.mf|, which inputs parameters from a temporary file `|z.mf|' that
  15521. contains special parameters of interest at the moment. \ (If file
  15522. |z.mf| does not exist, you'll get a chance to specify another
  15523. parameter file, online.) \looseness=-1
  15524. A more elaborate ^{pseudo-driver file} called `|6test.mf|' allows you
  15525. to test up to six parameter settings simultaneously, and to see the
  15526. results all at once on your screen, as illustrated in Chapter~23.
  15527. Here is the program that does the necessary magic:
  15528. \beginlines
  15529. |% try all characters on `test.mf' using six different sets of parameters|
  15530. |if unknown cmbase: input cmbase fi|
  15531. |mag=.5; % the user can override this equation|
  15532. |mode_setup; let mode_setup=\;|
  15533. \smallskip
  15534. |boolean running;|
  15535. |def abort = hide(scrollmode; running := false) enddef;|
  15536. |def pause = stop "done with char "&decimal charcode&". " enddef;|
  15537. |let iff = always_iff;|
  15538. |def ligtable text t=enddef;|
  15539. |def charlist text t=enddef;|
  15540. |def extensible text t=enddef;|
  15541. \smallbreak
  15542. |string currenttitle;|
  15543. |let semi = ;; let echar = endchar; let endchar = enddef;|
  15544. |def cmchar expr s = currenttitle := s;|
  15545. | let ; = testchar semi quote def chartext = enddef;|
  15546. |def testchar = semi let ; = semi;|
  15547. | running := true; errorstopmode;|
  15548. | for k=1 upto 6:|
  15549. |  if running: if known params[k]: scantokens params[k]; font_setup;|
  15550. |    currentwindow:=k;|
  15551. |    currenttitle & ", " & fontname[k];|
  15552. |    chartext echar; fi fi endfor|
  15553. | pause; enddef;|
  15554. \smallbreak
  15555. |string params[],fontname[];|
  15556. |params[1] = "roman_params";     fontname[1] = "cmr10";|
  15557. |params[2] = "sans_params";      fontname[2] = "cmssbx10";|
  15558. |params[3] = "ital_params";      fontname[3] = "cmti10";|
  15559. |params[4] = "tt_params";        fontname[4] = "cmtt10";|
  15560. |params[5] = "bold_params";      fontname[5] = "cmb10";|
  15561. |params[6] = "quote_params";     fontname[6] = "cmssqi8";|
  15562. \smallbreak
  15563. |w_rows = floor 1/2 screen_rows; w_cols = floor 1/3 screen_cols;|
  15564. |def open(expr k,i,j)=|
  15565. | openwindow k from ((i-1)*w_rows,(j-1)*w_cols) to (i*w_rows,j*w_cols)|
  15566. | at (-10,140) enddef;|
  15567. |def openit =|
  15568. | open(1,1,1); open(2,1,2); open(3,1,3);|
  15569. | open(4,2,1); open(5,2,2); open(6,2,3); enddef;|
  15570. \smallbreak
  15571. |begingroup delimiters begintext generate;|
  15572. | def makedef(expr s)(text t) =|
  15573. |  expandafter def scantokens s = t enddef; flushtext enddef;|
  15574. | def flushtext suffix t = enddef;|
  15575. | for k=1 upto 6: if known params[k]:|
  15576. | makedef(params[k])|
  15577. |  expandafter expandafter expandafter begintext|
  15578. |  scantokens ("input "&fontname[k]); fi endfor|
  15579. |endgroup;|
  15580. \smallskip
  15581. |input test; bye|
  15582. \endlines
  15583. ^^@errorstopmode@ ^^@scrollmode@ ^^@quote@ ^^@openwindow@ ^^@openit@
  15584. ^^"currentwindow" ^^@expandafter@ ^^@scantokens@
  15585. Parameters are moved from parameter files into macros, using a trick
  15586. discussed near the beginning of Appendix~D\null. Then ^@cmchar@ is redefined
  15587. so that the entire text of each character-to-be-tested will be embedded
  15588. in another macro called "chartext". Each instance of "chartext" is
  15589. repeatedly applied to each of the six font setups.
  15590. An error that occurs with the first or second set of parameters may be
  15591. so bad that you won't want to see what happens with the third, fourth,
  15592. fifth, and sixth sets. For example, when |test.mf| contains characters
  15593. that are being newly designed, some equations might have been omitted
  15594. or mistyped, so the results will be ludicrous. In this case you can
  15595. ^{interrupt} the program and type `|I|~^|abort|'. The |6test| routine
  15596. has an |abort| macro that will stop at the end of the current font setup
  15597. and move directly to the next character, without trying any of the
  15598. remaining parameter combinations.
  15599. It's possible to include material in |test.mf| that isn't part of
  15600. a character program. For example, you might want to redefine a subroutine
  15601. in the base file. Only the character programs themselves (i.e., the
  15602. sequences of tokens between `@cmchar@' and `@endchar@;') are subject to
  15603. six-fold repetition.
  15604. Some large characters may not appear in full, because there might not be
  15605. room for them on the screen at the stated magnification. You can make
  15606. everything smaller by running \MF\ with, say, `|\mag=1/3; input 6test|'.
  15607. The computer will stop with an error message, saying that the equation
  15608. `|mag=.5|' is ^{inconsistent}; but you can safely proceed, because you
  15609. will have the magnification you want.
  15610. \endchapter
  15611. An ensampull yn doyng ys more commendabull
  15612. \indent{\cmman\char'15}en ys techyng o{\cmman\char'15}er prechyng.
  15613. \author JOHN ^{MIRK},  {\sl The Festyuall\/} (c.\thinspace1400)
  15614.  % from MS page 123b; p216 in Erbe's transcription
  15615. \bigskip
  15616. Old people love to give good advice,
  15617. % Les vieillards aiment \`a donner de bons pr\'eceptes,
  15618. to console themselves for no longer being able to give bad examples.
  15619. % pour se consoler de n'\^etre plus en \'etat de donner de mauvais exemples.
  15620. \author ^{LA ROCHEFOUCALD},  {\sl Maximes\/} (1665)
  15621. \eject
  15622. \beginchapter Appendix F. Font Metric\\Information
  15623. The \TeX\ typesetting system assumes that some ``intelligence'' has been
  15624. built into the fonts it uses. In other words, information stored with
  15625. ^^{TeX} \TeX's fonts will have important effects on \TeX's behavior. This
  15626. has two consequences: (a)~Typesetting is quite flexible, since few
  15627. conventions are frozen into \TeX\ itself. (b)~Font designers must work
  15628. a little harder, since they have to tell \TeX\ what to do. The purpose
  15629. of this appendix is to explain how you, as a font designer, can cope
  15630. with~(b) in order to achieve spectacular successes with~(a).
  15631. The information used by \TeX\ is embedded in compact binary files called
  15632. \TeX\ Font Metric (^|tfm|) files. Although the `|t|' in `|tfm|' stands
  15633. for \TeX, this is an artifact of history, because other formatting systems
  15634. can work with |tfm| files too. The files should have been called just `|fm|',
  15635. but it's too late now.
  15636. \MF\ is able to produce two different kinds of binary output files.
  15637. One, a `|gf|' file, contains digitized character shapes and some additional
  15638. information needed by programs that drive printing devices; such files
  15639. are discussed in Appendix~G\null. The other type of output is a |tfm| file,
  15640. which contains font information used by formatting routines like \TeX;
  15641. such files are our present concern. You get a |tfm| file if and only
  15642. if \MF's internal quantity `^"fontmaking"' is positive at the end
  15643. of your job. \ (Plain \MF's @mode\_setup@ routine usually sets
  15644. "fontmaking" to an appropriate value automatically.)
  15645. \medskip\ninepoint
  15646. The |tfm| file contains some information about each character, some
  15647. information about combinations of characters, and some information
  15648. about the font as a whole. We shall consider these three kinds
  15649. of information in turn. All of the font metric data that refers to
  15650. physical dimensions should be expressed in device-independent,
  15651. ``^{sharp}'' units; when a particular font is produced with different
  15652. modes or magnifications, all its |tfm| files should be identical.
  15653. A formatting program like \TeX\ needs to know the size of each character's
  15654. ``^{bounding} ^{box}.'' For example, when \TeX\ typesets a word like
  15655. `box', it places the first letter `b' into a little box in such a way that
  15656. the \MF\ pixel whose lower left corner is at $(0,0)$ will appear
  15657. on the baseline of the current line being typeset, at the left edge
  15658. of the box. \ (We assume for simplicity that ^"xoffset" and ^"yoffset"
  15659. were zero when `b' was shipped out). \ The second letter,~`o', is placed
  15660. in a second little box adjacent to the first one, so we obviously must tell
  15661. \TeX\ how wide to make the `b'.
  15662. In fact, \TeX\ also wants to know the height and depth of each letter.
  15663. This affects the placing of ^{accents}, if you wish to typeset
  15664. `\d{\~b}\kern.28pt\d{\~o}\kern-.28pt\d{\~x}\d{\~y}', and it also
  15665. avoids overlap when adjacent lines contain boxes that go unusually
  15666. far above or below the baselines.
  15667. A total of four dimensions is given for each character, in sharp
  15668. units (i.e., in units of printer's points):
  15669. \smallskip
  15670. \item\bull ^"charwd", the width of the bounding box.
  15671. \item\bull ^"charht", the height (above the baseline) of the bounding box.
  15672. \item\bull ^"chardp", the depth (below the baseline) of the bounding box.
  15673. This is a {\sl positive\/} number if the character descends below the
  15674. baseline, even though the corresponding $y$ values are negative.
  15675. \item\bull ^"charic", the character's ``^{italic correction}.'' \TeX\
  15676. adds this amount to the width of the box (at the right-hand side)
  15677. in two cases: (a)~When the user specifies an italic correction explicitly,
  15678. by typing |\/| immediately after the character. (b)~When an ^{isolated}
  15679. character is used in math mode, unless it has a subscript but no
  15680. superscript. For example, the italic correction is applied to `$P$' in
  15681. the formulas `$P(x)$' and `$P^2$', but not in the formula `$P_n$';
  15682. it is applied to position the superscript but not the subscript
  15683. in `$P_n^2$'.
  15684. \smallskip\noindent
  15685. In plain \MF\ programs, you specify "charwd", "charht", and "chardp"
  15686. in a ^@beginchar@ command, and you specify "charic" (if it's positive)
  15687. in an ^@italcorr@ command. But @beginchar@ and @italcorr@ are macros,
  15688. not primitives of \MF\!\null. What really happens is that \MF\ records the
  15689. value of its internal quantities "charwd", "charht", "chardp", and "charic"
  15690. at the time of a ^@shipout@ command. These values (and all other
  15691. dimensions to be mentioned below) must be less than $2048"pt"\0$ in
  15692. absolute value.
  15693. A font contains at most 256 character codes; the ^{charexists} operator
  15694. can be used to tell which codes have already appeared. If two or more
  15695. characters are shipped out with the same code number (possibly with
  15696. different ^"charext" values), the "charwd",
  15697. "charht", "chardp", and "charic" of the final one are assumed to
  15698. apply to them all.
  15699. At most 15 different nonzero heights, 15 different nonzero depths,
  15700. and 63 different nonzero italic corrections may appear in a single
  15701. font. If these limits are exceeded, \MF\ will change one or more
  15702. values, by as little as possible, until the restriction holds.
  15703. A warning message is issued if such changes are necessary; for example,
  15704. ^^|some char values|
  15705. `|(some| |charht| |values| |had| |to| |be| |adjusted| |by| |as| |much|
  15706. |as| |0.12pt)|' means that~you had too many different nonzero heights, but
  15707. \MF\ found a way to reduce the number to at most~15 by changing some of
  15708. them; none of them had to be changed by more than 0.12 points. No warning
  15709. is actually given unless the maximum amount of perturbation exceeds
  15710. ${1\over16}\pt$.
  15711. \medbreak
  15712. The next kind of information that \TeX\ wants is concerned with
  15713. pairs of adjacent characters that are typeset from the same font.
  15714. For example, \TeX\ moves the~`x' slightly closer to the~`o' in the
  15715. word `box', and it moves the~`o' slightly away from the~`b', because
  15716. of information stored in the |tfm| file for the font you're now reading.
  15717. This space adjustment is called {\sl^{kerning}}. Otherwise (if the
  15718. three characters had simply been placed next to each other according
  15719. to their "charwd" values) the word would have been `b{}o{}x', which
  15720. looks slightly worse. Similarly, there's a difference between
  15721. `difference' and `dif{\null}ference', because the |tfm| file tells \TeX\
  15722. to substitute the ligature `ff' when there are two f's in a row.
  15723. Ligature information and kerning information is specified in short
  15724. ``^{ligtable programs}'' of a particularly simple form. Here's an example
  15725. that illustrates most of the features (although it is not a serious
  15726. example of typographic practice):
  15727. \beginlines
  15728. ^|ligtable|| "f": "f" =: oct"013", "i" |\||=: oct"020", skipto 1;|
  15729. |ligtable "o": "b": "p": "e" kern .5u#, "o" kern .5u#, "x" kern-.5u#,|
  15730. |          1:: "!" kern u#;|
  15731. \endlines
  15732. This sequence of instructions can be paraphrased as follows:
  15733. \smallskip
  15734. \hangindent 3pc
  15735. Dear \TeX, when you're typesetting an~`f' with this font, and when the
  15736. following character also belongs to this font, look at it closely because
  15737. you might need to do something special: If that following character is
  15738. another~`f', replace the two f's by character code |oct"013"|
  15739. [namely `\char'13'\kern.5pt];
  15740. if it's an `i', retain the `f' but replace the `i' by character code
  15741. |oct"020"| [a dotless `\char'20'\kern.5pt];
  15742. otherwise skip down to label `|1::|' for further instructions.
  15743. When you're typesetting an `o' or~`b' or~`p', if the next input to \TeX\ is
  15744. `e' or~`o', add a half unit
  15745. of space between the letters; if it's an `x', subtract a half unit; if it's an
  15746. exclamation point, add a full unit. The last instruction applies also
  15747. to exclamation points following~`f' (because of the label `|1::|').
  15748. \smallskip\noindent
  15749. When a character code appears in front of a colon, the colon ``labels''
  15750. the starting place for that character's ligature and kerning program,
  15751. which continues to the end of the ligtable statement. A double colon denotes
  15752. a ``local label''; a |skipto| instruction advances to the next matching local
  15753. label, which must appear before 128 ligtable steps intervene. The special
  15754. label \|\||:| can be used to initiate ligtable instructions for an invisible
  15755. ``left boundary character'' that is implicitly present just before every
  15756. word; an invisible ``right boundary character'' equal to ^"boundarychar" is
  15757. also implicitly present just after every word, if "boundarychar" lies between
  15758. 0 and~255.
  15759. The general syntax for ligtable programs is pretty easy to guess from
  15760. these examples, but we ought to exhibit it for completeness:
  15761. \beginsyntax \chardef\\=`\|
  15762. <ligtable command>\is[ligtable]<ligtable program><optional skip>
  15763. <ligtable program>\is<ligtable step>\alt<ligtable program>[,]<ligtable step>
  15764. <optional skip>\is[,] [skipto]<code>\alt<empty>
  15765. <ligtable step>\is<code><ligature op><code>
  15766.  \alt<code>[kern]<numeric expression>
  15767.  \alt<label><ligtable step>
  15768. <ligature op>\is[=:]\alt[\\=:]\alt[\\=:>]\alt[=:\\]\alt[=:\\>]%
  15769.   \alt[\\=:\\]\alt[\\=:\\>]\alt[\\=:\\>>]
  15770. <label>\is<code>[:]\alt<code>[::]\alt[\\\\:]
  15771. <code>\is<numeric expression>\alt<string expression>
  15772. \endsyntax
  15773. A \<code> should have a numeric value between 0 and 255, inclusive,
  15774. after having been rounded to the nearest integer; or it should be a
  15775. string of length~1, in which case it denotes the corresponding
  15776. ^{ASCII} code (Appendix~C\null). For example, |"A"| and |64.61| both
  15777. specify the code value 65. Vertical bars to the left or right of `|=:|'
  15778. tell \TeX\ to retain the original left and/or right character that invoked a
  15779. ligature. Additional `|>|' signs tell \TeX\ to advance its focus of attention
  15780. instead of doing any further ligtable operations at the current
  15781. character position.
  15782. {\sl Caution:\/} Novices often go overboard on kerning. Things usually
  15783. work out best if you kern by at most half of what looks right to you
  15784. at first, since kerning should not be noticeable by its presence
  15785. (only by its absence). Kerning that looks right in a logo or in a
  15786. headline display often interrupts the rhythm of reading when it appears
  15787. in ordinary textual material.
  15788. You can improve \TeX's efficiency by ordering the steps of a ligtable
  15789. program so that the most frequent alternatives come first.
  15790. \TeX\ will stop reading the program when it finds the first ``hit.''
  15791. \medbreak
  15792. Several characters of a font can be linked together in a series
  15793. by means of a ^@charlist@ command. For example,
  15794. \begintt
  15795. charlist oct"000": oct"020": oct"022": oct"040": oct"060"
  15796. \endtt
  15797. is used in the font ^|cmex10| to specify the left parentheses that
  15798. \TeX\ uses in displayed math formulas, in increasing order of size.
  15799. \TeX\ follows charlists to make variable-size delimiters and
  15800. variable-width ^{accents}, as well as to link text-size operators
  15801. like `$\sum$' to the display-size `$\displaystyle\sum$'.
  15802. \TeX\ builds up large delimiters by using ``^{extensible}'' characters,
  15803. which are specified by giving top, middle, bottom, and repeatable
  15804. characters in an ^@extensible@ command. For example, the extensible
  15805. left ^{parentheses} in |cmex10| are defined by
  15806. \begintt
  15807. extensible oct"060": oct"060", 0, oct"100", oct"102";
  15808. \endtt
  15809. this says that character code |oct"060"| specifies an extensible
  15810. delimiter constructed from itself as the top piece, from character number
  15811. |oct"100"| as the bottom piece, and from character number |oct"102"| as
  15812. the piece that should be repeated as often as necessary to reach
  15813. a desired size. In this particular example there is no middle
  15814. piece, but characters like curly braces have a middle piece as well.
  15815. A zero value in the top, middle, or bottom position means that
  15816. no character should be used in that part of the construction;
  15817. but a zero value in the final position means that character number zero
  15818. is the repeater. The width of an extensible character is taken to
  15819. be the width of the repeater. \looseness=-1
  15820. The first eight different sizes of parentheses available to \TeX\ in
  15821. |cmex10|, when the user asks for `|\left(|', look like this:
  15822. \begindisplay
  15823. $\bigl(\quad\Bigl(\quad\biggl(\quad\Biggl(\quad
  15824. \mathopen{\hbox{$\left(\vbox to20.5pt{}\right.\nulldelimiterspace=0pt$}}\quad
  15825. \mathopen{\hbox{$\left(\vbox to23.5pt{}\right.\nulldelimiterspace=0pt$}}\quad
  15826. \mathopen{\hbox{$\left(\vbox to26.5pt{}\right.\nulldelimiterspace=0pt$}}\quad
  15827. \mathopen{\hbox{$\left(\vbox to29.5pt{}\right.\nulldelimiterspace=0pt$}}$
  15828. \enddisplay
  15829. According to what we know from the examples of @charlist@ and @extensible@
  15830. above, the first four of these are the characters in positions
  15831. |oct"000"|, |oct"020"|, |oct"022"|, and |oct"040"|. The other four have
  15832. character |oct"060"| on top; character |oct"100"| is at the bottom;
  15833. and there are respectively zero, one, two, and three occurrences
  15834. of character |oct"102"| in the middle.
  15835. Here is the formal syntax:
  15836. \beginsyntax
  15837. <charlist command>\is[charlist]<labeled code>
  15838. <labeled code>\is<code>
  15839.  \alt<label><labeled code>
  15840. <extensible command>\is[extensible]<label><four codes>
  15841. <four codes>\is<code>[,]<code>[,]<code>[,]<code>
  15842. \endsyntax
  15843. Notice that a \<label> can appear in a ligtable, charlist, or extensible
  15844. command. These appearances are mutually exclusive: No code may be used
  15845. more than once as a label. Thus, for example, a character with a
  15846. ligature/kerning program cannot also be extensible, nor can it be
  15847. in a charlist (except as the final item).
  15848. \medbreak
  15849. The last type of information that appears in a |tfm| file applies to
  15850. the font as a whole. Two kinds of data are involved, bytes and
  15851. numerics; and they are specified in ``headerbyte'' and ``fontdimen''
  15852. commands, according to the following general syntax:
  15853. \beginsyntax
  15854. <headerbyte command>\is[headerbyte]<numeric expression>[:]<byte list>
  15855. <fontdimen command>\is[fontdimen]<numeric expression>[:]<numeric list>
  15856. <byte list>\is<code>
  15857.  \alt<byte list>[,]<code>
  15858. <numeric list>\is<numeric expression>
  15859.  \alt<numeric list>[,]<numeric expression>
  15860. \endsyntax
  15861. We shall defer discussion of header bytes until later, because they
  15862. are usually unnecessary. But @fontdimen@ commands are important.
  15863. Numeric parameters of a font can be specified by saying, e.g.,
  15864. \begintt
  15865. fontdimen 3: 2.5, 6.5, 0, 4x
  15866. \endtt
  15867. which means that parameters 3--6 are to be 2.5, 6.5, 0, and $4x$,
  15868. respectively. These are the parameters that \TeX\ calls |\fontdimen3|
  15869. thru |\fontdimen6|. \ (Parameter numbering is old-fashioned:
  15870. There is no |\fontdimen0|.)
  15871. The first seven fontdimen parameters have special significance, so plain
  15872. \MF\ has seven macros to specify them symbolically, one at a time:
  15873. \smallskip
  15874. \item\bull^@font\_slant@ (|\fontdimen1|) is the amount of ^{slant}
  15875. per point; \TeX\ uses this information when raising or lowering an
  15876. accent character.
  15877. \item\bull^@font\_normal\_space@ (|\fontdimen2|) is the interword spacing.
  15878. If the value is zero, all characters of this
  15879. font will be considered to be ``^{isolated}'' in math mode, so the
  15880. ^{italic correction} will be added more often than otherwise.
  15881. \item\bull^@font\_normal\_stretch@ (|\fontdimen3|) is the ^{stretchability}
  15882. of interword spacing, as explained in {\sl The \TeX book}.
  15883. \item\bull^@font\_normal\_shrink@ (|\fontdimen4|) is the ^{shrinkability}
  15884. of interword spacing, as explained in {\sl The \TeX book}.
  15885. \item\bull^@font\_x\_height@ (|\fontdimen5|) is the height of characters
  15886. for which accents are correctly positioned. An accent over a character
  15887. will be raised by the difference between the character's "charht"
  15888. and this value. The ^{x-height} is also the unit of height that
  15889. \TeX\ calls one `|ex|'.
  15890. \item\bull^@font\_quad@ (|\fontdimen6|) is the unit of width that
  15891. \TeX\ calls one `|em|'.
  15892. \item\bull^@font\_extra\_space@ (|\fontdimen7|) is the additional amount
  15893. added to the normal interword space between sentences, depending
  15894. on the ``spacefactor'' as defined in {\sl The \TeX book}.
  15895. \smallskip\noindent
  15896. Parameters are zero unless otherwise specified.
  15897. Math symbol fonts for \TeX\ are required to have at least 22 fontdimen
  15898. parameters, instead of the usual seven; math extension fonts need at least~13.
  15899. Appendix~G of {\sl The \TeX book\/} explains the precise significance
  15900. of these additional parameters, which control such things as the
  15901. placement of superscripts and subscripts.
  15902. \medbreak
  15903. The {\sl^{design size}\/} of a font is not one of the fontdimen
  15904. parameters; it's an internal quantity of \MF\ that is actually output
  15905. among the header bytes as explained below. When a \TeX\ user asks
  15906. for a font `|at|' a certain size, the font is scaled by the ratio
  15907. between the ``^{at size}'' and the design size. For example,
  15908. |cmr10| has a design size of $10\pt$; if a \TeX\ user requests
  15909. `|cmr10|~|at|~|15pt|', the result is the same as `|cmr10|~|scaled|~|1500|'
  15910. (or, in plain \MF\ terms, |cmr10| with |mag=1.5|).
  15911. What does the design size really mean? It's an imprecise notion,
  15912. because there need be no connection between the design size and any specific
  15913. measurement in a font. Typographers have always been vague when
  15914. they speak about ``10~point'' fonts, because some fonts look larger
  15915. than others even though the horizontal and vertical dimensions are the same.
  15916. It's something like dress sizes or shoe sizes.
  15917. In general, the design size is a statement about the approximate size
  15918. of the type. Type with a larger design size generally looks bigger
  15919. than type with a smaller design size. Two fonts with the same design
  15920. size are supposed to work well together; for example, |cmr9| and
  15921. |cmtt9| both have $9\pt$ design size, although the uppercase letters of
  15922. |cmtt9| are quite a bit smaller (`|A|' versus `A').
  15923. The "designsize" must be at least $1"pt"\0$. And, as with all |tfm|
  15924. dimensions, it must be less than $2048"pt"\0$. Any other value is
  15925. changed to $128"pt"\0$.
  15926. \MF\ looks at the value of ^"designsize" only when the job ends, so you
  15927. needn't set it before characters are shipped out. At the end of a job,
  15928. when the |tfm| file is being written, \MF\ checks to make sure that every
  15929. dimension of the font is less than 16 times the design size in absolute
  15930. value, because this limitation is imposed by the |tfm| file format.  Thus,
  15931. for example, if the design size is $10\pt$, you cannot have a character
  15932. whose width or height is $160\pt$ or more. If one or more dimensions prove
  15933. to be too big, \MF\ will tell you how many of them had to be changed.
  15934. \medbreak
  15935. The ^@headerbyte@ command is similar to @fontdimen@, but it gives
  15936. 8-bit \<code> data instead of numeric information. For example,
  15937. \begintt
  15938. headerbyte 33: 0, 214, 0, "c"
  15939. \endtt
  15940. says that bytes 33--36 of the |tfm| file header will be 0, 214,
  15941. 0, and~99. The first four header bytes (numbers 1--4) are automatically
  15942. set to a ^{check sum}, unless you have specified other values for
  15943. at least one of those bytes. \ (This check sum will match a similar
  15944. value in the |gf|~file, so that other typesetting software can check
  15945. the consistency of the different files they use.) \ Similarly,
  15946. the next four header bytes (numbers 5--8) are set automatically to
  15947. the design size times $2^{20}$, unless you have specified something
  15948. else. \looseness=-1
  15949. \TeX\ looks only at the first eight header bytes, so you needn't use
  15950. the headerbyte command if you are simply producing a font for
  15951. standard \TeX. But other software that reads |tfm| files may have
  15952. a need for more header information. For example, the original
  15953. |tfm| format (developed by Lyle ^{Ramshaw} at ^{Xerox} Palo Alto
  15954. Research Center) included ^@font\_coding\_scheme@ information
  15955. in bytes 9--48 of the header, and ^@font\_identifier@ information in
  15956. bytes 49--68. The design size of certain fonts was also packed into
  15957. byte~72. Each font in the ``Xerox world'' is uniquely identified by
  15958. its font identifier and its design size, rather than by its font file name.
  15959. The ``font coding scheme'' is merely a comment that can be used
  15960. to help understand large collections of fonts; it's usually a nice thing
  15961. to know. Some of the coding scheme names in common use are
  15962. \begindisplay
  15963. |TeX text|&|TeX math italic|\cr
  15964. |TeX typewriter text|&|TeX math symbols|\cr
  15965. |XEROX text|&|TeX math extension|\cr
  15966. |ASCII|&|TeX extended ASCII|\cr
  15967. |PI|&|GRAPHIC|\cr
  15968. \enddisplay
  15969. The coding-scheme string should not include parentheses.
  15970. Here are macros that can be used, if desired, to convert plain
  15971. \MF's @font\_identifier@ and @font\_coding\_scheme@ into the format
  15972. ^^{substring} ^^{BCPL strings}
  15973. required by Ramshaw's original |tfm| files:
  15974. \beginlines
  15975. |def BCPL_string(expr s,n) = % string s becomes an n-byte BCPL string|
  15976. | for l:=if length(s)>=n: n-1 else: length(s) fi: l|
  15977. |  for k:=1 upto l: , substring (k-1,k) of s endfor|
  15978. |  for k:=l+2 upto n: , 0 endfor endfor enddef;|
  15979. \smallskip
  15980. ^|inner|| end;|
  15981. |def bye = if fontmaking>0:|
  15982. |  headerbyte 9: BCPL_string(font_coding_scheme_,40);|
  15983. |  special "codingscheme " & font_coding_scheme_;|
  15984. |  headerbyte 49: BCPL_string(font_identifier_,20);|
  15985. |  special "identifier " & font_identifier_;|
  15986. |  headerbyte 72: max(0, 254 - round 2designsize); fi|
  15987. | end enddef;|
  15988. ^|outer|| bye,end;|
  15989. \endlines
  15990. These macros could be included among the ^|local.mf| extensions to
  15991. |plain.mf| at particular installations. When a user says `^@bye@' instead
  15992. of `^@end@', the additional headerbyte documentation will then be
  15993. automatically inserted into the |tfm| file.
  15994. \medbreak
  15995. Let us now conclude this appendix by summarizing what we've learned.
  15996. A \MF\ programmer can provide various types of information about how
  15997. to typeset with a font, by using font metric commands. Simple versions
  15998. of these commands, sufficient for simple fonts, are standard operations
  15999. in plain \MF; examples have appeared in Chapter~11
  16000. and the beginning of Appendix~E\null. The general cases are handled by
  16001. five types of font metric commands:
  16002. \beginsyntax
  16003. <font metric command>\is<ligtable command>
  16004.  \alt<charlist command>
  16005.  \alt<extensible command>
  16006.  \alt<fontdimen command>
  16007.  \alt<headerbyte command>
  16008. \endsyntax
  16009. This completes the syntax of \MF\ that was left slightly unfinished
  16010. in Chapter~26.
  16011. \endchapter
  16012. Such things induced me to untangle the chaos
  16013. % Voil\`a ce qui m'a engag\'e \`a d\'ebrouiller ce chaos,
  16014. by introducing order where it had never been before:
  16015. % en mettant dans cette partie un ordre qui n'y avoit jamais r\'egn\'e:
  16016. I think I may say I have had the good fortune to succeed
  16017. % je crois avoir eu le bonheur d'y r\'eussir
  16018. with an exactness \& a precision leaving nothing more to be desired,
  16019. % avec une justesse \& une pr\'ecision qui ne laissent rien \`a desirer,
  16020. by the invention of\/ {\rm Typographic points}.
  16021. % par l'invention des \it Points typographiques.
  16022. \author PIERRE ^{FOURNIER},  {\sl Manuel Typographique\/} (1764) % p129
  16023. \bigskip
  16024. One should absorb the color of life,
  16025. but one should never remember its details.
  16026. Details are always vulgar.
  16027. \author OSCAR ^{WILDE},  {\sl The Picture of Dorian Gray\/} (1890)
  16028.  % middle of ch6 in original edition [Lippincott's vol 46]; ch8 subsequently
  16029. \eject
  16030. \beginchapter Appendix G. Generic\\Font\\Files
  16031. \MF's main output goes into a ^|gf| or ``Generic Font'' file, so-called
  16032. because it can easily be translated into any other digital font format,
  16033. although it does not match the specifications of any ``name brand''
  16034. manufacturer. The purpose of this appendix is to explain exactly what
  16035. kinds of information go into the |gf| file, and under what circumstances
  16036. \MF\ puts things there.
  16037. \ninepoint\medskip
  16038. A |gf| file is a compact binary representation of a digitized font,
  16039. containing all the information needed by ``^{device driver}''
  16040. software that produces printed documents from \TeX's ^|dvi| files. The
  16041. exact internal representation scheme of |gf| files doesn't concern us
  16042. here, but we ought to know what type of data is encoded.
  16043. \smallskip
  16044. The first thing in a |gf| file is a string that explains its origin.
  16045. \MF\ writes strings of the form
  16046. \begintt
  16047. METAFONT output 1986.06.24:1635
  16048. \endtt
  16049. based on the values of the internal quantities ^"day", ^"month",
  16050. ^"year", and ^"time" when the |gf| file was started. \ (In this case
  16051. $"day"=24$, $"month"=6$, $"year"=1986$, % my 25th wedding anniversary
  16052. and $"time"=16\times60+35=995$.)
  16053. After the opening string, the |gf| file contains a sequence of
  16054. ``special'' commands interspersed with shipped-out character images.
  16055. ^{Special commands} are intended to provide a loophole for future
  16056. extensions to \MF's set of primitives, so that \MF\ itself will not
  16057. have to change. Some specials are predefined, but others will
  16058. undoubtedly be created in years to come. \ (\TeX\ has an analogous
  16059. |\special| command, which puts an arbitrary string into a |dvi| file.)
  16060. A special command gets into the |gf| file when you say `^@special@
  16061. \<string>' or `^@numspecial@ \<numeric>' at a time when
  16062. ^"proofing"$\null\ge0$.  A @special@ string should come before
  16063. @numspecial@, and it
  16064. should either be a keyword all by itself or it should consist of a keyword
  16065. followed by a space followed by additional information. Keywords that
  16066. specify operations requiring numeric arguments should be followed by
  16067. numbers produced by @numspecial@. For example, the `^@proofrule@' macro
  16068. in Appendix~B expands into a sequence of five special commands,
  16069. \begindisplay
  16070. @special@ |"rule"|;\cr
  16071. @numspecial@ $x_1$; \ @numspecial@ $y_1$;\cr
  16072. @numspecial@ $x_2$; \ @numspecial@ $y_2$;\cr
  16073. \enddisplay
  16074. this represents a rule on the proofsheet that runs from point $(x_1,y_1)$
  16075. to point $(x_2,y_2)$. If you say `|grayfont gray5|', the ^@grayfont@
  16076. macro in Appendix~B expands to `@special@ |"grayfont gray5"|'.
  16077. Software that reads |gf| files will examine all of the special strings,
  16078. until coming to a space or to the end of the string. If the resulting
  16079. keyword isn't known to the program, the special string will be ignored,
  16080. together with all numspecials that immediately follow. But when the
  16081. keyword is known, the program will be able to determine the corresponding
  16082. arguments.  For example, the |GFtoDVI| program described in Appendix~H
  16083. knows about the plain \MF\ keywords `|rule|' and `|grayfont|'.
  16084. \MF\ might also create @special@ commands on its own initiative, but only
  16085. when "proofing" is strictly greater than zero. There are
  16086. two cases: (1)~When a ^\<title> statement occurs,
  16087. the special string `|"title "|\thinspace\&\thinspace\<string>'
  16088. is output. \ (This is how the phrase `|The letter O|' got onto your
  16089. proofsheets in the experiments of Chapter~5.) \ (2)~Just before a
  16090. character image is shipped out, \MF\ implicitly executes the following
  16091. sequence of instructions:
  16092. \begindisplay
  16093. @if@ round $"xoffset"\ne0$: \ @special@ |"xoffset"|; \
  16094.  @numspecial@ round ^"xoffset"; @fi@\cr
  16095. @if@ round $"yoffset"\ne0$: \ @special@ |"yoffset"|; \
  16096.  @numspecial@ round ^"yoffset"; @fi@\cr
  16097. \enddisplay
  16098. A ^@shipout@ command sends a digitized picture to the |gf|
  16099. file, if $"proofing"\ge0$, but nothing is output if $"proofing"<0$.
  16100. Furthermore the current values of ^"charwd", ^"charht", ^"chardp", ^"charic",
  16101. ^"chardx", and ^"chardy" are stored away for the current ^"charcode";
  16102. these values are stored in all cases, regardless of the value of "proofing".
  16103. The current character code is henceforth said to ``exist.'' ^^@charexists@
  16104. When a ^{picture} is shipped out, its pixels of positive value are
  16105. considered to be ``black,'' and all other pixels are considered to be
  16106. ``white.'' The pattern of blacks and whites is encoded in such a way
  16107. that doubling the resolution approximately doubles the length of the
  16108. |gf| output, in most cases.
  16109. \MF\ reports its progress by typing `|[|$c$|]|' on the terminal
  16110. when character code~$c$ is being shipped out. \ (The `^|[|' is typed
  16111. before output conversion begins, and the `^|]|' is typed after; hence you
  16112. can see how much time output takes.) \ If "charext" is nonzero, after
  16113. being rounded to an integer, the typed message is `|[|$c.x$|]|' instead;
  16114. for example, `[65.3]' refers to character~65 with extension code~3.
  16115. \TeX\ allows only 256 characters per font, but extensions of \TeX\
  16116. intended for ^{oriental} languages will presumably use the "charext"
  16117. feature. All characters with the same code share the same width,
  16118. height, and depth, but they can correspond to distinct graphics if they have
  16119. different extension codes.
  16120. \medbreak
  16121. A @special@ command generally refers to the picture that follows it,
  16122. rather than the picture that precedes~it. Special commands before the
  16123. first digitized picture might, however, give instructions about
  16124. the font as a whole. Special commands that follow the final picture
  16125. invariably refer to the font as a whole. \ (For example, the
  16126. `^@bye@' macro at the end of Appendix~F creates two special
  16127. strings that will appear after the final character of a font.)
  16128. \medbreak
  16129. No |gf| file will be written unless a character is shipped out or a
  16130. special command is performed at a time when $"proofing"\ge0$, or unless a
  16131. title statement is encountered at a time when $"proofing">0$. When one of
  16132. these things first happens, the |gf| file receives its name.  If no
  16133. ^@input@ commands have yet occurred, \MF\ will set the job name to
  16134. `^|mfput|'; otherwise the job name will already have been determined. The
  16135. full name of the |gf| file will be
  16136. `\<jobname>|.|\<resolution>\thinspace|gf|', where the \<resolution> is
  16137. based on the current value of~^"hppp". \ (If $"hppp"\le0$, the resolution
  16138. will be omitted; otherwise it will be converted to an equivalent number of
  16139. pixels per inch, in the horizontal dimension.) \ Subsequent @input@
  16140. operations or changes to~"hppp" will not change the ^^{file name}
  16141. name of the |gf| file.
  16142. \medbreak
  16143. The end of a |gf| file contains a bunch of numeric data needed for
  16144. typesetting. First come the ^{design size} and the ^{check sum};
  16145. these match precisely the data in the |tfm| file, unless the header
  16146. bytes of the |tfm| have explicitly been set to something else.
  16147. Then come the values of "hppp" and "vppp". \ (These are the values
  16148. at the end of the job, so "hppp" might not agree with the \<resolution>
  16149. value in the |gf| file name.)
  16150. Finally, the |gf| file gets the ^"charwd", ^"chardx", and ^"chardy"
  16151. of each existing character code.  The values of "chardx" and "chardy"
  16152. represent desired ``escapements'' when characters are typeset on a
  16153. particular device (cf.\ Chapter~12).  The "charwd" values are identical to
  16154. the widths in the |tfm| file.
  16155. \medbreak
  16156. The check sum is based entirely on the "charwd" data; two fonts
  16157. with the same character widths will have the same check sum, but
  16158. two fonts with different character widths will almost never have
  16159. the same check sum.
  16160. The purpose of check sums can be understood by considering the following
  16161. scenario: A font named |cmr10| might be generated by \MF\ at any time,
  16162. producing a |tfm| file called |cmr10.tfm| and a |gf| file called,
  16163. say, |cmr10.300gf|. A document named |doc|, which uses |cmr10|,
  16164. might be generated by \TeX\ at any time, producing a |dvi| file
  16165. called |doc.dvi|; \TeX\ had to read |cmr10.tfm| in order to
  16166. produce this |dvi| file. Now on some future date, a ``^{device driver}''
  16167. program will be used to print |doc.dvi|, using the font
  16168. |cmr10.300gf|. Meanwhile, the font may have changed.
  16169. If the current |gf| file doesn't match the |tfm| file that was assumed
  16170. by \TeX, mysterious glitches will probably occur in the printed document,
  16171. because |dvi| information is kept concise by the assumption that the
  16172. device driver knows the |tfm| widths of all characters. Potential
  16173. problems are kept to a minimum if \TeX\ puts the assumed design size
  16174. and check sum of each font into the |dvi| files it produces;
  16175. a device driver can then issue a warning message when it finds a
  16176. |gf| file that is inconsistent with \TeX's assumptions.
  16177. \endchapter
  16178. But if our\/ {\rm Letter-Cutter} \kern-1pt will have no Forge,
  16179. yet he must of necessity accommodate himself %
  16180. with a\/ {\rm Vice, Hand-Vice, Hammers,}
  16181. \leavevmode{\rm Files, Small} \kern-1pt and\/ {\rm Fine Files} (commonly %
  16182.  called\/ \kern1pt{\rm Watch-makers Files})
  16183. of these he saves all, as they wear out.
  16184. \author JOSEPH ^{MOXON},  {\sl Mechanick Exercises\/} (1683)
  16185.  % part 12, section 1
  16186. \bigskip
  16187. The natural definition lists all possible generic characters.
  16188. % 189. NATURALIS Character (186) notas omnes (92--113)
  16189. % genericas possibiles (167) allegat;
  16190. \author ^{LINN\AE US},  {\sl Philosophia Botanica\/} (1751)
  16191.   % this translation due to Frans A. Stafleu
  16192. \eject
  16193. \beginchapter Appendix H. Hardcopy Proofs
  16194. A font cannot be proved correct like a mathematical theorem; a font must
  16195. be seen to be believed. Moreover, if some characters of a font are faulty,
  16196. the best way to fix them is to look at diagrams that indicate what went wrong.
  16197. Therefore \MF\ is incomplete by itself; additional programs are needed to
  16198. convert the output of \MF\ into graphic form.
  16199. The purpose of this appendix is to discuss two such auxiliary programs,
  16200. which serve as examples of many others that could be devised. The first
  16201. of these, called ^|GFtoDVI|\null, takes |gf| files and converts them into
  16202. ^|dvi| files, which can be printed just like the output of \TeX. Each
  16203. character image in the |gf| file will have a printed page to itself, with
  16204. labelled points and with bounding boxes just as in the illustrations
  16205. we have seen throughout this book. \ (Indeed, the illustrations in this
  16206. book were produced by |GFtoDVI|\null.) \ The second auxiliary program to
  16207. be discussed below is \TeX\ itself; we shall look at a set of \TeX\ macros
  16208. designed to facilitate font testing.
  16209. \ninepoint
  16210. \subsection Large scale proofs. The |gf| files produced by plain \MF\
  16211. when it is in ^"proof" mode or ^"smoke" mode can be converted to
  16212. annotated diagrams by running them through |GFtoDVI|\null, as we know from
  16213. the experiments in Chapter~5. It's also possible to study low-resolution
  16214. characters with |GFtoDVI|\null, especially if plain \MF's
  16215. `^|gfcorners|' feature has been used. ^^{low resolution proofs}
  16216. We shall now take a thorough look at what |GFtoDVI| can do.
  16217. All communication from \MF\ to |GFtoDVI| comes through the |gf| file and
  16218. from options that you might type when you run |GFtoDVI|\null. If there are
  16219. no ``^{special}'' commands in the |gf| file (cf.~Appendix~G\null), each page
  16220. of |GFtoDVI|'s output will show just the ``black'' pixels of a character;
  16221. furthermore there will be a title line at the top of the page, showing
  16222. the date and time of the \MF\ run, together with the character code
  16223. number and extension code (if they are nonzero). The black pixels are
  16224. typeset via characters of a so-called ``^{gray font},'' described in
  16225. detail below; by changing the gray font you can produce a variety of
  16226. different outputs from a single |gf| file.
  16227. To get other things on your proof sheets, ``special'' commands must
  16228. appear in the |gf| file. For example, \MF\ will automatically output
  16229. a |title| command, if $"proofing">0$, as explained in Appendix~G\null;
  16230. |GFtoDVI| will typeset this title on the title line of the next character
  16231. image that follows the command. If there are several title statements,
  16232. they all will appear; they are supposed to fit on a single line.
  16233. The most important special commands tell |GFtoDVI| to create labeled
  16234. points on the character diagram. When you say, for example,
  16235. `^@labels@$(1,2)$' in a plain \MF\ program, at a time when
  16236. ^"proofing"$\null>1$, the macros of Appendix~B will convert this to the
  16237. special commands
  16238. \begindisplay
  16239. @special@ |" 01"|; \ ^@numspecial@ $x_1$; \ @numspecial@ $y_1$;\cr
  16240. @special@ |" 02"|; \ @numspecial@ $x_2$; \ @numspecial@ $y_2$;\cr
  16241. \enddisplay
  16242. |GFtoDVI| will then put a dot labeled `|1|' at point $(x_1,y_1)$
  16243. and a dot labeled `|2|' at~$(x_2,y_2)$.
  16244. Labels are placed in one of four positions relative to their dots---%
  16245. either at the top, the left, the right, or the bottom. |GFtoDVI| will
  16246. ordinarily try to place all labels so that they don't interfere with
  16247. each other, and so that they stay clear of other dots.
  16248.  But if you want to exercise fine control over the placement
  16249. yourself, you can say, for example, `@labels@."top"$(1a,2a)$'; in this
  16250. case the specified labels will appear above their dots, regardless of whether or
  16251. not other labels and/or dots are thereby overprinted. The |gf| file
  16252. ^^{labels.top} in this case will contain
  16253. \begindisplay
  16254. @special@ |" 11a"|; \ @numspecial@ $x_{1a}$; \ @numspecial@ $y_{1a}$;\cr
  16255. @special@ |" 12a"|; \ @numspecial@ $x_{2a}$; \ @numspecial@ $y_{2a}$.\cr
  16256. \enddisplay
  16257. |GFtoDVI| looks at the character following a leading blank space to
  16258. determine what sort of labeling convention is desired; the subsequent
  16259. characters are the text of the label.
  16260. The command `@labels@."top"$(1a,2a)$' in plain \MF\ is just an
  16261. abbreviation for `^@makelabel@."top"(|"1a"|$,z_{1a}$);
  16262. @makelabel@."top"(|"2a"|$,z_{2a}$)', when $"proofing">1$; the @makelabel@
  16263. macro is really the fundamental one, and you should use it directly if you
  16264. want more unusual effects. Suppose, for example, you just want to
  16265. put a dot but no label at point~$z_5$; then you can say
  16266. `@makelabel@(|""|$,z_5$)'. And suppose you want to put a label to the
  16267. left of point~$z_5$ but with no dot; you can say
  16268. `@makelabel@."lft".^"nodot"(|"5"|$,z_5$)'. Furthermore you could say
  16269. `@makelabel@."lft".^"nodot"(|"5"|$,z_5-(2,3)$)' to move that label left
  16270. by~2 pixels and down by~3 pixels, thereby getting the effect of a label
  16271. that is diagonally adjacent to its dot. Labels without dots can also
  16272. be used to put words on a diagram.
  16273. |GFtoDVI| recognizes nine varieties of labels in all, based on the
  16274. first two characters of the special string command:
  16275. \smallskip
  16276. \item\bull@makelabel@ (special |" 0"|): choose the label position automatically.
  16277. \item\bull@makelabel@."top" (special |" 1"|): center the label just above
  16278. the dot.
  16279. \item\bull@makelabel@."lft" (special |" 2"|): place the label just left of
  16280. the dot.
  16281. \item\bull@makelabel@."rt" (special |" 3"|): place the label just right of
  16282. the dot.
  16283. \item\bull@makelabel@."bot" (special |" 4"|): center the label just below
  16284. the dot.
  16285. \item\bull@makelabel@."top"."nodot" (special |" 5"|): like "top", but omit
  16286. the dot.
  16287. \item\bull@makelabel@."lft"."nodot" (special |" 6"|): like "lft", but omit
  16288. the dot.
  16289. \item\bull@makelabel@."rt"."nodot" (special |" 7"|): like "rt", but omit
  16290. the dot.
  16291. \item\bull@makelabel@."bot"."nodot" (special |" 8"|): like "bot", but omit
  16292. the dot.
  16293. \smallskip\noindent
  16294. The first case is called {\sl autolabeling\/}; this is the normal command.
  16295. Autolabeling always places a dot, whether or not that dot overlaps other dots,
  16296. but you don't always get a label. Autolabels are typeset only after
  16297. all explicit labels have been established; then |GFtoDVI| tries to
  16298. place as many of the remaining labels as possible.
  16299. If there's no place to put an autolabel, an ``^{overflow equation}'' is
  16300. put in the upper right corner of the proofsheet. For example, the
  16301. overflow equation `|5 = 5r + (-4.9,0)|' means that there was no room
  16302. for label~|5|, whose dot is 4.9 pixels to the left of the dot for~|5r|
  16303. (which is labeled).
  16304. You can avoid overflow equations by sending |GFtoDVI| the special command
  16305. |" /"| instead of |" 0"|; ^^{/} this is a variant of autolabeling that
  16306. does everything as usual except that the label will simply be forgotten if
  16307. it can't be placed. To do this with plain \MF\!, set
  16308. `$"lcode\_":=\null$|" /"|' near the beginning of your program; ^"lcode\_"
  16309. is the string that @makelabel@ uses to specify autolabeling.
  16310. The next most important kind of annotation for proofs is a straight line
  16311. or ``^{rule}.'' Plain \MF's command for this is `^@proofrule@$(z_1,z_2)$',
  16312. which expands to
  16313. \begindisplay
  16314. @special@ |"rule"|; \ @numspecial@ $x_1$; \ @numspecial@ $y_1$;\cr
  16315. \qquad @numspecial@ $x_2$; \ @numspecial@ $y_2$.\cr
  16316. \enddisplay
  16317. |GFtoDVI| has trouble drawing diagonal rules, because standard ^|dvi|
  16318. format includes no provision for drawing straight lines unless they are
  16319. vertical or horizontal. Therefore you might get an error message
  16320. unless $x_1=x_2$ (vertical rule) or $y_1=y_2$ (horizontal rule).
  16321. However, a limited escape from this restriction is available via a
  16322. ``^{slant font},'' by which |GFtoDVI| is able to typeset diagonal lines
  16323. as sequences of characters. Only one slope is permitted per job,
  16324. but this is better than nothing (see below).
  16325. To control the weight of proof rules, you say, e.g., `^@proofrulethickness@
  16326. 1.5$"mm"\0$' in a plain \MF\ program; this expands to
  16327. \begindisplay
  16328. @special@ |"rulethickness"|; \ @numspecial@ $1.5"mm"\0$.
  16329. \enddisplay
  16330. Each horizontal or vertical rule is drawn as if by a pen of the current
  16331. rulethickness, hence you can get different weights of lines in a single
  16332. diagram. If the current rulethickness is negative, no rule will appear; if
  16333. it is zero, a default rulethickness based on a parameter of the gray font
  16334. will be used; if it is positive, the stated thickness will be increased if
  16335. necessary until it equals an integer number of pixels, and that value will
  16336. be used to draw the rule. At the beginning of each character the current
  16337. rulethickness is zero.
  16338. You can reposition an entire diagram on its page by saying `^@proofoffset@
  16339. $(x,y)$'; this expands to
  16340. \begindisplay
  16341. @special@ |"offset"|; \ @numspecial@ $x$; \ @numspecial@ $y$
  16342. \enddisplay
  16343. and it tells |GFtoDVI| to shift everything except the title line on the
  16344. next character image, $x$~pixels to the right and $y$~pixels upward.
  16345. |GFtoDVI| uses four fonts to typeset its output: (1) The {\sl
  16346. {title font}\/} is used for the top line on each page.
  16347. (2)~The {\sl{label font}\/} is used for all labels.
  16348. (3)~The {\sl{gray font}\/} is used for dots and for black pixels.
  16349. (4)~The {\sl{slant font}\/} is used for diagonal rules.
  16350. Appropriate default fonts will be used at each installation unless
  16351. you substitute specific fonts yourself, by using the @special@ commands
  16352. ^@titlefont@, ^@labelfont@, ^@grayfont@, or ^@slantfont@.
  16353. |GFtoDVI| also understands special strings like `|"grayfontarea
  16354. /usr/dek"|', which can be used to specify a nonstandard file area
  16355. or directory name for the gray font. Furthermore the |gf| file might
  16356. ^^{grayfontarea} ^^{labelfontat}
  16357. say, e.g.,
  16358. \begindisplay
  16359. @special@ |"labelfontat"|; @numspecial@ 20
  16360. \enddisplay
  16361. if you want the label font to be loaded at $20\pt$ instead of its ^{design
  16362. size}.  The area name and the at size must be given after the font name
  16363. itself; in other words, `|"grayfont"|' cancels a previous
  16364. `|"grayfontarea"|'.
  16365. The four fonts used by |GFtoDVI| must be established before the first
  16366. character bitmap appears in the |gf| file. This means that the special font
  16367. commands must be given before the first ^@shipout@ or ^@endchar@ in your
  16368. program; but they shouldn't appear until after ^@mode\_setup@, so that
  16369. your |gf| file will have the correct name.  If it's inconvenient to
  16370. specify the fonts that way, you can change them at run time when
  16371. you use |GFtoDVI|\null: Just type `^|/|' following the name of the |gf| file
  16372. that's being input, and you will be asked to type special strings online.
  16373. For example, the run-time dialog might look like this:
  16374. \begintt
  16375. This is GFtoDVI, Version 2.0
  16376. GF file name: io.2602gf/
  16377. Special font substitution: labelfont cmbx10
  16378. OK; any more?              grayfont black
  16379. OK; any more?
  16380. \endtt
  16381. After the final carriage return, |GFtoDVI| does its normal thing,
  16382. ignoring font specifications in the file that conflict with those
  16383. just given.
  16384. \subsection ^{Gray fonts}.  A proof diagram constructed by |GFtoDVI| can
  16385. be regarded as an array of rectangles, where each rectangle is either
  16386. blank or filled with a special symbol that we shall call `{\manual R}'. A
  16387. blank rectangle represents a white pixel, while {\manual R} represents a
  16388. black pixel.  Additional labels and reference lines are often superimposed
  16389. on this array of rectangles; hence it is usually best to choose a symbol
  16390. {\manual R} that has a somewhat gray appearance, although any symbol can
  16391. actually be used.
  16392. In order to construct such proofs, |GFtoDVI| needs to work with
  16393. a special type of font known as a ``gray font''; it's possible to
  16394. obtain a wide variety of different sorts of proofs by using different
  16395. sorts of gray fonts. The next few paragraphs explain exactly what gray
  16396. fonts are supposed to contain, in case you want to design your own.
  16397. The simplest gray font contains only two characters, namely {\manual R}
  16398. and another symbol that is used for dots that identify key points.
  16399. If proofs with relatively large pixels are desired, a two-character
  16400. gray font is all that's needed. However, if the pixel size is to be
  16401. relatively small, practical considerations make a two-character
  16402. font too inefficient, since it requires the typesetting of tens
  16403. of thousands of tiny little characters; printing-device drivers
  16404. rarely work very well when they are presented with data that is
  16405. so different from ordinary text. Therefore a gray font with small
  16406. pixels usually has a number of characters that replicate {\manual R} in
  16407. such a way that comparatively few characters actually need to be
  16408. typeset.
  16409. Since many printing devices are not able to cope with
  16410. arbitrarily large or complex characters, it is not possible for a
  16411. single gray font to work well on all machines. In fact,
  16412. {\manual R} must have a width that is an integer multiple of the printing
  16413. device's units of horizontal and vertical positioning,
  16414. since rounding the positions of grey
  16415. characters would otherwise produce unsightly streaks on proof output.
  16416. Thus, there is no way to make the gray font as device-independent as
  16417. normal fonts of type can be.
  16418. This understood, we can now take a look at what |GFtoDVI| expects to
  16419. see in a gray font. The character~{\manual R} always appears in position~1. It
  16420. must have positive height~$h$ and positive width~$w$; its depth
  16421. and italic correction are ignored.
  16422. Positions 2--120 of a gray font are reserved for special combinations of\/
  16423. {\manual R}'s and blanks, stacked on top of each other. None of these
  16424. character codes need be present in the font; but if they are, the slots
  16425. must be occupied by characters of width~$w$ that have certain
  16426. configurations of\/ {\manual R}'s and blanks, prescribed for each character
  16427. position. For example, position~3 of the font should either contain no
  16428. character at all, or it should contain a character consisting of two
  16429. {\manual R}'s, one above the other; one of these {\manual R}'s should rest
  16430. on the baseline, and the other should appear immediately below.
  16431. It will be convenient to use a horizontal notation like `{\manual RSRRS}'
  16432. to stand for a vertical stack of\/ {\manual R}'s and blanks. The convention
  16433. will be that the stack is built from bottom to top, and the topmost
  16434. rectangle should sit on the baseline. Thus, `{\manual RSRRS}' stands
  16435. actually for a character of height~$h$ and depth~$4h$ that looks like this:
  16436. \begindisplay
  16437. \vbox{\offinterlineskip\halign{\manual#\hfil\cr
  16438. \phantom{R}\cr
  16439. R\rm\smash{\hbox{\raise.5pt\hbox{$\longleftarrow$ baseline}}}\cr
  16440. \phantom{R}\cr
  16441. \enddisplay
  16442. We use a horizontal notation in this discussion instead of a vertical one
  16443. because column vectors take too much space, and because the horizontal
  16444. notation corresponds to binary numbers in a convenient way.
  16445. Positions 1--63 of a gray font are reserved for the patterns {\manual R},
  16446. {\manual RS}, {\manual RR}, {\manual RSS}, {\manual RSR}, and so~on up to
  16447. {\manual RRRRRR}, just as in the normal binary notation of the numbers
  16448. 1--63, with {\manual R}'s substituted for 1's and blanks for 0's.
  16449. Positions 64--70 are reserved for the special patterns {\manual RSSSSSS},
  16450. {\manual RRSSSSS}, {\manual RRRSSSS}, {\manual RRRRSSS}, {\manual
  16451. RRRRRSS}, {\manual RRRRRRS}, {\manual RRRRRRR} of length seven; positions
  16452. 71--78 are, similarly, reserved for the length-eight patterns {\manual
  16453. RSSSSSSS} through {\manual RRRRRRRR}. The length-nine patterns {\manual
  16454. RSSSSSSSS} through {\manual RRRRRRRRR} are assigned to positions 79--87,
  16455. the length-ten patterns to positions 88--97, the length-eleven patterns to
  16456. positions 98--108, and the length-twelve patterns to positions 109--120.
  16457. Position 0 of a gray font is reserved for the ``dot'' character, which
  16458. should have positive height~$h'$ and positive width~$w'$. When |GFtoDVI|
  16459. wants to put a dot at some place $(x,y)$ on the figure, it positions
  16460. the dot character so that its reference point is at $(x,y)$. The
  16461. dot will be considered to occupy a rectangle whose corners are at
  16462. $(x\pm w',y\pm h')$; the rectangular
  16463. box for a label will butt up against the rectangle enclosing the dot.
  16464. All other character positions of a gray font (namely, positions 121--255)
  16465. are unreserved, in the sense that they have no predefined meaning.
  16466. But |GFtoDVI| may access them via the ^@charlist@ feature of
  16467. |tfm| files, starting with any of the characters in positions
  16468. 1--120. In such a case each succeeding character in a list should be
  16469. equivalent to two of its predecessors, horizontally adjacent to each other.
  16470. For example, in
  16471. \begindisplay
  16472. @charlist@ 53: 121: 122: 123
  16473. \enddisplay
  16474. character 121 will stand for two 53's, character 122 for two 121's (i.e.,
  16475. four 53's), and character 123 for two 122's (i.e., eight 53's). Since
  16476. position~53 contains the pattern {\manual RRSRSR}, character~123 in this example
  16477. would have height~$h$, depth~$5h$, and width~$8w$, and it would stand for
  16478. the pattern
  16479. \begindisplay
  16480. \vbox{\offinterlineskip\halign{\manual#\hfil\cr
  16481. RRRRRRRR\cr
  16482. \phantom{SSSSSSSS}\rm
  16483.  \smash{\hbox{\raise.5pt\hbox{$\longleftarrow$ baseline}}}\cr
  16484. RRRRRRRR\cr
  16485. \phantom{SSSSSSSS}\cr
  16486. RRRRRRRR\cr
  16487. RRRRRRRR\cr
  16488. \enddisplay
  16489. Such a pattern is, of course, rather unlikely to occur in a |gf| file,
  16490. but |GFtoDVI| would be able to use if it were present. Designers
  16491. of gray fonts should provide characters only for patterns that they think
  16492. will occur often enough to make the doubling worthwhile. For example,
  16493. the character in position 120 ({\manual RRRRRRRRRRRR}), or whatever is the
  16494. tallest stack of\/ {\manual R}'s present in the font, is a natural candidate for
  16495. repeated doubling.
  16496. Here's how |GFtoDVI| decides what characters of the gray font will be used,
  16497. given a configuration of black and white pixels: If there are no black
  16498. pixels, stop. Otherwise look at the top row that contains at least one
  16499. black pixel, and the eleven rows that follow. For each such column,
  16500. find the largest~$k$ such that $1\leq k\leq120$ and the gray font contains
  16501. character~$k$ and the pattern assigned to position~$k$ appears in the
  16502. given column. Typeset character $k$ (unless no such character exists)
  16503. and erase the corresponding black pixels; use doubled characters,
  16504. if they are present in the gray font, if two or more consecutive equal
  16505. characters need to be typeset. Repeat the same process on the remaining
  16506. configuration, until all the black pixels have been erased.
  16507. If all characters in positions 1--63 are present, this process is guaranteed to
  16508. take care of at least six rows each time; and with characters 64--120 as well,
  16509. it usually takes care of twelve, since all patterns that contain at most
  16510. one ``run'' of\/ {\manual R}'s are present.
  16511. Some of the ^@fontdimen@ parameters discussed in Appendix~F are important
  16512. in gray fonts. The ^@font\_slant@ value~$s$, if nonzero, will cause
  16513. |GFtoDVI| to skew its output; in this case the character {\manual R} will
  16514. presumably be a parallelogram with a corresponding slant, rather than the
  16515. usual rectangle. \MF's coordinate $(x,y)$ will appear in physical position
  16516. $(xw+yhs,yh)$ on the proofsheets. \ (This is appropriate for proofing unslanted
  16517. fonts whose pixels will become slanted by mechanical obliquing.)
  16518. Parameter @fontdimen@ 8 of a gray font specifies the thickness of rules
  16519. that go on the proofs. If this parameter is zero, \TeX's default
  16520. rule thickness (0.4\thinspace pt) will be used.
  16521. The other parameters of a gray font are ignored by |GFtoDVI|\null, but
  16522. it is conventional to set ^@font\_normal\_space@ and ^@font\_quad@ to~$w$,
  16523. ^@font\_x\_height@ to~$h$.
  16524. For best results the designer of a gray font should choose $w$ and~$h$
  16525. so that the user's |dvi|-to-hardcopy software will not make any
  16526. rounding errors. Furthermore, the dot should be an even number~$2m$ of
  16527. pixels in diameter, and the rule thickness should work out to an
  16528. even number~$2n$ of pixels; then the dots and rules will be centered on
  16529. the correct positions, in the common case of integer coordinates. Gray fonts
  16530. are almost always intended for particular output devices, even though
  16531. `|dvi|' stands for ``device independent''; we use |dvi| files for \MF\
  16532. proofs chiefly because software to print |dvi| files is already in place.
  16533. The \MF\ program for a fairly versatile gray font generator, called
  16534. `^|grayf.mf|', appears on the next few pages. It should be invoked by a
  16535. parameter file that establishes values of several quantities:
  16536. \smallskip
  16537. \item\bull If ^"large\_pixels" is of type @boolean@, only 15 characters
  16538. will be generated; otherwise there will be 123.
  16539. \item\bull If ^"pix\_picture" is of type @picture@, it should be the
  16540. desired pixel image `{\manual R}', and in this case ^"pix\_wd" and
  16541. ^"pix\_ht" should be the width and height in pixels. Otherwise a default
  16542. gray pixel pattern will be used.
  16543. \item\bull If ^"rep" is known, it should be a positive integer; the default
  16544. pixel pattern will be magnified "rep" times so that the final
  16545. proofs will be this much bigger than usual, and the pattern will be clipped
  16546. slightly at the edges so that discrete pixels can be seen plainly.
  16547. \item\bull If ^"lightweight" is of type @boolean@, the default pixel
  16548. pattern will be only half as dark as usual.
  16549. \item\bull If ^"dotsize" is known, it should be the diameter of the
  16550. special dot character, in pixel units.
  16551. \item\bull The ^@font\_identifier@ should be specified.
  16552. \smallskip\noindent
  16553. (The "rep" and "lightweight" options are ignored if "pix\_picture" is
  16554. explicitly given.) \
  16555. Since gray fonts are inherently device-dependent, we do not start
  16556. with ``sharp'' dimensions as in normal fonts; we go backwards and
  16557. compute the sharp units from pixel units.
  16558. The name of each gray font should include the name of the device for
  16559. which it is intended. \ (A ``favorite'' proof device can also be chosen
  16560. at each installation, for which the alternate font names `^|gray|'
  16561. and `^|black|' are valid; these installation-dependent fonts are the
  16562. defaults for "proof" mode and "smoke" mode.)
  16563. Here, for example, is a suitable parameter file `|graycheap.mf|', which
  16564. generates a vanilla-flavored gray font for the hypothetical "cheapo"
  16565. printer:
  16566. \beginlines
  16567. |% Gray font for Cheapo with proofsheet resolution 50 pixels per inch|
  16568. \smallskip
  16569. |if mode<>cheapo: errmessage "This file is for cheapo only"; fi|
  16570. \smallskip
  16571. |font_identifier "GRAYCHEAP";|
  16572. |input grayf|
  16573. \endlines
  16574. (The proofsheet resolution will be 50 per inch, because "cheapo" has
  16575. 200 pixels per inch, and the default "pix\_picture" in |grayf|
  16576. will be four pixels square in this case.) \ If the default pixel pattern
  16577. turns out to be such a dark gray that the labels and rules are obscured,
  16578. the statement `|boolean lightweight|' should be added.  A solid black font
  16579. with slightly higher-resolution images can be generated by the following
  16580. file `|blackcheap.mf|':
  16581. \beginlines
  16582. |% Black font for Cheapo with proofsheet resolution 66.7 pixels per inch|
  16583. \smallskip
  16584. |if mode<>cheapo: errmessage "This file is for cheapo only"; fi|
  16585. \smallskip
  16586. |picture pix_picture; pix_wd := pix_ht := 3;|
  16587. |pix_picture := unitpixel scaled 3;|
  16588. \smallskip
  16589. |font_identifier "BLACKCHEAP";|
  16590. |input grayf|
  16591. \endlines
  16592. And here is a file `|graycheap5.mf|' that generates a gray font suitable
  16593. for studying large proofs of low-resolution characters:
  16594. \beginlines
  16595. |% Gray font for Cheapo with proofsheet resolution 10 pixels per inch|
  16596. \smallskip
  16597. |if mode<>cheapo: errmessage "This file is for cheapo only"; fi|
  16598. \smallskip
  16599. |rep=5; boolean large_pixels;|
  16600. \smallskip
  16601. |font_identifier "GRAYCHEAP";|
  16602. |input grayf|
  16603. \endlines
  16604. Now let's look at the program file `|grayf.mf|' itself. It begins with
  16605. a simple test to ensure that "mag" and "rep" are positive integers, if
  16606. they're known; then comes some less obvious code that handles
  16607. magnification in a nonstandard way:
  16608. \beginlines
  16609. |% More-or-less general gray font generator|
  16610. |% See Appendix H of The METAFONTbook for how to use it|
  16611. \smallskip
  16612. |forsuffixes m = mag,rep:|
  16613. | if unknown m: m := 1;|
  16614. | elseif (m<1) or (m<>floor m):|
  16615. |  errmessage "Sorry, " & str m & " must be a positive integer";|
  16616. |  m := 1; fi endfor|
  16617. \smallbreak
  16618. |mg := mag; mag := 1; mode_setup;|
  16619. |if mg>1: hppp := hppp*mg; vppp := vppp*mg;|
  16620. | extra_endchar:=|
  16621. |  "if charcode>0:currentpicture:=currentpicture scaled mg;fi"|
  16622. |  & extra_endchar; fi;|
  16623. \endlines
  16624. This circumlocution is the easiest way to guarantee that the ^|tfm| file
  16625. will be completely unaffected by magnification.
  16626. The next part of |grayf| computes the pixel representation, "pix\_picture".
  16627. \beginlines
  16628. |if picture pix_picture: rep := 1;|
  16629. | cull pix_picture keeping (1,infinity);|
  16630. |else: for z=(0,2),(1,0),(2,3),(3,1):|
  16631. |  fill unitsquare shifted z; endfor|
  16632. | if not boolean lightweight:|
  16633. |  addto currentpicture also|
  16634. |  currentpicture rotated 90 xscaled -1; fi|
  16635. | if unknown scale: scale := max(1,round(pixels_per_inch/300)); fi|
  16636. | pix_wd := pix_ht := 4scale;|
  16637. | if rep>1: picture pix;|
  16638. |  currentpicture := currentpicture shifted-(1,1); pix := currentpicture;|
  16639. |  for r=1 upto rep-1: addto currentpicture also pix shifted(4r,0); endfor|
  16640. |  cullit; pix := currentpicture;|
  16641. |  for r=1 upto rep-1: addto currentpicture also pix shifted(0,4r); endfor|
  16642. |  unfill unitsquare xscaled 4rep yscaled 2 shifted-(1,1);|
  16643. |  unfill unitsquare yscaled 4rep xscaled 2 shifted-(1,1); cullit; fi|
  16644. | picture pix_picture; pix_picture := currentpicture scaled scale;|
  16645. | pix_wd := pix_ht := 4scale*rep; fi|
  16646. \weakendlines
  16647. The lightweight pattern has 4 of every 16 pixels turned on; the normal
  16648. pattern has twice as many.
  16649. Character 0 is the dot, which is quite simple:
  16650. \beginlines
  16651. |def # = *72.27/pixels_per_inch enddef;|
  16652. |if unknown dotsize: dotsize := 2.5pix_wd/rep; fi|
  16653. \smallskip
  16654. |beginchar(0,1.2dotsize#,1.2dotsize#,0);|
  16655. |fill fullcircle scaled dotsize scaled mg; endchar;|
  16656. \endlines
  16657. The special coding scheme of gray fonts is implemented next:
  16658. \beginlines
  16659. |numeric a[]; newinternal b,k;|
  16660. |def next_binary =|
  16661. | k := 0; forever: if k>b: a[incr b] := 0; fi|
  16662. |  exitif a[k]=0; a[k] := 0; k := k+1; endfor|
  16663. | a[k] := 1 enddef;|
  16664. |def next_special_binary =|
  16665. | if a[0]=1: for k=0 upto b: a[k] := 0; endfor a[incr b]|
  16666. | else: k := 0; forever: exitif a[incr k]=1; endfor|
  16667. |  a[k-1] fi := 1 enddef;|
  16668. \smallbreak
  16669. |def make_char =|
  16670. | clearit; next_binary;|
  16671. | for k=0 upto b: if a[k]=1:|
  16672. |  addto currentpicture also pix_picture shifted(0,-k*pix_ht); fi endfor|
  16673. | charcode := charcode+1; chardp := b*charht;|
  16674. | scantokens extra_endchar; shipout currentpicture enddef;|
  16675. \endlines
  16676. Now we are ready to generate all the pixel characters.
  16677. ^^@charlist@^^"chardx"^^"charwd"^^"charht"
  16678. \beginlines
  16679. |charwd := pix_wd#; charht := pix_ht#; chardx := pix_wd*mg;|
  16680. |b := -1;|
  16681. \smallskip
  16682. |if boolean large_pixels:|
  16683. | for k=1 upto 7: make_char; charlist k:k+120; endfor|
  16684. | charcode := 120; b := -1;|
  16685. | addto pix_picture also pix_picture shifted (chardx,0);|
  16686. | charwd := 2charwd; chardx := 2chardx;|
  16687. | for k=1 upto 7: make_char; endfor|
  16688. |else: for k=1 upto 63: make_char; endfor|
  16689. | let next_binary = next_special_binary;|
  16690. | for k=64 upto 120: make_char; endfor|
  16691. | for k=121,122: charcode := k;|
  16692. |  addto currentpicture also currentpicture shifted (chardx,0);|
  16693. |  charwd := 2charwd; chardx := 2chardx;|
  16694. |  scantokens extra_endchar; shipout currentpicture; endfor|
  16695. | charlist 120:121:122; fi|
  16696. \endlines
  16697. The program closes by establishing fontwide parameters:
  16698. \beginlines
  16699. |font_coding_scheme "GFGRAY";|
  16700. |font_size 8(pix_wd#);|
  16701. |font_normal_space pix_wd#;|
  16702. |font_x_height pix_ht#;|
  16703. |font_quad pix_wd#;|
  16704. |fontdimen 8: if known rulethickness: rulethickness|
  16705. | else: pix_wd#/(2rep) fi;|
  16706. |bye.|
  16707. \weakendlines
  16708. (The extra complications of an ^"aspect\_ratio" or a slant have not
  16709. been addressed.)
  16710. \subsection ^{Slant fonts}.  |GFtoDVI| also makes use of another special
  16711. type of font, if it is necessary to typeset slanted rules. The format of
  16712. such so-called ``slant fonts'' is quite a bit simpler than the format of
  16713. gray fonts.
  16714. A slant font contains exactly $n$ characters, in positions 1 to~$n$,
  16715. for some positive integer~$n$.
  16716. The character in position~$k$ represents a slanted line $k$ units
  16717. tall, starting at the baseline. These lines all have a fixed slant ratio~$s$.
  16718. The vertical ``unit'' is usually chosen to be an integral number of pixels,
  16719. small enough so that it suffices to draw rules that are an
  16720. integer number of units high; in fact, it should probably be no larger
  16721. than the thickness of the rules being drawn.
  16722. The following simple algorithm is used to typeset a rule that is $m$ units
  16723. high: Compute $q=\lceil m/n\rceil$; then typeset $q$~characters of
  16724. approximately equal size, namely $(m\bmod q)$ copies of character number
  16725. $\lceil m/q\rceil$ and $q-(m\bmod q)$ copies of character number
  16726. $\lfloor m/q\rfloor$. For example, if $n=15$ and $m=100$, we have $q=7$;
  16727. a 100-unit-high rule will be composed of 7~pieces, using characters
  16728. 14,~14, 14, 14, 14, 15,~15.
  16729. |GFtoDVI| looks at the ^"charht" of character $n$ only, so the |tfm| file
  16730. need not be accurate about the heights of the other characters. \ (This is
  16731. fortunate, since ^|tfm| format allows at most 15 different nonzero
  16732. heights per font.)
  16733. The ^"charwd" of character~$k$ should be $k/n$ times $s$ times the "charht"
  16734. of~$n$.
  16735. The ^@font\_slant@ parameter should be $s$. It is customary to
  16736. set the parameter @fontdimen@~8 to the thickness of
  16737. the slanted rules, but |GFtoDVI| doesn't look at it.
  16738. Here's an example of a slant-font parameter file, `|slantcheap6|',
  16739. for the "cheapo" printer and a slant of 1/6:
  16740. \beginlines
  16741. |% Slant font for Cheapo with slope 1/6|
  16742. \smallskip
  16743. |if mode<>cheapo: errmessage "This file is for cheapo only"; fi|
  16744. \smallskip
  16745. |s=1/6;           % the slant ratio|
  16746. |n=30;            % the number of characters|
  16747. |r#=.4pt#;        % thickness of the rules|
  16748. |u=1;             % vertical unit|
  16749. \smallskip
  16750. |font_identifier "SLANTCHEAP6";|
  16751. |input slant|
  16752. \endlines
  16753. The corresponding program file `|slant.mf|' looks like this:
  16754. \beginlines
  16755. |% More-or-less general slant font generator for GFtoDVI|
  16756. |% The calling file should set the font_identifier and|
  16757. |%    n = number of characters|
  16758. |%    s = slant ratio|
  16759. |%    r# = rule thickness (in sharp units)|
  16760. |%    u = vertical unit   (in pixels)|
  16761. \smallskip
  16762. |if unknown mag: mag := 1;|
  16763. |elseif (mag<1) or (mag<>floor mag):|
  16764. | errmessage "Sorry, mag must be a positive integer"; mag := 1; fi|
  16765. \smallbreak
  16766. |mg := mag; mag := 1; mode_setup; u# := u*72.27/pixels_per_inch;|
  16767. |pixels_per_inch := pixels_per_inch*mg; fix_units;|
  16768. \smallbreak
  16769. |define_whole_pixels(u); define_blacker_pixels(r);|
  16770. |pickup pencircle scaled r; ruler := savepen;|
  16771. \smallbreak
  16772. |for k=1 upto n:|
  16773. | beginchar(k,k*u#*s,n*u#,0);|
  16774. | pickup ruler; draw origin--(k*u*s,k*u);   % draw the line|
  16775. | unfill (lft-1,bot -1)--(rt 1,bot -1)|
  16776. |  --(rt 1,0)--(lft-1,0)--cycle;            % clip the ends|
  16777. | unfill ((lft -1,0)--(rt 1,0)|
  16778. |  --(rt 1,top 1)--(lft -1,top 1)--cycle) shifted (k*u*s,k*u);|
  16779. | endchar; endfor|
  16780. \smallbreak
  16781. |font_size 16pt#;|
  16782. |font_slant s;|
  16783. |fontdimen 8: r#;|
  16784. |font_coding_scheme "GFSLANT";|
  16785. |bye.|
  16786. \endlines
  16787. \subsection Font samples. The real test of a font is its appearance
  16788. at the final size, after it has actually been typeset. The \TeX\
  16789. typesetting system can be used with the following example macro file
  16790. `^|testfont.tex|' (in addition to plain \TeX\ format) to
  16791. put a new font through its paces.
  16792. We shall comment on typical uses of |testfont| as we examine its parts.
  16793. At the beginning, |testfont.tex| turns off several of \TeX's normal features.
  16794. \beginlines
  16795. |% A testbed for font evaluation|
  16796. \smallskip
  16797. |\tracinglostchars=0                  % missing characters are OK|
  16798. |\tolerance=1000                      % and so are loose lines|
  16799. |\raggedbottom                        % pages can be short|
  16800. |\nopagenumbers                       % and they won't be numbered|
  16801. |\parindent=0pt                       % nor will paragraphs be indented|
  16802. |\hyphenpenalty=200                   % hyphens are discouraged|
  16803. |\doublehyphendemerits=30000          % and two in a row are terrible|
  16804. \smallskip
  16805. |\newlinechar=`@                      % we want to type multiline messages|
  16806. |\chardef\other=12                    % and redefine "catcodes"|
  16807. \smallskip
  16808. |\newcount\m \newcount\n \newcount\p \newdimen\dim   % temporary variables|
  16809. \endlines
  16810. Then there are macros to print the time and date---an extremely valuable
  16811. thing to have on any proofsheet.
  16812. \beginlines
  16813. |\def\today{\ifcase\month\or|
  16814. |  January\or February\or March\or April\or May\or June\or|
  16815. |  July\or August\or September\or October\or November\or December\fi|
  16816. |  \space\number\day, \number\year}|
  16817. |\def\hours{\n=\time \divide\n 60|
  16818. |  \m=-\n \multiply\m 60 \advance\m \time|
  16819. |  \twodigits\n\twodigits\m}|
  16820. |\def\twodigits#1{\ifnum #1<10 0\fi \number#1}|
  16821. \endlines
  16822. An online ``menu'' of the available test routines will be typed at your
  16823. terminal if you request |\help|.
  16824. \beginlines
  16825. |{\catcode`\|\||=0 \catcode`\\=\other    % use |\|| as the escape, temporarily|
  16826. \||gdef|\||help{|\||message{%|
  16827. |\init switches to another font;@%|
  16828. |\end or \bye finishes the run;@%|
  16829. |\table prints the font layout in tabular format;@%|
  16830. |\text prints a sample text, assuming TeX text font conventions;@%|
  16831. |\sample combines \table and \text;@%|
  16832. |\mixture mixes a background character with a series of others;@%|
  16833. |\alternation interleaves a background character with a series;@%|
  16834. |\alphabet prints all lowercase letters within a given background;@%|
  16835. |\ALPHABET prints all uppercase letters within a given background;@%|
  16836. |\series prints a series of letters within a given background;@%|
  16837. |\lowers prints a comprehensive test of lowercase;@%|
  16838. |\uppers prints a comprehensive test of uppercase;@%|
  16839. |\digits prints a comprehensive test of numerals;@%|
  16840. |\math prints a comprehensive test of TeX math italic;@%|
  16841. |\names prints a text that mixes upper and lower case;@%|
  16842. |\punct prints a punctuation test;@%|
  16843. |\bigtest combines many of the above routines;@%|
  16844. |\help repeats this message;@%|
  16845. |and you can use ordinary TeX commands (e.g., to \input a file).}}}|
  16846. \endlines
  16847. The program prompts you for a font name. If the font is in your local
  16848. directory instead of a system directory, you might have to
  16849. specify the directory name as part of the font name. You should
  16850. also specify scaling if the font has been magnified, as in the example
  16851. of Chapter~5. Several fonts can be tested during a single run, if you
  16852. say `|\init|' before `|\end|'.
  16853. \beginlines
  16854. |\def\init{\message{@Name of the font to test = }|
  16855. |  \read-1 to\fontname \startfont|
  16856. |  \message{Now type a test command (\string\help\space for help):}}|
  16857. |\def\startfont{\font\testfont=\fontname \spaceskip=0pt|
  16858. |  \leftline{\sevenrm Test of \fontname\unskip\ on \today\ at \hours}|
  16859. |  \medskip|
  16860. |  \testfont \setbaselineskip|
  16861. |  \ifdim\fontdimen6\testfont<10pt \rightskip=0pt plus 20pt|
  16862. |  \else\rightskip=0pt plus 2em \fi|
  16863. |  \spaceskip=\fontdimen2\testfont % space between words (\raggedright)|
  16864. |  \xspaceskip=\fontdimen2\testfont|
  16865. |  \advance\xspaceskip by\fontdimen7\testfont}|
  16866. \endlines
  16867. The specified font will be called |\testfont|. As soon as you have
  16868. specified it, |\init| calls on |\startfont|, which puts a title line
  16869. on the page; then it chooses what it hopes will be a good distance between
  16870. baselines, and gets ready to typeset text with ``^{ragged right}'' margins.
  16871. \ (The code above improves on plain \TeX's ^|\raggedright|.)
  16872. The baselineskip distance is taken to be $6\pt$ plus the height of the
  16873. tallest character plus the depth of the deepest character. This is the
  16874. distance between baselines for ``series'' tests, but it is decreased
  16875. by $4\pt$ when the sample text is set. If you
  16876. want to change the baseline distance chosen by |testfont|,
  16877. you can just say, e.g., `|\baselineskip=11pt|'.
  16878. \beginlines
  16879. |\def\setbaselineskip{\setbox0=\hbox{\n=0|
  16880. |\loop\char\n \ifnum \n<255 \advance\n 1 \repeat}  % 256 chars in \box0|
  16881. |\baselineskip=6pt \advance\baselineskip\ht0 \advance\baselineskip\dp0 }|
  16882. \endlines
  16883. When |testfont| prompts you for a ``^{background character}''
  16884. or a ``^{starting character}'' or an ``^{ending character},'' you
  16885. can type the character you want (assuming ASCII code);
  16886. or you can say, e.g., `|#35|' to get character code number 35.
  16887. Codes 0--32 and 127--255 have to be specified with the `|#|' option,
  16888. on non-fancy installations of \TeX,
  16889. and so does code 35 (which is the ASCII code of `|#|' itself).
  16890. \beginlines
  16891. |\def\setchar#1{{\escapechar-1\message{\string#1 character = }%|
  16892. |  \def\do##1{\catcode`##1=\other}\dospecials|
  16893. |  \read-1 to\next|
  16894. |  \expandafter\finsetchar\next\next#1}}|
  16895. |\def\finsetchar#1#2\next#3{\global\chardef#3=`#1|
  16896. |  \ifnum #3=`\# \global\chardef#3=#2 \fi}|
  16897. |\def\promptthree{\setchar\background|
  16898. |  \setchar\starting \setchar\ending}|
  16899. \endlines
  16900. (The \TeX\ hackery here is a bit subtle, because special characters
  16901. like `|\|' and `|$|' must temporarily lose their special significance.)
  16902. Suppose the background character is `|o|' and the starting and ending
  16903. characters are respectively `|p|' and~`|q|'. Then the ^|\mixture|
  16904. operation will typeset `|opooppooopppop|' and `|oqooqqoooqqqoq|';
  16905. the ^|\alternation| operation will typeset `|opopopopopopopopo|' and
  16906. `|oqoqoqoqoqoqoqoqo|'. Other patterns could be added in a similar way.
  16907. \beginlines
  16908. |\def\mixture{\promptthree \domix\mixpattern}|
  16909. |\def\alternation{\promptthree \domix\altpattern}|
  16910. |\def\mixpattern{\0\1\0\0\1\1\0\0\0\1\1\1\0\1}|
  16911. |\def\altpattern{\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0\1\0}|
  16912. |\def\domix#1{\par\chardef\0=\background \n=\starting|
  16913. |  \loop \chardef\1=\n #1\endgraf|
  16914. |  \ifnum \n<\ending \advance\n 1 \repeat}|
  16915. \endlines
  16916. The |\series| operation puts the background character between all the
  16917. others (e.g., `|opoqo|'). Special series containing the lowercase
  16918. letters of \TeX\ text fonts (including `\char'31', `\char'32',
  16919. `\char'33', and ~\char'34') and the uppercase letters (including
  16920. `\char'35', `\char'36', and~`\char'37') are provided.
  16921. Although |\mixture| and |\alternation| show you the effects of
  16922. ligatures and kerning, |\series| does not.
  16923. \beginlines
  16924. |\def\!{\discretionary{\background}{\background}{\background}}|
  16925. |\def\series{\promptthree \!\doseries\starting\ending\par}|
  16926. |\def\doseries#1#2{\n=#1\loop\char\n\!\ifnum\n<#2\advance\n 1 \repeat}|
  16927. |\def\complower{\!\doseries{`a}{`z}\doseries{'31}{'34}\par}|
  16928. |\def\compupper{\!\doseries{`A}{`Z}\doseries{'35}{'37}\par}|
  16929. |\def\compdigs{\!\doseries{`0}{`9}\par}|
  16930. |\def\alphabet{\setchar\background\complower}|
  16931. |\def\ALPHABET{\setchar\background\compupper}|
  16932. \endlines
  16933. (A long series might fill more than one line; \TeX's |\discretionary|
  16934. break operation is used here so that the background character will end
  16935. the line and be repeated at the beginning of the next.)
  16936. A ``comprehensive'' test uses a series of background characters
  16937. against a series of others. The series will consist of lowercase
  16938. letters (`^|\lowers|'), uppercase letters (`^|\uppers|'), or
  16939. numerals (`^|\digits|').
  16940. \beginlines
  16941. |\def\lowers{\docomprehensive\complower{`a}{`z}{'31}{'34}}|
  16942. |\def\uppers{\docomprehensive\compupper{`A}{`Z}{'35}{'37}}|
  16943. |\def\digits{\docomprehensive\compdigs{`0}{`4}{`5}{`9}}|
  16944. |\def\docomprehensive#1#2#3#4#5{\par\chardef\background=#2|
  16945. |  \loop{#1} \ifnum\background<#3\m=\background\advance\m 1|
  16946. |  \chardef\background=\m \repeat \chardef\background=#4|
  16947. |  \loop{#1} \ifnum\background<#5\m=\background\advance\m 1|
  16948. |  \chardef\background=\m \repeat}|
  16949. \endlines
  16950. The ^|\names| test puts uppercase letters and accents
  16951. together with lowercase letters. The accents will look funny
  16952. if the test font doesn't have them in plain \TeX's favorite positions.
  16953. \beginlines
  16954. |\def\names{ {\AA}ngel\aa\ Beatrice Claire|
  16955. |  Diana \'Erica Fran\c{c}oise Ginette H\'el\`ene Iris|
  16956. |  Jackie K\=aren {\L}au\.ra Mar{\'\i}a N\H{a}ta{\l}{\u\i}e {\O}ctave|
  16957. |  Pauline Qu\^eneau Roxanne Sabine T\~a{\'\j}a Ur\v{s}ula|
  16958. |  Vivian Wendy Xanthippe Yv{\o}nne Z\"azilie\par}|
  16959. \endlines
  16960. Punctuation marks are tested in juxtaposition with different
  16961. sorts of letters, by the `^|\punct|' macro:
  16962. \beginlines
  16963. |\def\punct{\par\dopunct{min}\dopunct{pig}\dopunct{hid}|
  16964. |  \dopunct{HIE}\dopunct{TIP}\dopunct{fluff}|
  16965. |  \$1,234.56 + 7/8 = 9\% @ \#0\par}|
  16966. |\def\dopunct#1{#1,\ #1:\ #1;\ `#1'\|
  16967. |   ?||`#1?\ !||`#1!\ (#1)\ [#1]\ #1*\ #1.\par}|
  16968. \endlines
  16969. Mixtures and alternations and series are excellent ways to discover
  16970. that letters are too dark, too light, or too tightly spaced. But
  16971. a font also has to be readable; in fact, this is the number one
  16972. objective. So |testfont| provides a sample `^|\text|'. One of the sentences
  16973. is optional, because it contains lots of accents and unusual letters;
  16974. you can omit it from the text by saying `^|\omitaccents|'.
  16975. Furthermore, you can type your own text, online, or you can input one from
  16976. ^^{Stanfords} ^^{Kafka} ^^{AEsop}
  16977. a file, instead of using this canned example.
  16978. \beginlines
  16979. |\def\text{{\advance\baselineskip-4pt|
  16980. |\setbox0=\hbox{abcdefghijklmnopqrstuvwxyz}|
  16981. |\ifdim\hsize>2\wd0 \ifdim 15pc>2\wd0 \hsize=15pc \else\hsize=2\wd0 \fi\fi|
  16982. |On November 14, 1885, Senator \& Mrs.~Leland Stanford called together at|
  16983. |their San Francisco mansion the 24~prominent men who had been chosen as|
  16984. |the first trustees of The Leland Stanford Junior University.  They|
  16985. |handed to the board the Founding Grant of the University, which they had|
  16986. |executed three days before. This document---with various amendments,|
  16987. |legislative acts, and court decrees---remains as the University's|
  16988. |charter.  In bold, sweeping language it stipulates that the objectives of|
  16989. |the University are ``to qualify students for personal success and direct|
  16990. |usefulness in life; and to promote the publick welfare by exercising an|
  16991. |influence in behalf of humanity and civilization, teaching the blessings|
  16992. |of liberty regulated by law, and inculcating love and reverence for the|
  16993. |great principles of government as derived from the inalienable rights of|
  16994. |man to life, liberty, and the pursuit of happiness.'' \moretext|
  16995. |(!||`THE DAZED BROWN FOX QUICKLY GAVE 12345--67890 JUMPS!)\par}}|
  16996. |\def\moretext{?||`But aren't Kafka's Schlo{\ss} and {\AE}sop's {\OE}uvres|
  16997. |often na{\"\i}ve  vis-\`a-vis the d{\ae}monic ph{\oe}nix's official|
  16998. |r\^ole in fluffy souffl\'es? }|
  16999. |\def\omitaccents{\let\moretext=\relax}|
  17000. \endlines
  17001. Now comes one of the hardest parts of the file, from the \TeX\
  17002. standpoint: The |\table| macro prints a font diagram, omitting
  17003. groups of sixteen characters that are entirely absent from the font.
  17004. The format of this table is the same as that used in Appendix~F
  17005. of {\sl The \TeX book}. When the font contains unusually large characters
  17006. that ought to be vertically centered, you should say `^|\centerlargechars|'
  17007. before `|\table|'. \ (A \TeX\ math symbol font or math extension font
  17008. would use this feature.)
  17009. \beginlines
  17010. |\def\oct#1{\hbox{\rm\'{}\kern-.2em\it#1\/\kern.05em}} % octal constant|
  17011. |\def\hex#1{\hbox{\rm\H{}\tt#1}} % hexadecimal constant|
  17012. |\def\setdigs#1"#2{\gdef\h{#2}% \h=hex prefix; \0\1=corresponding octal|
  17013. | \m=\n \divide\m by 64 \xdef\0{\the\m}%|
  17014. | \multiply\m by-64 \advance\m by\n \divide\m by 8 \xdef\1{\the\m}}|
  17015. |\def\testrow{\setbox0=\hbox{\penalty 1\def\\{\char"\h}%|
  17016. | \\0\\1\\2\\3\\4\\5\\6\\7\\8\\9\\A\\B\\C\\D\\E\\F%|
  17017. | \global\p=\lastpenalty}} % \p=1 if none of the characters exist|
  17018. |\def\oddline{\cr|
  17019. |  \noalign{\nointerlineskip}|
  17020. |  \multispan{19}\hrulefill&|
  17021. |  \setbox0=\hbox{\lower 2.3pt\hbox{\hex{\h x}}}\smash{\box0}\cr|
  17022. |  \noalign{\nointerlineskip}}|
  17023. |\newif\ifskipping|
  17024. |\def\evenline{\loop\skippingfalse|
  17025. | \ifnum\n<256 \m=\n \divide\m 16 \chardef\next=\m|
  17026. | \expandafter\setdigs\meaning\next \testrow|
  17027. | \ifnum\p=1 \skippingtrue \fi\fi|
  17028. | \ifskipping \global\advance\n 16 \repeat|
  17029. | \ifnum\n=256 \let\next=\endchart\else\let\next=\morechart\fi|
  17030. | \next}|
  17031. |\def\morechart{\cr\noalign{\hrule\penalty5000}|
  17032. | \chartline \oddline \m=\1 \advance\m 1 \xdef\1{\the\m}|
  17033. | \chartline \evenline}|
  17034. |\def\chartline{&\oct{\0\1x}&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&\:&&}|
  17035. |\def\chartstrut{\lower4.5pt\vbox to14pt{}}|
  17036. |\def\table{$$\global\n=0|
  17037. |  \halign to\hsize\bgroup|
  17038. |    \chartstrut##\tabskip0pt plus10pt&|
  17039. |    &\hfil##\hfil&\vrule##\cr|
  17040. |    \lower6.5pt\null|
  17041. |    &&&\oct0&&\oct1&&\oct2&&\oct3&&\oct4&&\oct5&&\oct6&&\oct7&\evenline}|
  17042. |\def\endchart{\cr\noalign{\hrule}|
  17043. |  \raise11.5pt\null&&&\hex 8&&\hex 9&&\hex A&&\hex B&|
  17044. |  &\hex C&&\hex D&&\hex E&&\hex F&\cr\egroup$$\par}|
  17045. |\def\:{\setbox0=\hbox{\char\n}%|
  17046. |  \ifdim\ht0>7.5pt\reposition|
  17047. |  \else\ifdim\dp0>2.5pt\reposition\fi\fi|
  17048. |  \box0\global\advance\n 1 }|
  17049. |\def\reposition{\setbox0=\vbox{\kern2pt\box0}\dim=\dp0|
  17050. |  \advance\dim 2pt \dp0=\dim}|
  17051. |\def\centerlargechars{|
  17052. |  \def\reposition{\setbox0=\hbox{$\vcenter{\kern2pt\box0\kern2pt}$}}}|
  17053. \endlines
  17054. Two of the most important combinations of tests are treated now:
  17055. ^|\sample| prints the |\table| and the |text|; ^|\bigtest| gives
  17056. you the works, plus a mysterious word that is traditional in type
  17057. specimens: ^^{hamburgefonstiv}
  17058. \beginlines
  17059. |\def\sample{\table\text}|
  17060. \smallskip
  17061. |\def\bigtest{\sample|
  17062. |  hamburgefonstiv HAMBURGEFONSTIV\par|
  17063. |  \names \punct \lowers \uppers \digits}|
  17064. \endlines
  17065. Finally, there's a |\math|
  17066. routine useful for checking out the spacing in the ^{math} ^{italic}
  17067. fonts used by plain \TeX; |\mathsy| does a similar thing for the
  17068. uppercase letters in a math symbols font.
  17069. \beginlines
  17070. |\def\math{\textfont1=\testfont \skewchar\testfont=\skewtrial|
  17071. | \mathchardef\Gamma="100 \mathchardef\Delta="101|
  17072. | \mathchardef\Theta="102 \mathchardef\Lambda="103 \mathchardef\Xi="104|
  17073. | \mathchardef\Pi="105 \mathchardef\Sigma="106 \mathchardef\Upsilon="107|
  17074. | \mathchardef\Phi="108 \mathchardef\Psi="109 \mathchardef\Omega="10A|
  17075. | \def\ii{i} \def\jj{j}|
  17076. | \def\\##1{|\||##1|\||+}\mathtrial|
  17077. | \def\\##1{##1_2+}\mathtrial|
  17078. | \def\\##1{##1^2+}\mathtrial|
  17079. | \def\\##1{##1/2+}\mathtrial|
  17080. | \def\\##1{2/##1+}\mathtrial|
  17081. | \def\\##1{##1,{}+}\mathtrial|
  17082. | \def\\##1{d##1+}\mathtrial|
  17083. | \let\ii=\imath \let\jj=\jmath \def\\##1{\hat##1+}\mathtrial}|
  17084. |\newcount\skewtrial \skewtrial='177|
  17085. |\def\mathtrial{$\\A \\B \\C \\D \\E \\F \\G \\H \\I \\J \\K \\L \\M \\N|
  17086. |  \\O \\P \\Q \\R \\S \\T \\U \\V \\W \\X \\Y \\Z \\a \\b \\c \\d \\e \\f|
  17087. |  \\g \\h \\\ii \\\jj \\k \\l \\m \\n \\o \\p \\q \\r \\s \\t \\u \\v \\w|
  17088. |  \\x \\y \\z \\\alpha \\\beta \\\gamma \\\delta \\\epsilon \\\zeta|
  17089. |  \\\eta \\\theta \\\iota \\\kappa \\\lambda \\\mu \\\nu \\\xi \\\pi|
  17090. |  \\\rho \\\sigma \\\tau \\\upsilon \\\phi \\\chi \\\psi \\\omega|
  17091. |  \\\vartheta \\\varpi \\\varphi \\\Gamma \\\Delta \\\Theta \\\Lambda|
  17092. |  \\\Xi \\\Pi \\\Sigma \\\Upsilon \\\Phi \\\Psi \\\Omega|
  17093. |  \\\partial \\\ell \\\wp$\par}|
  17094. |\def\mathsy{\begingroup\skewtrial='060 % for math symbol font tests|
  17095. | \def\mathtrial{$\\A \\B \\C \\D \\E \\F \\G \\H \\I \\J \\K \\L|
  17096. |  \\M \\N \\O \\P \\Q \\R \\S \\T \\U \\V \\W \\X \\Y \\Z$\par}|
  17097. | \math\endgroup}|
  17098. \endlines
  17099. The last line of |testfont| is
  17100. \beginlines
  17101. |\ifx\noinit!\else\init\fi|
  17102. \endlines
  17103. and it means ``automatically call `^|\init|' unless `|\noinit|' is
  17104. an exclamation point.'' Why this? Well,
  17105. you might have your own test file from which you'd like to use the
  17106. facilities of |testfont|, without typing commands online.
  17107. If your file says `|\let\noinit!| |\input testfont|' \TeX\ will
  17108. read in |testfont| but the routine will not prompt you for a file name.
  17109. The file can then continue to test one or more fonts by saying, e.g.,
  17110. \beginlines
  17111. |\def\fontname{cmbx10 }\startfont\sample\vfill\eject|
  17112. |\def\fontname{cmti10 scaled \magstep3}\startfont\sample\vfill\eject|
  17113. \endlines
  17114. thereby defining ^|\fontname| directly, and using ^|\startfont|
  17115. to do the initialization instead of |\init|.
  17116. \medbreak
  17117. To conclude this appendix, let's look at the listing of a file
  17118. that can be used to test special constructions in math fonts
  17119. with the conventions of plain \TeX:
  17120. \beginlines
  17121. |\raggedright \rightskip=2em plus 5em minus 2em|
  17122. \smallbreak
  17123. |$\hbar \not\equiv B$, but $\sqrt C \mapsto \sqrt x$,|
  17124. |$Z \hookrightarrow W$,       $Z \hookleftarrow W$,|
  17125. |$Z \longmapsto W$,   $Z \bowtie W$,  $Z \models W$,|
  17126. |$Z \Longrightarrow W$,       $Z \longrightarrow W$,|
  17127. |$Z \longleftarrow W$,        $Z \Longleftarrow W$,|
  17128. |$Z \longleftrightarrow W$,   $Z \Longleftrightarrow W$,|
  17129. |$\overbrace{\hbox{very long things for testing}}$,|
  17130. |$\underbrace{\hbox{very long things for testing}}$,|
  17131. |$Z \choose W$, $Z \brack W$, $Z \brace W$, $Z \sqrt W$,|
  17132. |$Z \cong W$,   $Z \notin W$, $Z \rightleftharpoons W$,|
  17133. |$\widehat Z$,    $\widehat{ZW}$,    $\widehat{Z+W}$,|
  17134. |$\widetilde Z$,  $\widetilde{ZW}$,  $\widetilde{Z+W}$.|
  17135. \smallbreak
  17136. |\def\sizetest#1#2{$$|
  17137. |  \Bigggl{#1}\bigggl{#1}\Biggl{#1}\biggl{#1}\Bigl{#1}\bigl{#1}\left#1|
  17138. |  \bullet|
  17139. |  \right#2\bigr{#2}\Bigr{#2}\biggr{#2}\Biggr{#2}\bigggr{#2}\Bigggr{#2}$$}|
  17140. |\def\biggg#1{{\hbox{$\left#1\vbox to20.5pt{}\right.$}}}|
  17141. |\def\bigggl{\mathopen\biggg}  \def\bigggr{\mathclose\biggg}|
  17142. |\def\Biggg#1{{\hbox{$\left#1\vbox to23.5pt{}\right.$}}}|
  17143. |\def\Bigggl{\mathopen\Biggg}  \def\Bigggr{\mathclose\Biggg}|
  17144. \smallbreak
  17145. |\sizetest ()     \sizetest []        \sizetest \lgroup\rgroup|
  17146. |\sizetest \lmoustache\rmoustache     \sizetest \vert\Vert|
  17147. |\sizetest \arrowvert\Arrowvert       \sizetest \uparrow\downarrow|
  17148. |\sizetest \updownarrow\Updownarrow   \sizetest \Uparrow\Downarrow|
  17149. |\sizetest \bracevert{\delimiter"342} \sizetest \backslash/|
  17150. |\sizetest \langle\rangle             \sizetest \lbrace\rbrace|
  17151. |\sizetest \lceil\rceil               \sizetest \lfloor\rfloor|
  17152. \smallbreak
  17153. |$$\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{\sqrt{-1}}}}}}}}}$$|
  17154. \smallbreak
  17155. |\def\dobig{\do\bigvee \do\bigwedge \do\bigotimes \do\bigoplus \do\bigodot|
  17156. | \do\bigcap \do\bigcup \do\biguplus \do\bigsqcup|
  17157. | \do\int \do\ointop \do\smallint \do\prod \do\coprod \do\sum}|
  17158. |\def\do#1{#1_a^b A} $\dobig$ $$\dobig$$|
  17159. \smallbreak
  17160. |\bye|
  17161. \endlines
  17162. \endchapter
  17163. Be sure of it: Giue me the Occular proofe.
  17164. \author WILLIAM ^{SHAKESPEARE},  {\sl Othello\/} (1604) % act 3 sc 3 l 360
  17165. \bigskip
  17166. The figure itself appears here
  17167. as a very necessary adjunct to the verbalization.
  17168. In Euclid's presentation we cannot wholly follow the argumentation
  17169. without the figure, and unless we are strong enough
  17170. to imagine the figure in our mind's eye, we would also be reduced
  17171. to supplying our own figure if the author had not done it for us.
  17172. Notice also that the language of the proof has a
  17173. formal and severely restricted quality about it.
  17174. This is not the language of history, nor of drama,
  17175. nor of day to day life;
  17176. this is language that has been sharpened and refined so as to serve
  17177. the precise needs of a precise but limited intellectual goal.
  17178. \author P. J. ^{DAVIS} and R. ^{HERSH}, {\sl Proof\/} (1981)
  17179.   % The Mathematical Experience (Birkh\"auser), near p150
  17180. \eject
  17181. \beginchapter Appendix I. Index
  17182. \maxdepth=4pt
  17183. The author has tried to provide as complete an index as possible, so that
  17184. people will be able to find things that are tucked away in obscure
  17185. corners of this long book. Therefore the index itself is rather long. A
  17186. short summary of the simpler aspects of \MF\ appears at the beginning of
  17187. Appendix~B; a summary of the standard character classes for tokens
  17188. can be found at the end of Chapter~6; a summary of other special things
  17189. appears under `tables' below.
  17190. \medskip\ninepoint
  17191. Page numbers are \underbar{underlined} in the index when they represent
  17192. the definition or the main source of information about whatever is being
  17193. indexed. \ (Underlined entries are the most definitive, but not
  17194. necessarily the easiest for a beginner to understand.) \ A page number is
  17195. given in italics (e.g., `{\it123\/}') when that page contains an instructive
  17196. example of how the concept in question might be used.  Sometimes both
  17197. underlining and italics are appropriate.  When an index entry refers to a
  17198. page containing a relevant exercise, the answer to that exercise (in
  17199. Appendix~A) might divulge further information; an answer page is not
  17200. indexed here unless it refers to a topic that isn't included in the
  17201. statement of the relevant exercise.
  17202. \smallskip
  17203. Index entries for quoted symbols like `T' refer to example programs
  17204. that draw the symbols in question.
  17205. \smallskip
  17206. Symbolic tokens that are preceded by an asterisk (*) in this index are
  17207. primitives of \MF; i.e., they are built in. It may be dangerous to
  17208. redefine them.
  17209. \begindoublecolumns
  17210. \eightpoint \baselineskip=9.9pt % shooting for 53 lines/page
  17211. \parskip=0pt plus .8pt
  17212. \newdimen\sqht \sqht=2.4pt % \square
  17213. \newbox\astbox \setbox\astbox=\hbox to0pt{\hss\lower1pt\hbox{*}}
  17214. \raggedright \tolerance=5000 \hbadness=5000 \parfillskip 0pt plus 3em
  17215. \ttglue=.4em
  17216. \def\<#1>{\leavevmode\hbox{$\mkern-2mu\langle$#1\/$\rangle$}}
  17217. \let\oldcstok=\cstok
  17218. \def\cstok{\leavevmode\kern-2pt\oldcstok}
  17219. \def\vdots{\vbox{\baselineskip 3pt\kern2pt\hbox{.}\hbox{.}\hbox{.}}}
  17220. \def\ddots{\mathinner{\mskip1mu\raise5pt\vbox{\kern2pt\hbox{.}}\mskip2mu
  17221.     \raise3pt\hbox{.}\mskip2mu\raise1pt\hbox{.}\mskip1mu}}
  17222. \def\see{{\sl see\/}~\ignorespaces}
  17223. \def\also{\hfil\penalty50\hfilneg{\sl see~also\/}~\ignorespaces}
  17224. \let\oldttv=\ttverbatim
  17225. \let\+=\relax
  17226. \def\sub{\penalty100 \vskip -\parskip \quad}
  17227. \def\LaTeX{L\kern -.36em\raise.6ex\hbox{\sixrm A}\kern-.15em\TeX}
  17228. \def\MF{{\manual opqrstuq}}
  17229. \def\ttverbatim{\oldttv \catcode`\*=\other \catcode`\,=\other
  17230.   \catcode`\.=\other \catcode`\;=\other \catcode`\@=\other \catcode`\+=\other}
  17231. \let\comma=, \let\period=. \let\asterisk=* \let\semicolon=;
  17232. \def\backup{\leavevmode\kern-1pt}\catcode`\-=11
  17233. \catcode`\*=\active \def*{\leavevmode\copy\astbox}
  17234. \catcode`\,=\active \def,{\eightrm\comma}
  17235. \catcode`\;=\active \def;{\/\eightrm\semicolon}
  17236. \catcode`\.=\active \def.{\eightrm\period\par\hangindent 2em }
  17237. \catcode`\+=\active \def+#1{\ifcat0\noexpand#1$\setbox0\hbox{#1}\dp0=0pt
  17238.    \underline{\box0}$\let\next=+%
  17239.   \else\let\next=#1\fi \next}
  17240. \catcode`\@=\active \let@=\eightit
  17241. \parindent=0pt
  17242. \hyphenpenalty=10000 \exhyphenpenalty=10000
  17243. \def\newletter{\medbreak\hangindent 2em}
  17244. \hangindent 2em
  17245. |#| (hash mark), \see sharped dimensions.
  17246. `\#', 200--201.
  17247. |##| (traced equation), 80--83, 239.
  17248. |###| (removed independent variable), 83.
  17249. |####| (deduced equation), 81.
  17250. *|#@| (prefix of at point), +177, @251.
  17251. |%| (percent sign), 43, +50.
  17252. *|&| (ampersand), 213--214, \see concatenation.
  17253. \sub for preloaded bases, +35, 279.
  17254. |'| (apostrophe or prime), @25, @55, @81.
  17255. |"| (double-quote mark), +50--+51.
  17256. |""| (empty string), +188, 236, 254, @276, @294, @328.
  17257. `(', 103--105, 128, 318.
  17258. |(| (left parenthesis), 59, +60, 61, @62--@63, 71--73, 165, 210--215.
  17259. |((|, 51.
  17260. |)| (right parenthesis), 59, +60, 61, @62--@63, 71--73, 165, 210--215.
  17261. |))|, 51.
  17262. *|[| (left bracket), 9--10, +54, 55, 60, +72, 80, 211--212, 298--299, 324.
  17263. |[[|, 61.
  17264. |[]| (collective subscript), +56, 177, @273.
  17265. |[1]| (progress report), 37, +324.
  17266. *|]| (right bracket), 9--10, +54, 55, 60, +72, 80, 211--212, 298--299, 324.
  17267. |]]|, 61, @162, +262, 299.
  17268. *|{| (left brace), 16--18, 60, +129, 213.
  17269. |{{|, 61, 289.
  17270. *|}| (right brace), 16--18, 60, +129, 213.
  17271. |}}|, 61, 289.
  17272. *|+| (plus sign), @62, @63, +72, 80, 211.
  17273. *|++| (Pythagorean addition), @+66, @67, 72, 211.
  17274. \sub (double edge), 117, 296--297.
  17275. |+++| (triple edge), 296--297.
  17276. *|+-+| (Pythagorean subtraction), @+66, 72, 211, @238.
  17277. *|-| (minus sign), @62, @63, +72, 80, 211, 297.
  17278. |--| (straight join), @24--@26, 127--129, @234, +262.
  17279. \sub (double edge), 117, 296--297.
  17280. |---| (tense join), @107, 127--129, +262.
  17281. \sub (triple edge), 296--297.
  17282. |->| (macro expansion), 44, 160, 249, 251.
  17283. `---' (em dash), 306.
  17284. |_| (underline), 49, +51, 173, 265, 270.
  17285. |*| (asterisk), 285--286.
  17286. \sub as prompt character, 31, 37, 279.
  17287. \sub \llap{\char`\*}as times sign, @59, @62--@64, +72, +73, 80, 211--212.
  17288. |**|, as command-line prompt, 31--32, 35--40, 187, 269, 279.
  17289. \sub as exponentiation sign, @59, @64, 72, @237, @251, +265.
  17290. |/| (slash), 328, 329.
  17291. \sub \llap{\char`\*}as divided-by sign, @59, @62, @63, +72, 80, 82, 210--211.
  17292. \| (vertical line), 117, 297.
  17293. *|\| (backslash), +179, @236, @262.
  17294. \sub at beginning of command line, @31, @38, 40.
  17295. |\\|, +262.
  17296. *|<| (less than sign), @64, @65, +170, 210, 237.
  17297. *|<=| (less than or equal to), @64, 65, +170, 210, 282.
  17298. |<-| (argument value), 160.
  17299. *|<>| (unequal to),  @64, 65, +170, 210, 282.
  17300. \<> (angle brackets), 49--50.
  17301. *|=| (equals sign), @5, @6, @23, @64, @75--@85, +88, 97, 165, 167, +170,
  17302.  171, 210, 218.
  17303. |==|, 292.
  17304. *|=:| (ligature replacement), @305, @306, @316, +317.
  17305. *\||=:|, @316, +317.
  17306. *\||=:>|, +317.
  17307. *|=:|\|, +317.
  17308. *|=:|\||>|, +317.
  17309. *\||=:|\|, +317.
  17310. *\||=:|\||>|, +317.
  17311. *\||=:|\||>>|, +317.
  17312. \leavevmode{\tt \rlap/=} (unequals sign), 282.
  17313. *|>| (greater than sign), @64, +170, 210, 237.
  17314. |>>| (shown value), 41, 62.
  17315. *|>=| (greater than or equal to), @64, 65, +170, 210, 282.
  17316. *|,| (comma), 57, 72, 73, 129, 155, 165--167, 171, 317, 318.
  17317. |,,|\thinspace, 51.
  17318. |.|~(period), 43, +50, 51.
  17319. `\char`\.', 306.
  17320. *|..| (free join), @7, @15--@19, @24, 127--133, 213.
  17321. |...| (bounded join), 18--19, 44, 127, 248, +262.
  17322. *|;| (semicolon), 155, 169, 171, 172, 187, 217, 223--224, 263, 312.
  17323. |;;|\thinspace, 51.
  17324. *|:| (colon), 169, 317--319.
  17325. *|::| (local label), +317.
  17326. *\|\||:| (left boundary label), +317.
  17327. *|:=| (gets), @28, @33, 87, +88, 97, @98, 155--156, 159, 165, 167, 171,
  17328.  176, 218, 282.
  17329. |?|, @41, +42--+43.
  17330. |???|, @224, +262.
  17331. |!| (exclamation point), 41, 189.
  17332. *|@| (at point), +177, @251.
  17333. *|@#| (suffix of at point), @176, +177, +178, 251, @273--@274.
  17334. \newletter
  17335. `a', 192.
  17336. `A', 163, 164, 248, 302--303.
  17337. |abort|, 312--313.
  17338. |abs| (absolute value), @66, 82, @238, +264.
  17339. accents, 315, 317.
  17340. accuracy, 50, @62--@69, @143, 237.
  17341. ad hoc dimensions, 92, @95.
  17342. Adams, John, 359.
  17343. addition of pictures, 115, @117, @245.
  17344. addition of vectors, 9, @68.
  17345. *|addto|, +118--+119, @144, @151, @242--@245.
  17346. \<addto command>, 220.
  17347. |adjust_fit|, 306--308.
  17348. {\AE}schylus, 47.
  17349. {\AE}sopus, 340.
  17350. affine transformations, 247.
  17351. algebraic operations, 59--73, 209--215, 230.
  17352. Algol, 57, 89.
  17353. Alingham, William, 189.
  17354. Allen, Fred (= Sullivan, John Florence), 85.
  17355. almost digitized character, 296.
  17356. *|also|, +118, 220, @242--@245.
  17357. |\alternation|, 338.
  17358. alternatives, 169.
  17359. |always_iff|, +307, @311--@312.
  17360. ambiguous points, 150, 198--200, 204.
  17361. American Mathematical Society, ii, ix.
  17362. anatomy of \MF, 169, 179, 217, 285, +344.
  17363. *|and|, @65, +129, +170, 210, 213, 288--289.
  17364. Anderson, Izett William, 299.
  17365. *|angle|, @29, @67, +72, @107, @135, 211.
  17366. angle brackets, 49--50.
  17367. angle of pen, 21--22, 26--28, 152, 164.
  17368. arguments, 159--160, +166--+167, 210, 288.
  17369. arithmetic, 59--63.
  17370. arrays, 54--57.
  17371. ASCII, 49, 188, 281--283, 317.
  17372. *|ASCII|, 72, +188, 211.
  17373. |aspect_ratio|, 94, 145, 204, 269, 335.
  17374. \<assignment>, 88.
  17375. assignments, @28, @33, 87--89, @98, 159.
  17376. *|at|, +191, 220, @252, @277, @312.
  17377. at size, 96, 319.
  17378. *|atleast|, 129, +132, 213, @262.
  17379. *|autorounding|, 127, 195, +204--+205, @206, 212, @262, @264, 271--272.
  17380. axis, 103.
  17381. \newletter
  17382. `b', 308.
  17383. background character, @40, 338--339.
  17384. Backus, John Warner, 49.
  17385. backwards path, 119.
  17386. |badio.mf|, 41, 223.
  17387. |barheight|, 96, 161, 199, 302--303.
  17388. base file, 34--35, 261, 278--279, +304, 307.
  17389. baseline, 75--77, +101.
  17390. \<basic path join>, 129, 213.
  17391. *|batchmode|, +219, 226.
  17392. BCPL strings, 320.
  17393. bean-like shape, 15--16, 21--22, 24--25.
  17394. beauty, v, 185.
  17395. Beethoven, Ludwig van, 185.
  17396. |beginchar|, 35, 76, @96, 102--103, 107, 115, 148, 156, 197, 199, 204,
  17397.  +275, 316.
  17398. *|begingroup|, +155--+157, 175, 178, 210--215, 217, @236, @243, @275, @289.
  17399. |beginlogochar|, 160, 302.
  17400. Bell, Eric Temple, 11.
  17401. bell-shaped distribution, 251.
  17402. Bernste{\u\i}n, Serge{\u\i} \thinspace Natanovich, 14.
  17403. \sub polynomials, 14, 133, 152, 246, 298--299.
  17404. B\'ezier, Pierre Etienne, 14.
  17405. Bibby, Duane Robert, i.
  17406. Bierce, Ambrose Gwinnett, ix.
  17407. |\bigtest|, +341.
  17408. Billawala, Nazneen Noorudin, 266, 294.
  17409. binary search, 176--177, @293--@294.
  17410. black, 270, 332--333.
  17411. black-letter, 294.
  17412. black/white reversal, 115.
  17413. |blacker|, 93--94, 268, +270--+271.
  17414. |blankpicture|, 192, +263.
  17415. Boole, George, 170.
  17416. *|boolean|, 55, +56.
  17417. \<boolean expression>, 170, 210.
  17418. Boolean expressions, 170, 257.
  17419. \<boolean primary>, 170, 210.
  17420. \<boolean secondary>, 170, 210.
  17421. \<boolean tertiary>, 170, 210.
  17422. |bot|, @23, 80, 147, 151, 204, +273.
  17423. boundaries, 24--29, 123--125.
  17424. *|boundarychar|, 212, 317.
  17425. bounded curves, 19, 132.
  17426. bounding box, 22, 35, 76, +101--+107, 276, 307, 315.
  17427. bounding triangle, 19, 132.
  17428. box, \see bounding box.
  17429. |bp| (big point), 92, +267, 268.
  17430. braces, 16--18, 60, +129, 213.
  17431. bracket notation, \see mediation.
  17432. brackets, 9--10, +54, 55, 60, +72, 80, 211--212, 298--299, 324.
  17433. broad-edge pens, 26--29, 151--152, 162--165.
  17434. Bront\"e, Emily Jane, 73.
  17435. Bruck, Richard Hubert, 29.
  17436. buffer size, 226, 286.
  17437. built-up symbols, 318.
  17438. Burkitt, William, 99.
  17439. Burns, Robert, 299.
  17440. |bye|, +278, 279, @306, +321, 324.
  17441. |byte|, +264, @275.
  17442. \<byte list>, 318.
  17443. \newletter
  17444. $c$ code, 106, 324.
  17445. Camden, William, 51.
  17446. Campbell, John Campbell, 359.
  17447. |cand|, 288--289.
  17448. |CAPSULE|, 239.
  17449. |capsule_def|, 264.
  17450. capsules, 159, 166, 172, 210, 239, 247, 254, 264.
  17451. Carter, Matthew, 207.
  17452. Cartesian coordinates, 5--6, 191.
  17453. |cc| (cicero), 92, +267, 268.
  17454. |ceiling|, @65, 66, 72, +264.
  17455. |\centerlargechars|, 340, +341.
  17456. chance, 183--185.
  17457. |change_width|, @199, +276, +309.
  17458. *|char|, 187, +188, 214, @263.
  17459. *|charcode|, 106, 210, 212, +220, @275, 324.
  17460. *|chardp|, 106, 212, 220, @275, +315--+316, 324.
  17461. *|chardx|, 106, 212, 220, @276, +324, @334.
  17462. *|chardy|, 212, +324.
  17463. *|charexists|, +106, 210, 316, 324.
  17464. *|charext|, 106, 212, +220, 316, 324.
  17465. *|charht|, 106, 212, 220, @275, +315--+316, 324, @334, @335.
  17466. *|charic|, 106, 212, 220, @275, +315--+316, 324.
  17467. *|charlist|, @317, +318, 331, @334, @335.
  17468. \<charlist command>, 318.
  17469. *|charwd|, 106, 212, 220, @275, +315--+316, 324, @334, @335.
  17470. |cheapo|, 91--93, 99, 278--279, 332--333.
  17471. check sums, 320, 324, +325.
  17472. Chinese characters, 3, 106, 324.
  17473. circles, 123--124, 148.
  17474. |clear_pen_memory|, 147, +273, @278, @310.
  17475. |clearit|, 115, @242, @275, +277, 295.
  17476. |clearpen|, +272, @275.
  17477. |clearxy|, @275, +277.
  17478. |cm| (centimeter), @18, 92, +267, 268.
  17479. |cm.base|, 35, 279, 311.
  17480. |cmchar|, @306, +307, 312--313.
  17481. |cmex10|, 317--318.
  17482. |cmmf|, 35, 279.
  17483. |cmr9|, 203, 320.
  17484. |cmr10|, 101, 305--306, 319.
  17485. |cmr10.mf|, 305.
  17486. |cmsl10|, 101.
  17487. |cmtt10|, 306.
  17488. \<code>, 317.
  17489. codes, 281--283.
  17490. Colburn, Dorothy, 107.
  17491. collective subscripts, 56, 177.
  17492. \<command>, 217.
  17493. command line, 38, 187, 269, 277, 301.
  17494. commands, 155, 217--220, 230, 321.
  17495. comments, 43, 50--51.
  17496. commutativity, 247.
  17497. comparison, @65--@66, 80, 170.
  17498. compass directions, 26, 119, 206--207, 228--229.
  17499. complex numbers, 69.
  17500. \<compound>, 217.
  17501. compound statement, +155, 217.
  17502. Computer Modern, 35, 103--105, 203, 206, 279, 304--313.
  17503. concatenation, of paths, @70--@71, @123, 127, 129, +130, @245.
  17504. \sub of strings, @69, 84--85, +187, @278, @286, @312.
  17505. \<condition>, 169.
  17506. conditional and/or, 288--289.
  17507. conditions, 169--171, 179, 219, 259.
  17508. constants, 59, @62, 263--264.
  17509. contents of this manual, table, x--xi.
  17510. *|contour|, +118--+119, 220.
  17511. control points, @13--@19, 70--71, 133, 229.
  17512. *|controls|, @19, 70--71, +129--+130, 133, @152, 213.
  17513. \<controls>, 129, 213.
  17514. conversion to pixel units, 259, +268.
  17515. convex polygons, @119, 147, 297--298.
  17516. Conway, John Horton, 121.
  17517. coordinates, 5--11, 23, 109, 191, 193.
  17518. |cor|, 288--289.
  17519. corner pixels, 93--94.
  17520. *|cosd|, @67, 72, 211.
  17521. cosines, 67, 69.
  17522. counterclockwise, 111, 119, 229, 255.
  17523. |counterclockwise|, +264.
  17524. Cowper, William, 51.
  17525. |craziness|, 184--185.
  17526. crispness, 103--104.
  17527. cube roots, 177.
  17528. cubes, 113.
  17529. *|cull|, 118, +120, @151, @243--@245.
  17530. \<cull command>, 118, 220.
  17531. culling, 113, 120, @151, @242--@245, 296.
  17532. |cullit|, @113, 120, @242, @243, +277.
  17533. Cundall, Frank, 299.
  17534. *|curl|, @17, +128--+131, 213, 234.
  17535. |currentbreadth|, 310--311.
  17536. |currentnull|, 295.
  17537. |currentpen|, 118, 147, 150, 204, +271--+272.
  17538. |currentpicture|, 114, @115, @116, 118, 120, 191, +271--+272, 295.
  17539. |currenttransform|, 94, @145, 204, +269, 271, 301, 310.
  17540. |currentwindow|, 192, @312.
  17541. curves, 13--19, \see paths.
  17542. cusps, 136.
  17543. |cutdraw|, @151, +271--+272.
  17544. |cutoff|, @150, +272.
  17545. *|cycle|, @15, @16, @24--@28, @69, +129--+131, 170, 171, 210, 213.
  17546. \newletter
  17547. |d|, 35, @76, 102, 204, +275.
  17548. `d', 294.
  17549. da Vinci, Leonardo, 19.
  17550. dangerous bend, vii, 11, 106--107, 115, 143.
  17551. Darwin, Charles Robert, 57.
  17552. data structures, 53--57.
  17553. Davis, Philip Jacob, 343.
  17554. *|day|, +212, 218, 323.
  17555. |dd| (didot point), 92, +267, 268.
  17556. de Casteljau, Paul de Faget, 14.
  17557. debugging tricks, 229--231, 286.
  17558. *|decimal|, +187--+188, 214.
  17559. \<decimal digit>, 50.
  17560. decimal point, 50--51.
  17561. decimal representation, 188.
  17562. \<declaration>, 56, 171.
  17563. \<declaration list>, 57.
  17564. declarations, 56--57.
  17565. declarative versus imperative, 87.
  17566. \<declared suffix>, 57.
  17567. \<declared variable>, 57, 175.
  17568. |decr|, +266.
  17569. *|def|, @36, @159--@162, +165--+167.
  17570. |default_wt_|, 271--272.
  17571. |define_blacker_pixels|, @33, 92--93, @106, +268, 302.
  17572. |define_corrected_pixels|, 93, 197, +268, 302.
  17573. |define_good_x_pixels|, 199, +268, 302.
  17574. |define_good_y_pixels|, 199, +268, 302.
  17575. |define_horizontal_corrected_pixels|, @204, +268, 302.
  17576. |define_pixels|, @33, 92, @106, 199, +268, 302.
  17577. |define_whole_blacker_pixels|, 202, +268.
  17578. |define_whole_pixels|, 199, +268, 302.
  17579. |define_whole_vertical_blacker_pixels|, +268.
  17580. |define_whole_vertical_pixels|, @204, +268, 302.
  17581. \<definition>, 165.
  17582. \<definition heading>, 165.
  17583. definitions, 159--167, 175--180.
  17584. deleting tokens, 42--43, 225.
  17585. \<delimited parameters>, 165.
  17586. delimiters, 61, 167, 210, 254, 288--289.
  17587. *|delimiters|, 61, 180, 210, +218, @221, @262, @296, @299, @313.
  17588. \<delimiters command>, 218.
  17589. dependent variables, +81--+83, 88, 224.
  17590. depth, 101.
  17591. Derek, Bo, 287.
  17592. Descartes, Ren\'e, 6, 11, 19.
  17593. design size, 96, +319--+320, 324, 329.
  17594. *|designsize|, 212, 320.
  17595. device drivers, 323, 325.
  17596. diagnostic aids, 229--231, 259, 286.
  17597. diamond-shaped nib, 148--149, 297.
  17598. Dickens, Charles John Huffam, 145.
  17599. difference of pictures, 115, @244.
  17600. digestion process, 179, 217--221.
  17601. \<digit string>, 50.
  17602. digitization, 111, 149, 195--207, 230.
  17603. |\digits|, 339.
  17604. dimensions, 92, +267.
  17605. |dir|, @18, @67, @68, @83--@84, @135, @163--@164, 175, @233, +264.
  17606. |direction|, @69, 70, @135, @235, +265.
  17607. \<direction specifier>, 129, 213.
  17608. |directionpoint|, @135, +265.
  17609. *|directiontime|, @135, @+136, 211, 245, 265, @295.
  17610. |dishing|, 152, 164.
  17611. *|display|, +191--+192, 220.
  17612. \<display command>, 220.
  17613. |displaying|, 269, 276, 278.
  17614. distance, 76, 84.
  17615. |ditto|, @187, +263.
  17616. |div|, +265.
  17617. division, @59, @62, @63, 80, 82.
  17618. \sub of numeric tokens, 61, 73.
  17619. Dopping, Olle, 181.
  17620. |dot|, 306, 311.
  17621. dot product, 69.
  17622. |dotprod|, @69, 178, @238, 265.
  17623. |dotsize|, 332, 334.
  17624. double-quote mark, 50--51, 187.
  17625. *|doublepath|, 118, +119, @151, 220.
  17626. doubly filled pixels, 110--112.
  17627. |down|, @32, +263.
  17628. |downto|, 172, +262.
  17629. |draw|, @7, @15--@19, 21, 112, 118--120, 145, 147, 150, 198, 230, +271, 295.
  17630. \sub one point, 22, 150, 200, 253.
  17631. |drawdot|, @31, 113, 147, +150, 234, +271.
  17632. Drayton, Michael, 279.
  17633. drift, 102, 106.
  17634. driver files, 304--306.
  17635. *|dropping|, 118, +120, 220.
  17636. D\"urer, Albrecht, 13, 19.
  17637. *|dump|, 217, +221, 262, @279, @311.
  17638. |.dvi|, 32, 40, 103, 106, 323, 327, 328.
  17639. \newletter
  17640. |e|, 27--29, 273.
  17641. `E', 96--97, 204, 302--303.
  17642. edge structure, 116--117, 296--297.
  17643. edges, 116.
  17644. editing, 46.
  17645. efficiency, 39, 99, 141, 144, 147, 228, 230, 234, 244, 264, 265, 277,
  17646.  291, 297, 298.
  17647. El Palo Alto, 124--126, 139, 228--229.
  17648. ellipses, 123, 126.
  17649. Ellis, Henry Havelock, 11.
  17650. *|else|, +169--+170, 179.
  17651. *|elseif|, +169--+170, 179.
  17652. em dash, 306.
  17653. emergency stops, 226.
  17654. empty option in {\bf for\/} list, 171, @299.
  17655. empty statement, 155, 217.
  17656. empty text argument, 299.
  17657. *|end|, @31, @37, 155, 167, 217, 221, 226, 278, 287, 305, @321.
  17658. end of a file, 287.
  17659. |endchar|, @36, 102, 156, 191, +276, 309, 311, 329.
  17660. *|enddef|, @94, @159--@164, 165, @175--@178.
  17661. *|endfor|, @18, @39, +171--+172, @173, 250, @290.
  17662. |ENDFOR|, 45, 286, 290.
  17663. *|endgroup|, +155--+157, 167, 175, 178, 210--215, 217, @236, @243,
  17664.  @276, @289, @290.
  17665. ending character, @40, 338--339.
  17666. *|endinput|, +179, @287--@288.
  17667. endpoints, 128, 150--151.
  17668. |ENE|, 119, 206--207, 228.
  17669. enormous number, 63, 236.
  17670. envelopes, 118--119, 150, 230.
  17671. |eps|, 93, @199--@200, 229, +263, @310--@311.
  17672. |epsilon|, @62--@69, 115, @135, 152, 229, +263.
  17673. equality test, general, 292.
  17674. equality versus equation, 171.
  17675. |equally_spaced|, 290.
  17676. \<equation>, 88.
  17677. equations, @5, @6, @23, @75--@85, 88, @141, 171.
  17678. \sub nonlinear, 84--85, 176--177, @292--@294.
  17679. equilateral triangle, 25, 203.
  17680. |erase|, @113, 120, 167, +271, 272.
  17681. *|errhelp|, +189, 219, @294.
  17682. *|errmessage|, @178, +189, 219, @294.
  17683. error messages, 41--46, 223--228.
  17684. *|errorstopmode|, +219, 227, @313.
  17685. |ESE|, 206--207, 228--229.
  17686. *|everyjob|, 180, +219.
  17687. \<everyjob command>, 219.
  17688. Evetts, L\period\ C\period, 153.
  17689. exercises, viii, 5--231.
  17690. \<exit clause>, 171.
  17691. *|exitif|, 171, +173, @176, 179, @262.
  17692. |exitunless|, 173, +262.
  17693. expandable tokens, 179, 230.
  17694. *|expandafter|, +179, 180, @270, @286--@290, @313.
  17695. expansion process, +179--+180, @285--@291.
  17696. *|expr|, @160, @162, 165, @166, 167, @176, 210.
  17697. |(EXPR|$_n$|)|, 44, 160, 249, 251.
  17698. |expr.mf|, +61, 62--71, 116--117, 132, 135--137, 142--143, 150, 173.
  17699. \<expression>, 167, +209.
  17700. expressions, 59--73, 209--215.
  17701. *|extensible|, 318.
  17702. \<extensible command>, 318.
  17703. external tags, 55, 218.
  17704. |extra_beginchar|, 275--276, @278.
  17705. |extra_endchar|, 276, @277, @309.
  17706. |extra_setup|, 269, @270, @278.
  17707. |!| |Extra| |tokens| |will| |be| |flushed|, 43--44, 224--225.
  17708. \newletter
  17709. `F', 97, 204, 302--303.
  17710. *|false|, 55, @64--@65, 170, 210.
  17711. faster operation, 39, 99, 141, 144, 147, 228, 230, 234, 244, 264, 265, 277,
  17712.  291, 297, 298.
  17713. |Fatal| |base| |file| |error|, 226.
  17714. fatter pens, 297--298.
  17715. *|fi|, +169--+170, 179.
  17716. |!| |File| |ended...|, 287.
  17717. file names, 36, 39, +180, 324, 329.
  17718. \<filename>, 179--180.
  17719. |fill|, @24--@27, 109--112, @116, 118--121, 145, 167, +271, 295.
  17720. |filldraw|, @103--@105, 112--113, 118--119, 147, 148, @152, @164,
  17721.  230, +271, @306, 310.
  17722. *|fillin|, +93--+94, 150, 212, 247, 268, 278--279.
  17723. |fine|, 103--104, 306--307, 310--311.
  17724. |fine.lft|, 311.
  17725. |fix_units|, +267.
  17726. flat spots, 196--197.
  17727. |flex|, @124--@125, 127, @152, 173, 228--229, +267.
  17728. *|floor|, @65, 66, 72, 83, @253, 211.
  17729. flushing, 43--44, 219, 224--225.
  17730. Font, Fray Pedro, 139, 231.
  17731. \<font metric command>, 321.
  17732. font metric information, 39, 220, 315--321.
  17733. |font_coding_scheme|, +277, @303, 304, +320--+321.
  17734. |font_extra_space|, +277, 319.
  17735. |font_identifier|, +277, @303, 304, @305, 320, @332--@333.
  17736. |font_normal_shrink|, @97, +276, @305, 319.
  17737. |font_normal_space|, @97, +276, @305, 319, 332.
  17738. |font_normal_stretch|, @97, +276, @305, 319.
  17739. |font_quad|, @97, +277, 308, 319, 332.
  17740. |font_setup|, 203, 305, 309--312.
  17741. |font_size|, @96, +276.
  17742. |font_slant|, +276, @305, 319, 331, @335--@336.
  17743. |font_x_height|, +277, 319, 332.
  17744. *|fontdimen|, @276--@277, +318--+319, 331--332, @335.
  17745. \<fontdimen command>, 318.
  17746. *|fontmaking|, 54, @94, 211, @270, +315.
  17747. |\fontname|, 342.
  17748. *|for|, @18, @39, @113, +171--+173, 179, 228, @285--@291, @299.
  17749. \<for list>, +171, 299.
  17750. forbidden tokens, +173, 218--219, 286.
  17751. *|forever|, @61, +171--+173, @176, 179.
  17752. *|forsuffixes|, +171--+172.
  17753. {\sevenrm FORTRAN} language, 237.
  17754. \<four codes>, 318.
  17755. four-point method for curves, 13--14, 133.
  17756. Fournier, Simon Pierre, 321. % Harry Carter says S.P. is right, not P.S.!
  17757. fractions, 61, @62--@63, +72, 73.
  17758. *|from| 191, 220, @252, @277, @312.
  17759. |fullcircle|, @114, 123--124, 126, @135--@137, +263, @266.
  17760. Fulton, A\period\ G\period, 157.
  17761. function values by interpolation, 294--295.
  17762. \<future pen primary>, 148, 214.
  17763. \<future pen secondary>, 148, 214.
  17764. future pens, 148--149, 170, 249, 264, 298.
  17765. \newletter
  17766. Galsworthy, John, 215.
  17767. Gardner, Martin, 126.
  17768. |generate|, 305, 307, 311, 313.
  17769. |gf|, 32, 241, 295, 323--325.
  17770. |gfcorners|, 277, +278, 327.
  17771. |GFtoDVI|, 32, 37, 187, 327--336.
  17772. |gimme|, 61--62.
  17773. Giotto de Bondone, 139.
  17774. |gobble|, @167, +262, @289.
  17775. |gobbled|, +262, @289--@290.
  17776. golden ratio, 11.
  17777. |good.bot|, 204, +273.
  17778. |good.lft|, 204, +273.
  17779. |good.rt|, 204, +273.
  17780. |good.top|, 204, +273.
  17781. |good.x|, @198, @268, +273.
  17782. |good.y|, @198, 204, @268, +273.
  17783. Goudy, Frederic William, 19.
  17784. grammatical rules, 49--50.
  17785. *|granularity|, +205, 212, 262, 310.
  17786. graph paper, 5, 102, 109, 188.
  17787. |gray|, 332.
  17788. gray fonts, 327, 330--335.
  17789. |grayf.mf|, 332--335.
  17790. |grayfont|, 270, +275, 323, 329.
  17791. |grayfontarea|, 329.
  17792. |grayfontat|, 329.
  17793. greater than or equal to, 65.
  17794. greatest integer function, \see floor.
  17795. grid, 5, 109, 275.
  17796. Grimm, Jakob Ludwig Karl, 73.
  17797. Grimm, Wilhelm Karl, 73.
  17798. group delimiters, 289.
  17799. group expressions, 157, 160.
  17800. groups, 155--157, 167.
  17801. Gu Guoan, 3.
  17802. \newletter
  17803. |h|, @22--@25, 35--36, @76--@78, 102, 204, +275.
  17804. `H', 163, 165.
  17805. Haggard, Sir Henry Rider, 107.
  17806. hairlines, 104--105.
  17807. |halfcircle|, 123, @136, +263.
  17808. hamburgefonstiv, 341.
  17809. hand tuning, 195.
  17810. *|headerbyte|, 318, +320--+321.
  17811. \<headerbyte command>, 318.
  17812. hearts, 134.
  17813. height, 101.
  17814. Hein, Piet, 126, 231.
  17815. help messages, 43--45, 189, 224--225.
  17816. Herbin, Auguste, 3.
  17817. Hersh, Reuben, 343.
  17818. *|hex|, +188, 211, 281.
  17819. hex symbol, 7--8, 28--29.
  17820. hexadecimal notation, 188.
  17821. |hide|, @116, @143, 167, @173, @227, +262.
  17822. hierarchy of operators, 60--61, 71--73, 137, 209, 289.
  17823. histogram, 251.
  17824. Hobby, John Douglas, viii, 3, 130, 131, 149, 252, 285.
  17825. holes, 110.
  17826. Holland, Philemon, 51.
  17827. Homerus, 51.
  17828. homogeneous transforms, 247.
  17829. *|hppp|, 92--93, 212, 267, 268, 324.
  17830. |hround|, +264, @268.
  17831. Hult\'en, Karl Gunnar Pontus, 3.
  17832. \newletter
  17833. `I', 28, 32, 39, 163, 164.
  17834. |!| |I| |can't| |go| |on|, 226.
  17835. IBM Corporation, ix.
  17836. |identity|, @141--@145, 215, +263.
  17837. *|if|, +169--+170, 179, 289.
  17838. |iff|, @306, +307, 311.
  17839. |imagerules|, 277, +278.
  17840. imperative versus declarative, 87.
  17841. impossible cube, 113.
  17842. |in| (inch), 92, +267, 268.
  17843. inaccessible token, 286.
  17844. incomplete string, 50--51.
  17845. inconsistent equations, 82, 313.
  17846. |incr|, @39, 176--177, +266.
  17847. independent variables, +81--+83, 88, 224.
  17848. infinite loops, 172, 226--227.
  17849. |infinity|, @62--@69, +263, @266.
  17850. inflection points, 18--19.
  17851. |INIMF|, 221, 262, 279.
  17852. |\init|, 342.
  17853. \<initial value>, 171.
  17854. *|inner|, 180, +218--+219, 286--287, @307, @321.
  17855. |inorder|, 290.
  17856. *|input|, +179, 180, @269, @287--@288, 324.
  17857. input stack size, 226, 287.
  17858. inserting text online, 42, 45, 61, 188, 223--225.
  17859. integers, 65--66.
  17860. |interact|, 230, +262.
  17861. interacting with \MF, 42--45, 61, 188--189, 191--193, 219, 223--225.
  17862. *|interim|, +155--+156, 230, @243, @244, @271, @272.
  17863. \<interim command>, 155, 218.
  17864. internal quantities, 54--55, 88, 218, 262.
  17865. \sub table, 211--212.
  17866. \<internal quantity>, 156, 218, 265.
  17867. |interpath|, 134, +267.
  17868. interpolation, 2, 134, 294--295.
  17869. interrupting \MF, 219, 227--228, 313.
  17870. intersection, of lines, 84.
  17871. \sub of paths, 136--137.
  17872. \sub of pictures, 120.
  17873. |intersectionpoint|, @107, @137, @138, 178, +265.
  17874. *|intersectiontimes|, @178, 213, @265, @294, @298.
  17875. |inverse|, @143, +264.
  17876. inverse video, 115, 118.
  17877. *|inwindow|, +191, @277.
  17878. Io, 33, 40, 47.
  17879. \<is>, 165, 171, 218.
  17880. Isis, 40.
  17881. |!| |Isolated expression|, 223.
  17882. isolated math characters, 316, 319.
  17883. |italcorr|, @103--@105, +275, @303, @306, @316.
  17884. italic corrections, 102, 105, 275, 276, 304, 315--316, 319.
  17885. italic type, 55, 206, 341.
  17886. \newletter
  17887. jaggies, 201.
  17888. *|jobname|, +187, 214, 324.
  17889. Johnson, Samuel, 167.
  17890. Johnston, Edward, 29.
  17891. |join_radius|, 266.
  17892. jokes, viii, 231.
  17893. Journal of Algorithms, 137--139.
  17894. |jut|, 162, 308.
  17895. \newletter
  17896. Kafka, Franz, 340.
  17897. Kandinski\u\i, Vasili\u\i\ Vasil'evich, 3.
  17898. \<keep or drop>, 118, 120.
  17899. *|keeping|, 118, +120, 220.
  17900. |keepit|, 295.
  17901. *|kern|, @97, @316, +317.
  17902. kerning, 97, 316--317.
  17903. knife, 24.
  17904. *|known|, @65, 79--82, 143, +170, 210.
  17905. Knuth, Donald Ervin, i, ii, ix, 3, 134, 192, 206, 255, 282, 291, 304, 308, 345,
  17906.  361.
  17907. Knuth, Nancy Jill Carter, ix, 134, 137.
  17908. \newletter
  17909. |l|, 308--309.
  17910. La Rochefoucald, Fran\c cois VI, 313.
  17911. \<label>, 317.
  17912. \<labeled code>, 318.
  17913. |labelfont|, +275, 329.
  17914. |labelfontarea|, 329.
  17915. |labelfontat|, 329.
  17916. |labels|, @107, +274--+275, 327--328.
  17917. labels in font metric information, 317--318.
  17918. labels on "proofmode" output, 37, 187, 274--275.
  17919. |labels.top|, 328.
  17920. Lam\'e, Gabriel, 126.
  17921. |large_pixels|, 332.
  17922. |lcode_|, 274, 328.
  17923. le B\'e, Pierre, 207.
  17924. least integer function; \see ceiling.
  17925. Leban, Bruce Philip, 242, 243, 270, 295.
  17926. |left|, @16, +263.
  17927. left-handed dangerous bend, 143.
  17928. |leftstemloc|, 96, 199, 302.
  17929. *|length|, @66, @69, 72, 211, 238.
  17930. less than or equal to, 65.
  17931. *|let|, 53, 180, +218, @287--@289, @299, @311.
  17932. \<let command>, 218.
  17933. |letter_fit|, 307--308.
  17934. \<leveldef>, 178.
  17935. \<leveldef heading>, 165, +178.
  17936. |lft|, @23, @77, 80, 147, 151, +273.
  17937. lies, viii, 231.
  17938. Life, 121.
  17939. \<ligature op>, 317.
  17940. ligatures, 305--306, 315--317.
  17941. |lightweight|, 332.
  17942. *|ligtable|, @97, @305, +316--+317.
  17943. \<ligtable command>, 317.
  17944. \<ligtable program>, 317.
  17945. \<ligtable step>, 317.
  17946. \<limit value>, 171.
  17947. line, point to be on, 83--84.
  17948. linear dependencies, 82--83.
  17949. linear forms, 64, 82.
  17950. Linn\'e, Karel von (= Linn\ae us), 325.
  17951. |local.mf|, 278--279, 321.
  17952. |localfont|, 39, 271, 278, @279.
  17953. locations of characters within a font, 106--107, 281--283, 320.
  17954. Lockyer, Sir Joseph Norman, 57.
  17955. log file, 42, 46, 62, 230, 295--297.
  17956. |loggingall|, 230, +263.
  17957. logo of \MF, ii, 22--23, 95--99, 160--161, 184--185, 199--200, 204, 301--304.
  17958. |logo.mf|, 95--98, 199, 302--303.
  17959. logos, {\it i},  97, @114, @137--@139.
  17960. |logo10.mf|, 95, 287, 301, 304.
  17961. \<loop>, 171.
  17962. \<loop header>, 171.
  17963. loop text, 171--172, 219, 286.
  17964. loops, 169, 179, 226--227, 259, 290--291, 299.
  17965. low-resolution proofs, 99, 327.
  17966. |\lowers|, 339.
  17967. |lowres|, 196, 201, 230, +270.
  17968. |lowres_fix|, 203, +268, 310.
  17969. |luxo|, 91--94, 99, 195, 278--279.
  17970. \newletter
  17971. `M', 23, 97, 200, 302--303.
  17972. macros, @36--@37, 53, 114, 159--167, 175--179, 285--299.
  17973. |mag|, @39, +91--+93, 98, 169, 230, 269, 278, 333--334.
  17974. magnets, 60--61.
  17975. magnification, 38--40, 91--99.
  17976. |magstep|, 98, +270.
  17977. |makebox|, 270, +276, 309.
  17978. |makegrid|, +275.
  17979. |makelabel|, +274, 328.
  17980. *|makepath|, +150, 213, 247, @298.
  17981. *|makepen|, +147--+148, 214, @264.
  17982. |maketicks|, 270, +276, 309.
  17983. mastication, 169, 179, 285.
  17984. |\math|, 341.
  17985. Matthew, Saint, 173.
  17986. |max|, @65, +266, 290--291.
  17987. maximum, 65.
  17988. mediation, 9--11, 14, @63, @68, 72, 80, 133, 298--299.
  17989. memory usage, 226--227.
  17990. *|message|, @61, +189, @262.
  17991. \<message command>, 189, 219.
  17992. \<message op>, 189, 219.
  17993. meta-design, 1--3, 103--105, 294.
  17994. meta-font, 1--3, 98, 192, 301--304.
  17995. meta-ness, 3, 301.
  17996. \MF, the logo, ii, 22--23, 95--99, 160--161, 184--185, 199--200,
  17997.  204, 301--304.
  17998. \sub the name, 1--3.
  17999. |METAFONT| |capacity| |exceeded|, 226--227.
  18000. \MF\kern1pt79, viii.
  18001. *|mexp|, @+67, 72, 211, @265, @270.
  18002. |mf|, 31, 35.
  18003. |.mf|, 36.
  18004. |mfput|, 31--32, 187, 324.
  18005. |MFT|, 262.
  18006. midpoints, 9, 13.
  18007. Mies van der Rohe, Ludwig, 185.
  18008. |min|, @65, +266, 290--291.
  18009. minimum, 65.
  18010. Mirk, John, 313.
  18011. |!| |Missing| |`)'| |has| |been| |inserted|, 254.
  18012. misspelling, 45, 224.
  18013. |\mixture|, @40, +338.
  18014. *|mlog|, @+67, 72, 211, @265.
  18015. |mm| (millimeter), @76, 91--92, +267, 268.
  18016. M\"obius, August Ferdinand, 114.
  18017. mock curvature, 131.
  18018. |mod|, @66, +265.
  18019. |mode|, @38--@39, @75, 91--94, 269, 278.
  18020. \<mode command>, 219.
  18021. |mode_def|, 94, 189, @+270, @278--@279.
  18022. |mode_name|, 269.
  18023. |mode_setup|, @32--@34, 75, 76, 91--94, @96, 115, 169, +269, 278, @304, @305,
  18024.  329.
  18025. |mono_charwd|, 308.
  18026. |monospace|, 305--308.
  18027. *|month|, +212, 323.
  18028. More, Sir Thomas, 215.
  18029. Morison, Stanley, ix, 283.
  18030. mouth, 169, 179, 285.
  18031. Moxon, Joseph, 325.
  18032. Mulford, Clarence Edward, 89.
  18033. multiplication, @59, @62--@64, 69, 79--80, 82.
  18034. \sub of vector by scalar, 9.
  18035. music, 183, 185.
  18036. \newletter
  18037. `n', 201--203.
  18038. `N', 184--185, 303.
  18039. |\names|, 339.
  18040. National Science Foundation, ix.
  18041. Naur, Peter, 49, 89.
  18042. negation, of pictures, 115.
  18043. \sub of vectors, 9.
  18044. |new_window|, 193.
  18045. *|newinternal|, 180, +218.
  18046. \<newinternal command>, 218.
  18047. nice tangent points, 177.
  18048. |NNE|, 119, 228.
  18049. |NNW|, 26, 119, 228--229.
  18050. |nodisplays|, 277, +278.
  18051. |nodot|, 274, 328.
  18052. nonlinear equations, 84--85, 176--177, @292--@294.
  18053. nonsquare pixels, 94, 145, 204.
  18054. *|nonstopmode|, +219, 226.
  18055. *|normaldeviate|, @68, 72, @183--@185, 210.
  18056. *|not|, @65, +170, 210.
  18057. |notransforms|, 277, +278.
  18058. *|nullpen|, +148, 214, @272.
  18059. *|nullpicture|, +115, 192, 214, @272, @277.
  18060. *|numeric|, 55, +56, @65, 88.
  18061. \<numeric atom>, 72, +210.
  18062. \<numeric expression>, 72, +211.
  18063. numeric expressions, 72--73, 257.
  18064. \<numeric list>, 318.
  18065. \<numeric operator>, 72, +211.
  18066. \<numeric primary>, 72, +211.
  18067. \<numeric secondary>, 72, 178, +211.
  18068. \<numeric tertiary>, 72, +211.
  18069. \<numeric token>, 50, 236.
  18070. \<numeric token atom>, 210.
  18071. \<numeric token primary>, 72.
  18072. numeric tokens, 49--50, 166.
  18073. \sub maximum value, 50.
  18074. \sub rounded fractional values, 50.
  18075. |numeric_pickup_|, +272, 310.
  18076. *|numspecial|, 220, @274, +323--+324, @327--@329.
  18077. |numtok|, @+274.
  18078. \newletter
  18079. |o|, @23, @34, +93, 197, 200, 204, 302.
  18080. `o', 203.
  18081. `O', 32--37, 199, 303.
  18082. |o_correction|, 93--94, 268.
  18083. *|oct|, +188, 211, 281.
  18084. octal notation, 188.
  18085. octants, 119, 206--207, 228--230.
  18086. *|odd|, +170, 210, 250.
  18087. *|of|, 73, 129, 165--167, 187, 211--214.
  18088. of-the-way function, \see mediation.
  18089. off by $x$, 82.
  18090. Office of Naval Research, ix.
  18091. |!| |OK|, 219, 224.
  18092. |\omitaccents|, 340.
  18093. one-point {\bf draw}, 22, 150, 200, 253.
  18094. online interaction, 42--45, 61, 188--189, 191--193, 219, 223--225.
  18095. |openit|, +277, 312.
  18096. *|openwindow|, +191--+193, 220, @277, @312--@313.
  18097. \<openwindow command>, 191, 220.
  18098. operands, 59.
  18099. operators, 59, 230.
  18100. \<optional skip>, 317.
  18101. *|or|, @65, +170, 210, 237, 288--289.
  18102. order of operations, 60--61, 137, 247, 289.
  18103. oriental characters, 3, 106, 324.
  18104. |origin|, @77--@78, @243, @251, +263.
  18105. ornament, 144--145.
  18106. Orwell, George (= Blair, Eric Hugh), 85.
  18107. *|outer|, 180, +218--+219, 221, 286--287, @307, @321.
  18108. outlines, 121.
  18109. output of \MF, 39, 42, 315--325.
  18110. |overdraw|, 114, 243.
  18111. overflow labels, 37, 328.
  18112. overlays, 295.
  18113. overshoot, 23, 34, 93, 197, 200, 204.
  18114. \newletter
  18115. `P', 207.
  18116. Paget, Francis Edward, 279.
  18117. *|pair|, 55, +56, 65.
  18118. \<pair expression>, 73, +213.
  18119. pair expressions, 73, 171, 258.
  18120. \<pair part>, +211.
  18121. \<pair primary>, 73, +212.
  18122. \<pair secondary>, 73, +212.
  18123. \<pair tertiary>, 73, +213.
  18124. Palais, Richard Sheldon, ii.
  18125. parallel lines, 84.
  18126. parallelogram, 293--294.
  18127. \<parameter>, 178.
  18128. parameter files, 301, 304.
  18129. \<parameter heading>, 165.
  18130. \<parameter tokens>, 165.
  18131. \<parameter type>, 165.
  18132. parameters, v, 1--3.
  18133. \sub to fonts, 95, 103--104, 305.
  18134. \sub to macros, 159--167, 175--178.
  18135. parentheses, 51, 59, +60, 61, 71, 128, 210--215, 247.
  18136. Pascal language, 54.
  18137. *|path|, 55, +56, 171.
  18138. \<path expression>, 129, +213.
  18139. path expressions, 129--134, 258.
  18140. \<path join>, 129--130, 171, 213.
  18141. \<path primary>, 129, +213.
  18142. \<path secondary>, 129, +213.
  18143. \<path tertiary>, 129, +213.
  18144. paths, 13--19, 123--139.
  18145. *|pausing|, 211, +231.
  18146. |pc| (pica), 92, +267, 268.
  18147. pels, \see pixels.
  18148. *|pen|, 55, +56, @65, 170.
  18149. \<pen expression>, 147, 148, +214.
  18150. pen expressions, 147--148, 258, 298.
  18151. \<pen primary>, 148, +214.
  18152. \<pen secondary>, 148, +214.
  18153. \<pen tertiary>, 148, +214.
  18154. |pen_bot|, 151, +272.
  18155. |pen_lft|, 151, +272.
  18156. |pen_rt|, 151, +272.
  18157. |pen_top|, 151, +272.
  18158. *|pencircle|, @21--@23, @28, @29, +147--+149, @150--@152, 198, 200, 214.
  18159. |penlabels|, 36, +274.
  18160. *|penoffset|, +150, 230, 212, @298.
  18161. |penpos|, @26--@29, 37, @103, @162, +273, 310.
  18162. |penrazor|, @107, @112, 147, 150, +264, 297.
  18163. pens, 21--39, 147--152, 297--298.
  18164. |penspeck|, +264, @271.
  18165. |pensquare|, 147, 152, +264, 275.
  18166. |penstroke|, 27--29, @138, +273.
  18167. perpendicular, 29, 69, 84, 235.
  18168. |pickup|, @21--@23, 145, 147, +272.
  18169. *|picture|, 55, +56, @114.
  18170. \<picture command>, 118, 220.
  18171. \<picture expression>, 115, 214.
  18172. picture expressions, 115, 258.
  18173. \sub transformation of, 144, 297.
  18174. \<picture primary>, 115, 214.
  18175. \<picture secondary>, 115, 214.
  18176. \<picture tertiary>, 115, 214.
  18177. pictures, 109--121.
  18178. pimples, 196--197, 204.
  18179. |pix_ht|, 332, @333.
  18180. |pix_picture|, 332, @333.
  18181. |pix_wd|, 332, @333.
  18182. pixels, 5, 109, 259, 324.
  18183. |pixels_per_inch|, 267, 268.
  18184. plain \MF\ base, 34, +257--279.
  18185. |plain.mf|, 261--278.
  18186. \<plus or minus>, 72, 211.
  18187. *|point|, @69--@70, 73, @114, +133, 212, @267.
  18188. polygonal path, 24, 297.
  18189. pool size, 226, 286.
  18190. |pos|, 310.
  18191. *|postcontrol|, +134, 212, @267.
  18192. |posttension|, 136.
  18193. precedence, 60--61, 71--73, 137, 289.
  18194. *|precontrol|, +134, 212, @267.
  18195. |pretension|, 136.
  18196. pretty-printed \MF\ programs, 262.
  18197. *|primary|, 165, 167.
  18198. \<primary>, 71, 170, +209.
  18199. *|primarydef|, 166, @+178.
  18200. prime numbers, 173.
  18201. primitives, 53, 209, 345.
  18202. private tokens, 173, 265, 270.
  18203. product, @59, @62--@64, 69, 79--80, 82.
  18204. \sub of vector by scalar, 9.
  18205. \<program>, 155, 217.
  18206. program files, 304, 306.
  18207. \<progression>, 171.
  18208. |proof| mode, 92, 93, 104, +270, 327.
  18209. *|proofing|, @94, 187, 211, 220, @270, 274, +323--+324, 327.
  18210. |proofoffset|, +275, 329.
  18211. |proofrule|, +274, 323, 328--329.
  18212. |proofrulethickness|, +275, 329.
  18213. proofsheets, 37, 261, 327--343.
  18214. \<protection command>, 218.
  18215. pseudo-driver files, 311--313.
  18216. |pt| (printer's point), @21--@23, @33, 91--92, +267, 268.
  18217. |\punct|, 339.
  18218. punctuation marks, 306.
  18219. Pythagorean addition, @+66, @67, 72, 211.
  18220. \<Pythagorean plus or minus>, 72, 211.
  18221. Pythagorean subtraction, @+66, 72, 211, @238.
  18222. \newletter
  18223. `Q', 207.
  18224. |quartercircle|, 123, +263.
  18225. Quick, Jonathan Horatio, 54, 137.
  18226. *|quote|, +166, 172, @270, @286, @312.
  18227. \newletter
  18228. |r|, 308--309.
  18229. `R', 207.
  18230. |\raggedright|, 338.
  18231. Ramshaw, Lyle Harold, 320.
  18232. random numbers, 183--185.
  18233. *|randomseed|, 185, 218.
  18234. \<randomseed command>, 218.
  18235. |range|, @107, @138, @200, +274.
  18236. raster, 5, 91, 109, 195.
  18237. *|readstring|, @61, +187--+188, 214.
  18238. recipes, 2.
  18239. recursion, 227.
  18240. redundant equations, 82.
  18241. reference point, 77, +101.
  18242. |reflectedabout|, @138, 141, @142, 160, +266.
  18243. reinitializing a variable, 88, 157.
  18244. \<relation>, 170, 210.
  18245. relations, @64--@65, 170--171.
  18246. |relax|, @31, +262, @307.
  18247. remainder, 66.
  18248. |rep|, 332, 335.
  18249. replacement text, 159, +166, 219.
  18250. resolution, 6, 38--39, 91--99, 116.
  18251. \<return> key, 31.
  18252. *|reverse|, 129, +132, 213.
  18253. reverse video, 115, 118.
  18254. Reynolds, Lloyd Jay, 153.
  18255. |right|, @26, @68, +263.
  18256. \<right-hand side>, +88, 171.
  18257. *|rotated|, @21--@22, @25, 27, 44, @68, 73, @107, @114, @117, +141, 212, @238.
  18258. |rotatedabout|, +266.
  18259. |rotatedaround|, @138, 141, @142, @144, 159--160, +266.
  18260. |round|, @66, 196, 202, +264, @273.
  18261. rounding, 34--35, 50, 195--207, 308.
  18262. |rt|, @23, @77, 80, @103, 147, 151, 273.
  18263. |rtest.mf|, 311.
  18264. |rulepen|, +274, 275.
  18265. rules on proofsheets, 328--329.
  18266. runaway, 287.
  18267. Running, Theodore Rudolph, 47.
  18268. Ruskin, John, 139.
  18269. \newletter
  18270. `S', 40, 114.
  18271. |safefill|, 121.
  18272. |\sample|, 341.
  18273. sans-serif, 105, 305, 308.
  18274. *|save|, +155--+156, @160, 173, @178, 218, @236, @244, @296, 299.
  18275. \<save command>, 155, 218.
  18276. |savepen|, @96, 147, +272, @310.
  18277. \<scalar multiplication operator>, 72, 211.
  18278. *|scaled|, @21--@23, @68, 73, +141, 212, 244, 291.
  18279. *|scantokens|, @61, +179, @180, 189, 251, @269, @270, @286--@288, @313.
  18280. scatter plots, 183.
  18281. \<screen coordinates>, 191, 220.
  18282. \<screen place>, 191, 220.
  18283. |screen_cols|, 193, 277, @278.
  18284. |screen_rows|, 277, @278.
  18285. |screenchars|, 191, +277.
  18286. |screenrule|, 274, 278.
  18287. |screenstrokes|, 191, +277.
  18288. *|scrollmode|, @61, +219, @313.
  18289. *|secondary|, 165, 167.
  18290. \<secondary>, 71, +209.
  18291. *|secondarydef|, 166, @178.
  18292. selective complement, 120.
  18293. semantics, 50.
  18294. semicolons, 155, 169, 171, 172, 187, 217, 223--224, 263, 312.
  18295. |serif_fit|, 308.
  18296. serifs, 152, 162--165, 308.
  18297. Serlio, Sebastiano, 19.
  18298. |setu_|, 266, 291.
  18299. Shakespeare, William, 173, 255, 343.
  18300. sharped dimensions, @32--@35, 91--99, 102--103, 268, 315.
  18301. |shiftdef|, 311.
  18302. *|shifted|, @68, 73, @117, +141, 213.
  18303. |shipit|, @31, @276, +277, 295.
  18304. *|shipout|, 106, 210, +220, @277, @295, 316, 324, 329.
  18305. \<shipout command>, 220.
  18306. *|show|, 142, +219, @227, 230, @250, 296.
  18307. \<show command>, 219.
  18308. *|showdependencies|, 81, 83, +219, @262.
  18309. |showit|, @31, 191, @276, +277, 295.
  18310. *|showstats|, +219.
  18311. *|showstopping|, 211, @227, 230, @262.
  18312. *|showtoken|, 180, +219, @221.
  18313. *|showvariable|, 175, 177, 180, +219.
  18314. |shrink_fit|, 308--310.
  18315. shrinkability, 319.
  18316. shuffled binary numbers, 137.
  18317. sidebearings, 10, 34--35, 307--308.
  18318. {\sevenrm SIMULA67} language, 175.
  18319. *|sind|, @67, 72, 211.
  18320. *|skipto|, @316, +317.
  18321. skyline, 251.
  18322. |slant|, 105, 206, 301--303, 310, 319.
  18323. slant fonts, 329, 335--336.
  18324. *|slanted|, @68, 73, 105, +141, 213.
  18325. |slantfont|, +275, 329.
  18326. |slantfontarea|, 329.
  18327. |slantfontat|, 329.
  18328. |smode|, 269.
  18329. |smoke| mode, 38, 75, 93, +270, 327.
  18330. *|smoothing|, 55, 195, 205--206, 212, @262.
  18331. |softjoin|, 262, +266.
  18332. |solve|, 176--177, +267, @292--@294.
  18333. |(some| |charht| |values...)|, 316.
  18334. Southall, Richard Francis, 176.
  18335. spaces, 43, 50, 236.
  18336. sparks, +53--+55, 156, 175, 215, 219, 289.
  18337. *|special|, 220, @240--@241, @274, +323--+324, @327--@329.
  18338. \<special command>, 220.
  18339. special-purpose macros, 160, 248.
  18340. *|sqrt|, @59, @64, 72, 211.
  18341. square roots, 66, \also |sqrt|.
  18342. |SSE|, 206--207, 228--229.
  18343. |SSW|, 119, 228--229.
  18344. stack positions, 227.
  18345. Stanford, Amasa Leland, 340.
  18346. Stanford, Jane Elizabeth Lathrop, 340.
  18347. Stanford University, 125, 340.
  18348. star, 114.
  18349. |\startfont|, +337, 338, @342.
  18350. starting a job, 39, 95, 259, 277.
  18351. starting character, @40, 338--339.
  18352. \<statement>, 155, 171, 217.
  18353. \<statement list>, 155, 217.
  18354. statements, 155, 217--221.
  18355. \sub summary, 260--261.
  18356. stems, 201--203.
  18357. *|step|, @18, 171.
  18358. \<step size>, 171.
  18359. stomach, 169, 217, 285.
  18360. |stop|, +262, @311--@312.
  18361. stopping \MF, \see |end|.
  18362. *|str|, +187--+188, 214, @250, @251.
  18363. strange paths, 110--111, 119, 121, 136, 152, 228--229.
  18364. Stravinski{\u\i}, Igor' F\"edorovich, 193.
  18365. stretchability, 319.
  18366. Strindberg, Johan August, 185.
  18367. *|string|, 55, +56, 69.
  18368. \<string expression>, 73, 187, +214.
  18369. string expressions, 187--189, 258, 286.
  18370. \<string primary>, 187, 214.
  18371. \<string secondary>, 187, 214.
  18372. \<string tertiary>, 187, 214.
  18373. string tokens, 49--51.
  18374. |stroke|, @306, 310.
  18375. *|subpath|, @70, @71, 114, 129, +133, 134, 188, 213, @298.
  18376. subroutines, \see macros.
  18377. \<subscript>, 54.
  18378. subscripts, 54--57.
  18379. *|substring|, @69, 187, +188, 214, @320.
  18380. subtraction, of pictures, 115, @244.
  18381. \sub of vectors, 9.
  18382. Suetonius Tranquillus, Gaius, 181.
  18383. *|suffix|, @161, 165, @176.
  18384. \<suffix>, +54, 161, 176, 188.
  18385. \<suffix list>, 171.
  18386. |(SUFFIX|$_n$|)|, 44, 251.
  18387. sum, of pictures, 115, @117, @245.
  18388. \sub of transforms, 178.
  18389. \sub of vectors, 9.
  18390. |superellipse|, @126, @138, +267.
  18391. superellipses, 126, 161.
  18392. |superness|, 126.
  18393. Sutherland, Ivan Edward, 121.
  18394. Swift, Jonathan, 99, 121.
  18395. \<symbolic token list>, 155, 218.
  18396. symbolic tokens, 49--51.
  18397. symmetric difference, 120.
  18398. syntax rules, 49--50.
  18399. System Development Foundation, ix.
  18400. \newletter
  18401. `T', 22--23, 97, 151, 199--200, 302--303.
  18402. tables of \MF\ trivia:
  18403. \sub character classes, 51.
  18404. \sub character codes, 281--282.
  18405. \sub expandable tokens, 179--180.
  18406. \sub |fontdimen| parameters, 319.
  18407. \sub internal quantities, 211--212.
  18408. \sub language features, 257--261.
  18409. \sub proof\/ label options, 328.
  18410. \sub types, 55.
  18411. \sub units of measure, 92.
  18412. tags, +53--+55, 156, 175, 218--219.
  18413. |takepower|, +265.
  18414. taller pens, 297--298.
  18415. tapered stroke, 28.
  18416. |tensepath|, 128, +264, @298.
  18417. *|tension|, @15--@16, @114, +129--+132, 136, @296.
  18418. \<tension>, 129, 213.
  18419. \<tension amount>, 129, 213.
  18420. *|tertiary|, 165, 167.
  18421. \<tertiary>, 71, @137, +209.
  18422. *|tertiarydef|, 166, +178, @266.
  18423. |test.mf|, 311--312.
  18424. |testfont.tex|, 40, 336--342.
  18425. \TeX, 1, 34, 40, 91, 96, 98, 101--102, 315, 336--343, 361.
  18426. *|text|, @161, +165--+167.
  18427. |\text|, 340.
  18428. |(TEXT|$_n$|)|, 45, 249, 251.
  18429. text arguments, 219, 288--290, 299.
  18430. |.tfm|, 39, 315--317, 333, 335.
  18431. |!| |This| |can't| |happen|, 226.
  18432. Thomson, James, 189.
  18433. Thoreau, Henry David, 221.
  18434. |thru|, @107, @138, @200, +274.
  18435. tilde, 152.
  18436. *|time|, +212, 218, 323.
  18437. time in paths, 119, 133--137.
  18438. \<times or over>, 72, 211.
  18439. Tinguely, Jean, 3.
  18440. \<title>, +187, 217--218, 323.
  18441. |titlefont|, +275, 329.
  18442. |titlefontarea|, 329.
  18443. |titlefontat|, 329.
  18444. *|to|, 191, 220, @252, @277, @312.
  18445. |<to| |be| |read| |again>|, 223.
  18446. Tobin, Georgia Kay Mase, ii, 240.
  18447. tokens, 42--43, +49--+51, 210.
  18448. |tolerance|, 176, 251, 293, 267.
  18449. |top|, @23, @77, 80, @103, 147, 151, 204, +273.
  18450. Tory, Geoffroy, 19.
  18451. |totalnull|, 295.
  18452. *|totalweight|, +115, 211, @292.
  18453. |tracingall|, 230, +263, 288.
  18454. *|tracingcapsules|, 211, 219, 239.
  18455. *|tracingchoices|, 211, +229.
  18456. *|tracingcommands|, 211, +230.
  18457. *|tracingedges|, 211, +230, @295--@296.
  18458. *|tracingequations|, 80--83, 211, 229.
  18459. *|tracingmacros|, +160, 211, 229.
  18460. |tracingnone|, 230, +263.
  18461. *|tracingonline|, @61, 80, 211, 219, +230.
  18462. *|tracingoutput|, 211, +229--+230, 296.
  18463. *|tracingpens|, 211, +229, 230.
  18464. *|tracingrestores|, +156, 211, 229.
  18465. *|tracingspecs|, 206--207, 211, +229.
  18466. *|tracingstats|, 211, +227, 230.
  18467. *|tracingtitles|, 55, @94, +187, 211, 229.
  18468. Trajanus, 153.
  18469. trajectories, \see paths.
  18470. transcript file, 42, 46, 62, 230, 295--297.
  18471. *|transform|, 55, +56, 57, 141--143, @160, 266.
  18472. \<transform expression>, 215.
  18473. transform expressions, 141--143, 170, 178, 258.
  18474. \<transform part>, 211.
  18475. \<transform primary>, 215.
  18476. \<transform secondary>, 215.
  18477. \<transform tertiary>, 215.
  18478. transformations, 44, 141--145.
  18479. *|transformed|, 73, 213, 141--145.
  18480. \<transformer>, 73, 213.
  18481. transition lines, 230.
  18482. |transum|, 178.
  18483. trial path, 235.
  18484. triangle, 24--25, 203.
  18485. trigonometric functions, 67, 69, 131, 177.
  18486. *|true|, 55, @64, 170, 210.
  18487. truth, viii, 217, 221.
  18488. {\sl TUGboat}, ix, 361.
  18489. turning numbers, 110, +111, 112, 119, 136, 147.
  18490. *|turningcheck|, 112, +119, 212, 229, @244, 262, 296.
  18491. *|turningnumber|, 111, 211, 257, @264.
  18492. Twain, Mark (= Clemens, Samuel Langhorne), 145.
  18493. \<type>, +56, 171.
  18494. type declarations, 56.
  18495. types, 55.
  18496. typewriter type, 55, 105.
  18497. typographic errors, 45, 224.
  18498. \newletter
  18499. |u|, 103--104, 305--308.
  18500. |!| |Undefined| |coordinate|, 224.
  18501. undelimited arguments, +167.
  18502. \<undelimited parameters>, 165.
  18503. undelimited suffix parameters, +167, 176, 265, 270.
  18504. underline characters, 49, +51, 173, 265, 270.
  18505. |undraw|, 113, 118, 120, 242, +271.
  18506. |undrawdot|, 113, +271.
  18507. unequal to, 65.
  18508. |unfill|, @25, 27, 109--110, 118, @126, +271.
  18509. |unfilldraw|, 113, 118, +271.
  18510. *|uniformdeviate|, @68, 72, +183, 184, 211.
  18511. union, 120.
  18512. Union Jack, 7.
  18513. |unitpixel|, +263, @333.
  18514. units of measure, 33, 91--99, 267--268.
  18515. \sub table, 92.
  18516. |unitsquare|, @116, 128, 132, 136, +263.
  18517. |unitvector|, @238, +264.
  18518. *|unknown|, 79--82, 143, +170, 210.
  18519. unknown quantities, nonnumeric, 84--85.
  18520. \sub numeric, 79--83.
  18521. *|until|, @18, 171.
  18522. |up|, @32, @129, +263.
  18523. |\uppers|, 339.
  18524. |upto|, @39, 172, +262.
  18525. utility files, 311--313.
  18526. \newletter
  18527. \<vacuous expression>, 215.
  18528. vacuous expressions, 209, +215, 250, 262, 289, 292.
  18529. \<vacuous primary>, 215.
  18530. \<vacuous secondary>, 215.
  18531. \<vacuous tertiary>, 215.
  18532. valentine, 134.
  18533. values, disappearance of, 56, 88, 156--157.
  18534. *|vardef|, 166, @175--@178, 289.
  18535. \<vardef heading>, 178.
  18536. \<variable>, 54, +55, 210.
  18537. variables, 53--57, 59.
  18538. \sub reinitializing, 88, 157.
  18539. vector subtraction principle, 9.
  18540. vectors, 9--10, 77.
  18541. velocity zero, 136, 298.
  18542. Venezky, Richard Lawrence, 193.
  18543. *|vppp|, 212, 267, 324.
  18544. |vround|, @204, @+264, @268.
  18545. \newletter
  18546. |w|, @22--@25, 35--36, @76--@78, 102--103, 106, +275--+276, 308--310.
  18547. `w', 202.
  18548. *|warningcheck|, 212, @269, 270.
  18549. Warren, Mercy Otis, 359.
  18550. Webster, Noah, 167.
  18551. |whatever|, @83--@84, @138, 157, @233, 239, +264, @290.
  18552. width, 101.
  18553. Wilde, Oscar Fingal O'Flahertie Wills, 321.
  18554. Wilkins, John, ii, 283.
  18555. Willis, Ellen Jane, 157.
  18556. \<window>, 191, 220.
  18557. \<window spec>, 191, 220.
  18558. \<with clause>, 118, 120.
  18559. *|withpen|, 118, 220, @242.
  18560. *|withweight|, 118, 220, @242, @297.
  18561. |WNW|, 119, 228--229.
  18562. |WSW|, 119, 228--229.
  18563. \newletter
  18564. $x$ coordinates, @5--@7.
  18565. x-height, 319.
  18566. Xerox Corporation, 320.
  18567. |xgap|, 95--96, 199.
  18568. *|xoffset|, 212, +220, @309, 315, 324.
  18569. xor, 120.
  18570. *|xpart|, @68, 72, @138, 142, 211.
  18571. *|xscaled|, @21--@23, @68, 73, +141, 213, 244, 291.
  18572. *|xxpart|, 72, 142, @160, 211.
  18573. |xy_swap|, 297.
  18574. *|xypart|, 142, @160, 211.
  18575. \newletter
  18576. $y$ coordinates, @5--@7.
  18577. *|year|, +212, 323.
  18578. |ygap|, 96, 199.
  18579. *|yoffset|, 212, +220, 315, 324.
  18580. *|ypart|, @68, 72, 142, 211, 238.
  18581. *|yscaled|, @21--@23, @68, 73, +141, 213, 244, 291.
  18582. *|yxpart|, 142, @160, 211.
  18583. *|yypart|, 142, @160, 211.
  18584. \newletter
  18585. |z| convention, 7, @68, 69, 251, +277.
  18586. Zapf, Hermann, iii, 221.
  18587. zero, 236.
  18588. *|zscaled|, @68--@69, 73, +141, 213.
  18589. \enddoublecolumns
  18590. \endchapter
  18591. The more we search,
  18592. the More are we Deceived.
  18593. \author MERCY OTIS ^{WARREN}, ^^{Adams} {\sl To Mr.\thinspace Adams\/} (1773)
  18594.  % in Mass. Historical Soc. Collections, vol73 (1917), p402; line 32
  18595. \bigskip
  18596. A heavy weight is now to be removed from my conscience.
  18597. So essential did I consider an Index to be to every book,
  18598. that I proposed to bring a Bill into Parliament
  18599. to deprive an author who publishes a book without an Index
  18600. of the privilege of copyright; and, moreover,
  18601. to subject him, for his offence, to a pecuniary penalty.
  18602. Yet, from difficulties started by my printers,
  18603. my own books have hitherto been without an Index.
  18604. \author LORD ^{CAMPBELL},  {\sl Lives of the Chief Justices %
  18605.  of England}, vol.\thinspace 3 (1857) % end of the preface
  18606. \eject
  18607. \beginchapter Appendix J. Joining the\\\TeX\ Community
  18608. This appendix is about grouping of another kind: \TeX\ and \MF\ users from
  18609. around the world have banded together to form the \TeX\ Users Group (TUG),
  18610. in order to exchange information about common problems and solutions.
  18611. A newsletter/journal called {\sl TUGboat\/} has been published
  18612. since 1980, featuring articles about all aspects of \TeX\ and \MF\!\null.
  18613. ^^{TeX} TUG has a network of ``site coordinators'' who serve as focal points of
  18614. communication for people with the same computer configurations.
  18615. Occasional short courses are given,
  18616. to provide concentrated training in special topics; videotapes of
  18617. these courses are available for rental.
  18618. Meetings of the entire TUG membership are held at least once a year.
  18619. You can buy \MF\ T-shirts at these meetings.
  18620. Information about membership in TUG and subscription to {\sl TUGboat\/}
  18621. is available from
  18622. \smallskip
  18623. {\obeylines
  18624. \TeX\ Users Group
  18625. P.O. Box 9506
  18626. Providence RI 02940\kern.05em-9506, USA.
  18627. \endchapter
  18628. TUG is established to serve members having a common interest
  18629. in \TeX, a system for typesetting technical text,
  18630. and in {\manual \char`\\]\char`\^\char`\_efg\char`\^}\!, %
  18631.  a system for font design.
  18632. \author T\kern-.15em\lower.5ex\hbox{E}\kern-.005em X %
  18633.  USERS GROUP, {\sl Bylaws, Article II\/} (1983) % TUGboat 4 (1983) p60
  18634. \bigskip
  18635. Don't delay, write today! That number again is
  18636. \TeX\ Users Group
  18637. P.O. Box 9506
  18638. Providence RI 02940\kern.05em-9506, USA.
  18639. \author DONALD E. ^{KNUTH}, {\sl The \TeX book\/} (1985) % Appendix J
  18640. \eject
  18641.