<< . .

. 4
( : 45)

. . >>

(Figure 3bb will be inserted here; too bad you can™t see it now.)

It is sometimes desirable to avoid points of in¬‚ection, when d is positive, and
to require the curve to remain inside the triangle determined by its initial and
¬nal directions. This can be achieved by using three dots instead of two when you
specify a curve: The program
for d = 0 step 10 until 120:
draw (0, 0){dir 60} . . . {dir ’d}(6cm , 0); endfor
Chapter 3: Curves 19

generates the curves bounded
D¨ rer
Da Vinci
(Figure 3cc will be inserted here; too bad you can™t see it now.)

which are the same as before except that in¬‚ection points do not occur for the small
values of d. The ˜. . .™ speci¬cation keeps the curve “bounded” inside the triangle that
is de¬ned by the endpoints and directions; but it has no e¬ect when there is no such
triangle. More precisely, suppose that the curve goes from z0 to z1 ; if there™s a point z
such that the initial direction is from z0 to z and the ¬nal direction is from z to z1 ,
then the curve speci¬ed by ˜. . .™ will stay entirely within the triangle whose corners are
z0 , z1 , and z. But if there™s no such triangle (e.g., if d < 0 or d > 120 in our example
program), both ˜. . .™ and ˜. .™ will produce the same curves.

In this chapter we have seen lots of di¬erent ways to get
to draw curves. And there™s one more way, which subsumes all of the others.
If changes to tensions, curls, directions, and/or boundedness aren™t enough to
produce the sort of curve that a person wants, it™s always possible as a last
resort to specify all four of the points in the four-point method. For example,
the command
draw z4 . . controls z1 and z2 . . z6
will draw the following curve from z4 to z6 :

(Figure 3n will be inserted here; too bad you can™t see it now.)

And so I think I have omitted nothing
that is necessary to an understanding of curved lines.
” RENE DESCARTES, La G´om´trie (1637)
e e

Rules or substitutes for the artist™s hand must necessarily be inadequate,
although, when set down by such men as
D¨rer, Tory, Da Vinci, Serlio, and others,
they probably do establish canons of proportion and construction
which a¬ord a sound basis upon which to present new expressions.
” FREDERIC W. GOUDY, Typologia (1940)
(page 20)

Chapter 4: Pens 21

Our examples so far have involved straight lines or curved lines that look as pen
if they were drawn by a felt-tip pen, where the nib of that pen was perfectly bean
round. A mathematical “line” has no thickness, so it™s invisible; but when we scaled
plot circular dots at each point of an in¬nitely thin line, we get a visible line draw
that has constant thickness. pencircle
Lines of constant thickness have their uses, but also provides xscaled
several other kinds of scrivener™s tools, and we shall take a look at some of them yscaled
in this chapter. We™ll see not only that the sizes and shapes of pen nibs can be
varied, but also that characters can be built up in such a way that the outlines
of each stroke are precisely controlled.
First let™s consider the simplest extensions of what we have seen before.
The letter ˜ ™ of Chapter 2 and the kidney-bean ˜ ™ of Chapter 3 were drawn
with circular pen nibs of diameter 0.4 pt, where ˜pt™ stands for a printer™s point;*
0.4 pt is the standard thickness of a ruled line ˜ ™ drawn by TEX. Such a
penpoint can be speci¬ed by telling to

pickup pencircle scaled 0.4pt ;

will use the pen it has most recently picked up whenever it is asked
to ˜draw™ anything. A pencircle is a circular pen whose diameter is the width
of one pixel. Scaling it by 0.4pt will change it to the size that corresponds
to 0.4 pt in the output, because pt is the number of pixels in 1 pt. If the key
points (z1 , z2 , z3 , z4 , z5 , z6 ) of Chapters 2 and 3 have already been de¬ned, the

pickup pencircle scaled 0.8pt ;
draw z5 . . z4 . . z1 . . z3 . . z6 . . cycle

will produce a bean shape twice as thick as before: ˜ ™ instead of ˜ ™.
More interesting e¬ects arise when we use non-circular pen nibs. For
example, the command

pickup pencircle xscaled 0.8pt yscaled 0.2pt

picks up a pen whose tip has the shape of an ellipse, 0.8 pt wide and 0.2 pt tall;
magni¬ed 10 times, it looks like this: ˜ ™. (The operation of “xscaling” mul-
tiplies x coordinates by a speci¬ed amount but leaves y coordinates unchanged,
and the operation of “yscaling” is similar.) Using such a pen, the ˜ ™ becomes
˜ ™, and ˜ ™ becomes ˜ ™. Furthermore,

pickup pencircle xscaled 0.8pt yscaled 0.2pt rotated 30

takes that ellipse and rotates it 30—¦ counterclockwise, obtaining the nib ˜ ™; this
changes ˜ ™ into ˜ ™ and ˜ ™ into ˜ ™. An enlarged view of the bean shape shows

* 1 in = 2.54 cm = 72.27 pt exactly, as explained in The TEXbook.
22 Chapter 4: Pens

more clearly what is going on: draw
bounding box
(Figure 4a will be inserted here; too bad you can™t see it now.)

The right-hand example was obtained by eliminating the clause ˜yscaled 0.2pt ™;
this makes the pen almost razor thin, only one pixel tall before rotation.
Describe the pen shapes de¬ned by (a) pencircle xscaled 0.2pt yscaled 0.8pt ;
(b) pencircle scaled 0.8pt rotated 30; (c) pencircle xscaled .25 scaled 0.8pt .
We™ve seen many examples of ˜draw™ used with two or more points. What do
you think will do if you ask it to perform the following commands?
draw z1 ; draw z2 ; draw z3 ; draw z4 ; draw z5 ; draw z6 .
Let™s turn now to the design of a real letter that has already appeared
many times in this manual, namely the ˜ ™ of ˜ ™. All seven of the
distinct letters in ˜ ™ will be used to illustrate various ideas as we get
into the details of the language; we might as well start with ˜ ™, because it
occurs twice, and (especially) because it™s the sim- (0,h) (w,h)
plest. An enlarged version of this letter is shown at
the right of this paragraph, including the locations
of its four key points (z1 , z2 , z3 , z4 ) and its bounding
box. Typesetting systems like TEX are based on the
assumption that each character ¬ts in a rectangular (Figure 4b will be inserted here;
too bad you can™t see it now.)
box; we shall discuss boxes in detail later, but for
now we will be content simply to know that such
boundaries do exist.* Numbers h and w will have
been computed so that the corners of the box are at
positions (0, 0), (0, h), (w, 0), and (w, h) as shown. (0,0) (w,0)
Each of the letters in ˜ ™ is drawn
with a pen whose nib is an unrotated ellipse, 90% as tall as it is wide. In the
10-point size, which is used for the main text of this book, the pen is 2/3 pt wide,

* Strictly speaking, the bounding box doesn™t actually have to “bound” the black pixels
of a character; for example, the ˜ ™ protrudes slightly below the baseline at point 4,
and italic letters frequently extend rather far to the right of their boxes. However,
TEX positions all characters by lumping boxes together as if they were pieces of metal
type that contain all of the ink.
Chapter 4: Pens 23

so it has been speci¬ed by the command o
pickup pencircle scaled 2 pt yscaled 9 top
3 10 lft
or something equivalent to this. bot
We shall assume that a special value ˜o™ has been computed so that the coordinates
bottom of the vertical stroke in ˜ ™ should descend exactly o pixels below the METAFONT logo
baseline; this is called the amount of “overshoot.” Given h, w, and o, it is a
simple matter to de¬ne the four key points and to draw the ˜ ™:
top lft z1 = (0, h); top rt z2 = (w, h);
top z3 = (.5w, h); bot z4 = (.5w, ’o);
draw z1 . . z2 ; draw z3 . . z4 .
Sometimes it is easier and/or clearer to de¬ne the x and y coordinates sepa-
rately. For example, the key points of the ˜ ™ could also be speci¬ed thus:
w ’ x2 = x1 ;
lft x1 = 0; x3 = x4 = .5w;
bot y4 = ’o;
top y1 = h; y1 = y2 = y3 .
The equation w ’ x2 = x1 expresses the fact that x2 is just as far from the right edge
of the bounding box as x1 is from the left edge.
What exactly does ˜top™ mean in a equation? If the currently-
picked-up pen extends l pixels to the left of its center, r pixels to the right,
t pixels upward and b downward, then
bot z = z ’ (0, b), lft z = z ’ (l, 0),
top z = z + (0, t), rt z = z + (r, 0),
when z is a pair of coordinates. But”as the previous paragraph shows, if you study it
carefully”we also have
bot y = y ’ b, lft x = x ’ l,
top y = y + t, rt x = x + r,
when x and y are single values instead of coordinate pairs. You shouldn™t apply ˜top™
or ˜bot ™ to x coordinates, nor ˜lft ™ or ˜rt ™ to y coordinates.
True or false: top bot z = z, whenever z is a pair of coordinates.
(0,h) (w,h)
An enlarged picture of ™s
˜ ™ shows that it has ¬ve key points. Assum-
ing that special values ss and ygap have been
precomputed and that the equations
x1 = ss = w ’ x5 ; y3 ’ y1 = ygap (Figure 4c will be inserted here; too bad you
can™t see it now.)
have already been given, what further equa-
tions and ˜draw™ commands will complete the
speci¬cation of this letter? (The value of w
will be greater for ˜ ™ than it was for ˜ ™; it
stands for the pixel width of whatever char- (0,0) (w,0)
acter is currently being drawn.)
24 Chapter 4: Pens

™s ability to ˜draw™ allows it to produce character shapes that ¬ll
are satisfactory for many applications, but the shapes are inherently limited by knife
the fact that the simulated pen nib must stay the same through an entire stroke. cycle
Human penpushers are able to get richer e¬ects by using di¬erent amounts of “
pressure and/or by rotating the pen as they draw. ..
polygonal path
We can obtain ¬ner control over the characters we produce if we specify
their outlines, instead of working only with key points that lie somewhere in the
middle. In fact, works internally with outlines, and the computer
¬nds it much easier to ¬ll a region with solid black than to ¬gure out what pixels
are blackened by a moving pen. There™s a ˜¬ll™ command that does region ¬lling;
for example, the solid bean shape

(Figure 4d will be inserted here; too bad you can™t see it now.)

can be obtained from our six famous example points by giving the command
¬ll z5 . . z4 . . z1 . . z3 . . z6 . . cycle.
The ¬lled region is essentially what would be cut out by an in¬nitely sharp knife
blade if it traced over the given curve while cutting a piece of thin ¬lm. A draw
command needs to add thickness to its curve, because the result would otherwise
be invisible; but a ¬ll command adds no thickness.
The curve in a ¬ll command must end with ˜cycle™, because an entire
region must be ¬lled. It wouldn™t make sense to say, e.g., ˜¬ll z1 . . z2 ™. The cycle
being ¬lled shouldn™t cross itself, either; would have lots of trouble
trying to ¬gure out how to obey a command like ˜¬ll z1 . . z6 . . z3 . . z4 . . cycle™.
Chapter 3 discusses the curve z5 . . z4 . . z1 . . z3 . . z6 . . z5 , which isn™t smooth
at z5 . Since this curve doesn™t end with ˜cycle™, you can™t use it in a ¬ll command. But
it does de¬ne a closed region. How can be instructed to ¬ll that region?

The black triangle ˜ ™ that appears in the statement of exercises in this
book was drawn with the command
¬ll z1 - - z2 - - z3 - - cycle
after appropriate corner points z1 , z2 , and z3 had been speci¬ed. In this case the
outline of the region to be ¬lled was speci¬ed in terms of the symbol ˜- -™ instead
of ˜. .™; this is a convention we haven™t discussed before. Each ˜- -™ introduces
a straight line segment, which is independent of the rest of the path that it
belongs to; thus it is quite di¬erent from ˜. .™, which speci¬es a possibly curved
Chapter 4: Pens 25

line segment that connects smoothly with neighboring points and lines of a path. equilateral
In this case ˜- -™ was used so that the triangular region would have straight edges un¬ll
and sharp corners. We might say informally that ˜. .™ means “Connect the points
with a nice curve,” while ˜- -™ means “Connect the points with a straight line.”
The corner points z1 , z2 , and z3 were de¬ned care- (0,h) (w,h)
fully so that the triangle would be equilateral, i.e.,
so that all three of its sides would have the same length.
Since an equilateral triangle has 60—¦ angles, the following
equations did the job:
(Figure 4e will be inserted
x1 = x2 = w ’ x3 = s; here; too bad you can™t see
it now.)
y3 = .5h;
z1 ’ z2 = (z3 ’ z2 ) rotated 60.

Here w and h represent the character™s width and height,
and s is the distance of the triangle from the left and right
(0,0) (w,0)
edges of the type.

The ¬ll command has a companion called un¬ll, which changes pixels from
black to white inside a given region. For example, the solid bean shape on the
previous page can be changed to

(Figure 4f will be inserted here; too bad you can™t see it now.)

if we say also ˜un¬ll 1 [z4 , z2 ] . . 3 [z4 , z2 ] . . cycle; un¬ll 1 [z6 , z2 ] . . 3 [z6 , z2 ] . . cycle™.
4 4 4 4
This example shows, incidentally, that converts a two-point speci¬cation
like ˜z1 . . z2 . . cycle™ into a more-or-less circular path, even though two points by
themselves de¬ne only a straight line.

Let z0 be the point (.8[x1 , x2 ], .5[y1 , y4 ]), and introduce six new points by
letting zk = .2[zk , z0 ] for k = 1, 2, . . . , 6. Explain how to obtain the shape

(Figure 4g will be inserted here; too bad you can™t see it now.)

in which the interior region is de¬ned by z1 . . . z6 instead of by z1 . . . z6 .
26 Chapter 4: Pens

The ability to ¬ll between outlines makes it possible to pretend that we broad-edge pens
angle of pen
have broad-edge pens that change in direction and pressure as they glide over “
the paper, if we consider the separate paths traced out by the pen™s left edge penpos
compass directions
and right edge. For example, the stroke

(Figure 4h will be inserted here; too bad you can™t see it now.)

can be regarded as drawn by a pen that starts at the left, inclined at a 30—¦ angle;
as the pen moves, it turns gradually until its edge is strictly vertical by the time
it reaches the right end. The pen motion was horizontal at positions 2 and 3.
This stroke was actually obtained by the command
¬ll z1l . . z2l {right } . . {right } z3l
- - z3r {left } . . {left } z2r . . z1r
- - cycle;
i.e., was asked to ¬ll a region bounded by a “left path” from z1l to
z2l to z3l , followed by a straight line to z3r , then a reversed “right path” from
z3r to z2r to z1r , and ¬nally a straight line back to the starting point z1l .
Key positions of the “pen” are represented in this example by sets of
three points, like (z1l , z1 , z1r ), which stand for the pen™s left edge, its midpoint,
and its right edge. The midpoint doesn™t actually occur in the speci¬cation of
the outline, but we™ll see examples of its usefulness. The relationships between
such triples of points are established by a ˜penpos ™ command, which states the
breadth of the pen and its angle of inclination at a particular position. For
example, positions 1, 2, and 3 in the stroke above were established by saying
penpos1 (1.2pt , 30); penpos2 (1.0pt , 45); penpos3 (0.8pt , 90);
this made the pen 1.2 pt broad and tipped 30—¦ with respect to the horizontal at
position 1, etc. In general the idea is to specify ˜penposk (b, d)™, where k is the
position number or position name, b is the breadth (in pixels), and d is the angle
(in degrees). Pen angles are measured counterclockwise from the horizontal.
Thus, an angle of 0 makes the right edge of the pen exactly b pixels to the right
of the left edge; an angle of 90 makes the right pen edge exactly b pixels above
the left; an angle√ ’90 makes it exactly b pixels below. An angle of 45 makes
of √
the right edge b/ 2 pixels above and b/ 2 pixels to the right of the left edge;
√ √
an angle of ’45 makes it b/ 2 pixels below and b/ 2 to the right. When the
pen angle is between 90—¦ and 180—¦ , the “right” edge actually lies to the left of
the “left” edge. In terms of compass directions on a conventional map, an angle
of 0—¦ points due East, while 90—¦ points North and ’90—¦ points South. The angle
corresponding to Southwest is ’135—¦ , also known as +225—¦ .
What angle corresponds to the direction North-Northwest?
Chapter 4: Pens 27

EXERCISE 4.8 rotated
What are the pen angles at positions 1, 2, 3, and 4 in e
the circular shape shown here? [Hint: Each angle is a
multiple of 30—¦ . Note that z3r lies to the left of z3l .] (Figure 4i will be inserted
here; too bad you can™t see
it now.)
What are the coordinates of z1l and z1r after the com-
mand ˜penpos1 (10, ’90)™, if z1 = (25, 25)?
The statement ˜penposk (b, d)™ is simply an abbreviation for two equations,
˜zk = 1 [zkl , zkr ]™ and ˜zkr = zkl + (b, 0) rotated d ™. You might want to use
other equations to de¬ne the relationship between zkl , zk , and zkr , instead of giving a
penpos command, if an alternative formulation turns out to be more convenient.
After ˜penpos ™ has speci¬ed the relations between three points, we still
don™t know exactly where they are; we only know their positions relative to each
other. Another equation or two is needed in order to ¬x the horizontal and
vertical locations of each triple. For example, the three penpos commands that
led to the pen stroke on the previous page were accompanied by the equations
z1 = (0, 2pt ); z2 = (4pt , 0); x3 = 9pt ; y3l = y2r ;

<< . .

. 4
( : 45)

. . >>