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