Get rid of the old texinfo.
[dragonfly.git] / contrib / groff / doc / pic.ms
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: pic.ms,v 1.19 2002/09/20 12:14:56 wlemb Exp $      
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
24 ..
25 .\" Definitions end here
26 .TL
27 Making Pictures With GNU PIC
28 .AU
29 Eric S. Raymond
30 .AI
31 \[la]\fIesr@snark.thyrsus.com\fP\[ra]
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 \[lq]DWB pic\[rq].  Details on the history of the program are given at the
68 end 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
96 .R
97 .KE
98 .LP
99 where \[la]nnn\[ra] is a line number, and \[la]token\[ra] is a token near (usually
100 just after) the error location.
101 .NH 1
102 Basic PIC Concepts
103 .PP
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:
109 .KS
110 .PS
111 ellipse "document";
112 arrow;
113 box width 0.6 "\fIgpic\/\fP(1)"
114 arrow;
115 box width 1.1 "\fIgtbl\/\fP(1) or \fIgeqn\/\fP(1)" "(optional)" dashed;
116 arrow;
117 box width 0.6 "\fIgtroff\/\fP(1)";
118 arrow;
119 ellipse "PostScript"
120 .PE
121 .CE "1: Flow of \fBpic\fP data"
122 .PP
123 This was produced from the following \fBpic\fP program:
124 .KS
125 .DS
126 .ps -1
127 .vs -1
128 .CW
129 \&.PS
130 ellipse "document";
131 arrow;
132 box width 0.6 "\efIpic\e/\efP(1)"
133 arrow;
134 box width 1.1 "\efIgtbl\e/\efP(1) or \efIgeqn\e/\efP(1)" "(optional)" dashed;
135 arrow;
136 box width 0.6 "\efIgtroff\e/\efP(1)";
137 arrow;
138 ellipse "PostScript"
139 \&.PE
140 .DE
141 .R
142 .KE
143 .LP
144 This little program illustrates several \fBpic\fP basics.  Firstly, we
145 see how to invoke three object types; ellipses, arrows, and boxes.  We
146 see how to declare text lines to go within an object (and that text
147 can have font changes in it).  We see how to change the line style of
148 an object from solid to dashed.  And we see that a box can be made
149 wider than its default size to accommodate more text (we'll discuss
150 this facility in detail in the next section).
151 .PP
152 We also get to see \fBpic\fP's simple syntax.  Statements are ended by
153 newlines or semicolons.  String quotes are required around all text
154 arguments, whether or not they contain spaces.  In general, the order
155 of command arguments and modifiers like \[lq]width 1.2\[rq] or
156 \[lq]dashed\[rq] doesn't matter, except that the order of text arguments
157 is significant.
158 .PP
159 Here are all but one of the basic \fBpic\fP objects at their default sizes:
160 .KS
161 .PS
162 box "box";
163 move;
164 line "line" "";
165 move;
166 arrow "arrow" "";
167 move;
168 circle "circle";
169 move;
170 ellipse "ellipse";
171 move;
172 arc; down; move; "arc"
173 .PE
174 .CE "2: Basic \fBpic\fP objects"
175 .PP
176 The missing simple object type is a \fIspline\fP.  There is also a way
177 to collect objects into \fIblock composites\fP which allows you to
178 treat the whole group as a single object (resembling a box) for many
179 purposes.  We'll describe both of these later on.
180 .PP
181 The box, ellipse, circle, and block composite objects are \fIclosed\/\fR;
182 lines, arrows, arcs and splines are \fIopen\fP.  This distinction
183 will often be important in explaining command modifiers.
184 .PP
185 Figure \n[H1]-2 was produced by the following \fBpic\fP program,
186 which introduces some more basic concepts:
187 .KS
188 .DS
189 .CW
190 \&.PS
191 box "box";
192 move;
193 line "line" "";
194 move;
195 arrow "arrow" "";
196 move;
197 circle "circle";
198 move;
199 ellipse "ellipse";
200 move;
201 arc; down; move; "arc"
202 \&.PE
203 .DE
204 .ft R
205 .KE
206 .PP
207 The first thing to notice is the \fImove\fP command, which moves a
208 default distance (1/2 inch) in the current movement direction.
209 .PP
210 Secondly, see how we can also decorate lines and arrows with text.
211 The line and arrow commands each take two arguments here, specifying
212 text to go above and below the object.  If you wonder why one argument
213 would not do, contemplate the output of \fBarrow "ow!"\fP:
214 .KS
215 .PS
216 arrow "ow!"
217 .PE
218 .CE "3: Text centered on an arrow"
219 .PP
220 When a command takes one text string, \fBpic\fP tries to place it at
221 the object's geometric center.  As you add more strings, \fBpic\fP
222 treats them as a vertical block to be centered.  The program
223 .KS
224 .DS
225 .CW
226 line "1";
227 line "1" "2";
228 line "1" "2" "3";
229 line "1" "2" "3" "4";
230 line "1" "2" "3" "4" "5";
231 .DE
232 .ft R
233 .KE
234 .LP
235 for example, gives you this:
236 .KS
237 .sp 2
238 .PS
239 line "1";
240 line "1" "2";
241 line "1" "2" "3";
242 line "1" "2" "3" "4";
243 line "1" "2" "3" "4" "5";
244 .PE
245 .sp 2
246 .CE "4: Effects of multiple text arguments"
247 .PP
248 The last line of Figure 3.2's program, `\fBarc; down; move;
249 "arc"\fP', describing the captioned arc, introduces several new ideas.
250 Firstly, we see how to change the direction in which objects are
251 joined.  Had we written \fBarc; move; "arc"\fP,
252 omitting \fBdown\fP the caption would have been joined to the top
253 of the arc, like this:
254 .KS
255 .PS
256 arc; move; "arc";
257 .PE
258 .CE "5: Result of \fBarc; move; \"arc\"\fP"
259 .PP
260 This is because drawing an arc changes the default direction to the
261 one its exit end points at.  To reinforce this point, consider:
262 .KS
263 .PS
264 arc cw; move; "arc";
265 .PE
266 .CE "6: Result of \fBarc cw; move; \"arc\"\fP"
267 .PP
268 All we've done differently here is specify \[lq]cw\[rq] for a clockwise arc
269 (\[lq]ccw\[rq] specifies counter-clockwise direction).
270 Observe how it changes the default direction to down, rather than up.
271 .PP
272 Another good way to see this via with the following program:
273 .KS
274 .DS
275 .CW
276 line; arc; arc cw; line
277 .DE
278 .ft R
279 .KE
280 .LP
281 which yields:
282 .KS
283 .PS
284 line; arc; arc cw; line;
285 .PE
286 .CE "7: Result of \fBline; arc; arc cw; line\fP"
287 .LP
288 Notice that we did not have to specify \[lq]up\[rq] for the second arc to be
289 joined to the end of the first.
290 .PP
291 Finally, observe that a string, alone, is treated as text to be
292 surrounded by an invisible box of a size either specified by width
293 and height attributes or by the defaults \fBtextwid\fR and
294 \fBtextht\fR.  Both are initially zero (because we don't know the
295 default font size).
296 .NH 1 
297 Sizes and Spacing
298 .PP
299 Sizes are specified in inches.  If you don't like inches, it's
300 possible to set a global style variable \fBscale\fP that changes the
301 unit.  Setting \fBscale = 2.54\fP will effectively change the internal
302 unit to centimeters (all other size variable values will be scaled
303 correspondingly).
304 .NH 2
305 Default Sizes of Objects
306 .PP
307 Here are the default sizes for \fBpic\fP objects:
308 .TS H
309 center, tab(@), linesize(2);
310 lb | lb
311 l | l.
312 .sp 2p
313 Object@Default Size
314 .sp 2p
315 _
316 .sp 2p
317 .TH
318 box@0.75" wide by 0.5" high
319 circle@0.5" diameter
320 ellipse@0.75" wide by 0.5" high
321 arc@0.5" radius
322 line@0.5" long
323 arrow@0.5" long
324 .sp 5p
325 _
326 .TE
327 .PP
328 The simplest way to think about these defaults is that they make the
329 other basic objects fit snugly into a default-sized box.
330 .NH 2
331 Objects Do Not Stretch!
332 .PP
333 Text is rendered in the current font with normal troff line spacing.
334 Boxes, circles, and ellipses do \fInot\fP automatically resize to fit
335 enclosed text.  Thus, if you say \fBbox "this text far too long for a
336 default box"\fP you'll get this:
337 .KS
338 .PS
339 box "this text is far too long for a default box"
340 .PE
341 .CE "1: Boxes do not automatically resize"
342 .LP
343 which is probably not the effect you want.
344 .NH 2
345 Resizing Boxes
346 .PP
347 To change the box size, you can specify a box width with the \[lq]width\[rq]
348 modifier:
349 .KS
350 .PS
351 box width 3 "this text is far too long for a default box"
352 .PE
353 .CE "2: Result of \fBbox width 3 \"text far too long\"\fP"
354 .PP
355 This modifier takes a dimension in inches.  There is also a \[lq]height\[rq]
356 modifier that will change a box's height.  The \fBwidth\fP keyword may
357 be abbreviated to \fBwid\fP; the \fBheight\fP keyword to \fBht\fP.
358 .NH 2
359 Resizing Other Object Types
360 .PP
361 To change the size of a circle, give it a \fBrad[ius]\fP or
362 \fBdiam[eter]\fP modifier; this changes the radius or diameter of the
363 circle, according to the numeric argument that follows.
364 .KS
365 .PS
366 {circle rad 0.1; move down 0.2 from last circle .s; "0.1"};
367 move; circle rad 0.2 "0.2"; move; circle rad 0.3 "0.3";
368 .PE
369 .CE "3: Circles with increasing radii"
370 .PP
371 The \fBmove\fP command can also take a dimension, which just tells
372 it how many inches to move in the current direction.
373 .PP
374 Ellipses are sized to fit in the rectangular box defined by their
375 axes, and can be resized with \fBwidth\fP and \fBheight\fP like boxes.
376 .PP
377 You can also change the radius of curvature of an arc with \fBrad[ius]\fP
378 (which specifies the radius of the circle of which the arc is a segment).
379 Larger values yield flatter arcs.
380 .KS
381 .PS
382 {arc rad 0.1; move down 0.3 from last arc .center; "0.1"};
383 move;
384 {arc rad 0.2; move down 0.4 from last arc .center; "0.2"};
385 move;
386 {arc rad 0.3; move down 0.5 from last arc .center; "0.3"};
387 .PE
388 .CE "4: \fBarc rad\fP with increasing radii"
389 .PP
390 Observe that because an arc is defined as a quarter circle, increasing
391 the radius also increases the size of the arc's bounding box.
392 .NH 2
393 The `same' Keyword
394 .PP
395 In place of a dimension specification, you can use the keyword
396 \fBsame\fR.  This gives the object the same size as the previous one
397 of its type.  As an example, the program
398 .KS
399 .DS
400 .CW
401 \&.PS
402 box; box wid 1 ht 1; box same; box
403 \&.PE
404 .R
405 .DE
406 .KE
407 .LP
408 gives you
409 .KS
410 .PS
411 box; box wid 1 ht 1; box same; box
412 .PE
413 .CE "5: The \fBsame\fP keyword"
414
415 .NH 1
416 Generalized Lines and Splines
417 .NH 2
418 Diagonal Lines
419 .PP
420 It is possible to specify diagonal lines or arrows by adding multiple \fBup\fP,
421 \fBdown\fP, \fBleft\fP, and \fBright\fP modifiers to the line object.
422 Any of these can have a multiplier.  To understand the effects, think
423 of the drawing area as being gridded with standard-sized boxes.
424 .KS
425 .PS
426 # Draw a demonstration up left arrow with grid box overlay
427 define gridarrow
428 {
429         move right 0.1
430         [
431                 {arrow up left $1;}
432                 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
433                 for i = 2 to ($1 / 0.5) do {
434                         box wid 0.5 ht 0.5 dotted with .sw at last box .se;
435                 }
436                 move down from last arrow .center;
437                 [
438                         if ( $1 == boxht ) then {
439                                 "\fBline up left\fP"
440                         } else {
441                                 sprintf("\fBarrow up left %g\fP", $1)
442                         }
443                 ]
444         ] 
445         move right 0.1 from last [] .e;
446 }
447 gridarrow(0.5);
448 gridarrow(1);
449 gridarrow(1.5);
450 gridarrow(2);
451 undef gridarrow
452 .PE
453 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
454 .NH 2
455 Multi-Segment Line Objects
456 .PP
457 A \[lq]line\[rq] or \[lq]arrow\[rq] object may actually be a path
458 consisting of any number of segments of varying lengths and directions.
459 To describe a path, connect several line or arrow commands with the
460 keyword \fBthen\fP.
461 .KS
462 .PS
463 define zigzag { $1 right 1 then down .5 left 1 then right 1 }
464 zigzag(line); 
465 .PE
466 .CE "2: \fBline right 1 then down .5 left 1 then right 1\fP"
467 .NH 2
468 Spline Objects
469 .PP
470 If you start a path with the \fBspline\fP keyword, the path vertices
471 are treated as control points for a spline curve fit.
472 .KS
473 .PS
474 [zigzag(spline);]
475 move down 0.2 from last [] .s;
476 "The spline curve..."
477 move right from last [] .e;
478 [
479         zigzag(line dashed);
480         spline from start of last line right 1 then down .5 left 1 then right 1;
481         "1" at last spline .start + (-0.1, 0);
482         "2" at last spline .start + (1.1, 0);
483         "3" at last spline .end + (-1.1, 0);
484         "4" at last spline .end + (0.1, 0);
485 ]
486 move down 0.2 from last [] .s;
487 "...with tangents displayed"
488 undef zigzag;
489 .PE
490 .CE "3: \fBspline right 1 then down .5 left 1 then right 1\fP"
491 .PP
492 You can describe many natural-looking but irregular curves this
493 way.  For example: 
494 .KS
495 .PS
496 [spline right then up then left then down ->;]
497 move down 0.2 from last [] .s;
498 ["\fBspline right then up then left then down ->;\fP"]
499 move right 3 from last [] .se;
500 "\fBspline left then up right then down right ->;\fP"
501 move up 0.2;
502 [spline left then up right then down right ->;]
503 .PE
504 .CE "4: Two more spline examples"
505 .LP
506 Note the arrow decorations.  Arrowheads can be applied naturally to
507 any path-based object, line or spline.  We'll see how in the next
508 section.
509 .NH 1
510 Decorating Objects
511 .NH 2
512 Dashed Objects
513 .PP
514 We've already seen that the modifier \fBdashed\fP can change the line
515 style of an object from solid to dashed.  GNU \fBgpic\fP permits you to
516 dot or dash ellipses, circles, and arcs (and splines in \*[tx] mode
517 only); some versions of DWB may only permit dashing of lines and
518 boxes.  It's possible to change the dash interval by specifying a
519 number after the modifier.
520 .PP
521 .KS
522 .PS
523 box dashed "default";
524 move;
525 box dashed 0.05 "0.05";
526 move;
527 box dashed 0.1 "0.1";
528 move;
529 box dashed 0.15 "0.15";
530 move;
531 box dashed 0.2 "0.2";
532 .PE
533 .CE "1: Dashed objects"
534 .NH 2
535 Dotted Objects
536 .PP
537 Another available qualifier is \fBdotted\fP.  GNU \fBgpic\fP permits
538 you to dot or dash ellipses, circles, and arcs (and splines in \*[tx]
539 mode only); some versions of DWB may only permit dashing of lines and
540 boxes.  It too can be suffixed with a number to specify the interval
541 between dots:
542 .KS
543 .PS
544 box dotted "default";
545 move;
546 box dotted 0.05 "0.05";
547 move;
548 box dotted 0.1 "0.1";
549 move;
550 box dotted 0.15 "0.15";
551 move;
552 box dotted 0.2 "0.2";
553 .PE
554 .CE "2: Dotted objects"
555 .NH 2
556 Rounding Box Corners
557 .PP
558 It is also possible, in GNU \fBgpic\fP only, to modify a box so it has
559 rounded corners:
560 .KS
561 .PS
562 box rad 0.05 "rad 0.05";
563 move;
564 box rad 0.1 "rad 0.1";
565 move;
566 box rad 0.15 "rad 0.15"; 
567 move;
568 box rad 0.2 "rad 0.2"; 
569 move;
570 box rad 0.25 "rad 0.25"; 
571 .PE
572 .CE "3: \fBbox rad\fP with increasing radius values"
573 .PP
574 Radius values higher than half the minimum box dimension are silently
575 truncated to that value.
576 .NH 2
577 Arrowheads
578 .PP
579 Lines and arcs can be decorated as well.  Any line or arc (and any
580 spline as well) can be decorated with arrowheads by adding one or more
581 as modifiers:
582 .KS
583 .PS
584 line <- ->
585 .PE
586 .CE "4: Double-headed line made with  \fBline <- ->\fP"
587 .PP
588 In fact, the \fBarrow\fP command is just shorthand for \fBline ->\fP.  And
589 there is a double-head modifier <->, so the figure above could have been made
590 with \fBline <->\fP.
591 .PP
592 Arrowheads have a \fBwidth\fP attribute, the distance across the rear;
593 and a \fBheight\fP attribute, the length of the arrowhead along the shaft.
594 .PP
595 Arrowhead style is controlled by the style variable \fBarrowhead\fP.
596 The DWB and GNU versions interpret it differently.  DWB defaults to
597 open arrowheads and an \fBarrowhead\fP value of\~2; the Kernighan
598 paper says a value of\~7 will make solid arrowheads.  GNU \fBgpic\fP
599 defaults to solid arrowheads and an \fBarrowhead\fP value of\~1; a
600 value of\~0 will produce open arrowheads.  Note that solid arrowheads are
601 always filled with the current outline color.
602 .NH 2
603 Line Thickness
604 .PP
605 It's also possible to change the line thickness of an object (this is
606 a GNU extension, DWB \fBpic\fP doesn't support it).  
607 The default thickness of the lines used to draw objects is controlled by the
608 .B linethick
609 variable.
610 This gives the thickness of lines in points.
611 A negative value means use the default thickness:
612 in \*[tx] output mode, this means use a thickness of 8 milliinches;
613 in \*[tx] output mode with the
614 .B -c
615 option, this means use the line thickness specified by
616 .B .ps
617 lines; in troff output mode, this means use a thickness proportional
618 to the pointsize.  A zero value means draw the thinnest possible line
619 supported by the output device.  Initially it has a value of -1.
620 There is also a \fBthickness\fP attribute (which can be abbreviated to
621 \fBthick\fP).  For example, \fBcircle thickness 1.5\fP would draw a
622 circle using a line with a thickness of 1.5 points.  The thickness of
623 lines is not affected by the value of the
624 .B scale
625 variable, nor by any width or height given in the
626 .B .PS
627 line.
628 .NH 2
629 Invisible Objects
630 .PP
631 The modifier \fBinvis[ible]\fP makes an object entirely invisible.  This
632 used to be useful for positioning text in an invisible object that is
633 properly joined to neighboring ones.  Newer DWB versions and GNU
634 \fBpic\fP treat stand-alone text in exactly this way.
635 .NH 2
636 Filled Objects
637 .PP
638 It is possible to fill boxes, circles, and ellipses.  The
639 modifier \fBfill[ed]\fP accomplishes this.  You can suffix it with a fill
640 value; the default is given by the stule variable \fBfillval\fP.
641 .PP
642 DWB \fBpic\fP and \fBgpic\fP have opposite conventions for fill values
643 and different defaults.  DWB \fBfillval\fP defaults to 0.3 and smaller
644 values are darker; GNU \fBfillval\fP uses 0 for white and 1 for black.
645 .KS
646 .PS
647 circle fill; move; circle fill 0.4; move; circle fill 0.9;
648 .PE
649 .CE "5: \fBcircle fill; move; circle fill 0.4; move; circle fill 0.9;\fR"
650 .PP
651 GNU \fBgpic\fP makes some additional guarantees.  A fill value greater
652 than 1 can also be used: this means fill with the shade of gray that
653 is currently being used for text and lines.  Normally this will be
654 black, but output devices may provide a mechanism for changing this.
655 The invisible attribute does not affect the filling of objects.  Any
656 text associated with a filled object will be added after the object
657 has been filled, so that the text will not be obscured by the filling.
658 .PP
659 The closed-object modifier \fBsolid\fP is equivalent to \fBfill\fP
660 with the darkest fill value (DWB \fBpic\fP had this capability but
661 mentioned it only in a reference section).  
662 .NH 2
663 Colored Objects
664 .PP
665 As a GNU extension, three additional modifiers are available to specify
666 colored objects.  \fBoutline\fP sets the color of the outline, \fBshaded\fP
667 the fill color, and \fBcolor\fP sets both.  All three keywords expect a
668 suffix specifying the color.  Example:
669 .KS
670 .PS
671 box color "yellow"; arrow color "cyan"; circle shaded "green" outline "black";
672 .PE
673 .CE "6: \fBbox color ""yellow""; arrow color ""cyan""; \
674 circle shaded ""green"" outline ""black"";\fR"
675 .PP
676 Alternative spellings are \fBcolour\fP, \fBcolored\fP, \fBcoloured\fP,
677 and \fBoutlined\fP.
678 .PP
679 Currently, color support is not available in \*[tx] mode.  Predefined color
680 names for \fIgroff\/\fP(1) are in the device macro files, for example
681 \f(CWps.tmac\fP; additional colors can be defined with the \fB.defcolor\fP
682 request (see the manual page of GNU \fItroff\/\fP(1) for more details).
683 .PP
684 \fBpic\fP assumes that at the beginning of a picture both glyph and fill
685 color are set to the default value.
686 .NH 1
687 More About Text Placement
688 .PP
689 By default, text is centered at the geometric center of the object it is
690 associated with.  The modifier \fBljust\fP causes the left end to be
691 at the specified point (which means that the text lies to the right of
692 the specified place!), the modifier \fBrjust\fP puts the right end at
693 the place.  The modifiers \fBabove\fP and \fBbelow\fP center the text
694 one half line space in the given direction.
695 .PP
696 Text attributes can be combined:
697 .KS
698 .PS
699 [line up "ljust text" ljust;] 
700 move 1.5;
701 [line up "rjust text" rjust;] 
702 move;
703 [arrow 1 "ljust above" ljust above;]
704 move;
705 [arrow 1 "rjust below" rjust below;]
706 .PE
707 .CE "1: Text attributes"
708 .PP
709 What actually happens is that \fIn\fP text strings are centered in a box
710 that is \fBtextwid\fP wide by \fBtextht\fP high.  Both these variables
711 are initially zero (that is \fBpic\fR's way of not making assumptions
712 about \fI[tg]roff\/\fP(1)'s default point size).
713 .PP
714 In GNU \fBgpic\fR, objects can have an
715 .B aligned
716 attribute.
717 This will only work when the postprocessor is
718 \fBgrops\fP.
719 Any text associated with an object having the
720 .B aligned
721 attribute will be rotated about the center of the object
722 so that it is aligned in the direction from the start point
723 to the end point of the object.
724 Note that this attribute will have no effect for objects whose start and
725 end points are coincident.
726 .NH 1
727 More About Direction Changes
728 .PP
729 We've already seen how to change the direction in which objects are
730 composed from rightwards to downwards.  Here are some more
731 illustrative examples:
732 .KS
733 .PS
734 down;
735 [
736         "\fBright; box; arrow; circle; arrow; ellipse\fP";
737         move 0.2;
738         [right; box; arrow; circle; arrow; ellipse;]
739 ]
740 move down 0.3 from last [] .s;
741 [
742         "\fBleft; box; arrow; circle; arrow; ellipse\fP"
743         move 0.2;
744         [left; box; arrow; circle; arrow; ellipse;]
745 ]
746 # move down 0.3 from last [] .sw;
747 # To re-join this illustrations, delete everything from here down to
748 # the next #-comment, and uncomment the move line above
749 .PE
750 .CE "1: Effects of different motion directions (right and left)"
751 .KS
752 .PS
753 # To re-join this illustrations, delete everything down to here, then
754 # comment out the next `down' line.
755 # Don't forget to re-number the figures following!
756 down;
757 [
758         "\fBdown; box; arrow; circle; arrow; ellipse;\fP"
759         move 0.2;
760         box; arrow; circle; arrow; ellipse;
761 ]
762 move right 2 from last [] .e;
763 [
764         up; box; arrow; circle; arrow; ellipse;
765         move 0.2;
766         "\fBup; box; arrow; circle; arrow; ellipse;\fP"
767 ]
768 .PE
769 .CE "2: Effects of different motion directions (up and down)"
770 .PP
771 Something that may appear surprising happens if you change directions 
772 in the obvious way:
773 .KS
774 .PS
775 box; arrow; circle; down; arrow; ellipse
776 .PE
777 .CE "3: \fBbox; arrow; circle; down; arrow; ellipse\fP"
778 .LP
779 You might have expected that program to yield this:
780 .KS
781 .PS
782 box; arrow; circle; move to last circle .s; down; arrow; ellipse
783 .PE
784 .CE "4: More intuitive?"
785 .LP
786 But, in fact, to get Figure \*[SN]3 you have to do this:
787 .KS
788 .DS
789 .CW
790 \&.PS
791 box;
792 arrow;
793 circle;
794 move to last circle .s;
795 down;
796 arrow;
797 ellipse
798 \&.PE
799 .R
800 .DE
801 .KE
802 .LP
803 Why is this?  Because the exit point for the current direction is
804 already set when you draw the object.  The second arrow in Figure
805 \*[SN]2 dropped downwards from the circle's attachment point for an
806 object to be joined to the right.
807 .PP
808 The meaning of the command \fBmove to last circle .s\fP should be obvious.
809 In order to see how it generalizes, we'll need to go into detail on two
810 important topics; locations and object names.
811 .NH 1
812 Naming Objects
813 .PP
814 The most natural way to name locations in \fBpic\fP is relative to
815 objects.  In order to do this, you have to be able you have to be able
816 to name objects.  The \fBpic\fP language has rich facilities for this
817 that try to emulate the syntax of English.
818 .NH 2
819 Naming Objects By Order Of Drawing
820 .PP
821 The simplest (and generally the most useful) way to name an object is
822 with a \fBlast\fP clause.  It needs to be followed by an object type
823 name; \fBbox\fP, \fBcircle\fP, \fBellipse\fP, \fBline\fP, \fBarrow\fP,
824 \fBspline\fP, \fB""\fP, or \fB[]\fP (the last type refers to a \fIcomposite
825 object\fP which we'll discuss later).  So, for example, the \fBlast
826 circle\fP clause in the program attached to Figure \*[SN]3 refers to the
827 last circle drawn.
828 .PP
829 More generally, objects of a given type are implicitly numbered
830 (starting from\~1).  You can refer to (say) the third ellipse in the
831 current picture with \fB3rd ellipse\fP, or to the first box as \fB1st
832 box\fP, or to the fifth text string (which isn't an attribute to another
833 object) as \fB5th ""\fP.
834 .PP
835 Objects are also numbered backwards by type from the last one.
836 You can say \fB2nd last box\fP to get the second-to-last box, or
837 \fB3rd last ellipse\fP to get the third-to-last ellipse.
838 .PP
839 In places where \fIn\/\fBth\fR is allowed, \fB`\fIexpr\/\fB'th\fR is
840 also allowed.  Note that
841 .B 'th
842 is a single token: no space is allowed between the
843 .B '
844 and the \fBth\fP.
845 For example,
846 .IP
847 .KS
848 .DS
849 .CW
850 for i = 1 to 4 do {
851    line from `i'th box.nw to `i+1'th box.se
852 }
853 .DE
854 .R
855 .KE
856 .NH 2
857 Naming Objects With Labels
858 .PP
859 You can also specify an object by referring to a label.  A label is a
860 word (which must begin with a capital letter) followed by a colon;
861 you declare it by placing it immediately before the object drawing command.
862 For example, the program
863 .KS
864 .DS
865 .CW
866 \&.PS
867 A: box "first" "object"
868 move;
869 B: ellipse "second" "object"
870 move;
871 arrow right at A .r;
872 \&.PE
873 .R
874 .DE
875 .KE
876 .LP
877 declares labels \fBA\fP and \fBB\fP for its first and second objects.
878 Here's what that looks like:
879 .KS
880 .PS
881 A: box "first" "object"
882 move;
883 B: ellipse "second" "object"
884 move;
885 arrow right at A .r;
886 .PE
887 .CE "1: Example of label use"
888 The \fBat\fP statement in the fourth line uses the label \fBA\fP (the
889 behavior of \fBat\fP will be explained in the next section).  We'll
890 see later on that labels are most useful for referring to block composite
891 objects.  
892 .PP
893 Labels are not constants but variables (you can view colon as a sort
894 of assignment).  You can say something like \fBA: A + (1,0);\fP
895 and the effect will be to reassign the label \fBA\fR to designate a
896 position one inch to the right of its old value. 
897 .NH 1
898 Describing locations
899 .PP
900 The location of points can be described in many different ways.  All these
901 forms are interchangeable as for as the \fBpic\fP language syntax is
902 concerned; where you can use one, any of the others that would make 
903 semantic sense are allowed.
904 .PP
905 The special label \fBHere\fR always refers to the current position.
906 .NH 2
907 Absolute Coordinates
908 .PP
909 The simplest is absolute coordinates in inches; \fBpic\fP uses a
910 Cartesian system with (0, 0) at the lower left corner of the virtual
911 drawing surface for each picture (that is, X increases to the right
912 and Y increases upwards).  An absolute location may always be written in the
913 conventional form as two comma-separated numbers surrounded by
914 parentheses (and this is recommended for clarity).  In contexts where
915 it creates no ambiguity, the pair of X and Y coordinates suffices
916 without parentheses.
917 .PP
918 It is a good idea to avoid absolute coordinates, however.  They tend
919 to make picture descriptions difficult to understand and modify.
920 Instead, there are quite a number of ways to specify locations
921 relative to \fBpic\fP objects and previous locations.
922 .PP
923 .NH 2
924 Locations Relative to Objects
925 .PP
926 The symbol \fBHere\fP always refers to the position of the last object
927 drawn or the destination of the last \fBmove\fP.
928 .PP
929 Alone and unqualified, a \fBlast circle\fP or any other way of
930 specifying a closed-object or arc location refers as a position to the
931 geometric center of the object.  Unqualified, the name of a line or
932 spline object refers to the position of the object start.
933 .PP
934 Also, \fBpic\fP objects have quite a few named locations
935 associated with them.  One of these is the object center, which can be
936 indicated (redundantly) with the suffix \fB.center\fP (or just \fB.c\fP).
937 Thus, \fBlast circle \&.center\fP is equivalent to \fBlast
938 circle\fP.
939 .NH 3
940 Locations Relative to Closed Objects
941 .PP
942 Every closed object (box, circle, ellipse, or block composite) also
943 has eight compass points associated with it;
944 .KS
945 .PS
946 define dot {circle fill rad 0.02 at $1}
947
948 define compass { [
949         ME: $1;
950         dot(ME.c);  "\fB .c\fP"  at ME .c ljust;
951         dot(ME.n);  "\fB.n\fP"   at ME .n above
952         dot(ME.ne); "\fB .ne\fP" at ME .ne above
953         dot(ME.e);  "\fB .e\fP"  at ME .e ljust
954         dot(ME.se); "\fB .se\fP" at ME .se below
955         dot(ME.s);  "\fB.s\fP"   at ME .s below
956         dot(ME.sw); "\fB.sw \fP" at ME .sw below
957         dot(ME.w);  "\fB.w \fP"  at ME .w rjust
958         dot(ME.nw); "\fB.nw \fP" at ME .nw above
959 ] }
960 compass(box wid 1.5 ht 1);
961 move right from last [] .e;
962 compass(circle diam 1);
963 move right from last [] .e;
964 compass(ellipse wid 1.5 ht 1);
965 .PE
966 .CE "1: Compass points"
967 .LP
968 these are the locations where eight compass rays from the geometric center
969 would intersect the figure.  So when we say \fBlast circle .s\fP we are
970 referring to the south compass point of the last circle drawn.  The
971 explanation of Figure 7.3's program is now complete.
972 .PP
973 (In case you dislike compass points, the names \fB.top\fP,
974 \&\fB.bottom\fP, \fB.left\fP and \fB.right\fP are synonyms for \fB.n\fP,
975 \&\fB.s\fP, \fB.e\fP, and \fB.w\fP respectively; they can even be
976 abbreviated to \fB.t\fP, \fB.b\fP, \fB.l\fP and \fB.r\fP).
977 .PP
978 The names \fBcenter\fP, \fBtop\fP, \fBbottom\fP, \fBleft\fP, \fBright\fP,
979 \fBnorth\fP, \fBsouth\fP, \fBeast\fP, and \fBwest\fP can also be used
980 (without the leading dot) in a prefix form marked by \fBof\fP; thus,
981 \fBcenter of last circle\fP and \fBtop of 2nd last ellipse\fP are both
982 valid object references.  Finally, the names \fBleft\fP and \fBright\fP
983 can be prefixed with \fBupper\fP and \fBlower\fP which both have the
984 obvious meaning.
985 .PP
986 Arc objects also have compass point; they are the compass points of
987 the implied circle.
988 .NH 3
989 Locations Relative to Open Objects
990 .PP
991 Every open object (line, arrow, arc, or spline) has three named
992 points: \fB.start\fP, \fB.center\fP (or \fB.c\fP), and \fB.end\fP.  They
993 can also be used without leading dots in the \fBof\fP prefix form.
994 The center of an arc is the center of its circle, but the center of
995 a line, path, or spline is halfway between its endpoints.
996 .KS
997 .PS
998 define critical {
999         [ ME: $1;
1000                 dot(ME.c);     "\fB.center\fP" rjust at ME.center + (-0.1, 0.1)
1001                 dot(ME.start); "\fB.start\fP"  rjust at ME.start  + (-0.1, 0.1)
1002                 dot(ME.end);   "\fB.end\fP"    rjust at ME.end    + (-0.1, 0.1)
1003         ]
1004 }
1005 critical(line up right 1);
1006 move right 1 from last [] .e;
1007 critical(arc rad 0.5 cw);
1008 move down 0.5 from 2nd last [] .s;
1009 critical(line right 1 then down .5 left 1 then right 1);
1010 move right 1 from last [] .e;
1011 critical(spline right 1 then up right then left then left 1);
1012 .PE
1013 .CE "2: Special points on open objects"
1014 .PP
1015 .NH 2
1016 Ways of Composing Positions
1017 .PP
1018 Once you have two positions to work with, there are several ways to
1019 combine them to specify new positions.
1020 .NH 3
1021 Vector Sums and Displacements
1022 .PP
1023 Positions may be added or subtracted to yield a new position (to be
1024 more precise, you can only add a position and an expression pair; the
1025 latter must be on the right side of the addition or subtraction sign).
1026 The result is the conventional vector sum or difference of coordinates.
1027 For example, \fBlast box .ne + (0.1, 0)\fP is a valid position.  This 
1028 example illustrates a common use, to define a position slightly offset
1029 from a named one (say, for captioning purposes).
1030 .NH 3
1031 Interpolation Between Positions
1032 .PP
1033 A position may be interpolated between any two positions.  The syntax
1034 is `\fIfraction\fP \fBof the way between\fP \fIposition1\fP \fBand\fP
1035 \fIposition2\fP'.  For example, you can say \fB1/3 of the way between
1036 here and last ellipse .ne\fP.  The fraction may be in
1037 numerator/denominator form or may be an ordinary number (values are
1038 \fInot\fP restricted to [0,1]).  As an alternative to this verbose
1039 syntax, you can say `\fIfraction\fP  \fB<\,\fP\fIposition1\fP \fB,\fP
1040 \fIposition2\/\fP\fB>\fP'; thus, the example could also be written as
1041 \fB1/3 <here, last ellipse>\fP.
1042 .KS
1043 .PS
1044 arrow up right;
1045 P: 1/3 of the way between last arrow .start and last arrow .end;
1046 dot(P); move right 0.1; "P";
1047 .PE
1048 .CE "3: \fBP: 1/3 of the way between last arrow .start and last arrow .end\fP"
1049 .PP
1050 This facility can be used, for example, to draw double connections.
1051 .KS
1052 .PS
1053 A: box "yin"; move;
1054 B: box "yang";
1055 arrow right at 1/4 <A.e,A.ne>;
1056 arrow left  at 1/4 <B.w,B.sw>;
1057 .PE
1058 .CE "4: Doubled arrows"
1059 .LP
1060 You can get Figure \n[H1]-4 from the following program:
1061 .KS
1062 .DS
1063 .CW
1064 \&.PS
1065 A: box "yin"; move;
1066 B: box "yang";
1067 arrow right at 1/4 <A.e,A.ne>;
1068 arrow left  at 1/4 <B.w,B.sw>;
1069 \&.PE
1070 .R
1071 .DE
1072 .KE
1073 .LP
1074 Note the use of the short form for interpolating points.
1075 .NH 3
1076 Projections of Points
1077 .PP
1078 Given two positions \fIp\fP and \fIq\fP, the position
1079 \fB(\,\fP\fIp\fP\fB,\fP \fIq\fP\fB)\fP has the X coordinate of \fIp\fP
1080 and the Y coordinate of \fIq\fP.  This can be helpful in placing an
1081 object at one of the corners of the virtual box defined by two other
1082 objects.
1083 .KS
1084 .PS
1085 box invis wid 2 height 1;
1086 dot(last box .ne); "\fB(B,A)\fP is here" ljust at last circle + (0.1, 0.1);
1087 dot(last box .se); "B" ljust at last circle + (0.1, -0.1)
1088 dot(last box .sw); "\fB(A,B)\fP is here" rjust at last circle + (-0.1, -0.1);
1089 dot(last box .nw); "A" ljust at last circle + (-0.1, 0.1)
1090 .PE
1091 .CE "5: Using (\fIx\fP, \fIy\fP) composition"
1092 .NH 2
1093 Using Locations
1094 .PP
1095 There are four ways to use locations; \fBat\fP, \fBfrom\fP, \fBto\fP,
1096 and \fBwith\fP.  All three are object modifiers; that is, you use them
1097 as suffixes to a drawing command.
1098 .PP
1099 The \fBat\fP modifier says to draw a closed object or arc with its
1100 center at the following location, or to draw a line/spline/arrow
1101 starting at the following location.
1102 .PP
1103 The \fBto\fP modifier can be used alone to specify a move destination.
1104 The \fBfrom\fP modifier can be used alone in the same way as \fBat\fP.
1105 .PP
1106 The \fBfrom\fP and \fBto\fP modifiers can be used with a \fBline\fR or
1107 \fBarc\fR command to specify start and end points of the object.  In
1108 conjunction with named locations, this offers a very flexible
1109 mechanism for connecting objects.  For example, the following program
1110 .KS
1111 .DS
1112 .CW
1113 \&.PS
1114 box "from"
1115 move 0.75;
1116 ellipse "to"
1117 arc cw from 1/3 of the way \e
1118     between last box .n and last box .ne to last ellipse .n;
1119 \&.PE
1120 .R
1121 .DE
1122 .KE
1123 .LP
1124 yields:
1125 .KS
1126 .PS
1127 box "from"
1128 move 0.75;
1129 ellipse "to"
1130 arc cw from 1/3 of the way \
1131     between last box .n and last box .ne to last ellipse .n;
1132 .PE
1133 .CE "6: A tricky connection specified with English-like syntax"
1134 .PP
1135 The \fBwith\fP modifier allows you to identify a named attachment
1136 point of an object (or a position within the object) with another point.
1137 This is very useful for connecting objects in a natural way.  For an
1138 example, consider these two programs:
1139 .KS
1140 .PS
1141 [
1142         [
1143                 box wid 0.5 ht 0.5;
1144                 box wid 0.75 ht 0.75;
1145         ]
1146         move down 0.3 from last [] .s 0.1;
1147         "\fBbox wid 0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1148 ]
1149 move from last [].e 1.5
1150 [
1151         [
1152                 box wid 0.5 ht 0.5;
1153                 box wid 0.75 ht 0.75 with .sw at last box .se;
1154         ]
1155         move down 0.3 from last [] .s 0.1;
1156         box invisible "\fBbox wid 0.5 ht 0.5;\fP" \
1157           "\fBbox wid 0.75 ht 0.75 with .sw at last box .se;\fP"
1158 ]
1159 .PE
1160 .CE "7: Using the \fBwith\fP modifier for attachments"
1161 .NH 2
1162 The `chop' Modifier
1163 .PP
1164 When drawing lines between circles that don't intersect them at a
1165 compass point, it is useful to be able to shorten a line by the radius 
1166 of the circle at either or both ends.  Consider the following program:
1167 .KS
1168 .DS
1169 .CW
1170 \&.PS
1171 circle "x"
1172 circle "y" at 1st circle - (0.4, 0.6) 
1173 circle "z" at 1st circle + (0.4, -0.6) 
1174 arrow from 1st circle to 2nd circle chop 
1175 arrow from 2nd circle to 3rd circle chop 
1176 arrow from 3rd circle to 1st circle chop 
1177 \&.PE
1178 .DE
1179 .R
1180 .KE
1181 .LP
1182 It yields the following:
1183 .KS
1184 .PS
1185 circle "x"
1186 circle "y" at 1st circle - (0.4, 0.6) 
1187 circle "z" at 1st circle + (0.4, -0.6) 
1188 arrow from 1st circle to 2nd circle chop 
1189 arrow from 2nd circle to 3rd circle chop 
1190 arrow from 3rd circle to 1st circle chop 
1191 .PE
1192 .CE "8: The \fBchop\fR modifier"
1193 .LP
1194 Notice that the \fBchop\fR attribute moves arrowheads rather than
1195 stepping on them.  By default, the \fBchop\fR modifier shortens both
1196 ends of the line by \fBcirclerad\fR.  By suffixing it with a number
1197 you can change the amount of chopping.
1198 .PP
1199 If you say \fBline .\|.\|.\& chop \fIr1\fP chop \fIr2\fP\fR with \fIr1\fP
1200 and \fIr2\fP both numbers, you can vary the amount of chopping at both
1201 ends.  You can use this in combination with trigonometric functions
1202 to write code that will deal with more complex intersections.
1203 .NH 1
1204 Object Groups
1205 .PP
1206 There are two different ways to group objects in \fBpic\fP; \fIbrace
1207 grouping\fP and \fIblock composites\fP.
1208 .NH 2
1209 Brace Grouping
1210 .PP
1211 The simpler method is simply to group a set of objects within curly
1212 bracket or brace characters.  On exit from this grouping, the current
1213 position and direction are restored to their value when the opening
1214 brace was encountered.
1215 .NH 2
1216 Block Composites
1217 .PP
1218 A block composite object is created a series of commands enclosed by
1219 square brackets.  The composite can be treated for most purposes like
1220 a single closed object, with the size and shape of its bounding box.
1221 Here is an example.  The program fragment
1222 .KS
1223 .DS
1224 .CW
1225 A: [
1226     circle;
1227     line up 1 at last circle .n;
1228     line down 1 at last circle .s;
1229     line right 1 at last circle .e;
1230     line left 1 at last circle .w;
1231     box dashed with .nw at last circle .se + (0.2, -0.2); 
1232     Caption: center of last box;
1233 ]
1234 .R
1235 .DE
1236 .KE
1237 .LP
1238 yields the block in figure \n[H1]-1, which we show both with and
1239 without its attachment points.  The block's location becomes the
1240 value of \fBA\fP.
1241 .KS
1242 .PS
1243 define junction {
1244         circle;
1245         line up 1 at last circle .n;
1246         line down 1 at last circle .s;
1247         line right 1 at last circle .e;
1248         line left 1 at last circle .w;
1249         box dashed with .nw at last circle .se + (0.2, -0.2); 
1250         Caption: center of last box;
1251 }
1252 [junction();]
1253 move;
1254 compass([junction()]);
1255 .PE
1256 .CE "1: A sample composite object"
1257 .LP
1258 To refer to one of the composite's attachment points, you can say
1259 (for example) \fBA .s\fP.  For purposes of object naming, composites
1260 are a class.  You could write \fBlast [] .s\fP as an equivalent
1261 reference, usable anywhere a location is needed.  This construction is
1262 very important for putting together large, multi-part diagrams.
1263 .PP 
1264 Blocks are also a variable-scoping mechanism, like a \fIgroff\/\fP(1)
1265 environment.  All variable assignments done inside a block are undone
1266 at the end of it.  To get at values within a block, write a name of
1267 the block followed by a dot, followed by the label you
1268 want.  For example, we could refer the the center of the box in the
1269 above composite as \fBlast [] .Caption\fP or \fBA.Caption\fP.
1270 .PP
1271 This kind of reference to a label can be used in any way any other
1272 location can be.  For example, if we added \fB"Hi!" at A.Caption\fP
1273 the result would look like this:
1274 .KS
1275 .PS
1276 A: [junction();]
1277 "Hi!" at A.Caption;
1278 .PE
1279 .CE "2: Adding a caption using interior labeling"
1280 .PP
1281 You can also use interior labels in either part of a \fBwith\fR
1282 modifier.  This means that the example composite could be placed
1283 relative to its caption box by a command containing \fBwith A.Caption
1284 at\fP.
1285 .PP
1286 Note that both width and height of the block composite object are always
1287 positive:
1288 .KS
1289 .PS
1290 [
1291         [
1292                 box wid -0.5 ht 0.5
1293                 box wid 0.75 ht 0.75
1294         ]
1295         move down 0.3 from last [].s 0.1
1296         "\fBbox wid -0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1297 ]
1298 move from last [].e 2
1299 [
1300         [
1301                 [ box wid -0.5 ht 0.5 ]
1302                 box wid 0.75 ht 0.75
1303         ]
1304         move down 0.3 from last [].s 0.1
1305         "\fB[box wid -0.5 ht 0.5]; box wid 0.75 ht 0.75\fP"
1306 ]
1307 .PE
1308 .CE "3: Composite block objects always have positive width and height
1309 .PP
1310 Blocks may be nested.  This means you can use block attachment points
1311 to build up complex diagrams hierarchically, from the inside out.
1312 Note that \fBlast\fP and the other sequential naming mechanisms
1313 don't look inside blocks, so if you have a program that looks 
1314 like 
1315 .KS
1316 .DS
1317 .CW
1318 \&.PS
1319 P: [box "foo"; ellipse "bar"];
1320 Q: [
1321         [box "baz"; ellipse "quxx"]
1322         "random text";
1323    ]
1324 arrow from 2nd last [];
1325 \&.PE
1326 .R
1327 .DE
1328 .KE
1329 .LP
1330 the arrow in the last line will be attached to object \fBP\fP, not 
1331 object \fBQ\fP.
1332 .PP
1333 In DWB \fBpic\fP, only references one level deep into enclosed blocks
1334 were permitted.  GNU \fBgpic\fP removes this restriction.
1335 .PP
1336 The combination of block variable scoping, assignability of labels and
1337 the macro facility that we'll describe later on can be used to
1338 simulate functions with local variables (just wrap the macro body in
1339 block braces).
1340 .NH 1
1341 Style Variables
1342 .PP
1343 There are a number of global style variables in \fBpic\fR that can be used to
1344 change its overall behavior.  We've mentioned several of them in
1345 previous sections.  They're all described here.  For each variable,
1346 the default is given.
1347 .TS H
1348 center, tab(@), linesize(2);
1349 lb | lb | lb
1350 l | n | l.
1351 .sp 2p
1352 Style Variable@Default@What It Does
1353 .sp 2p
1354 _
1355 .sp 2p
1356 .TH
1357 boxht@0.5@Default height of a box
1358 boxwid@0.75@Default width of a box
1359 lineht@0.5@Default length of vertical line
1360 linewid@0.75@Default length of horizontal line
1361 linethick@-1@Default line thickness
1362 arcrad @0.25@Default radius of an arc
1363 circlerad@0.25@Default radius of a circle
1364 ellipseht@0.5@Default height of an ellipse
1365 ellipsewid@0.75@Default width of an ellipse
1366 moveht@0.5@Default length of vertical move
1367 movewid@0.75@Default length of horizontal move
1368 textht@0@Default height of box enclosing a text object
1369 textwid@0@Default width of box enclosing a text object
1370 arrowht@0.1@Length of arrowhead along shaft
1371 arrowwid@0.05@Width of rear of arrowhead
1372 arrowhead@1@Enable/disable arrowhead filling
1373 dashwid@0.05@Interval for dashed lines
1374 maxpswid@11@Maximum width of picture
1375 maxpsht@8.5@Maximum height of picture
1376 scale@1@Unit scale factor
1377 fillval@0.5@Default fill value
1378 .sp 5p
1379 _
1380 .TE
1381 Any of these variables can be set with a simple assignment statement.
1382 For example:
1383 .KS
1384 .PS
1385 [boxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;]
1386 .PE
1387 .CE "1: \fBboxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;\fP"
1388 .PP
1389 In GNU \fBpic\fR, setting the \fBscale\fR variable re-scales all
1390 size-related state variables so that their values remain equivalent in
1391 the new units.
1392 .PP
1393 The command \fBreset\fP resets all style variables to their defaults.
1394 You can give it a list of variable names as arguments (optionally
1395 separated by commas), in which case it resets only those.
1396 .PP
1397 State variables retain their values across pictures until reset.
1398 .NH 1
1399 Expressions, Variables, and Assignment
1400 .PP
1401 A number is a valid expression, of course (all numbers are stored
1402 internally as floating-point).  Decimal-point notation is acceptable;
1403 in GNU \fBgpic\fR, scientific notation in C's `e' format (like
1404 \f(CW5e-2\fP) is accepted.
1405 .PP
1406 Anywhere a number is expected, the language will also accept a
1407 variable.  Variables may be the built-in style variable described in
1408 the last section, or new variables created by assignment.
1409 .PP
1410 DWB \fBpic\fP supports only the ordinary assignment via \fB=\fP, which
1411 defines the variable (on the left side of the equal sign) in the current
1412 block if it is not already defined there, and then changes the value (on
1413 the right side) in the current block.  The variable is not visible outside
1414 of the block.  This is similar to the C\~programming language where a
1415 variable within a block shadows a variable with the same name outside of
1416 the block.
1417 .PP
1418 GNU \fBgpic\fP supports an alternate form of assignment using \fB:=\fP.
1419 The variable must already be defined, and the value will be assigned to
1420 that variable without creating a variable local to the current block.
1421 For example, this
1422 .KS
1423 .DS
1424 .CW
1425 x=5
1426 y=5
1427 [
1428   x:=3
1429   y=3
1430 ]
1431 print x " " y
1432 .DE
1433 .KE
1434 .LP
1435 prints \fB3 5\fP.
1436 .PP
1437 You can use the height, width, radius, and x and y coordinates of any
1438 object or corner in expressions.  If \fBA\fP is an object label or name,
1439 all the following are valid:
1440 .KS
1441 .DS
1442 .CW
1443 A.x                  # x coordinate of the center of A
1444 A.ne.y               # y coordinate of the northeast corner of A
1445 A.wid                # the width of A
1446 A.ht                 # and its height
1447 2nd last circle.rad  # the radius of the 2nd last circle
1448 .R
1449 .DE
1450 .KE
1451 .LP
1452 Note the second expression, showing how to extract a corner coordinate.
1453 .PP
1454 Basic arithmetic resembling those of C operators are available; \fB+\fP,
1455 \fB*\fP, \fB-\fP, \fB/\fP, and \fB%\fP.  So is \fB^\fP for exponentiation.
1456 Grouping is permitted in the usual way using parentheses.  GNU \fBgpic\fP
1457 allows logical operators to appear in expressions; \fB!\&\fP (logical
1458 negation, not factorial), \fB&&\fP, \fB|\||\fP, \fB==\fP, \fB!=\fP,
1459 \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
1460 .PP
1461 Various built-in functions are supported: \fBsin(\fIx\fB)\fR,
1462 \fBcos(\fIx\fB)\fR, \fBlog(\fIx\fB)\fR, \fBexp(\fIx\fB)\fR,
1463 \fBsqrt(\fIx\fB)\fR, \fBmax(\fIx\fB,\fIy\fB)\fR,
1464 \fBatan2(\fIx\fB,\fIy\fB)\fR, \fBmin(\fIx\fB,\fIy\fB)\fR,
1465 \fBint(\fIx\fB)\fR, \fBrand()\fP, and \fBsrand()\fP.
1466 Both \fBexp\fP and \fBlog\fP are
1467 base\~10; \fBint\fP does integer truncation; \fBrand()\fP returns a
1468 random number in [0-1), and \fBsrand()\fP sets the seed for 
1469 a new sequence of pseudo-random numbers to be returned by \fBrand()\fP
1470 (\fBsrand()\fP is a GNU extension).
1471 .PP
1472 GNU \fBgpic\fP also documents a one-argument form or rand,
1473 \fBrand(\fIx\fB)\fR, which returns a random number between 1 and
1474 \fIx\fP, but this is deprecated and may be removed in a future
1475 version.
1476 .PP
1477 The function \fBsprintf()\fP behaves like a C \fIsprintf\/\fP(3)
1478 function that only takes %, %e, %f, and %g format strings.
1479 .NH 1
1480 Macros
1481 .PP
1482 You can define macros in \fBpic\fP.  This is useful for diagrams with
1483 repetitive parts.  In conjunction with the scope rules for block
1484 composites, it effectively gives you the ability to write functions.
1485 .PP
1486 The syntax is
1487 .DS
1488 .CW
1489 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement text \fB}\fP
1490 .R
1491 .DE
1492 .LP
1493 This defines \fIname\fR as a macro to be replaced by the replacement
1494 text (not including the braces).  The macro may be called as 
1495 .DS
1496 .CW
1497 \fIname\fB(\fIarg1, arg2, \|.\|.\|.\& argn\fB)\fR
1498 .R
1499 .DE
1500 .LP
1501 The arguments (if any) will be substituted for tokens \fB$1\fP, \fB$2\fP
1502 \&.\|.\|.\& \fB$n\fP
1503 appearing in the replacement text.
1504 .PP
1505 As an example of macro use, consider this:
1506 .KS
1507 .DS
1508 .CW
1509 .ps -1
1510 .vs -1
1511 \&.PS
1512 # Plot a single jumper in a box, $1 is the on-off state.
1513 define jumper { [
1514     shrinkfactor = 0.8;
1515     Outer: box invis wid 0.45 ht 1;
1516
1517     # Count on end ] to reset these
1518     boxwid = Outer.wid * shrinkfactor / 2;
1519     boxht  = Outer.ht  * shrinkfactor / 2;
1520
1521     box fill (!$1) with .s at center of Outer;
1522     box fill ($1)  with .n at center of Outer;
1523 ] }
1524
1525 # Plot a block of six jumpers.
1526 define jumperblock {
1527     jumper($1);
1528     jumper($2);
1529     jumper($3);
1530     jumper($4);
1531     jumper($5);
1532     jumper($6);
1533
1534     jwidth  = last [].Outer.wid;
1535     jheight = last [].Outer.ht;
1536
1537     box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1538
1539     # Use {} to avoid changing position from last box draw.
1540     # This is necessary so move in any direction will work as expected
1541     {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0, -0.2);}
1542 }
1543
1544 # Sample macro invocations.
1545 jumperblock(1,1,0,0,1,0);
1546 move;
1547 jumperblock(1,0,1,0,1,1);
1548 \&.PE
1549 .ps
1550 .vs
1551 .R
1552 .DE
1553 .KE
1554 .LP
1555 It yields the following:
1556 .KS
1557 .PS
1558 # Plot a single jumper in a box, $1 is the on-off state.
1559 define jumper { [
1560     shrinkfactor = 0.8;
1561     Outer: box invis wid 0.45 ht 1;
1562
1563     # Count on end ] to reset these
1564     boxwid = Outer.wid * shrinkfactor / 2;
1565     boxht  = Outer.ht  * shrinkfactor / 2;
1566
1567     box fill (!$1) with .s at center of Outer;
1568     box fill ($1)  with .n at center of Outer;
1569 ] }
1570
1571 # Plot a block of six jumpers
1572 define jumperblock {
1573     jumper($1);
1574     jumper($2);
1575     jumper($3);
1576     jumper($4);
1577     jumper($5);
1578     jumper($6);
1579
1580     jwidth  = last [].Outer.wid;
1581     jheight = last [].Outer.ht;
1582
1583     box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1584
1585     # Use {} to avoid changing position from last box draw.
1586     # This is necessary so move in any direction will work as expected
1587     {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0, -0.2);}
1588 }
1589
1590 # Sample macro invocations
1591 jumperblock(1,1,0,0,1,0);
1592 move 0.25;
1593 jumperblock(1,0,1,0,1,1);
1594 .PE
1595 .CE "1: Sample use of a macro"
1596 .LP
1597 This macro example illustrates how you can combine [], brace grouping,
1598 and variable assignment to write true functions.
1599 .PP
1600 One detail the example above does not illustrate is the fact that
1601 macro argument parsing is not token-oriented.  If you call
1602 \fBjumper(\ 1\ )\fP, the value of $1 will be \fB"\ 1\ "\fP.  You could
1603 even call \fBjumper(big\ string)\fP to give $1 the value
1604 \fB"big\ string"\fP.
1605 .PP
1606 If you want to pass in a coordinate pair, you can avoid getting
1607 tripped up by the comma by wrapping the pair in parentheses.
1608 .PP
1609 Macros persist through pictures.  To undefine a macro, say \fBundef\fP
1610 \fIname\fR; for example,
1611 .DS
1612 \f(CWundef jumper\fP
1613 \f(CWundef jumperblock\fP
1614 .DE
1615 .LP
1616 would undefine the two macros in the jumper block example.
1617 .NH 1
1618 Import/Export Commands
1619 .PP
1620 Commands that import or export data between \fBpic\fR and its
1621 environment are described here.
1622 .NH 2
1623 File and Table Insertion
1624 .PP
1625 The statement
1626 .DS
1627 \f(CWcopy\fP \fIfilename\fR
1628 .DE
1629 .LP
1630 inserts the contents of \fIfilename\fR in the \fBpic\fP input stream.
1631 Any \fB.PS\fP/\fB.PE\fP pair in the file will be ignored.  This, you
1632 can use this to include pre-generated images.
1633 .PP
1634 A variant of this statement replicates the \fBcopy thru\fP feature of
1635 \fIgrap\fP(1).  The call
1636 .DS
1637 \f(CWcopy\fP \fIfilename\fR \f(CWthru\fP \fImacro\fP
1638 .DE
1639 .LP
1640 calls \fImacro\fP (which may be either a name or replacement text)
1641 on the arguments obtained by breaking each line of the file into
1642 blank-separated fields.  The macro may have up to 9\~arguments.  The
1643 replacement text may be delimited by braces or by a pair of instances
1644 of any character not appearing in the rest of the text.
1645 .PP
1646 If you write
1647 .DS
1648 \f(CWcopy\fP \f(CWthru\fP \fImacro\fP
1649 .DE
1650 .LP
1651 omitting the filename, lines to be parsed are taken from the input
1652 source up to the next \fB.PE\fP.
1653 .PP
1654 In either of the last two \fBcopy\fP commands, GNU \fBgpic\fP permits a
1655 trailing `\fBuntil\fP \fIword\/\fP' clause to be added which terminates
1656 the copy when the first word matches the argument (the default
1657 behavior is therefore equivalent to \fBuntil .PE\fP).
1658 .PP
1659 Accordingly, the command
1660 .RS
1661 .KS
1662 .IP
1663 .ft CW
1664 .nf
1665 \&.PS
1666 copy thru % circle at ($1,$2) % until "END"
1667 1 2
1668 3 4
1669 5 6
1670 END
1671 box
1672 \&.PE
1673 .R
1674 .fi
1675 .KE
1676 .RE
1677 .LP
1678 is equivalent to
1679 .RS
1680 .KS
1681 .IP
1682 .ft CW
1683 .nf
1684 \&.PS
1685 circle at (1,2)
1686 circle at (3,4)
1687 circle at (5,6)
1688 box
1689 \&.PE
1690 .R
1691 .fi
1692 .KE
1693 .RE
1694 .NH 2
1695 Debug Messages
1696 .PP
1697 The command \fBprint\fR accepts any number of arguments, concatenates
1698 their output forms, and writes the result to standard error.  Each
1699 argument must be an expression, a position, or a text string.
1700 .NH 2
1701 Escape to Post-Processor
1702 .PP
1703 If you write
1704 .DS
1705 \fBcommand\fR \fIarg\fR\|.\|.\|.
1706 .DE
1707 .LP
1708 \fBpic\fP concatenates the arguments and pass them through as a line
1709 to troff or \*[tx].  Each
1710 .I arg
1711 must be an expression, a position, or text.
1712 This has a similar effect to a line beginning with
1713 .B .
1714 or
1715 \fB\e\fR\|,
1716 but allows the values of variables to be passed through.
1717 .NH 2
1718 Executing Shell Commands
1719 .PP
1720 The command 
1721 .DS
1722 \f(CWsh\fP \f(CW{\fP \fIanything.\|.\|.\fP \f(CW}\fP
1723 .DE
1724 .LP
1725 macro-expands the text in braces, then executes it as a shell command.
1726 This could be used to generate images or data tables for later
1727 inclusion.  The delimiters shown as {} here may also be two copies of
1728 any one character not present in the shell command text.  In either
1729 case, the body may contain balanced {} pairs.  Strings in the body
1730 may contain balanced or unbalanced braces in any case.
1731 .NH 1
1732 Control-flow constructs
1733 .PP
1734 The \fBpic\fP language provides conditionals and looping.  For
1735 example,
1736 .KS
1737 .DS
1738 .CW
1739 pi = atan2(0, -1);
1740 for i = 0 to 2 * pi by 0.1 do {
1741     "-" at (i/2, 0);
1742     "." at (i/2, sin(i)/2);
1743     ":" at (i/2, cos(i)/2);
1744 }
1745 .R
1746 .DE
1747 .KE
1748 .LP
1749 which yields this:
1750 .KS
1751 .PS
1752 pi = atan2(0, -1);
1753 for i = 0 to 2 * pi by 0.1 do {
1754     "-" at (i/2, 0);
1755     "." at (i/2, sin(i)/2);
1756     ":" at (i/2, cos(i)/2);
1757 }
1758 .PE
1759 .CE "1: Plotting with a \fBfor\fP loop"
1760 .LP
1761 The syntax of the \fBfor\fP statement is:
1762 .DS
1763 \fBfor\fR \fIvariable\fR \fB=\fR \fIexpr1\/\fR \fBto\fR \fIexpr2\/\fR \
1764 [\fBby\fR [\fB*\fR]\fIexpr3\/\fR] \fBdo\fR \fIX\fR \fIbody\fR \fIX\fR
1765 .DE
1766 The semantics are as follows:  Set
1767 .I variable
1768 to \fIexpr1\fR.
1769 While the value of
1770 .I variable
1771 is less than or equal to
1772 \fIexpr2\fR,
1773 do
1774 .I body
1775 and increment
1776 .I variable
1777 by
1778 \fIexpr3\fR;
1779 if
1780 .B by
1781 is not given, increment
1782 .I variable
1783 by\~1.
1784 If
1785 .I expr3
1786 is prefixed by\~\c
1787 .B *
1788 then
1789 .I variable
1790 will instead be multiplied by
1791 \fIexpr3\fR.
1792 .I X
1793 can be any character not occurring in
1794 \fIbody\fR; or the two \fIX\/\fPs may be paired braces (as in the
1795 \fBsh\fR command).
1796 .PP
1797 The syntax of the \fBif\fP statement is as follows:
1798 .DS
1799 \fBif\fR \fIexpr\fR \fBthen\fR \fIX\fR \fIif-true\fR \fIX\fR \
1800 [\fBelse\fR \fIY\fR \fIif-false\fR \fIY\/\fR]
1801 .DE
1802 Its semantics are as follows: Evaluate
1803 \fIexpr\fR;
1804 if it is non-zero then do
1805 \fIif-true\fR,
1806 otherwise do
1807 \fIif-false\fR.
1808 .I X
1809 can be any character not occurring in
1810 \fIif-true\fR.
1811 .I Y
1812 can be any character not occurring in
1813 \fIif-false\fR.
1814 .PP
1815 Eithe or both of the
1816 .I X
1817 or
1818 .I Y
1819 pairs may instead be balanced pairs of
1820 braces ({ and\~}) as in the \fBsh\fR command.  In either case, the
1821 \fIif-true\fR may contain balanced pairs of braces.  None of these
1822 delimiters will be seen inside strings.
1823 .PP
1824 All the usual relational operators my be used in conditional expressions;
1825 \fB!\&\fP (logical negation, not factorial), \fB&&\fP, \fB|\||\fP, \fB==\fP,
1826 \fB!=\fP, \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
1827 .PP
1828 String comparison is also supported using \fB==\fP and \fB!=\fP.  String
1829 comparisons may need to be parenthesized to avoid syntactic
1830 ambiguities.
1831 .NH 1
1832 Interface To [gt]roff
1833 .PP
1834 The output of \fBpic\fP is \fB[gt]roff\fP drawing commands.  The GNU
1835 \fIgpic\/\fP(1) command warns that it relies on drawing extensions
1836 present in \fIgroff\/\fP(1) that are not present in \fItroff\/\fP(1).
1837 .NH 2
1838 Scaling Arguments
1839 .PP
1840 The DWB \fIpic\/\fP(1) program will accept one or two arguments to
1841 \&\fB.PS\fP, which is interpreted as a width and height in inches to
1842 which the results of \fIpic\/\fP(1) should be scaled (width and height
1843 scale independently).  If there is only one argument, it is
1844 interpreted as a width to scale the picture to, and height will be
1845 scaled by the same proportion.
1846 .PP
1847 GNU \fBgpic\fP is less general; it will accept a single width to scale
1848 to, or a zero width and a maximum height to scale to.  With
1849 two non-zero arguments, it will scale to the maximum height.
1850 .NH 2
1851 How Scaling is Handled
1852 .PP
1853 When \fBpic\fP processes a picture description on input, it passes
1854 \fB.PS\fP and \fB.PE\fP through to the postprocessor.  The \fB.PS\fP
1855 gets decorated with two numeric arguments which are the X and
1856 Y\~dimensions of the picture in inches.  The post-processor can use
1857 these to reserve space for the picture and center it.
1858 .PP
1859 The GNU incarnation of the \fBms\fP macro package, for example, includes
1860 the following definitions:
1861 .KS
1862 .DS
1863 .ps -1
1864 .vs -1
1865 .CW
1866 \&.de PS
1867 \&.br
1868 \&.sp \e\en[DD]u
1869 \&.ie \e\en[.$]<2 .@error bad arguments to PS (not preprocessed with pic?)
1870 \&.el \e{\e
1871 \&.     ds@need (u;\e\e$1)+1v
1872 \&.     in +(u;\e\en[.l]-\e\en[.i]-\e\e$2/2>?0)
1873 \&.\e}
1874 \&..
1875 \&.de PE
1876 \&.par@reset
1877 \&.sp \e\en[DD]u+.5m
1878 \&..
1879 .R
1880 .DE
1881 .ps
1882 .vs
1883 .KE
1884 .LP
1885 Equivalent definition will be supplied by GNU \fIpic\/\fP(1) if you use
1886 the \-mpic option; this should make it usable with macro pages other
1887 than \fIms\/\fR(1).
1888 .PP
1889 If \fB.PF\fP is used instead of \fB.PE\fP, the \fBtroff\fP position is
1890 restored to what it was at the picture start (Kernighan notes that
1891 the\~F stands for \[lq]flyback\[rq]).
1892 .PP
1893 The invocation
1894 .DS
1895 \&\fB.PS <\,\fP\fIfile\fP
1896 .DE
1897 .LP
1898 causes the contents of \fIfile\fP to replace the \fB.PS\fP line.  This
1899 feature is deprecated; use `\fBcopy\fP \fIfile\fR' instead).
1900 .PP
1901 By default, input lines that begin with a period are passed to the
1902 postprocessor, embedded at the corresponding point in the output.
1903 Messing with horizontal or vertical spacing is an obvious recipe for
1904 bugs, but point size and font changes will usually be safe.
1905 .PP
1906 Point sizes and font changes are also safe within text strings, as
1907 long as they are undone before the end of string.
1908 .PP
1909 The state of \fB[gt]roff\fP's fill mode is preserved across pictures.
1910 .PP
1911 The Kernighan paper notes that there is a subtle problem with
1912 complicated equations inside \fBpic\fR pictures; they come out wrong if
1913 \fIeqn\/\fP(1) has to leave extra vertical space for the equation.
1914 If your equation involves more than subscripts and superscripts, you
1915 must add to the beginning of each equation the extra information
1916 \fBspace\~0\fP.  He gives the following example:
1917 .KS
1918 .DS
1919 .CW
1920 arrow
1921 box "$space 0 {H( omega )} over {1 - H( omega )}$"
1922 arrow
1923 .R
1924 .DE
1925 .KE
1926 .EQ
1927 delim @@
1928 .EN
1929 .KS
1930 .PS
1931 arrow
1932 box "@space 0 {H( omega )} over {1 - H( omega )}@"
1933 arrow
1934 .PE
1935 .CE "1: Equations within pictures"
1936 .NH 1
1937 Interface to TeX
1938 .PP
1939 .PP
1940 \*[tx] mode is enabled by the
1941 .B \-t
1942 option.
1943 In \*[tx] mode, pic will define a vbox called
1944 .B \egraph
1945 for each picture.
1946 You must yourself print that vbox using, for example, the command
1947 .RS
1948 .LP
1949 .CW
1950 \ecenterline{\ebox\egraph}
1951 .RE
1952 .LP
1953 Actually, since the vbox has a height of zero this will produce
1954 slightly more vertical space above the picture than below it;
1955 .RS
1956 .LP
1957 .CW
1958 \ecenterline{\eraise 1em\ebox\egraph}
1959 .RE
1960 .LP
1961 would avoid this.
1962 .PP
1963 You must use a \*[tx] driver that supports the
1964 .B tpic
1965 specials, version\~2.
1966 .PP
1967 Lines beginning with
1968 .B \e
1969 are passed through transparently; a
1970 .B %
1971 is added to the end of the line to avoid unwanted spaces.
1972 You can safely use this feature to change fonts or to
1973 change the value of \fB\ebaselineskip\fR.
1974 Anything else may well produce undesirable results; use at your own risk.
1975 Lines beginning with a period are not given any special treatment.
1976 .PP
1977 The \*[tx] mode of \fIpic\/\fP(1) will \fInot\fP translate \fBtroff\fP
1978 font and size changes included in text strings!
1979 .NH 1
1980 Obsolete Commands
1981 .PP
1982 GNU \fIgpic\/\fP(1)  has a command
1983 .DS
1984 \fBplot\fR \fIexpr\fR [\fB"\fItext\fB"\fR]
1985 .DE
1986 This is a text object which is constructed by using
1987 .I text
1988 as a format string for sprintf
1989 with an argument of
1990 \fIexpr\fP.
1991 If
1992 .I text
1993 is omitted a format string of \fB"%g"\fP is used.
1994 Attributes can be specified in the same way as for a normal text
1995 object.
1996 Be very careful that you specify an appropriate format string;
1997 \fBpic\fP does only very limited checking of the string.
1998 This is deprecated in favour of
1999 \fBsprintf\fP.
2000 .NH 1
2001 Some Larger Examples
2002 .PP
2003 Here are a few larger examples, with complete source code.
2004 One of our earlier examples is generated in an instructive way using a
2005 for loop:
2006 .KS
2007 .DS
2008 .ps -1
2009 .vs -1
2010 .CW
2011 \&.PS
2012 # Draw a demonstration up left arrow with grid box overlay
2013 define gridarrow
2014 {
2015     move right 0.1
2016     [
2017         {arrow up left $1;}
2018         box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2019         for i = 2 to ($1 / 0.5) do
2020         {
2021             box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2022         }
2023         move down from last arrow .center;
2024         [
2025             if ( $1 == boxht ) \e
2026             then { "\efBline up left\efP" } \e
2027             else { sprintf("\efBarrow up left %g\efP", $1) };
2028         ]
2029     ] 
2030     move right 0.1 from last [] .e;
2031 }
2032 gridarrow(0.5);
2033 gridarrow(1);
2034 gridarrow(1.5);
2035 gridarrow(2);
2036 undef gridarrow
2037 \&.PE
2038 .R
2039 .DE
2040 .ps
2041 .vs
2042 .KE
2043 .KS
2044 .PS
2045 # Draw a demonstration up left arrow with grid box overlay
2046 define gridarrow
2047 {
2048         move right 0.1
2049         [
2050                 {arrow up left $1;}
2051                 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2052                 for i = 2 to ($1 / 0.5) do
2053                 {
2054                         box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2055                 }
2056                 move down from last arrow .center;
2057                 [
2058                         if ( $1 == boxht ) \
2059                         then { "\fBline up left\fP" } \
2060                         else { sprintf("\fBarrow up left %g\fP", $1) };
2061                 ]
2062         ] 
2063         move right 0.1 from last [] .e;
2064 }
2065 gridarrow(0.5);
2066 gridarrow(1);
2067 gridarrow(1.5);
2068 gridarrow(2);
2069 undef gridarrow
2070 .PE
2071 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
2072 .PP
2073 Here's an example concocted to demonstrate layout of a large,
2074 multiple-part pattern:
2075 .KS
2076 .DS
2077 .ps -1
2078 .vs -1
2079 .CW
2080 \&.PS
2081 define filter {box ht 0.25 rad 0.125}
2082 lineht = 0.25;
2083 Top: [
2084     right;
2085     box "\efBms\efR" "sources";
2086     move;
2087     box "\efBHTML\efR" "sources";
2088     move;
2089     box "\efBlinuxdoc-sgml\efP" "sources" wid 1.5;
2090     move;
2091     box "\efBTexinfo\efP" "sources";
2092
2093     line down from 1st box .s lineht;
2094     A: line down;
2095     line down from 2nd box .s; filter "\efBhtml2ms\efP";
2096     B: line down;
2097     line down from 3rd box .s; filter "\efBformat\efP";
2098     C: line down;
2099     line down from 4th box .s; filter "\efBtexi2roff\efP";
2100     D: line down;
2101 ]
2102 move down 1 from last [] .s;
2103 Anchor: box wid 1 ht 0.75 "\efBms\efR" "intermediate" "form";
2104 arrow from Top.A.end to Anchor.nw;
2105 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2106 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2107 arrow from Top.D.end to Anchor.ne
2108 {
2109     # PostScript column
2110     move to Anchor .sw;
2111     line down left then down ->;
2112     filter "\efBpic\efP";
2113     arrow;
2114     filter "\efBeqn\efP";
2115     arrow;
2116     filter "\efBtbl\efP";
2117     arrow;
2118     filter "\efBgroff\efP";
2119     arrow;
2120     box "PostScript";
2121
2122     # HTML column
2123     move to Anchor .se;
2124     line down right then down ->;
2125     A: filter dotted "\efBpic2img\efP";
2126     arrow;
2127     B: filter dotted "\efBeqn2html\efP";
2128     arrow;
2129     C: filter dotted "\efBtbl2html\efP";
2130     arrow;
2131     filter "\efBms2html\efP";
2132     arrow;
2133     box "HTML";
2134
2135     # Nonexistence caption
2136     box dashed wid 1 at B + (2, 0) "These tools" "don't yet exist";
2137     line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2138     line chop 0 chop 0.1 dashed from last box .w  to B.e ->;
2139     line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2140 }
2141 \&.PE
2142 .R
2143 .DE
2144 .ps
2145 .vs
2146 .KE
2147 .KS
2148 .PS
2149 define filter {box ht 0.25 rad 0.125}
2150 lineht = 0.25;
2151 Top: [
2152     right;
2153     box "\fBms\fR" "sources";
2154     move;
2155     box "\fBHTML\fR" "sources";
2156     move;
2157     box "\fBlinuxdoc-sgml\fP" "sources" wid 1.5;
2158     move;
2159     box "\fBTexinfo\fP" "sources";
2160
2161     line down from 1st box .s lineht;
2162     A: line down;
2163     line down from 2nd box .s; filter "\fBhtml2ms\fP";
2164     B: line down;
2165     line down from 3rd box .s; filter "\fBformat\fP";
2166     C: line down;
2167     line down from 4th box .s; filter "\fBtexi2roff\fP";
2168     D: line down;
2169 ]
2170 move down 1 from last [] .s;
2171 Anchor: box wid 1 ht 0.75 "\fBms\fR" "intermediate" "form";
2172 arrow from Top.A.end to Anchor.nw;
2173 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2174 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2175 arrow from Top.D.end to Anchor.ne
2176 {
2177     # PostScript column
2178     move to Anchor .sw;
2179     line down left then down ->;
2180     filter "\fBpic\fP";
2181     arrow;
2182     filter "\fBeqn\fP";
2183     arrow;
2184     filter "\fBtbl\fP";
2185     arrow;
2186     filter "\fBgroff\fP";
2187     arrow;
2188     box "PostScript";
2189
2190     # HTML column
2191     move to Anchor .se;
2192     line down right then down ->;
2193     A: filter dotted "\fBpic2img\fP";
2194     arrow;
2195     B: filter dotted "\fBeqn2html\fP";
2196     arrow;
2197     C: filter dotted "\fBtbl2html\fP";
2198     arrow;
2199     filter "\fBms2html\fP";
2200     arrow;
2201     box "HTML";
2202
2203     # Nonexistence caption
2204     box dashed wid 1 at B + (2, 0) "These tools" "don't yet exist";
2205     line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2206     line chop 0 chop 0.1 dashed from last box .w  to B.e ->;
2207     line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2208 }
2209 .PE
2210 .CE "2: Hypothetical production flow for dual-mode publishing"
2211 .LP
2212 .\"%%REFERENCE%%
2213 .NH 1
2214 PIC Reference
2215 .PP
2216 This is an annotated grammar of \fBpic\fP.
2217 .NH 2
2218 Lexical Items
2219 .PP
2220 In general, \fBpic\fP is a free-format, token-oriented language that
2221 ignores whitespace outside strings.  But certain lines and contructs
2222 are specially interpreted at the lexical level:
2223 .PP
2224 A comment begins with \fB#\fP and continues to \fB\en\fP (comments may
2225 also follow text in a line).  A line beginning with a period or
2226 backslash may be interpreted as text to be passed through to the
2227 post-processor, depending on command-line options.  An end-of-line
2228 backslash is interpreted as a request to continue the line; the
2229 backslash and following newline are ignored.
2230 .PP
2231 .RS
2232 Here are the grammar terminals:
2233 .IP \s[-1]INT\s[0]
2234 A positive integer.
2235 .IP \s[-1]NUMBER\s[0]
2236 A floating point numeric constant.  May contain a decimal point or be
2237 expressed in scientific notation in the style of \fIprintf\/\fP(3)'s %e
2238 escape.  A trailing `i' or `I' (indicating the unit `inch') is ignored.
2239 .IP \s[-1]TEXT\s[0]
2240 A string enclosed in double quotes.  A double quote within \s[-1]TEXT\s[0]
2241 must be preceded by a backslash.  Instead of \s[-1]TEXT\s[0] you can use
2242 .DS
2243 .CW
2244 sprintf ( TEXT [, <expr> ...] )
2245 .R
2246 .DE
2247 .IP
2248 except after the `until' and `last' keywords, and after all ordinal
2249 keywords (`th' and friends).
2250 .IP \s[-1]VARIABLE\s[0]
2251 A string starting with a character from the set [a-z], optionally
2252 followed by one or more characters of the set [a-zA-Z0-9_].
2253 (Values of variables are preserved across pictures.)
2254 .IP \s[-1]LABEL\s[0]
2255 A string starting with a character from the set [A-Z], optionally
2256 followed by one or more characters of the set [a-zA-Z0-9_].
2257 .IP \s[-1]COMMAND-LINE\s[0]
2258 A line starting with a command character (`.' in groff mode, `\e' in
2259 \*[tx] mode).
2260 .IP \s[-1]BALANCED-TEXT\s[0]
2261 A string either enclosed by `{' and `}' or with \fIX\fP and \fIX\fP,
2262 where \fIX\fP doesn't occur in the string.
2263 .IP \s[-1]BALANCED-BODY\s[0]
2264 Delimiters as in \s[-1]BALANCED-TEXT\s[0]; the body will be interpreted as
2265 `\fB\[la]command\[ra].\|.\|.\fP'.
2266 .IP \s[-1]FILENAME\s[0]
2267 The name of a file.  This has the same semantics as \s[-1]TEXT\s[0].
2268 .IP \s[-1]MACRONAME\s[0]
2269 Either \s[-1]VARIABLE\s[0] or \s[-1]LABEL\s[0].
2270 .RE
2271 .NH 2
2272 Semi-Formal Grammar
2273 .PP
2274 Tokens not enclosed in \[la]\|\[ra] are literals, except:
2275 .IP 1.
2276 \fB\en\fP is a newline.
2277 .IP 2.
2278 Three dots is a suffix meaning `replace with 0 or more repetitions
2279 of the preceding element(s).
2280 .IP 3.
2281 An enclosure in square brackets has its usual meaning of `this clause is
2282 optional'.
2283 .IP 4.
2284 Square-bracket-enclosed portions within tokens are optional.  Thus,
2285 `h\^[eigh]\^t' matches either `height' or `ht'.
2286 .LP
2287 If one of these special tokens has to be referred to literally, it is
2288 surrounded with single quotes.
2289 .PP
2290 The top-level \fBpic\fP object is a picture.
2291 .DS
2292 .CW
2293 <picture> ::=
2294   .PS [NUMBER [NUMBER]]\en
2295   <statement> ...
2296   .PE \en
2297 .R
2298 .DE
2299 .PP
2300 The arguments, if present, represent the width and height of the picture,
2301 causing \fBpic\fR to attempt to scale it to the given dimensions in
2302 inches.  In no case, however, will the X and Y\~dimensions of the
2303 picture exceed the values of the style variables \fBmaxpswid\fP and
2304 \fBmaxpsheight\fP (which default to the normal 8.5\^i by 11\^i page size).
2305 .PP
2306 If the ending `.PE' is replaced by `.PF', the page vertical position is
2307 restored to its value at the time `.PS' was encountered.  Another
2308 alternate form of invocation is `.PS\ <\s[-1]FILENAME\s[0]', which
2309 replaces the `.PS' line with a file to be interpreted by \fBpic\fR (but
2310 this feature is deprecated).
2311 .PP
2312 The `.PS', `.PE', and `.PF' macros to perform centering and scaling are
2313 normally supplied by the post-processor.
2314 .PP
2315 In the following, either `|' or a new line starts an alternative.
2316 .DS
2317 .CW
2318 <statement> ::=
2319   <command> ;
2320   <command> \en
2321 .R
2322 .DE
2323 .DS
2324 .CW
2325 <command> ::=
2326   <primitive> [<attribute>]
2327   LABEL : [;] <command>
2328   LABEL : [;] <command> [<position>]
2329   { <command> ... }
2330   VARIABLE [:] = <any-expr>
2331   up | down | left | right
2332   COMMAND-LINE
2333   command <print-arg> ...
2334   print <print-arg> ...
2335   sh BALANCED-TEXT
2336   copy FILENAME
2337   copy [FILENAME] thru MACRONAME [until TEXT]
2338   copy [FILENAME] thru BALANCED-BODY [until TEXT]
2339   for VARIABLE = <expr> to <expr> [by [*] <expr>] do BALANCED-BODY
2340   if <any-expr> then BALANCED-BODY [else BALANCED-BODY]
2341   reset [VARIABLE [[,] VARIABLE ...]]
2342 .R
2343 .DE
2344 .DS
2345 .CW
2346 <print-arg> ::=
2347   TEXT
2348   <expr>
2349   <position>
2350 .R
2351 .DE
2352 .PP
2353 The current position and direction are saved on entry to a `{\ .\|.\|.\ }'
2354 construction and restored on exit from it.
2355 .PP
2356 Note that in `if' constructions, newlines can only occur in
2357 \s[-1]BALANCED-BODY\s[0].  This means that
2358 .DS
2359 .CW
2360 if
2361 { ... }
2362 else
2363 { ... }
2364 .R
2365 .DE
2366 .PP
2367 will fail.  You have to use the braces on the same line as the keywords:
2368 .DS
2369 .CW
2370 if {
2371 \&...
2372 } else {
2373 \&...
2374 }
2375 .R
2376 .DE
2377 .PP
2378 This restriction doesn't hold for the body after the `do' in a `for'
2379 construction.
2380 .DS
2381 .CW
2382 <any-expr> ::=
2383   <expr>
2384   <text-expr>
2385   <any-expr> <logical-op> <any-expr>
2386   ! <any-expr>
2387 .R
2388 .DE
2389 .DS
2390 .CW
2391 <logical-op> ::=
2392   == | != | && | '||'
2393 .R
2394 .DE
2395 .DS
2396 .CW
2397 <text-expr> ::=
2398   TEXT == TEXT
2399   TEXT != TEXT
2400 .R
2401 .DE
2402 .PP
2403 Logical operators are handled specially by \fBpic\fP since they can
2404 deal with text strings also.  \fBpic\fP uses \%\fIstrcmp\/\fP(3) to test
2405 for equality of strings; an empty string is considered as `false' for
2406 `&&' and `|\||'.
2407 .DS
2408 .CW
2409 <primitive> ::=
2410   box                   \fR# closed object \[em] rectangle\fP
2411   circle                \fR# closed object \[em] circle\fP
2412   ellipse               \fR# closed object \[em] ellipse\fP
2413   arc                   \fR# open object \[em] quarter-circle\fP
2414   line                  \fR# open object \[em] line\fP
2415   arrow                 \fR# open object \[em] line with arrowhead\fP
2416   spline                \fR# open object \[em] spline curve\fP
2417   move
2418   TEXT TEXT ...         \fR# text within invisible box\fP
2419   plot <expr> TEXT      \fR# formatted text\fP
2420   '[' <command> ... ']'
2421 .R
2422 .DE
2423 .PP
2424 Drawn objects within `[\ .\|.\|.\ ]' are treated as a single composite
2425 object with a rectangular shape (that of the bounding box of all the
2426 elements).  Variable and label assignments within a block are local to
2427 the block.  Current direction of motion is restored to the value at start
2428 of block upon exit.  Position is \fInot\fR restored (unlike `{\ }');
2429 instead, the current position becomes the exit position for the current
2430 direction on the block's bounding box.
2431 .DS
2432 .CW
2433 <attribute> ::=
2434   h[eigh]t <expr>       \fR# set height of closed figure \fP
2435   wid[th] <expr>        \fR# set width of closed figure \fP
2436   rad[ius] <expr>       \fR# set radius of circle/arc \fP
2437   diam[eter] <expr>     \fR# set diameter of circle/arc \fP
2438   up [<expr>]           \fR# move up \fP
2439   down [<expr>]         \fR# move down \fP
2440   left [<expr>]         \fR# move left \fP
2441   right [<expr>]        \fR# move right \fP
2442   from <position>       \fR# set from position of open figure\fP
2443   to <position>         \fR# set to position of open figure\fP
2444   at <position>         \fR# set center of open figure\fP
2445   with <path>           \fR# fix corner/named point at specified location\fP
2446   with <position>       \fR# fix position of object at specified location\fP
2447   by <expr-pair>        \fR# set object's attachment point\fP
2448   then                  \fR# sequential segment composition\fP
2449   dotted [<expr>]       \fR# set dotted line style\fP
2450   dashed [<expr>]       \fR# set dashed line style\fP
2451   thick[ness] <expr>    \fR# set thickness of lines\fP
2452   chop [<expr>]         \fR# chop end(s) of segment\fP
2453   '->' | '<-' | '<->'   \fR# decorate with arrows\fP
2454   invis[ible]           \fR# make primitive invisible\fP
2455   solid                 \fR# make closed figure solid\fP
2456   fill[ed] [<expr>]     \fR# set fill density for figure\fP
2457   colo[u]r[ed] TEXT     \fR# set fill and outline color for figure\fP
2458   outline[d] TEXT       \fR# set outline color for figure\fP
2459   shaded TEXT           \fR# set fill color for figure\fP
2460   same                  \fR# copy size of previous object\fP
2461   cw | ccw              \fR# set orientation of curves\fP
2462   ljust | rjust         \fR# adjust text horizontally\fP
2463   above | below         \fR# adjust text vertically\fP
2464   aligned               \fR# align parallel to object\fP
2465   TEXT TEXT ...         \fR# text within object\fP
2466   <expr>                \fR# motion in the current direction\fR
2467 .R
2468 .DE
2469 .PP
2470 Missing attributes are supplied from defaults; inappropriate ones are
2471 silently ignored.  For lines, splines, and arcs, height and width
2472 refer to arrowhead size.
2473 .PP
2474 The `at' primitive sets the center of the current object.  The
2475 `with' attribute fixes the specified feature of the given object
2476 to a specified location.  (Note that `with' is incorrectly described
2477 in the Kernighan paper.)
2478 .PP
2479 The `by' primitive is not documented in the tutorial portion of
2480 the Kernighan paper, and should probably be considered unreliable.
2481 .PP
2482 The primitive `arrow' is a synonym for `line\ ->'.
2483 .PP
2484 Text is normally an attribute of some object, in which case successive
2485 strings are vertically stacked and centered on the object's center by
2486 default.  Standalone text is treated as though placed in an invisible
2487 box.
2488 .PP
2489 A text item consists of a string or sprintf-expression, optionally
2490 followed by positioning information.  Text (or strings specified with
2491 `sprintf' may contain [gtn]roff font changes, size changes, and local
2492 motions, provided those changes are undone before the end of the current
2493 item.
2494 .PP
2495 A position is an (x,y) coordinate pair.  There are lots of different
2496 ways to specify positions:
2497 .DS
2498 .CW
2499 <position> ::=
2500   <position-not-place>
2501   <place>
2502 .R
2503 .DE
2504 .DS
2505 .CW
2506 <position-not-place> ::=
2507   <expr-pair>
2508   <position> + <expr-pair>
2509   <position> - <expr-pair>
2510   ( <position> , <position> )
2511   <expr> [of the way] between <position> and <position>
2512   <expr> '<' <position> , <position> '>'
2513 .R
2514 .DE
2515 .DS
2516 .CW
2517 <expr-pair> ::=
2518   <expr> , <expr>
2519   ( expr-pair )
2520 .R
2521 .DE
2522 .DS
2523 .CW
2524 <place> ::=
2525   <label>
2526   <label> <corner>
2527   <corner> [of] <label>
2528   Here
2529 .R
2530 .DE
2531 .DS
2532 .CW
2533 <label> ::=
2534   LABEL [. LABEL ...]
2535   <nth-primitive>
2536 .R
2537 .DE
2538 .DS
2539 .CW
2540 <corner> ::=
2541   .n | .e | .w | .s
2542   .ne | .se | .nw | .sw
2543   .c[enter] | .start | .end
2544   .t[op] | .b[ot[tom]] | .l[eft] | .r[ight]
2545   left | right | <top-of> | <bottom-of>
2546   <north-of> | <south-of> | <east-of> | <west-of>
2547   <center-of> | <start-of> | <end-of>
2548   upper left | lower left | upper right | lower right
2549 .R
2550 .DE
2551 .DS
2552 .CW
2553 <xxx-of> ::=
2554   xxx                   \fR# followed by `of'\fP
2555 .R
2556 .DE
2557 .DS
2558 .CW
2559 <nth-primitive> ::=
2560   <ordinal> <object-type>
2561   [<ordinal>] last <object-type>
2562 .R
2563 .DE
2564 .DS
2565 .CW
2566 <ordinal> ::=
2567   INT th
2568   INT st | INT nd | INT rd
2569   ` <any-expr> 'th
2570 .R
2571 .DE
2572 .DS
2573 .CW
2574 <object-type> ::=
2575   box
2576   circle
2577   ellipse
2578   arc
2579   line
2580   arrow
2581   spline
2582   '[]'
2583   TEXT
2584 .R
2585 .DE
2586 .PP
2587 As Kernighan notes, \[lq]since barbarisms like \fB1th\fP and \fB3th\fP are
2588 barbaric, synonyms like \fB1st\fP and \fB3rd\fP are accepted as well.\[rq]
2589 Objects of a given type are numbered from 1 upwards in order of
2590 declaration; the \fBlast\fP modifier counts backwards.
2591 .PP
2592 The \[lq]'th\[rq] form (which allows you to select a previous object with
2593 an expression, as opposed to a numeric literal) is not documented in DWB's
2594 \fIpic\/\fR(1).
2595 .PP
2596 The \[la]\|\fIxxx\fP-of\|\[ra] rule is special: The lexical parser checks whether
2597 \fIxxx\fP is followed by the token `of' without eliminating it so that
2598 the grammar parser can still see `of'.  Valid examples of specifying a
2599 place with corner and label are thus
2600 .DS
2601 .CW
2602 A .n
2603 \&.n of A
2604 \&.n A
2605 north of A
2606 .R
2607 .DE
2608 .LP
2609 while
2610 .DS
2611 .CW
2612 north A
2613 A north
2614 .R
2615 .DE
2616 both cause a syntax error.  (DWB \fBpic\fP also allows the weird form
2617 `A\ north\ of'.)
2618 .PP
2619 Here the special rules for the `with' keyword using a path:
2620 .DS
2621 .CW
2622 <path> ::=
2623   <relative-path>
2624   ( <relative-path> , <relative-path> )
2625 .R
2626 .DE
2627 .DS
2628 .CW
2629 <relative-path> ::=
2630   <corner>
2631   . LABEL [. LABEL ...] [<corner>]
2632 .R
2633 .DE
2634 .PP
2635 The following style variables control output:
2636 .TS H
2637 center tab(@), linesize(2);
2638 lb | lb | lb
2639 l | n | l.
2640 .sp 2p
2641 Style Variable@Default@What It Does
2642 .sp 2p
2643 _
2644 .sp 2p
2645 .TH
2646 boxht@0.5@Default height of a box
2647 boxwid@0.75@Default height of a box
2648 lineht@0.5@Default length of vertical line
2649 linewid@0.75@Default length of horizontal line
2650 arcrad @0.25@Default radius of an arc
2651 circlerad@0.25@Default radius of a circle
2652 ellipseht@0.5@Default height of an ellipse
2653 ellipsewid@0.75@Default width of an ellipse
2654 moveht@0.5@Default length of vertical move
2655 movewid@0.75@Default length of horizontal move
2656 textht@0@Default height of box enclosing a text object
2657 textwid@0@Default width of box enclosing a text object
2658 arrowht@0.1@Length of arrowhead along shaft
2659 arrowwid@0.05@Width of rear of arrowhead
2660 arrowhead@1@Enable/disable arrowhead filling
2661 dashwid@0.05@Interval for dashed lines
2662 maxpswid@11@Maximum width of picture
2663 maxpsht@8.5@Maximum height of picture
2664 scale@1@Unit scale factor
2665 fillval@0.5@Default fill value
2666 .sp 5p
2667 _
2668 .TE
2669 Any of these can be set by assignment, or reset using the \fBreset\fP
2670 statement.  Style variables assigned within `[\ ]' blocks are restored to
2671 their beginning-of-block value on exit; top-level assignments persist
2672 across pictures.  Dimensions are divided by \fBscale\fR on output.
2673 .PP
2674 All \fBpic\fP expressions are evaluated in floating point; units
2675 are always inches (a trailing `i' or `I' is ignored).  Expressions have
2676 the following simple grammar, with semantics very similar to
2677 C\~expressions:
2678 .DS
2679 .CW
2680 <expr> ::=
2681   VARIABLE
2682   NUMBER
2683   <place> <place-attribute>
2684   <expr> <op> <expr>
2685   - <expr>
2686   ( <any-expr> )
2687   ! <expr>
2688   <func1> ( <any-expr> )
2689   <func2> ( <any-expr> , <any-expr> )
2690   rand ( )
2691 .R
2692 .DE
2693 .DS
2694 .CW
2695 <place-attribute>
2696  .x | .y | .h[eigh]t | .wid[th] | .rad
2697 .R
2698 .DE
2699 .DS
2700 .CW
2701 <op> ::=
2702   + | - | * | / | % | ^ | '<' | '>' | '<=' | '>='
2703 .R
2704 .DE
2705 .DS
2706 .CW
2707 <func1> ::=
2708   sin | cos | log | exp | sqrt | int | rand | srand
2709 .R
2710 .DE
2711 .DS
2712 .CW
2713 <func2> ::=
2714   atan2 | max | min
2715 .R
2716 .DE
2717 .LP
2718 Both \fBexp\fP and \fBlog\fP are base 10; \fBint\fP does integer
2719 truncation; and \fBrand()\fP returns a random number in [0-1).
2720 .PP
2721 There are \fBdefine\fP and \fBundef\fR statements which are not part
2722 of the grammar (they behave as pre-processor macros to the language).
2723 These may be used to define pseudo-functions.
2724 .DS
2725 .CW
2726 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement-text\fP \fB}\fP
2727 .R
2728 .DE
2729 .LP
2730 This defines \fIname\fR as a macro to be replaced by the replacement
2731 text (not including the braces).  The macro may be called as 
2732 .DS
2733 .CW
2734 \fIname\/\fB(\,\fIarg1, arg2, .\|.\|., argn\fB\/)\fR
2735 .R
2736 .DE
2737 .LP
2738 The arguments (if any) will be substituted for tokens $1, $2 .\|.\|.\& $n
2739 appearing in the replacement text.  To undefine a macro, say \fBundef\fP
2740 \fIname\fR, specifying the name to be undefined.
2741 .\"%%POSTLUDE%%
2742 .NH 1
2743 History and Acknowledgements
2744 .PP
2745 Original \fBpic\fP was written to go with Joseph Ossanna's original
2746 \fItroff\/\fP(1) by Brian Kernighan, and later re-written by Kernighan
2747 with substantial enhancements (apparently as part of the evolution of
2748 \fItroff\/\fP(1) into \fIditroff\/\fP(1) to generate
2749 device-independent output).
2750 .PP
2751 The language had been inspired by some earlier graphics languages
2752 including \fBideal\fP and \fBgrap\fP.  Kernighan credits Chris van Wyk
2753 (the designer of \fBideal\fP) with many of the ideas that went into
2754 \fBpic\fP.
2755 .PP
2756 .\" the original definitions of EQ and EN cause insertion of vertical
2757 .\" space which is not appropriate here
2758 .de EQ
2759 ..
2760 .de EN
2761 ..
2762 .EQ
2763 delim $$
2764 .EN
2765 The \fBpic\fP language was originally described by Brian Kernighan in
2766 Bell Labs Computing Science Technical Report #116 (you can obtain a
2767 PostScript copy of the revised version, [1], by sending a mail message to
2768 \fInetlib@research.att.com\fP with a body of `send 116 from
2769 research/cstr').  There have been two revisions, in 1984 and 1991.
2770 .PP
2771 The document you are reading effectively subsumes Kernighan's
2772 description; it was written to fill in lacun\[ae] in the exposition and
2773 integrate in descriptions of the GNU \fIgpic\/\fP(1) features.
2774 .PP
2775 The GNU \fBgpic\fR implementation was written by James Clark
2776 \[la]\,\fIjjc@jclark.com\/\fP\[ra].  It is currently maintained by Werner
2777 Lemberg \[la]\,\fIwl@gnu.org\/\fP\[ra].
2778 .NH 1
2779 Bibliography
2780 .IP 1.
2781 Kernighan, B. W.  \fBPIC \[em] A Graphics Language for Typesetting
2782 (Revised User Manual)\fP.  Bell Labs Computing Science Technical Report
2783 #116, December 1991.
2784 .IP 2.
2785 Van Wyk, C. J.  \fBA high-level language for specifying pictures\fP.
2786 \fIACM Transactions On Graphics\fP 1,2 (1982) 163-182.
2787 .
2788 .\" end of pic.ms