* doc/groff.texinfo: Add documentation of most missing requests.
[s-roff.git] / doc / pic.ms
blobe63ded70a6ebe8751108e280e38c61d9baee1767
1 .\" For tolerably obvious reason, this needs to be processed through PIC.
2 .\" It also needs to be processed through TBL and EQN.  Use "groff -p -e -t".
3 .\" There is no hope that this will ever look right under nroff.
4 .\"
5 .\" Comments beginning with %% are cut lines so portions of this
6  \" document can be automatically extracted.  %%TUTORIAL%% begins the
7 .\" tutorial part; %%REFERENCE%% the reference part.  %%POSTLUDE%% the
8  \" bibliography and end matter after the reference part.  
9 .\"
10 .\" This document was written for free use and redistribution by
11 .\" Eric S. Raymond <esr@thyrsus.com> in August 1995.
12 .\"
13 .\"     $Id$    
14 .\"
15 .\" Set a proper TeX
16 .ie t .ds tx T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X
17 .el .ds tx TeX
18 .\"
19 .de CE\"        Centered caption for figure.  Assumes previous .KS
20 .ce 1
21 Figure \\n(H1-\\$1
22 .sp 1
23 .KE
25 .\" Definitions end here
26 .TL
27 Making Pictures With GNU PIC
28 .AU
29 Eric S. Raymond
30 .AI
31 <esr@snark.thyrsus.com>
32 .AB
33 The \fBpic\fP language is a \fBtroff\fP extension that makes it easy
34 to create and alter box-and-arrow diagrams of the kind frequently used
35 in technical papers and textbooks.  This paper is both an introduction
36 to and reference for \fIgpic\fP(1), the implementation distributed by
37 the Free Software Foundation for use with \fIgroff\fP(1).
38 .AE
39 .\"%%TUTORIAL%%
40 .NH 1
41 Introduction to PIC
42 .NH 2
43 Why PIC?
44 .PP
45 The \fBpic\fP language provides an easy way to write procedural
46 box-and-arrow diagrams to be included in \fBtroff\fP documents.  The
47 language is sufficiently flexible to be quite useful for state charts,
48 Petri-net diagrams, flow charts, simple circuit schematics, jumper
49 layouts, and other kinds of illustration involving repetitive uses of
50 simple geometric forms and splines.  Because these descriptions are
51 procedural and object-based, they are both compact and easy to modify.
52 .PP
53 The \fIgpic\fP(1) implementation of \fBpic\fP is distributed by the
54 Free Software Foundation for use with their \fIgroff\fP(1)
55 implementation of \fBtroff\fP.  Because both implementations are
56 widely available in source form for free, they are good bets for
57 writing very portable documentation.
58 .NH 2
59 PIC Versions
60 .PP
61 The original 1984 pre-\fIditroff\fP(1) version of \fBpic\fP is long
62 obsolete.  The rewritten 1991 version is still available as part of
63 the Documenter's Work Bench module of System V.
64 .PP
65 Where differences between Documenter's Work Bench (1991) \fBpic\fP and GNU
66 \fBpic\fP need to be described, original \fBpic\fP is referred to as
67 "DWB pic".  Details on the history of the program are given at the end
68 of this document.
69 .PP
70 In this document, the \fIgpic\fP(1) extensions will be marked as such.
71 .NH 1
72 Invoking PIC
73 .PP
74 Every \fBpic\fP description is a little program, which gets compiled
75 by \fIpic\fP(1) into \fIgtroff\fP(1) macros.  Programs that process or
76 display \fIgtroff\fP(1) output need not know or care that parts of the
77 image began life as \fBpic\fP descriptions.
78 .PP
79 The \fIpic\fP(1) program tries to translate anything between \fB.PS\fP
80 and \fB.PE\fP markers, and passes through everything else.  The normal
81 definitions of \fB.PS\fP and \fB.PE\fP in the \fIms\fP macro package
82 and elsewhere have also the side-effect of centering the \fBpic\fP output
83 on the page.
84 .NH 2
85 PIC Error Messages
86 .PP
87 If you make a \fBpic\fP syntax error, \fIgpic\fP(1) will issue an
88 error message in the standard \fIgcc\fP(1)-like syntax.  A typical
89 error message looks like this,
90 .KS
91 .DS
92 .CW
93 pic:pic.ms:<nnn>: parse error before `<token>'
94 pic:pic.ms:<nnn>: giving up on this picture
95 .DE
97 .KE
98 .LP
99 where <nnn> is a line number, and <token> is a token near (usually
100 just after) the error location.
101 .NH 1
102 Basic PIC Concepts
104 Pictures are described procedurally, as collections of objects
105 connected by motions.  Normally, \fBpic\fP tries to string together
106 objects left-to-right in the sequence they are described, joining them
107 at visually natural points.  Here is an example illustrating the
108 flow of data in \fBpic\fP processing:
111 ellipse "document";
112 arrow;
113 box "\fIgpic\fP(1)"
114 arrow;
115 box width 1.2 "\fIgtbl\fP(1) or \fIgeqn\fP(1)" "(optional)" dashed;
116 arrow;
117 box "\fIgtroff\fP(1)";
118 arrow;
119 ellipse "PostScript"
121 .CE "1: Flow of \fBpic\fP data"
123 This was produced from the following \fBpic\fP program:
127 \&.PS
128 ellipse "document";
129 arrow;
130 box "\efIpic\efP(1)"
131 arrow;
132 box width 1.2 "\efIgtbl\efP(1) or \efIgeqn\efP(1)" "(optional)" dashed;
133 arrow;
134 box "\efIgtroff\efP(1)";
135 arrow;
136 ellipse "PostScript"
137 \&.PE
142 This little program illustrates several \fBpic\fP basics.  Firstly, we
143 see how to invoke three object types; ellipses, arrows, and boxes.  We
144 see how to declare text lines to go within an object (and that text
145 can have font changes in it).  We see how to change the line style of
146 an object from solid to dashed.  And we see that a box can be made
147 wider than its default size to accommodate more text (we'll discuss
148 this facility in detail in the next section).
150 We also get to see \fBpic\fP's simple syntax.  Statements are ended by
151 newlines or semicolons.  String quotes are required around all text
152 arguments, whether or not they contain spaces.  In general, the order
153 of command arguments and modifiers like "width 1.2" or "dashed" doesn't
154 matter, except that the order of text arguments is significant.
156 Here are all but one of the basic \fBpic\fP objects at their default sizes:
159 box "box";
160 move;
161 line "line" "";
162 move;
163 arrow "arrow" "";
164 move;
165 circle "circle";
166 move;
167 ellipse "ellipse";
168 move;
169 arc; down; move; "arc"
171 .CE "2: Basic \fBpic\fP objects"
173 The missing simple object type is a \fIspline\fP.  There is also a way
174 to collect objects into \fIblock composites\fP which allows you to
175 treat the whole group as a single object (resembling a box) for many
176 purposes.  We'll describe both of these later on.
178 The box, ellipse, circle, and block composite objects are \fIclosed\fR;
179 lines, arrows, arcs and splines are \fIopen\fP.  This distinction
180 will often be important in explaining command modifiers.
182 Figure \n[H1]-2 was produced by the following \fBpic\fP program,
183 which introduces some more basic concepts:
187 \&.PS
188 box "box";
189 move;
190 line "line" "";
191 move;
192 arrow "arrow" "";
193 move;
194 circle "circle";
195 move;
196 ellipse "ellipse";
197 move;
198 arc; down; move; "arc"
199 \&.PE
201 .ft R
204 The first thing to notice is the \fImove\fP command, which moves a
205 default distance (1/2 inch) in the current movement direction.
207 Secondly, see how we can also decorate lines and arrows with text.
208 The line and arrow commands each take two arguments here, specifying
209 text to go above and below the object.  If you wonder why one argument
210 would not do, contemplate the output of \fBarrow "ow!"\fP:
213 arrow "ow!"
215 .CE "3: Text centered on an arrow"
217 When a command takes one text string, \fBpic\fP tries to place it at
218 the object's geometric center.  As you add more strings, \fBpic\fP
219 treats them as a vertical block to be centered.  The program
223 line "1";
224 line "1" "2";
225 line "1" "2" "3";
226 line "1" "2" "3" "4";
227 line "1" "2" "3" "4" "5";
229 .ft R
232 for example, gives you this:
234 .sp 2
236 line "1";
237 line "1" "2";
238 line "1" "2" "3";
239 line "1" "2" "3" "4";
240 line "1" "2" "3" "4" "5";
242 .sp 2
243 .CE "4: Effects of multiple text arguments"
245 The last line of Figure 3.2's program, `\fBarc; down; move;
246 "arc"\fP', describing the captioned arc, introduces several new ideas.
247 Firstly, we see how to change the direction in which objects are
248 joined.  Had we written \fBarc; move; "arc"\fP,
249 omitting \fBdown\fP the caption would have been joined to the top
250 of the arc, like this:
253 arc; move; "arc";
255 .CE "5: Result of \fBarc; move; \"arc\"\fP"
257 This is because drawing an arc changes the default direction to the
258 one its exit end points at.  To reinforce this point, consider:
261 arc cw; move; "arc";
263 .CE "6: Result of \fBarc cw; move; \"arc\"\fP"
265 All we've done differently here is specify "cw" for a clockwise arc.
266 Observe how it changes the default direction to down, rather than up.
268 Another good way to see this via with the following program:
272 line; arc; arc cw; line
274 .ft R
277 which yields:
280 line; arc; arc cw; line;
282 .CE "7: Result of \fBline; arc; arc cw; line\fP"
284 Notice that we did not have to specify "up" for the second arc to be
285 joined to the end of the first.
287 Finally, observe that a string, alone, is treated as text to be
288 surrounded by an invisible box of a size either specified by width
289 and height attributes or by the defaults \fBtextwid\fR and
290 \fBtextht\fR.  Both are initially zero (because we don't know the
291 default font size).
292 .NH 1 
293 Sizes and Spacing
295 Sizes are specified in inches.  If you don't like inches, it's
296 possible to set a global style variable \fBscale\fP that changes the
297 unit.  Setting \fBscale = 2.54\fP will effectively change the internal
298 unit to centimeters (all other size variable valuess will be scaled
299 correspondingly).
300 .NH 2
301 Default Sizes of Objects
303 Here are the default sizes for \fBpic\fP objects:
307 tab(@), linesize(2);
308 lb | lb
309 l | l.
310 .sp 2p
311 Object@Default Size
312 .sp 2p
314 .sp 2p
315 box@0.75" wide by 0.5" high
316 circle@0.5" diameter
317 ellipse@0.75" wide by 0.5" high
318 arc@0.5" radius
319 line@0.5" long
320 arrow@0.5" long
321 .sp 5p
327 The simplest way to think about these defaults is that they make the
328 other basic objects fit snugly into a default-sized box.
329 .NH 2
330 Objects Do Not Stretch!
332 Text is rendered in the current font with normal troff line spacing.
333 Boxes, circles, and ellipses do \fInot\fP automatically resize to fit
334 enclosed text.  Thus, if you say \fBbox "text far too long"\fP
335 you'll get this:
338 box "this text is far too long for a default box"
340 .CE "1: Boxes do not automatically resize"
342 which is probably not the effect you want.
343 .NH 2
344 Resizing Boxes
346 To change the box size, you can specify a box width with the "width"
347 modifier:
350 box width 3 "this text is far too long for a default box"
352 .CE "2: Result of \fBbox width 3 \"text far too long\"\fP"
354 This modifier takes a dimension in inches.  There is also a "height"
355 modifier that will change a box's height.  The \fBwidth\fP keyword may
356 be abbreviated to \fBwid\fP; the \fBheight\fP keyword to \fBht\fP.
357 .NH 2
358 Resizing Other Object Types
360 To change the size of a circle, give it a \fBrad\fP or \fBdiam\fP
361 modifier; this changes the radius or diameter of the circle, according
362 to the numeric argument that follows.
365 {circle rad 0.1; move down 0.2 from last circle .s; "0.1"};
366 move; circle rad 0.2 "0.2"; move; circle rad 0.3 "0.3";
368 .CE "3: Circles with increasing radii"
370 The \fBmove\fP command can also take a dimension, which just tells
371 it how many inches to move in the current direction.
373 Ellipses are sized to fit in the rectangular box defined by their
374 axes, and can be resized with \fBwidth\fP and \fBheight\fP like boxes.
376 You can also change the radius of curvature of an arc with \fBrad\fP
377 (which specifies the radius of the circle of which the arc is a segment).
378 Larger values yield flatter arcs.
381 {arc rad 0.1; move down 0.3 from last arc .center; "0.1"};
382 move;
383 {arc rad 0.2; move down 0.4 from last arc .center; "0.2"};
384 move;
385 {arc rad 0.3; move down 0.5 from last arc .center; "0.3"};
387 .CE "4: \fBarc rad\fP with increasing radii"
389 Observe that because an arc is defined as a quarter circle, increasing
390 the radius also increases the size of the arc's bounding box.
391 .NH 2
392 The `same' Keyword
394 In place of a dimension specification, you can use the keyword
395 \fBsame\fR.  This gives the object the same size as the previous one
396 of its type.  As an example, the program
400 \&.PS
401 box; box wid 1 ht 1; box same; box
402 \&.PE
407 gives you
410 box; box wid 1 ht 1; box same; box
412 .CE "5: The \fBsame\fP keyword"
414 .NH 1
415 Generalized Lines and Splines
416 .NH 2
417 Diagonal Lines
419 It is possible to specify diagonal lines or arrows by adding multiple \fBup\fP,
420 \fBdown\fP, \fBleft\fP, and \fBright\fP modifiers to the line object.
421 Any of these can have a multiplier.  To understand the effects, think
422 of the drawing area as being gridded with standard-sized boxes.
425 # Draw a demonstration up left arrow with grid box overlay
426 define gridarrow
428         [
429                 {arrow up left $1;}
430                 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
431                 for i = 2 to ($1 / 0.5) do
432                 {
433                         box wid 0.5 ht 0.5 dotted with .sw at last box .se;
434                 }
435                 move down from last arrow .center;
436                 [
437                         if ( $1 == boxht ) then { "\fBline up left\fP" } else { sprintf("\fBarrow up left %g\fP", $1) };
438                 ]
439         ] 
440         move right from last [] .e;
442 gridarrow(0.5);
443 gridarrow(1);
444 gridarrow(1.5);
445 gridarrow(2);
446 undef gridarrow
448 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
449 .NH 2
450 Multi-Segment Line Objects
452 A "line" or "arrow" object may actually be a path consisting of any number of
453 segments of varying lengths and directions.  To describe a path,
454 connect several line or arrow commands with the keyword \fBthen\fP.
457 define zigzag { $1 right 1 then down .5 left 1 then right 1 }
458 zigzag(line); 
460 .CE "2: \fBline right 1 then down .5 left 1 then right 1\fP"
461 .NH 2
462 Spline Objects
464 If you start a path with the \fBspline\fP keyword, the path vertices
465 are treated as control points for a spline curve fit.
468 [zigzag(spline);]
469 move down 0.2 from last [] .s;
470 "The spline curve..."
471 move right from last [] .e;
473         zigzag(line dashed);
474         spline from start of last line right 1 then down .5 left 1 then right 1;
475         "1" at last spline .start + (-0.1, 0);
476         "2" at last spline .start + (1.1, 0);
477         "3" at last spline .end + (-1.1, 0);
478         "4" at last spline .end + (0.1, 0);
480 move down 0.2 from last [] .s;
481 "...with tangents displayed"
482 undef zigzag;
484 .CE "3: \fBspline right 1 then down .5 left 1 then right 1\fP"
486 You can describe many natural-looking but irregular curves this
487 way. For example: 
490 [spline right then up then left then down ->;]
491 move down 0.2 from last [] .s;
492 ["\fBspline right then up then left then down ->;\fP"]
493 move right 3 from last [] .se;
494 "\fBspline left then up right then down right ->;\fP"
495 move up 0.2;
496 [spline left then up right then down right ->;]
498 .CE "4: Two more spline examples"
500 Note the arrow decorations.  Arrowheads can be applied naturally to
501 any path-based object, line or spline.  We'll see how in the next
502 section.
503 .NH 1
504 Decorating Objects.
505 .NH 2
506 Dashed Objects
508 We've already seen that the modifier \fBdashed\fP can change the line
509 style of an object from solid to dashed.  GNU \fBgpic\fP permits you to
510 dot or dash ellipses, circles, and arcs (and splines in \*(tx mode
511 only); some versions of DWB may only permit dashing of lines and
512 boxes.  It's possible to change the dash interval by specifying a
513 number after the modifier.
517 box dashed "default";
518 move;
519 box dashed 0.05 "0.05";
520 move;
521 box dashed 0.1 "0.1";
522 move;
523 box dashed 0.15 "0.15";
524 move;
525 box dashed 0.2 "0.2";
527 .CE "1: Dashed objects"
528 .NH 2
529 Dotted Objects
531 Another available qualifier is \fBdotted\fP.  GNU \fBgpic\fP permits
532 you to dot or dash ellipses, circles, and arcs (and splines in \*(tx
533 mode only); some versions of DWB may only permit dashing of lines and
534 boxes.  It too can be suffixed with a number to specify the interval
535 between dots:
538 box dotted "default";
539 move;
540 box dotted 0.05 "0.05";
541 move;
542 box dotted 0.1 "0.1";
543 move;
544 box dotted 0.15 "0.15";
545 move;
546 box dotted 0.2 "0.2";
548 .CE "2: Dotted objects"
549 .NH 2
550 Rounding Box Corners
552 It is also possible, in GNU \fBgpic\fP only, to modify a box so it has
553 rounded corners
556 box rad 0.05 "rad 0.05";
557 move;
558 box rad 0.1 "rad 0.1";
559 move;
560 box rad 0.15 "rad=0.15"; 
561 move;
562 box rad 0.2 "rad=0.2"; 
563 move;
564 box rad 0.25 "rad=0.25"; 
566 .CE "3: \fBbox rad\fP with increasing radius values"
568 Radius values higher than half the minimum box dimension are silently
569 truncated to that value.
570 .NH 2
571 Arrowheads
573 Lines and arcs can be decorated as well.  Any line or arc (and any
574 spline as well) can be decorated with arrowheads by adding one or more
575 as modifiers:
578 line <- ->
580 .CE "4: Double-headed line made with  \fBline <- ->\fP"
582 In fact, the \fBarrow\fP command is just shorthand for \fBline ->\fP.  And
583 there is a double-head modifier <->, so the figure above could have been made
584 with \f(CWline <->\fP.
586 Arrowheads have a \fBwidth\fP attribute, the distance across the rear;
587 and a \fBheight\fP attribute, the length of the arrowhead along the shaft.
589 Arrowhead style is controlled by the style variable \fBarrowhead\fP.
590 The DWB and GNU versions interpret it differently.  DWB defaults to
591 open arrowheads and an \fBarrowhead\fP value of 2; the Kernighan
592 paper says a value of 7 will make solid arrowheads.  GNU \fBgpic\fP
593 defaults to solid arrowheads and an \fBarrowhead\fP value of 1; a
594 value of 0 will produce open arrowheads.
595 .NH 2
596 Line Thickness
598 It's also possible to change the line thickness of an object (this is
599 a GNU extension, DWB \fBpic\fP doesn't support it).  
600 The default thickness of the lines used to draw objects is controlled by the
601 .B linethick
602 variable.
603 This gives the thickness of lines in points.
604 A negative value means use the default thickness:
605 in \*(tx output mode, this means use a thickness of 8 milliinches;
606 in \*(tx output mode with the
607 .B -c
608 option, this means use the line thickness specified by
609 .B .ps
610 lines; in troff output mode, this means use a thickness proportional
611 to the pointsize.  A zero value means draw the thinnest possible line
612 supported by the output device.  Initially it has a value of -1.
613 There is also a \fBthickness\fP attribute (which can be abbreviated to
614 \fBthick\fP).  For example, \fBcircle thickness 1.5\fP would draw a
615 circle using a line with a thickness of 1.5 points.  The thickness of
616 lines is not affected by the value of the
617 .B scale
618 variable, nor by any width or height given in the
619 .B .PS
620 line.
621 .NH 2
622 Invisible Objects
624 The modifier \fBinvis\fP makes an object entirely invisible.  This
625 used to be useful for positioning text in an invisible object that is
626 properly joined to neighboring ones.  Newer DWB versions and GNU
627 \fBpic\fP treat standalone text in exactly this way.
628 .NH 2
629 Filled Objects
631 It is possible to fill boxes, circles, and ellipses.  The
632 modifier \fBfill[ed]\fP accomplishes this.  You can suffix it with a fill
633 value; the default is given by the stule variable \fBfillval\fP.
635 DWB \fBpic\fP and \fBgpic\fP have opposite conventions for fill values
636 and different defaults.  DWB \fBfillval\fP defaults to 0.3 and smaller
637 values are darker; GNU \fBfillval\fP uses 0 for white and 1 for black.
640 circle fill; move; circle fill 0.4; move; circle fill 0.9;
642 .CE "5: \fBcircle fill; move; circle fill 0.4; move; circle fill 0.9;\fR"
644 GNU \fBgpic\fP makes some additional guarantees.  A fill value greater
645 than 1 can also be used: this means fill with the shade of gray that
646 is currently being used for text and lines.  Normally this will be
647 black, but output devices may provide a mechanism for changing this.
648 The invisible attribute does not affect the filling of objects.  Any
649 text associated with a filled object will be added after the object
650 has been filled, so that the text will not be obscured by the filling.
652 The closed-object modifier \fBsolid\fP is equivalent to \fBfill\fP
653 with the darkest fill value (DWB \fBpic\fP had this capability but
654 mentioned it only in a reference section).  
655 .NH 2
656 Colored Objects
658 As a GNU extension, three additional modifiers are available to specify
659 colored objects.  \fBoutline\fP sets the color of the outline, \fBshaded\fP
660 the fill color, and \fBcolor\fP sets both.  All three keywords expect a
661 suffix specifying the color.  Example:
664 box color "yellow"; arrow color "cyan"; circle shaded "green" outline "black";
666 .CE "6: \fBbox color ""yellow""; arrow color ""cyan""; \
667 circle shaded ""green"" outline ""black"";\fR"
669 Alternative spellings are \fBcolour\fP, \fBcolored\fP, \fBcoloured\fP,
670 and \fBoutlined\fP.
672 Currently, color support is not available in \*(tx mode.  Predefined color
673 names for \fIgroff\fP(1) are in the device macro files, for example
674 \f(CWps.tmac\fP; additional colors can be defined with the \f(CW.defcolor\fP
675 request (see the manual page of GNU \fItroff\fP(1) for more details).
676 .NH 1
677 More About Text Placement
679 By default, text is centered at the geometric center of the object it is
680 associated with.  The modifier \fBljust\fP causes the left end to be
681 at the specified point (which means that the text lies to the right of
682 the specified place!), the modifier \fBrjust\fP puts the right end at
683 the place.  The modifiers \fBabove\fP and \fBbelow\fP center the text
684 one half line space in the given direction.
686 Text attributes can be combined:
689 [line up "ljust text" ljust;] 
690 move 1.5;
691 [line up "rjust text" rjust;] 
692 move;
693 [arrow 1 "ljust above" ljust above;]
694 move;
695 [arrow 1 "rjust below" rjust below;]
697 .CE "1: Text attributes"
699 What actually happens is that n text strings are centered in a box
700 that is \fBtextwid\fP wide by \fBtextht\fP high.  Both these variables
701 are initially zero (that is \fBpic\fR's way of not making assumptions
702 about \fI[tg]roff\fP(1)'s default point size).
704 In GNU \fBgpic\fR, objects can have an
705 .B aligned
706 attribute.
707 This will only work when the postprocessor is
708 \fBgrops\fP.
709 Any text associated with an object having the
710 .B aligned
711 attribute will be rotated about the center of the object
712 so that it is aligned in the direction from the start point
713 to the end point of the object.
714 Note that this attribute will have no effect for objects whose start and
715 end points are coincident.
716 .NH 1
717 More About Direction Changes
719 We've already seen how to change the direction in which objects are
720 composed from rightwards to downwards.  Here are some more
721 illustrative examples:
724 down;
726         "\fBright; box; arrow; circle; arrow; ellipse\fP";
727         move 0.2;
728         [right; box; arrow; circle; arrow; ellipse;]
730 move down 0.3 from last [] .s;
732         "\fBleft; box; arrow; circle; arrow; ellipse\fP"
733         move 0.2;
734         [left; box; arrow; circle; arrow; ellipse;]
736 # move down 0.3 from last [] .sw;
737 # To re-join this illustrations, delete everything from here down to
738 # the next #-comment, and uncomment the move line above
740 .CE "1: Effects of different motion directions (right and left)"
743 # To re-join this illustrations, delete everything down to here, then
744 # comment out the next `down' line.
745 # Don't forget to re-number the figures following!
746 down;
748         "\fBdown; box; arrow; circle; arrow; ellipse;\fP"
749         move 0.2;
750         box; arrow; circle; arrow; ellipse;
752 move right 2 from last [] .e;
754         up; box; arrow; circle; arrow; ellipse;
755         move 0.2;
756         "\fBup; box; arrow; circle; arrow; ellipse;\fP"
759 .CE "2: Effects of different motion directions (up and down)"
761 Something that may appear surprising happens if you change directions 
762 in the obvious way:
765 box; arrow; circle; down; arrow; ellipse
767 .CE "3: \fBbox; arrow; circle; down; arrow; ellipse\fP"
769 You might have expected that program to yield this:
772 box; arrow; circle; move to last circle .s; down; arrow; ellipse
774 .CE "4: More intuitive?"
776 But, in fact, to get Figure \*[SN]3 you have to do this:
780 \&.PS
781 box;
782 arrow;
783 circle;
784 move to last circle .s;
785 down;
786 arrow;
787 ellipse
788 \&.PE
792 Why is this?  Because the exit point for the current direction is
793 already set when you draw the object.  The second arrow in Figure
794 \*[SN]2 dropped downwards from the circle's attachment point for an
795 object to be joined to the right.
797 The meaning of the command \fBmove to last circle .s\fP should be obvious.
798 In order to see how it generalizes, we'll need to go into detail on two
799 important topics; locations and object names.
800 .NH 1
801 Naming Objects
803 The most natural way to name locations in \fBpic\fP is relative to
804 objects.  In order to do this, you have to be able you have to be able
805 to name objects.  The \fBpic\fP language has rich facilities for this
806 that try to emulate the syntax of English.
807 .NH 2
808 Naming Objects By Order Of Drawing
810 The simplest (and generally the most useful) way to name an object is
811 with a \fBlast\fP clause.  It needs to be followed by an object type
812 name; \fBbox\fP, \fBcircle\fP, \fBellipse\fP, \fBline\fP, \fBarrow\fP,
813 \fBspline\fP or \fB[]\fP (the last type refers to a \fIcomposite
814 object\fP which we'll discuss later).  So, for example, the \fBlast
815 circle\fP clause in the program attached to Figure \*[SN]3 refers to the
816 last circle drawn.
818 More generally, objects of a given type are implicitly numbered
819 (starting from 1).  You can refer to (say) the third ellipse in the
820 current picture with \fB3rd ellipse\fP, or to the first box as \fB1st
821 box\fP, or to the fifth line as \fB5th line\fP.
823 Objects are also numbered backwards by type from the last one of 
824 You can say \fB2nd last box\fP to get the second-to-last box, or
825 \fB3rd last ellipse\fP to get the third-to-last box.
827 In places where \fIn\fBth\fR is allowed, \fB`\fIexpr\fB'th\fR is also allowed.
828 Note that
829 .B 'th
830 is a single token: no space is allowed between the
831 .B '
832 and the \fBth\fP.
833 For example,
838 for i = 1 to 4 do {
839    line from `i'th box.nw to `i+1'th box.se
844 .NH 2
845 Naming Objects With Labels
847 You can also specify an object by referring to a label.  A label is a
848 word (which must begin with a capital letter) followed by a colon;
849 you declare it by placing it immediately before the object drawing command.
850 For example, the program
854 \&.PS
855 A: box "first" "object"
856 move;
857 B: ellipse "second" "object"
858 move;
859 arrow left at A;
860 \&.PE
865 declares labels \fBA\fP and \fBB\fP for its first and second objects.
866 Here's what that looks like:
869 A: box "first" "object"
870 move;
871 B: ellipse "second" "object"
872 move;
873 arrow left at A .l;
875 .CE "1: Example of label use"
876 The \fBat\fP statement in the fourth line uses the label \fBA\fP (the
877 behavior of \fBat\fP will be explained in the next section).  We'll
878 see later on that labels are most useful for referring to block composite
879 objects.  
881 Labels are not constants but variables (you can view colon as a sort
882 of assignment).  You can say something like \fBA: A + (1,0);\fP
883 and the effect will be to reassign the label \fBA\fR to designate a
884 position one inch to the right of its old value. 
885 .NH 1
886 Describing locations
888 The location of points can be described in many different ways.  All these
889 forms are interchangeable as for as the \fBpic\fP language syntax is
890 concerned; where you can use one, any of the others that would make 
891 semantic sense are allowed.
893 The special label \fBHere\fR always refers to the current position.
894 .NH 2
895 Absolute Coordinates
897 The simplest is absolute coordinates in inches; \fBpic\fP uses a
898 Cartesian system with (0, 0) at the lower left corner of the virtual
899 drawing surface for each picture (that is, X increases to the right
900 and Y increases upwards).  An absolute location may always be written in the
901 conventional form as two comma-separated numbers surrounded by
902 parentheses (and this is recommended for clarity).  In contexts where
903 it creates no ambiguity, the pair of X and Y coordinates suffices
904 without punctuation.
906 It is a good idea to avoid absolute coordinates, however.  They tend
907 to make picture descriptions difficult to understand and modify.
908 Instead, there are quite a number of ways to specify locations
909 relative to \fBpic\fP objects and previous locations.
911 .NH 2
912 Locations Relative to Objects
914 The symbol \fBhere\fP always refers to the position of the last object
915 drawn or the destination of the last \fBmove\fP.
917 Alone and unqualified, a \fBlast circle\fP or any other way of
918 specifying a closed-object or arc location refers as a position to the
919 geometric center of the object.  Unqualified, the name of a line or
920 spline object refers to the position of the object start.
922 Also, \fBpic\fP objects have quite a few named locations
923 associated with them.  One of these is the object center, which can be
924 indicated (redundantly) with the suffix \fB.center\fP (or just \fB.c\fP).
925 Thus, \fBlast circle \&.center\fP is equivalent to \fBlast
926 circle\fP.
927 .NH 3
928 Locations Relative to Closed Objects
930 Every closed object (box, circle, ellipse, or block composite) also
931 has eight compass points associated with it;
934 define dot {circle fill rad 0.02 at $1}
936 define compass { [
937         ME: $1;
938         dot(ME.c);  "\fB .c\fP"  at ME .c ljust;
939         dot(ME.n);  "\fB.n\fP"   at ME .n above
940         dot(ME.ne); "\fB .ne\fP" at ME .ne above
941         dot(ME.e);  "\fB .e\fP"  at ME .e ljust
942         dot(ME.se); "\fB .se\fP" at ME .se below
943         dot(ME.s);  "\fB.s\fP"   at ME .s below
944         dot(ME.sw); "\fB.sw \fP" at ME .sw below
945         dot(ME.w);  "\fB.w \fP"  at ME .w rjust
946         dot(ME.nw); "\fB.nw \fP" at ME .nw above
947 ] }
948 compass(box wid 1.5 ht 1);
949 move right from last [] .e;
950 compass(circle diam 1);
951 move right from last [] .e;
952 compass(ellipse wid 1.5 ht 1);
954 .CE "1: Compass points"
956 these are the locations where eight compass rays from the geometric center
957 would intersect the figure.  So when we say \fBlast circle .s\fP we are
958 referring to the south compass point of the last circle drawn.  The
959 explanation of Figure 7.3's program is now complete.
961 (In case you dislike compass points, the names \fB.top\fP,
962 \&\fB.bottom\fP, \fB.left\fP and \fB.right\fP are synonyms for \fB.n\fP,
963 \&\fB.s\fP, \fB.e\fP, and \fB.w\fP respectively; they can even be
964 abbreviated to \fB.t\fP, \fB.b\fP, \fB.l\fP and \fB.r\fP).
966 The names \fBcenter\fP, \fBtop\fP, \fBbottom\fP, \fBleft\fP and
967 \fBright\fP can also be used (without the leading dot) in a prefix
968 form marked by \fBof\fP; thus, \fBcenter of last circle\fP and
969 \fBtop of 2nd last ellipse\fP are both valid object references.
971 Arc objects also have compass point; they are the compass points of
972 the implied circle.
973 .NH 3
974 Locations Relative to Open Objects
976 Every open object (line, arrow, arc, or spline) has three named
977 points: \fB.start\fP, \fB.center\fP, and \fB.end\fP.  They can
978 also be used without leading dots in the \fBof\fP prefix form.
979 The center of an arc is the center of its circle, but the center of
980 a line, path, or spline is halfway between its endpoints.
983 define critical {
984         [ ME: $1;
985                 dot(ME.c);     ".center" rjust at ME.center + (-0.1, 0.1)
986                 dot(ME.start); ".start"  rjust at ME.start  + (-0.1, 0.1)
987                 dot(ME.end);   ".end"    rjust at ME.end    + (-0.1, 0.1)
988         ]
989         move down 0.2 from last [] .s;
991 critical(line up right 1);
992 move right from last [] .e;
993 critical(arc rad 0.5 cw);
994 move right from last [] .e;
995 critical(line right 1 then down .5 left 1 then right 1);
996 move right from last [] .e;
997 critical(spline right 1 then up right then left then left 1);
999 .CE "2: Special points on open objects"
1001 .NH 2
1002 Ways of Composing Positions
1004 Once you have two positions to work with, there are several ways to
1005 combine them to specify new positions.
1006 .NH 3
1007 Vector Sums and Displacements
1009 Any two positions may be added or subtracted to yield a new position.
1010 The result is the conventional vector sum or difference of coordinates.
1011 For example, \fBlast box .ne + (0.1, 0)\fP is a valid position.  This 
1012 example illustrates a common use, to define a position slightly offset
1013 from a named one (say, for captioning purposes).
1014 .NH 3
1015 Interpolation Between Positions
1017 A position may be interpolated between any two positions.  The syntax
1018 is `\fIfraction\fP \fBof the way between\fP \fIposition1\fP \fBand\fP
1019 \fIposition2\fP.'  For example, you can say \fB1/3 of the way between
1020 here and last ellipse .ne\fP.  The fraction may be in
1021 numerator/denominator form or may be an ordinary number (values are
1022 \fInot\fP restricted to [0,1]).  As an alternative to this verbose
1023 syntax, you can say `\fIfraction\fP  \fB<\fP\fIposition1\fP \fB,\fP
1024 \fIposition2\fP\fB>\fP.'; thus, the example could also be written
1025 \fB1/3 <here, last ellipse>\fP.
1028 arrow up right;
1029 P: 1/3 of the way between last arrow .start and last arrow .end;
1030 dot(P); move right 0.1; "P";
1032 .CE "3: \fBP: 1/3 of the way between last arrow .start and last arrow .end\fP"
1034 This facility can be used, for example, to double connections.
1037 A: box "yin"; move; B: box "yang";
1038 arrow right at 1/4 <A.e,A.ne>;
1039 arrow left  at 1/4 <B.w,B.sw>;
1041 .CE "4: Doubled arrows"
1043 You can get Figure \n[H1]-4 from the following program:
1047 \&.PS
1048 A: box "yin"; move;
1049 B: box "yang";
1050 arrow right at 1/4 <A.e,A.ne>;
1051 arrow left  at 1/4 <B.w,B.sw>;
1052 \&.PE
1057 Note the use of the short form for interpolating points.
1058 .NH 3
1059 Projections of Points
1061 Given two positions \fIp\fP and \fIq\fP, the position
1062 \fB(\fP\fIp\fP\fB,\fP \fIq\fP\fB)\fP has the X coordinate of \fIp\fP
1063 and the Y coordinate of \fIq\fP.  This can be helpful in placing an
1064 object at one of the corners of the virtual box defined by two other
1065 objects.
1068 box invis wid 2 height 1;
1069 dot(last box .ne); "\fB(B,A)\fP is here" ljust at last circle + (0.1, 0.1);
1070 dot(last box .se); "B" ljust at last circle + (0.1, -0.1)
1071 dot(last box .sw); "\fB(A,B)\fP is here" rjust at last circle + (-0.1, -0.1);
1072 dot(last box .nw); "A" ljust at last circle + (-0.1, 0.1)
1074 .CE "5: Using (\fIx\fP, \fIy\fP) composition"
1075 .NH 2
1076 Using Locations
1078 There are four ways to use locations; \fBat\fP, \fBfrom\fP, \fBto\fP,
1079 and \fBwith\fP.  All three are object modifiers; that is, you use them
1080 as suffixes to a drawing command.
1082 The \fBat\fP modifier says to draw a closed object or arc with its
1083 center at the following location, or to draw a line/spline/arrow
1084 starting at the following location.
1086 The \fBto\fP modifier can be used alone to specify a move destination.
1087 The \fBfrom\fP modifier can be used alone in the same way as \fBat\fP.
1089 The \fBfrom\fP and \fBto\fP modifiers can be used with a \fBline\fR or
1090 \fBarc\fR command to specify start and end points of the object.  In
1091 conjunction with named locations, this offers a very flexible
1092 mechanism for connecting objects.  For example, the following program
1096 \&.PS
1097 box "from"
1098 move 0.75;
1099 ellipse "to"
1100 arc cw from 1/3 of the way \e
1101     between last box .n and last box .ne to last ellipse .n;
1102 \&.PE
1107 yields:
1110 box "from"
1111 move 0.75;
1112 ellipse "to"
1113 arc cw from 1/3 of the way between last box .n and last box .ne to last ellipse .n;
1115 .CE "6: A tricky connection specified with English-like syntax"
1117 The \fBwith\fP modifier allows you to identify a named attachment
1118 point of an object with another point.  This is very useful for connecting
1119 objects in a natural way.  For an example, consider these two programs:
1123         box wid 0.5 ht 0.5; box wid 0.75 ht 0.75;
1124         move down from last box .s 0.1;
1125         "\fBbox wid 0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1127 move from last [].e 2
1129         box wid 0.5 ht 0.5; box wid 0.75 ht 0.75 with .sw at last box .se;
1130         move down from last box .s 0.1;
1131         "\fBbox wid 0.5 ht 0.5; box wid 0.75 ht 0.75 with .sw at last box .se;\fP"
1134 .CE "7: Using the \fBwith\fP modifier for attachments"
1135 .NH 2
1136 The chop modifier
1138 When drawing lines between circles that don't intersect them at a
1139 compass point, it is useful to be able to shorten a line by the radius 
1140 of the circle at either or both ends.  Consider the following program:
1143 \&.PS
1144 circle "x"
1145 circle "y" at 1st circle - (0.4, 0.6) 
1146 circle "z" at 1st circle + (0.4, -0.6) 
1147 arrow from 1st circle to 2nd circle chop 
1148 arrow from 2nd circle to 3rd circle chop 
1149 arrow from 3rd circle to 1st circle chop 
1150 \&.PE
1154 It yields the following:
1157 circle "x"
1158 circle "y" at 1st circle - (0.4, 0.6) 
1159 circle "z" at 1st circle + (0.4, -0.6) 
1160 arrow from 1st circle to 2nd circle chop 
1161 arrow from 2nd circle to 3rd circle chop 
1162 arrow from 3rd circle to 1st circle chop 
1164 .CE "8: The \fBchop\fR modifier"
1166 Notice that the \fBchop\fR attribute moves arrowheads rather than
1167 stepping on them. By default, the \fBchop\fR modifier shortens both
1168 ends of the line by \fBcirclerad\fR.  By suffixing it with a number
1169 you can change the amount of chopping.
1171 If you say \fBline ... chop \fIr1\fP chop \fIr2\fP\fR with \fIr1\fP
1172 and \fIr2\fP both numbers, you can vary the amount of chopping at both
1173 ends.  You can use this in combination with trigonometric functions
1174 to write code that will deal with more complex intersections.
1175 .NH 1
1176 Object Groups
1178 There are two different ways to group objects in \fBpic\fP; \fIbrace
1179 grouping\fP and \fIblock composites\fP.
1180 .NH 2
1181 Brace Grouping
1183 The simpler method is simply to group a set of objects within curly
1184 bracket or brace characters.  On exit from this grouping, the current
1185 position and direction are restored to their value when the opening
1186 brace was encountered.
1187 .NH 2
1188 Block Composites
1190 A block composite object is created a series of commands enclosed by
1191 square brackets.  The composite can be treated for most purposes like
1192 a single closed object, with the size and shape of its bounding box.
1193 Here is an example.  The program fragment
1197 A: [
1198     circle;
1199     line up 1 at last circle .n;
1200     line down 1 at last circle .s;
1201     line right 1 at last circle .e;
1202     line left 1 at last circle .w;
1203     box dashed with .nw at last circle .se + (0.2, -0.2); 
1204     Caption: center of last box;
1210 yields the block in figure \n[H1]-1, which we show both with and
1211 without its attachment points.  The block's location becomes the
1212 value of \fBA\fP.
1215 define junction {
1216         circle;
1217         line up 1 at last circle .n;
1218         line down 1 at last circle .s;
1219         line right 1 at last circle .e;
1220         line left 1 at last circle .w;
1221         box dashed with .nw at last circle .se + (0.2, -0.2); 
1222         Caption: center of last box;
1224 [junction();]
1225 move;
1226 compass([junction()]);
1228 .CE "1: A sample composite object"
1230 To refer to one of the composite's attachment points, you can say
1231 (for example) \fBA .s\fP.  For purposes of object naming, composites
1232 are a class.  You could write \fBlast [] .s\fP as an equivalent
1233 refrence, usable anywhere a location is needed.  This construction is
1234 very important for putting together large, multi-part diagrams.
1235 .PP 
1236 Blocks are also a variable-scoping mechanism, like a \fIgroff\fP(1)
1237 environment.  All variable assignments done inside a block are undone
1238 at the end of it.  To get at values within a block, write a name of
1239 the block followed by a dot, followed by the variable or label you
1240 want.  For example, we could refer the the center of the box in the
1241 above composite as \fBlast [] .Caption\fP or \fBA.Caption\fP.
1243 This kind of reference to a label can be used in any way any other
1244 location can be.  For example, if we added \fB"Hi!" at A.Caption\fP
1245 the result would look like this:
1248 A: [junction();]
1249 "Hi!" at A.Caption;
1251 .CE "2: Adding a caption using interior labeling"
1253 You can also use interior labels in either part of a \fBwith\fR
1254 modifier.  This means that the example composite could be placed
1255 relative to its caption box by a command containing \fBwith A.Caption
1256 at\fP.
1258 Blocks may be nested.  This means you can use block attachment points
1259 to build up complex diagrams hierarchically, from the inside out.
1260 Note that \fBlast\fP and the other sequential naming mechanisms
1261 don't look inside blocks, so if you have a program that looks 
1262 like 
1266 \&.PS
1267 P: [box "foo"; ellipse "bar"];
1268 Q: [
1269         [box "baz"; ellipse "quxx"]
1270         "random text";
1271    ]
1272 arrow from 2nd last [];
1273 \&.PE
1278 the arrow in the last line will be attached to object \fBP\fP, not 
1279 object \fBQ\fP.
1281 In DWB \fBpic\fP, only references one level deep into enclosed blocks
1282 were permitted. GNU \fBgpic\fP removes this restriction.
1284 The combination of block variable scoping, assignability of labels and
1285 the macro facility that we'll describe later on can be used to
1286 simulate functions with local variables (just wrap the macro body in
1287 block braces).
1288 .NH 1
1289 Style Variables
1291 There are a number of global style variables in \fBpic\fR that can be used to
1292 change its overall behavior.  We've mentioned several of them in
1293 previous sections.  They're all described here.  For each variable,
1294 the default is given.
1295 .TS H
1296 tab(@), linesize(2);
1297 lb | lb | lb
1298 l | n | l.
1299 .sp 2p
1300 Style Variable@Default@What It Does
1301 .sp 2p
1303 .sp 2p
1305 boxht@0.5@Default height of a box
1306 boxwid@0.75@Default height of a box
1307 lineht@0.5@Default length of vertical line
1308 linewid@0.75@Default length of horizontal line
1309 linethick@-1@Default line thickness
1310 arcrad @0.25@Default radius of an arc
1311 circlerad@0.25@Default radius of a circle
1312 ellipseht@0.5@Default height of an ellipse
1313 ellipsewid@0.75@Default width of an ellipse
1314 moveht@0.5@Default length of vertical move
1315 movewid@0.75@Default length of horizontal move
1316 textht@0@Default height of box enclosing a text object
1317 textwid@0@Default width of box enclosing a text object
1318 arrowht@0.1@Length of arrowhead along shaft
1319 arrowwid@0.05@Width of rear of arrowhead
1320 arrowhead@1@Enable/disable arrowhead filling
1321 dashwid@0.05@Interval for dashed lines
1322 maxpswid@11@Maximum width of picture
1323 maxpsht@8.5@Maximum height of picture
1324 scale@1@Unit scale factor
1325 fillval@0.5@Default fill value
1326 .sp 5p
1329 Any of these variables can be set with a simple assignment statement.
1330 For example:
1333 [boxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;]
1335 .CE "1: \fBboxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;\fP"
1337 In GNU \fBpic\fR, setting the \fBscale\fR variable re-scales all
1338 size-related state variables so that their values remain equivalent in
1339 the new units.
1341 The command \fBreset\fP resets all style variables to their defaults.
1342 You can give it a comma-separated list of variable names as arguments,
1343 in which case it resets only those.
1345 State variables retain their values across pictures until reset.
1346 .NH 1
1347 Expressions, Variables, and Assignment
1349 A number is a valid expression, of course (all numbers are stored
1350 internally as floating-point).  Decimal-point notation is acceptable;
1351 in GNU \fBgpic\fR, scientific notation in C's `e' format (like
1352 \f(CW5e-2\fP) is accepted.
1354 Anywhere a number is expected, the language will also accept a
1355 variable.  Variables may be the built-in style variable described in
1356 the last section, or new variables created by assignment.
1358 DWB \fBpic\fP supports only the ordinary assignment via =, defines the
1359 variable in the current block if it is not already defined there, and
1360 then changes the value in the current block.
1361 GNU \fBgpic\fP supports an alternate form of assignment using :=. The
1362 .I variable
1363 (right side) must already be defined,
1364 and the value of
1365 .I variable
1366 will be changed only in the innermost block in which it is defined.
1368 You can use the height, width, radius, and x and y coordinates of any
1369 object or corner in expressions If \fBA\fP is an object label or name,
1370 all the following are valid:
1374 A.x                  # x coordinate of the center of A
1375 A.ne.y               # y coordinate of the northeast corner of A
1376 A.wid                # the width of A
1377 A.ht                 # and its height
1378 2nd last circle.rad  # the radius of the 2nd last circle
1382 Note the second expression, showing how to extract a corner coordinate.
1384 Basic arithmetic resembling those of C operators are available; +, *,
1385 -, /, and %.  So is ^ for exponentiation.  Grouping is permitted in
1386 the usual way using parentheses.  GNU \fBgpic\fP allows logical
1387 operators to appear in expressions; ! (logical negation, not
1388 factorial), &&, ||, ==, !=, >=, <=, <, >.
1390 Various built-in functions are supported: \fBsin(\fIx\fB)\fR,
1391 \fBcos(\fIx\fB)\fR, \fBlog(\fIx\fB)\fR, \fBexp(\fIx\fB)\fR,
1392 \fBsqrt(\fIx\fB)\fR, \fBmax(\fIx\fB,\fIy\fB)\fR,
1393 \fBatan2(\fIx\fB,\fIy\fB)\fR, \fBmin(\fIx\fB,\fIy\fB)\fR,
1394 \fBint(\fIx\fB)\fR, \fBrand()\fP, and \fBsrand()\fP.
1395 Both \fBexp\fP and \fBlog\fP are
1396 base 10; \fBint\fP does integer truncation; \fBrand()\fP returns a
1397 random number in [0-1), and \fBsrand()\fP sets the seed for 
1398 a new sequence of pseudo-random numbers to be returned by \fBrand()\fP
1399 (\fBsrand()\fP is a GNU extension).
1401 GNU \fBgpic\fP also documents a one-argument form or rand,
1402 \fBrand(\fIx\fB)\fR, which returns a random number between 1 and
1403 \fIx\fP, but this is deprecated and may be removed in a future
1404 version.
1406 The function \fBsprintf()\fP behaves like a C \fIsprintf\fP(3) that
1407 only takes %, %e, %f, and %g format strings.
1408 .NH 1
1409 Macros
1411 You can define macros in \fBpic\fP.  This is useful for diagrams with
1412 repetitive parts.  In conjunction with the scope rules for block
1413 composites, it effectively gives you the ability to write functions.
1415 The syntax is
1418 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement text \fB}\fP
1422 This defines \fIname\fR as a macro to be replaced by the replacement
1423 text (not including the braces).  The macro may be called as 
1426 \fIname\fB(\fIarg1, arg2, ... argn\fB)\fR
1430 The arguments (if any) will be substituted for tokens $1, $2 ... $n
1431 appearing in the replacement text.
1433 As an example of macro use, consider the following:
1437 \&.PS
1438 # Plot a single jumper in a $1 by $2 box, $3 is the on-off state
1439 define jumper { [
1440     shrinkfactor = 0.8;
1441     Outer: box invis wid 0.5 ht 1;
1443     # Count on end ] to reset these
1444     boxwid = Outer.wid * shrinkfactor / 2;
1445     boxht  = Outer.ht  * shrinkfactor / 2;
1447     box fill (!$1) with .s at center of Outer;
1448     box fill ($1)  with .n at center of Outer;
1449 ] }
1451 # Plot a block of six jumpers
1452 define jumperblock {
1453     jumper($1);
1454     jumper($2);
1455     jumper($3);
1456     jumper($4);
1457     jumper($5);
1458     jumper($6);
1460     jwidth  = last [].Outer.wid;
1461     jheight = last [].Outer.ht;
1463     box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1465     # Use {} to avoid changing position from last box draw.
1466     # This is necessary so move in any direction will work as expected
1467     {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0, -0.2);}
1470 # Sample macro invocations
1471 jumperblock(1,1,0,0,1,0);
1472 move;
1473 jumperblock(1,0,1,0,1,1);
1474 \&.PE
1478 It yields the following:
1481 # Plot a single jumper in a $1 by $2 box, $3 is the on-off state
1482 define jumper { [
1483     shrinkfactor = 0.8;
1484     Outer: box invis wid 0.5 ht 1;
1486     # Count on end ] to reset these
1487     boxwid = Outer.wid * shrinkfactor / 2;
1488     boxht  = Outer.ht  * shrinkfactor / 2;
1490     box fill (!$1) with .s at center of Outer;
1491     box fill ($1)  with .n at center of Outer;
1492 ] }
1494 # Plot a block of six jumpers
1495 define jumperblock {
1496     jumper($1);
1497     jumper($2);
1498     jumper($3);
1499     jumper($4);
1500     jumper($5);
1501     jumper($6);
1503     jwidth  = last [].Outer.wid;
1504     jheight = last [].Outer.ht;
1506     box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1508     # Use {} to avoid changing position from last box draw.
1509     # This is necessary so move in any direction will work as expected
1510     {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0, -0.2);}
1513 # Sample macro invocations
1514 jumperblock(1,1,0,0,1,0);
1515 move;
1516 jumperblock(1,0,1,0,1,1);
1518 .CE "1: Sample use of a macro"
1520 This macro example illustrates how you can combine [], brace grouping,
1521 and variable assignment to write true functions.
1523 One detail the example above does not illustrate is the fact that
1524 macro argument parsing is not token-oriented.  If you call \fBjumper(
1525 1 )\fP, the value of $1 will be \fB" 1 "\fP. You could even call
1526 \fBjumper(big  string)\fP to give $1 the value \fB"big  string"\fP.
1528 If you want to pass in a coordinate pair, you can avoid getting
1529 tripped up by the comma by wrapping the pair in parentheses.
1531 Macros persist through pictures.  To undefine a macro, say \fBundef\fP
1532 \fIname\fR; for example,
1534 \f(CWundef jumper\fP
1535 \f(CWundef jumperblock\fP
1538 would undefine the two macros in the jumper block example.
1539 .NH 1
1540 Import/Export Commands
1542 Commands that import or export data between \fBpic\fR and its
1543 environment are described here.
1544 .NH 2
1545 File and Table Insertion
1547 The statement
1549 \f(CWcopy\fP \fIfilename\fR
1551 inserts the contents of \fIfilename\fR in the \fBpic\fP input stream.
1552 Any .PS/.PE pair in the file will be ignored.  This, you can use this
1553 to include pre-generated images.
1555 A variant of this statement replicates the \fBcopy thru\fP feature of
1556 \fIgrap\fP(1).  If you say
1558 \f(CWcopy\fP \fIfilename\fR \f(CWthru\fP \fImacro\fP
1561 calls the \fImacro\fP (which may be either a name or replacement text)
1562 on the arguments obtained by breaking each line of the file into
1563 blank-separated fields.  The macro may have up to 9 arguments.  The
1564 replacement text may be delimited by braces or by a pair of instances
1565 of any character not appearing in the rest of the text.
1567 If you write
1569 \f(CWcopy thru\fP \fImacro\fP
1572 omitting the filename, lines to be parsed are taken from the input
1573 source up to the next .PE.
1575 In either of the \fBcopy\fP commands, GNU \fBgpic\fP permits a
1576 trailing `\fBuntil\fP \fIword\fP' clause to be added which terminates
1577 the copy when the first word matches the argument (the default
1578 behavior is therefore equivalent to \fBuntil .PE\fP).
1580 Accordingly, the command
1583 .ft CW
1585 \&.PS
1586 copy thru % circle at ($1,$2) % until "END"
1587 1 2
1588 3 4
1589 5 6
1592 \&.PE
1597 is equivalent to
1600 .ft CW
1602 \&.PS
1603 circle at (1,2)
1604 circle at (3,4)
1605 circle at (5,6)
1607 \&.PE
1611 .NH 2
1612 Debug Messages
1614 The command \fBprint\fR accepts any number of comma-separated
1615 arguments, concatenates their output forms, and writes the result to
1616 standard error.  Each argument must be an expression, a position, or
1617 a text string.
1618 .NH 2
1619 Escape to Post-Processor
1621 If you write
1623 \fBcommand\fR \fIarg\fR\|.\|.\|.
1626 \fBpic\fP concatenates the arguments and pass them through as a line
1627 to troff or \*(tx.  Each
1628 .I arg
1629 must be an expression, a position, or text.
1630 This has a similar effect to a line beginning with
1631 .B .
1633 \fB\e\fR,
1634 but allows the values of variables to be passed through.
1635 .NH 2
1636 Executing Shell Commands
1638 The command 
1640 \f(CWsh { \fIanything...\fP }\fP
1643 macroexpands the text in braces, then executes it as a shell command.
1644 This could be used to generate images or data tables for later
1645 inclusion.  The delimiters shown as {} here may also be two copies of
1646 any one character not present in the shell command text.  In either
1647 case, the body may contain balanced {} pairs.  Strings in the body
1648 may contain balanced or unbalanced braces in any case.
1649 .NH 1
1650 Control-flow constructs
1652 The \fBpic\fP language provides conditionals and looping.  For
1653 example,
1657 pi = atan2(0, -1);
1658 for i = 0 to 2 * pi by 0.1 do {
1659     "-" at (i/2, 0);
1660     "." at (i/2, sin(i)/2);
1661     ":" at (i/2, cos(i)/2);
1667 which yields this:
1670 pi = atan2(0, -1);
1671 for i = 0 to 2 * pi by 0.1 do {
1672     "-" at (i/2, 0);
1673     "." at (i/2, sin(i)/2);
1674     ":" at (i/2, cos(i)/2);
1677 .CE "1: Plotting with a \fBfor\fP loop"
1679 The syntax of the \fBfor\fP statement is:
1681 \fBfor\fR \fIvariable\fR \fB=\fR \fIexpr1\fR \fBto\fR \fIexpr2\fR \
1682 [\fBby\fR [\fB*\fR]\fIexpr3\fR] \fBdo\fR \fIX\fR \fIbody\fR \fIX\fR
1684 The semantics are as follows:  Set
1685 .I variable
1686 to \fIexpr\fR1 .
1687 While the value of
1688 .I variable
1689 is less than or equal to
1690 \fIexpr2\fR,
1692 .I body
1693 and increment
1694 .I variable
1696 \fIexpr3\fR;
1698 .B by
1699 is not given, increment
1700 .I variable
1701 by 1.
1703 .I expr3
1704 is prefixed by
1705 .B *
1706 then
1707 .I variable
1708 will instead be multiplied by
1709 \fIexpr3\fR.
1710 .I X
1711 can be any character not occurring in
1712 \fIbody\fR; or the two Xs may be paired braces (as in the \fBsh\fR command).
1714 The syntax of the \fBif\fP statement is as follows:
1716 \fBif\fR \fIexpr\fR \fBthen\fR \fIX\fR \fIif-true\fR \fIX\fR \
1717 [\fBelse\fR \fIY\fR \fIif-false\fR \fIY\fR]
1719 Its semantics are as follows: Evaluate
1720 \fIexpr\fR;
1721 if it is non-zero then do
1722 \fIif-true\fR,
1723 otherwise do
1724 \fIif-false\fR.
1725 .I X
1726 can be any character not occurring in
1727 \fIif-true\fR.
1728 .I Y
1729 can be any character not occurring in
1730 \fIif-false\fR.
1732 Eithe or both of the X or Y pairs may instead be balanced pairs of
1733 braces ({ and }) as in the \fBsh\fR command.  In either case, the
1734 \fIif-true\fR may contain balanced pairs of braces.  None of these
1735 delimiters will be seen inside strings.
1737 All the usual relational operators my be used in conditional expressions;
1738 ! (logical negation, not factorial), &&, ||, ==, !=, >=, <=, <, >.
1740 String comparison is also supported using == and !=.  String
1741 comparisons may need to be parenthesized to avoid syntactic
1742 ambiguities.
1743 .NH 1
1744 Interface To [gt]roff
1746 The output of \fBpic\fP is \fB[gt]roff\fP drawing commands.  The GNU
1747 \fIgpic\fP(1) command warns that it relies on drawing extensions
1748 present in \fIgroff\fP(1) that are not present in \fItroff\fP(1).
1749 .NH 2
1750 Scaling Arguments
1752 The DWB \fIpic\fP(1) program will accept one or two arguments to
1753 \&\fB.PS\fP, which is interpreted as a width and height in inches to
1754 which the results of \fIpic\fP(1) should be scaled (width and height
1755 scale independently).  If there is only one argument, it is
1756 interpreted as a width to scale the picture to, and height will be
1757 scaled by the same proportion.
1759 GNU \fBgpic\fP is less general; it will accept a single width to scale
1760 to, or a zero width and a maximum height to scale to.  With
1761 two nonzero arguments, it will scale to the maximum height.
1762 .NH 2
1763 How Scaling is Handled
1765 When \fBpic\fP processes a picture description on input, it passes .PS
1766 and .PE through to the postprocessor. The .PS gets decorated with two
1767 numeric arguments which are the X and Y dimensions of the picture in
1768 inches.  The post-processor can use these to reserve space for the
1769 picture and center it.
1771 The \fBmgs\fP macros, for example, include the following definitions:
1775 \&.de PS
1776 \&.br
1777 \&.sp \e\en[DD]u
1778 \&.ie \e\en[.$]<2 .@error bad arguments to PS (not preprocessed with pic?)
1779 \&.el \e{\e
1780 \&.     ds@need (u;\e\e$1)+1v
1781 \&.     in +(u;\e\en[.l]-\e\en[.i]-\e\e$2/2>?0)
1782 \&.\e}
1783 \&..
1784 \&.de PE
1785 \&.par@reset
1786 \&.sp \e\en[DD]u+.5m
1787 \&..
1792 Equivalent definition will be supplied by GNU \fIpic\fP(1) if you use
1793 the -mpic option; this should make it usable with macro pages other
1794 than \fIms\fR(1).
1796 If .PF is used instead of .PE, the \fBtroff\fP position is restored to
1797 what it was at the picture start (Kernighan notes that the F stands
1798 for "flyback").
1800 The invocation
1802 \&\fB.PS <\fP\fIfile\fP
1805 causes the contents of \fIfile\fP to replace the .PS line.  This
1806 feature is deprecated; use \fBcopy file\fR instead).
1808 By default, input lines that begin with a period are passed to the
1809 postprocessor, embedded at the corresponding point in the output.
1810 Messing with horizontal or vertical spacing is an obvious recipe for
1811 bugs, but point size and font changes will usually be safe.
1813 Point sizes and font changes are also safe within text strings, as
1814 long as they are undone before the end of string.
1816 The state of \fB[gt]roff\fP's fill mode is preserved across pictures.
1818 The Kernighan paper notes that there is a subtle problem with
1819 complicated equations inside \fBpic\fR pictures; they come out wrong if
1820 \fIeqn\fP(1)  has to leave extra vertical space for the equation.
1821 If your equation involves more than subscripts and superscripts, you
1822 must add to the beginning of each equation the extra information
1823 \f(CWspace 0\fP.  He gives the following example:
1827 arrow
1828 box "$space 0 {H( omega )} over {1 - H( omega )}$"
1829 arrow
1834 delim @@
1838 arrow
1839 box "@space 0 {H( omega )} over {1 - H( omega )}@"
1840 arrow
1842 .CE "1: Equations within pictures"
1843 .NH 1
1844 Interface to TeX
1847 \*(tx mode is enabled by the
1848 .B \-t
1849 option.
1850 In \*(tx mode, pic will define a vbox called
1851 .B \egraph
1852 for each picture.
1853 You must yourself print that vbox using, for example, the command
1857 \ecenterline{\ebox\egraph}
1860 Actually, since the vbox has a height of zero this will produce
1861 slightly more vertical space above the picture than below it;
1865 \ecenterline{\eraise 1em\ebox\egraph}
1868 would avoid this.
1870 You must use a \*(tx driver that supports the
1871 .B tpic
1872 specials, version 2.
1874 Lines beginning with
1875 .B \e
1876 are passed through transparently; a
1877 .B %
1878 is added to the end of the line to avoid unwanted spaces.
1879 You can safely use this feature to change fonts or to
1880 change the value of \fI\ebaselineskip\fR.
1881 Anything else may well produce undesirable results; use at your own risk.
1882 Lines beginning with a period are not given any special treatment.
1884 The \*(tx mode of \fIpic\fP(1) will \fInot\fP translate \fBtroff\fP
1885 font and size changes included in text strings!
1886 .NH 1
1887 Obsolete Commands
1889 GNU \fIgpic\fP(1)  has a command
1891 \fBplot\fR \fIexpr\fR [\fB"\fItext\fB"\fR]
1893 This is a text object which is constructed by using
1894 .I text
1895 as a format string for sprintf
1896 with an argument of
1897 \fIexpr\fP.
1899 .I text
1900 is omitted a format string of "%g" is used.
1901 Attributes can be specified in the same way as for a normal text
1902 object.
1903 Be very careful that you specify an appropriate format string;
1904 \fBpic\fP does only very limited checking of the string.
1905 This is deprecated in favour of
1906 \fBsprintf\fP.
1907 .NH 1
1908 Some Larger Examples
1910 Here are a few larger examples, with complete source code.
1912 One of our earlier examples is generated in an instructive way using a
1913 for loop:
1917 \&.PS
1918 # Draw a demonstration up left arrow with grid box overlay
1919 define gridarrow
1921     [
1922         {arrow up left $1;}
1923         box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
1924         for i = 2 to ($1 / 0.5) do
1925         {
1926             box wid 0.5 ht 0.5 dotted with .sw at last box .se;
1927         }
1928         move down from last arrow .center;
1929         [
1930             if ( $1 == boxht ) \e
1931             then { "\efBline up left\efP" } \e
1932             else { sprintf("\efBarrow up left %g\efP", $1) };
1933         ]
1934     ] 
1935     move right from last [] .e;
1937 gridarrow(0.5);
1938 gridarrow(1);
1939 gridarrow(1.5);
1940 gridarrow(2);
1941 undef gridarrow
1942 \&.PE
1948 # Draw a demonstration up left arrow with grid box overlay
1949 define gridarrow
1951         [
1952                 {arrow up left $1;}
1953                 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
1954                 for i = 2 to ($1 / 0.5) do
1955                 {
1956                         box wid 0.5 ht 0.5 dotted with .sw at last box .se;
1957                 }
1958                 move down from last arrow .center;
1959                 [
1960                         if ( $1 == boxht ) \
1961                         then { "\fBline up left\fP" } \
1962                         else { sprintf("\fBarrow up left %g\fP", $1) };
1963                 ]
1964         ] 
1965         move right from last [] .e;
1967 gridarrow(0.5);
1968 gridarrow(1);
1969 gridarrow(1.5);
1970 gridarrow(2);
1971 undef gridarrow
1973 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
1975 Here's an example concocted to demonstrate layout of a large,
1976 multiple-part pattern:
1980 \&.PS
1981 define filter {box ht 0.25 rad 0.125}
1982 lineht = 0.25;
1983 Top: [
1984     right;
1985     box "\efBms\efR" "sources";
1986     move;
1987     box "\efBHTML\efR" "sources";
1988     move;
1989     box "\efBlinuxdoc-sgml\efP" "sources" wid 1.5;
1990     move;
1991     box "\efBTexinfo\efP" "sources";
1993     line down from 1st box .s lineht;
1994     A: line down;
1995     line down from 2nd box .s; filter "\efBhtml2ms\efP";
1996     B: line down;
1997     line down from 3rd box .s; filter "\efBformat\efP";
1998     C: line down;
1999     line down from 4th box .s; filter "\efBtexi2roff\efP";
2000     D: line down;
2002 move down 1 from last [] .s;
2003 Anchor: box wid 1 ht 0.75 "\efBms\efR" "intermediate" "form";
2004 arrow from Top.A.end to Anchor.nw;
2005 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2006 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2007 arrow from Top.D.end to Anchor.ne
2009     # PostScript column
2010     move to Anchor .sw;
2011     line down left then down ->;
2012     filter "\efBpic\efP";
2013     arrow;
2014     filter "\efBeqn\efP";
2015     arrow;
2016     filter "\efBtbl\efP";
2017     arrow;
2018     filter "\efBgroff\efP";
2019     arrow;
2020     box "PostScript";
2022     # HTML column
2023     move to Anchor .se;
2024     line down right then down ->;
2025     A: filter dotted "\efBpic2img\efP";
2026     arrow;
2027     B: filter dotted "\efBeqn2html\efP";
2028     arrow;
2029     C: filter dotted "\efBtbl2html\efP";
2030     arrow;
2031     filter "\efBms2html\efP";
2032     arrow;
2033     box "HTML";
2035     # Nonexistence caption
2036     box dashed wid 1 at B + (2, 0) "These tools" "don't yet exist";
2037     line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2038     line chop 0 chop 0.1 dashed from last box .w  to B.e ->;
2039     line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2041 \&.PE
2047 define filter {box ht 0.25 rad 0.125}
2048 lineht = 0.25;
2049 Top: [
2050     right;
2051     box "\fBms\fR" "sources";
2052     move;
2053     box "\fBHTML\fR" "sources";
2054     move;
2055     box "\fBlinuxdoc-sgml\fP" "sources" wid 1.5;
2056     move;
2057     box "\fBTexinfo\fP" "sources";
2059     line down from 1st box .s lineht;
2060     A: line down;
2061     line down from 2nd box .s; filter "\fBhtml2ms\fP";
2062     B: line down;
2063     line down from 3rd box .s; filter "\fBformat\fP";
2064     C: line down;
2065     line down from 4th box .s; filter "\fBtexi2roff\fP";
2066     D: line down;
2068 move down 1 from last [] .s;
2069 Anchor: box wid 1 ht 0.75 "\fBms\fR" "intermediate" "form";
2070 arrow from Top.A.end to Anchor.nw;
2071 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2072 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2073 arrow from Top.D.end to Anchor.ne
2075     # PostScript column
2076     move to Anchor .sw;
2077     line down left then down ->;
2078     filter "\fBpic\fP";
2079     arrow;
2080     filter "\fBeqn\fP";
2081     arrow;
2082     filter "\fBtbl\fP";
2083     arrow;
2084     filter "\fBgroff\fP";
2085     arrow;
2086     box "PostScript";
2088     # HTML column
2089     move to Anchor .se;
2090     line down right then down ->;
2091     A: filter dotted "\fBpic2img\fP";
2092     arrow;
2093     B: filter dotted "\fBeqn2html\fP";
2094     arrow;
2095     C: filter dotted "\fBtbl2html\fP";
2096     arrow;
2097     filter "\fBms2html\fP";
2098     arrow;
2099     box "HTML";
2101     # Nonexistence caption
2102     box dashed wid 1 at B + (2, 0) "These tools" "don't yet exist";
2103     line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2104     line chop 0 chop 0.1 dashed from last box .w  to B.e ->;
2105     line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2108 .CE "2: Hypothetical production flow for dual-mode publishing"
2110 .\"%%REFERENCE%%
2111 .NH 1
2112 PIC Reference
2114 This is an annotated grammar of PIC.
2115 .NH 2
2116 Lexical Items
2118 In general, \fBpic\fP is a free-format, token-oriented language that
2119 ignores whitespace outside strings.  But certain lines and contructs
2120 are specially interpreted at the lexical level:
2122 A comment begins with # and continues to \en (comments may also follow
2123 text in a line).  A line beginning with a period or backslash may be
2124 interpreted as text to be passed through to the post-processor,
2125 depending on command-line options.  An end-of-line backslash is
2126 interpreted as a request to continue the line; the backslash and
2127 following newline are ignored.
2129 Here are the grammar terminals:
2130 .IP <number> 
2131 A decimal numeric constant.  May contain a decimal point or be
2132 expressed in scientific notation in the style of \fIprintf\fP(3)'s %e
2133 escape. (All variables are represented internally in floating-point.)
2134 .IP <string>
2135 Any ASCII characters surrounded by a pair of double quotes.  May
2136 contain a double quote if preceded by a backslash.
2137 .IP <variable>
2138 A lower-case alphabetic character, followed by any number of
2139 alphanumerics.  (Values of variables are preserved across pictures.)
2140 .IP <label>
2141 An upper-case alphabetic character, followed by any number of
2142 alphanumerics.
2143 .NH 2
2144 Semi-Formal Grammar
2146 Tokens not enclosed in <> are literals, except:
2147 .IP 1.
2148 \en is a newline
2149 .IP 2.
2150 three dots is a suffix meaning \&`replace with 0 or more repetitions
2151 of the preceding element.
2152 .IP 3.
2153 enclosure in square brackets has its usual meaning of `this clause is
2154 optional'.
2155 .IP 4.
2156 Square-bracket-enclosed portions within tokens are optional.  Thus,
2157 \fBh[eigh]t\fR matches either `height' or `ht'.
2159 If one of these special tokens has to be referred to literally, it is
2160 surrounded with single quotes.
2162 The top-level \fBpic\fP object is a picture.
2165 <picture>    ::= .PS [width [height]]\en
2166                  <statement> ...
2167                  .PE \en
2171 The \fIwidth\fP and \fIheight\fP arguments, if present, cause
2172 \fBpic\fR to attempt to scale the picture to the given dimensions in
2173 inches.  In no case, however, will the X and Y dimensions of the
2174 picture exceed the values of the style variables \fBmaxpswid\fP,
2175 \fBmaxpsheight\fP (which default to the normal 8.5 by 11 page size)\fP.
2177 If the ending .PS is replaced by .PF, the page vertical position is
2178 restored to its value at the time .PS was encountered.  Another
2179 alternate form of invocation is \f(CW.PS <\fIfilename\fR, which
2180 replaces the .PS line with a file to be interpreted by \fBpic\fR (but
2181 this feature is deprecated).
2183 The .PS, .PE, and .PF macros to perform centering and scaling are
2184 normally supplied by the post-processor.
2188 <statement>  ::= <command> ;
2189                  <command> \en
2191 <command>    ::= <primitive> <modifier>...
2192                  <label> : <command>
2193                  <label> : <position>
2194                  <variable> = <expr>
2195                  <direction>
2196                  { <command> ... }
2197                  '[' <command> ... ']'
2198                  for <var> = <expr> to <expr> [by <expr>] do { <command> ... }
2199                  if <expr> then { <command> ... } [else { <command> ... }]
2200                  copy <filename> [until <word>]
2201                  copy <filename> thru <macroname> [until <word>] 
2202                  sh <balanced-text>
2203                  print <print-item>
2204                  reset [ <variable> ... ]
2208 The current position and direction are saved on entry to a { } and
2209 restored on exit from it.
2211 Drawn objects within [ ] are treated as a single composite object with
2212 a rectangular shape (that of the bounding box of all the elements).
2213 Variable and label assignments within a block are local to the block.
2214 Current direction of motion is restored to the value at start of block
2215 upon exit.  Position is \fInot\fR restored (unlike { }) instead, the
2216 current position becomes the exit position for the current direction
2217 on the block's bounding box.
2220 <primitive>  ::= box                   \fR# Closed object -- rectangle\fP
2221                  circle                \fR# Closed object -- circle\fP
2222                  ellipse               \fR# Closed object -- ellipse\fP
2223                  arc                   \fR# Open object -- quarter-circle\fP
2224                  line                  \fR# Open object -- line\fP
2225                  arrow                 \fR# Open object -- line with arrowhead\fP
2226                  spline                \fR# Open object -- spline curve\fP
2227                  move
2228                  <text> <text> ...     \fR# Text within invisible box\fP
2230 <attribute>  ::= h[eigh]t <expr>       \fR# Set height of closed figure \fP
2231                  wid[th] <expr>        \fR# Set width of closed figure \fP
2232                  rad[ius] <expr>       \fR# Set radius of circle/arc \fP
2233                  diam[eter] <expr>     \fR# Set diameter of circle/arc \fP
2234                  up [ <expr> ]         \fR# Move up \fP
2235                  down [ <expr> ]       \fR# Move down \fP
2236                  left [ <expr> ]       \fR# Move left \fP
2237                  right [ <expr> ]      \fR# Move right \fP
2238                  from <position>       \fR# Set from position of open figure\fP
2239                  to <position>         \fR# Set to position of open figure\fP
2240                  at <position>         \fR# Set center of open figure\fP
2241                  with <corner>         \fR# Fix corner at specified location\fP
2242                  by <expr> <expr>      \fR# Set object's attachment point\fP
2243                  then                  \fR# Sequential segment composition\fP
2244                  dotted [ <expr> ]     \fR# Set dotted line style\fP
2245                  dashed [ <expr> ]     \fR# Set dashed line style\fP
2246                  chop [ <expr> ]       \fR# Chop end(s) of segment\fP
2247                  ->                    \fR# Decorate with "to" arrow\fP
2248                  <-                    \fR# Decorate with "from" arrow\fP
2249                  <->                   \fR# Decorate with both arrows\fP
2250                  invis                 \fR# Make primitive invisible\fP
2251                  solid                 \fR# Make closed figure solid\fP
2252                  fill <expr>           \fR# Set fill density for figure\fP
2253                  colo[u]r[ed] <word>   \fR# Set fill and outline color for figure\fP
2254                  outline[d] <word>     \fR# Set outline color for figure\fP
2255                  shaded <word>         \fR# Set fill color for figure\fP
2256                  same                  \fR# Copy size of previous object\fP
2257                  <text> <text> ...     \fR# Text within object\fP
2258                  <expr>                \fR# Motion in the current direction\fR
2262 Missing attributes are supplied from defaults; inappropriate ones are
2263 silently ignored.  For lines, splines, and arcs, height and width
2264 refer to arrowhead size.
2266 The \f(CWat\fP primitive sets the center of the current object.  The
2267 \f(CWwith\fP attribute fixes the specified feature of the given object
2268 to a specified location.
2270 The \f(CWby\fR primitive is not documented in the tutorial portion of
2271 the Kernighan paper, and should probably be considered unreliable.
2273 The primitive \fBarrow\fR is a synonym for \fBline ->\fR.
2276 <text>  ::=      <string> [ <placement> ... ]
2277                  sprintf("format", <expr> ...) [ <placement> ... ]
2279 <placement> ::=  center | ljust | rjust | above | below
2283 Text is normally an attribute of some object, in which case successive
2284 strings are vertically stacked and centered on the object's center by
2285 default.  Standalone text is treated as though placed in an invisible
2286 box.
2288 A text item consists of a string or sprintf-expression, optionally
2289 followed by positioning information.  Text or format strings may
2290 contain {gtn}roff font changes, size changes, and local motions,
2291 provided those changes are undone before the end of the current item.
2293 A position is an (x, y) coordinate pair.  There are lots of different
2294 ways to specify positions:
2297 <position>  ::=  <expr> , <expr>
2298                  <place> {+-} <expr> , <expr> 
2299                  <place> {+-} ( <expr> , <expr> )
2300                  ( <position> , <position> )
2301                  <expr> [of the way] between <position> and <position> 
2302                  <expr> '<' <position> , <position> '>'
2303                  ( <position> )
2305 <place>  ::=     <label> [ <dot-corner> ]
2306                  <corner> of <label>
2307                  [0|1|2|3|4|5|6|7|8|9]th [last] <primitive> <dot-corner>
2308                  <expr>'th [last]<primitive> <dot-corner>
2309                  <corner> of [0|1|2|3|4|5|6|7|8|9]th [last] <primitive>
2310                  <corner> of <expr>'th [last] <primitive>
2311                  Here
2313 <dot-corner> ::= .n | .e | .w | .s | .ne | .nw | .se | .sw | .c | .start | .end
2315 <corner> ::=     top | bot | left | right | start | end
2319 As Kernighan notes, "since barbarisms like \fB1th\fP and \fB3th\fP are
2320 barbaric, synonyms like \fB1st\fP and \fB3rd\fP are accepted as well".
2321 Objects of a given type are numbered from 1 upwards in order of
2322 declaration; the \fBlast\fP modifier counts backwards.
2324 The "'th" form (which allows you to select a previous object with an
2325 expression, as opposed to a numeric literal) is not documented in DWB
2326 \fBpic\fR(1).
2328 The following style variables control output:
2329 .TS H
2330 tab(@), linesize(2);
2331 lb | lb | lb
2332 l | n | l.
2333 .sp 2p
2334 Style Variable@Default@What It Does
2335 .sp 2p
2337 .sp 2p
2339 boxht@0.5@Default height of a box
2340 boxwid@0.75@Default height of a box
2341 lineht@0.5@Default length of vertical line
2342 linewid@0.75@Default length of horizontal line
2343 arcrad @0.25@Default radius of an arc
2344 circlerad@0.25@Default radius of a circle
2345 ellipseht@0.5@Default height of an ellipse
2346 ellipsewid@0.75@Default width of an ellipse
2347 moveht@0.5@Default length of vertical move
2348 movewid@0.75@Default length of horizontal move
2349 textht@0@Default height of box enclosing a text object
2350 textwid@0@Default width of box enclosing a text object
2351 arrowht@0.1@Length of arrowhead along shaft
2352 arrowwid@0.05@Width of rear of arrowhead
2353 arrowhead@1@Enable/disable arrowhead filling
2354 dashwid@0.05@Interval for dashed lines
2355 maxpswid@11@Maximum width of picture
2356 maxpsht@8.5@Maximum height of picture
2357 scale@1@Unit scale factor
2358 fillval@0.5@Default fill value
2359 .sp 5p
2362 Any of these can be set by assignment, or reset using the \fBreset\fP
2363 statement.  Style variables assigned within [] blocks are restored to
2364 their beginning-of-block value on exit; top-level assignments persist
2365 across pictures.  Dimensions are divided by \fBscale\fR on output.
2367 All \fBpic\fP expressions are evaluated in floating point; units
2368 default to inches.  Expressions have the following simple grammar,
2369 with semantics very similar to C expressions:
2372 <expr> ::=       <expr> <op> <expr>
2373                  ! <expr>
2374                  ( <expr> )
2375                  - <expr>
2376                  <variable>
2377                  <number>
2378                  <place> .x
2379                  <place> .y
2380                  <place> .ht
2381                  <place> .wid
2382                  <place> .rad
2383                  sin(<expr>)
2384                  cos(<expr>)
2385                  log(<expr>)
2386                  exp(<expr>)
2387                  sqrt(<expr>)
2388                  max(<expr>, <expr>...)
2389                  atan2(<expr>, <expr>)
2390                  min(<expr>, <expr>...)
2391                  int(<expr>)
2392                  rand()
2394 <op>  :=         + | - | * | / | % | ^ |
2395                  != | == | '<' | '>' | >= | <= |
2396                  '||' | &&
2400 Both \fBexp\fP and \fBlog\fP are base 10; \fBint\fP does integer
2401 truncation; and \fBrand()\fP returns a random number in [0-1).
2403 There are \fBdefine\fP and \fBundef\fR statements which are not part
2404 of the grammar (they behave as pre-processor macros to the language).
2405 These may be used to define pseudo-functions.
2408 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement text \fB}\fP
2412 This defines \fIname\fR as a macro to be replaced by the replacement
2413 text (not including the braces).  The macro may be called as 
2416 \fIname\fB(\fIarg1, arg2, ... argn\fB)\fR
2420 The arguments (if any) will be substituted for tokens $1, $2 ... $n
2421 appearing in the replacement text. To undefine a macro, say \fBundef\fP
2422 \fIname\fR, specifying the name to be undefined.
2423 .\"%%POSTLUDE%%
2424 .NH 1
2425 History and Acknowledgements
2427 Original \fBpic\fP was written to go with Joseph Ossanna's original
2428 \fItroff\fP(1) by Brian Kernighan, and later re-written by Kernighan
2429 with substantial enhancements (apparently as part of the evolution of
2430 \fItroff\fP(1) into \fIditroff\fP(1) to generate
2431 device-independent output).
2433 The language had been inspired by some earlier graphics languages
2434 including \fBideal\fP and \fBgrap\fP.  Kernighan credits Chris van Wyk
2435 (the designer of \fBideal\fP) with many of the ideas that went into
2436 \fBpic\fP.
2438 delim $$
2441 The \fBpic\fP language was originally described by Brian Kernighan in
2442 Bell Labs Computing Science Technical Report #116 (you can obtain a
2443 PostScript copy of the revised version, [1], by sending a mail message to
2444 \fInetlib@research.att.com\fP with a body of \&`send 116 from
2445 research/cstr').  There have been two revisions, in 1984 and 1991.
2447 The document you are reading effectively subsumes Kernighan's
2448 description; it was written to fill in lacunae in the exposition and
2449 integrate in descriptions of the GNU \fIgpic\fP(1) features.
2451 The GNU \fBgpic\fR implementation was written and is maintained by
2452 James Clark \fI<jjc@jclark.com>\fP.
2453 .NH 1
2454 Bibliography
2455 .IP 1.
2456 Kernighan, B. W. \fBPIC -- A Graphics Language for Typesetting
2457 (Revised User Manual)\fP Bell Labs Computing Science Technical Report
2458 #116, December 1991.
2459 .IP 2.
2460 Van Wyk, C.J. \fBA high-level language for specifying pictures\fP \fIACM
2461 Transactions On Graphics\fP 1,2 (1982) 163-182.