1 .\" Copyright (C) 2006, 2007, 2008
2 .\" Free Software Foundation, Inc.
3 .\" Written by Eric S. Raymond <esr@thyrsus.com>
5 .\" This file is part of groff.
7 .\" groff is free software; you can redistribute it and/or modify it under
8 .\" the terms of the GNU General Public License as published by the Free
9 .\" Software Foundation; either version 2, or (at your option) any later
12 .\" groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 .\" WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 .\" You should have received a copy of the GNU General Public License along
18 .\" with groff; see the file COPYING. If not, write to the Free Software
19 .\" Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
21 .\" For tolerably obvious reason, this needs to be processed through PIC.
22 .\" It also needs to be processed through TBL and EQN. Use "groff -p -e -t".
23 .\" There is no hope that this will ever look right under nroff.
25 .\" Comments beginning with %% are cut lines so portions of this
26 .\" document can be automatically extracted. %%TUTORIAL%% begins the
27 .\" tutorial part; %%REFERENCE%% the reference part. %%POSTLUDE%% the
28 .\" bibliography and end matter after the reference part.
30 .\" This document was written for free use and redistribution by
31 .\" Eric S. Raymond <esr@thyrsus.com> in August 1995. It has been put
32 .\" under the GPL in March 2006.
37 .\" Set a proper TeX and LaTeX
39 . ds tx T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X\"
40 . ds lx L\h'-0.36m'\v'-0.22v'\s-2A\s0\h'-0.15m'\v'0.22v'\*(tx\"
47 .\" Centered caption for figure. Assumes previous .KS
55 .\" Definitions end here
59 Making Pictures With GNU PIC
63 \[la]\fIesr@snark.thyrsus.com\fP\[ra]
65 The \fBpic\fP language is a \fBtroff\fP extension that makes it easy
66 to create and alter box-and-arrow diagrams of the kind frequently used
67 in technical papers and textbooks. This paper is both an introduction
68 to and reference for \fIgpic\/\fP(1), the implementation distributed by
69 the Free Software Foundation for use with \fIgroff\/\fP(1). It also
70 catalogs other implementations and explains the differences among them.
81 The \fBpic\fP language provides an easy way to write procedural
82 box-and-arrow diagrams to be included in \fBtroff\fP documents. The
83 language is sufficiently flexible to be quite useful for state charts,
84 Petri-net diagrams, flow charts, simple circuit schematics, jumper
85 layouts, and other kinds of illustration involving repetitive uses of
86 simple geometric forms and splines. Because these descriptions are
87 procedural and object-based, they are both compact and easy to modify.
89 The phrase \[lq]GNU pic\[rq] may refer to either of two \fBpic\fP
90 implementations distributed by the Free Software Foundation and
91 intended to accept the same input language. The \fIgpic\/\fP(1)
92 implementation is for use with the \fIgroff\/\fP(1) implementation of
93 \fBtroff\fP. The \fIpic2plot\/\fP(1) implementation runs standalone
94 and is part of the \fBplotutils\fR package. Because both
95 implementations are widely available in source form for free, they are
96 good bets for writing very portable documentation.
101 The original 1984 pre-\fIditroff\/\fP(1) version of \fBpic\fP is long
102 obsolete. The rewritten 1991 version is still available as part of
103 the Documenter's Work Bench module of System V.
105 Where differences between Documenter's Work Bench (1991) \fBpic\fP and GNU
106 \fBpic\fP need to be described, original \fBpic\fP is referred to as
107 \[lq]DWB pic\[rq]. Details on the history of the program are given at the
108 end of this document.
110 The \fBpic2plot\fR program does not require the rest of the
111 \fIgroff\/\fP(1) toolchain to render graphics. It can display
112 \fBpic\fR diagrams in a X\~window, or generate output plots in a large
113 number of other formats. These formats include: PNG, PBM, PGM, PPM, GIF,
114 SVG, Adobe Illustrator format, idraw-editable Postscript, the WebCGM
115 format for Web-based vector graphics, the format used by the \fBxfig\fP
116 drawing editor, the Hewlett-Packard PCL\~5 printer language, the
117 Hewlett-Packard Graphics Language (by default, HP-GL/2), the ReGIS
118 (remote graphics instruction set) format developed by DEC, Tektronix
119 format, and device-independent GNU graphics metafile format.
121 In this document, \fIgpic\/\fP(1) and \fIpic2plot\/\fP(1) extensions are
128 Every \fBpic\fP description is a little program describing drawing
129 actions. The \fB[gtn]roff\fP-dependent versions compile the program
130 by \fIpic\/\fP(1) into \fIgtroff\/\fP(1) macros; the
131 \fIpic2plot\/\fP(1) implementation uses a plotting library to draw the
132 picture directly. Programs that process or display
133 \fIgtroff\/\fP(1) output need not know or care that parts of the image
134 began life as \fBpic\fP descriptions.
136 The \fIpic\/\fP(1) program tries to translate anything between \fB.PS\fP
137 and \fB.PE\fP markers, and passes through everything else. The normal
138 definitions of \fB.PS\fP and \fB.PE\fP in the \fIms\fP macro package
139 and elsewhere have also the side-effect of centering the \fBpic\fP output
145 If you make a \fBpic\fP syntax error, \fIgpic\/\fP(1) issues an
146 error message in the standard \fIgcc\/\fP(1)-like syntax. A typical
147 error message looks like this,
151 pic:pic.ms:<nnn>: parse error before `<token>'
152 pic:pic.ms:<nnn>: giving up on this picture
157 where \[la]nnn\[ra] is a line number, and \[la]token\[ra] is a token near (usually
158 just after) the error location.
164 Pictures are described procedurally, as collections of objects
165 connected by motions. Normally, \fBpic\fP tries to string together
166 objects left-to-right in the sequence they are described, joining them
167 at visually natural points. Here is an example illustrating the
168 flow of data in \fBpic\fP processing:
173 box width 0.6 "\fIgpic\/\fP(1)"
175 box width 1.1 "\fIgtbl\/\fP(1) or \fIgeqn\/\fP(1)" "(optional)" dashed;
177 box width 0.6 "\fIgtroff\/\fP(1)";
181 .CE "1: Flow of \fBpic\fP data"
183 This was produced from the following \fBpic\fP program:
192 box width 0.6 "\efIpic\e/\efP(1)"
194 box width 1.1 "\efIgtbl\e/\efP(1) or \efIgeqn\e/\efP(1)" "(optional)" dashed;
196 box width 0.6 "\efIgtroff\e/\efP(1)";
204 This little program illustrates several \fBpic\fP basics. Firstly, we
205 see how to invoke three object types; ellipses, arrows, and boxes. We
206 see how to declare text lines to go within an object (and that text
207 can have font changes in it). We see how to change the line style of
208 an object from solid to dashed. And we see that a box can be made
209 wider than its default size to accommodate more text (we'll discuss
210 this facility in detail in the next section).
212 We also get to see \fBpic\fP's simple syntax. Statements are ended by
213 newlines or semicolons. String quotes are required around all text
214 arguments, whether or not they contain spaces. In general, the order
215 of command arguments and modifiers like \[lq]width 1.2\[rq] or
216 \[lq]dashed\[rq] doesn't matter, except that the order of text arguments
219 Here are all but one of the basic \fBpic\fP objects at their default sizes:
232 arc; down; move; "arc"
234 .CE "2: Basic \fBpic\fP objects"
236 The missing simple object type is a \fIspline\fP. There is also a way
237 to collect objects into \fIblock composites\fP which allows you to
238 treat the whole group as a single object (resembling a box) for many
239 purposes. We'll describe both of these later on.
241 The box, ellipse, circle, and block composite objects are \fIclosed\/\fR;
242 lines, arrows, arcs and splines are \fIopen\fP. This distinction
243 is often important in explaining command modifiers.
245 Figure \n[H1]-2 was produced by the following \fBpic\fP program,
246 which introduces some more basic concepts:
261 arc; down; move; "arc"
267 The first thing to notice is the \fImove\fP command, which moves a
268 default distance (1/2 inch) in the current movement direction.
270 Secondly, see how we can also decorate lines and arrows with text.
271 The line and arrow commands each take two arguments here, specifying
272 text to go above and below the object. If you wonder why one argument
273 would not do, contemplate the output of \fBarrow "ow!"\fP:
278 .CE "3: Text centered on an arrow"
280 When a command takes one text string, \fBpic\fP tries to place it at
281 the object's geometric center. As you add more strings, \fBpic\fP
282 treats them as a vertical block to be centered. The program
289 line "1" "2" "3" "4";
290 line "1" "2" "3" "4" "5";
295 for example, gives you this:
302 line "1" "2" "3" "4";
303 line "1" "2" "3" "4" "5";
306 .CE "4: Effects of multiple text arguments"
308 The last line of Figure 3.2's program, `\fBarc; down; move;
309 "arc"\fP', describing the captioned arc, introduces several new ideas.
310 Firstly, we see how to change the direction in which objects are
311 joined. Had we written \fBarc; move; "arc"\fP,
312 omitting \fBdown\fP the caption would have been joined to the top
313 of the arc, like this:
318 .CE "5: Result of \fBarc; move; \"arc\"\fP"
320 This is because drawing an arc changes the default direction to the
321 one its exit end points at. To reinforce this point, consider:
326 .CE "6: Result of \fBarc cw; move; \"arc\"\fP"
328 All we've done differently here is specify \[lq]cw\[rq] for a clockwise arc
329 (\[lq]ccw\[rq] specifies counter-clockwise direction).
330 Observe how it changes the default direction to down, rather than up.
332 Another good way to see this via with the following program:
336 line; arc; arc cw; line
344 line; arc; arc cw; line;
346 .CE "7: Result of \fBline; arc; arc cw; line\fP"
348 Notice that we did not have to specify \[lq]up\[rq] for the second arc to be
349 joined to the end of the first.
351 Finally, observe that a string, alone, is treated as text to be
352 surrounded by an invisible box of a size either specified by width
353 and height attributes or by the defaults \fBtextwid\fR and
354 \fBtextht\fR. Both are initially zero (because we don't know the
361 Sizes are specified in inches. If you don't like inches, it's
362 possible to set a global style variable \fBscale\fP that changes the
363 unit. Setting \fBscale = 2.54\fP effectively changes the internal
364 unit to centimeters (all other size variable values are scaled
368 Default Sizes of Objects
370 Here are the default sizes for \fBpic\fP objects:
372 center, tab(@), linesize(2);
381 box@0.75" wide by 0.5" high
383 ellipse@0.75" wide by 0.5" high
391 The simplest way to think about these defaults is that they make the
392 other basic objects fit snugly into a default-sized box.
394 \fIpic2plot\/\fP(1) does not necessarily emit a physical inch for
395 each virtual inch in its drawing coordinate system. Instead, it draws
396 on a canvas 8\~virtual inches by 8\~virtual inches wide. If its
397 output page size is \[lq]letter\[rq], these virtual inches will map to
398 real ones. Specifying a different page size (such as, say,
399 \[lq]a4\[rq]) will scale virtual inches so they are output as one
400 eighth of the page width. Also, \fIpic2plot\/\fP(1) centers all
401 images by default, though the \fB\-n\fP option can be used to prevent
405 Objects Do Not Stretch!
407 Text is rendered in the current font with normal troff line spacing.
408 Boxes, circles, and ellipses do \fInot\fP automatically resize to fit
409 enclosed text. Thus, if you say \fBbox "this text far too long for a
410 default box"\fP you'll get this:
413 box "this text is far too long for a default box"
415 .CE "1: Boxes do not automatically resize"
417 which is probably not the effect you want.
422 To change the box size, you can specify a box width with the \[lq]width\[rq]
426 box width 3 "this text is far too long for a default box"
428 .CE "2: Result of \fBbox width 3 \"text far too long\"\fP"
430 This modifier takes a dimension in inches. There is also a \[lq]height\[rq]
431 modifier that changes a box's height. The \fBwidth\fP keyword may
432 be abbreviated to \fBwid\fP; the \fBheight\fP keyword to \fBht\fP.
435 Resizing Other Object Types
437 To change the size of a circle, give it a \fBrad[ius]\fP or
438 \fBdiam[eter]\fP modifier; this changes the radius or diameter of the
439 circle, according to the numeric argument that follows.
442 {circle rad 0.1; move down 0.2 from last circle .s; "0.1"};
443 move; circle rad 0.2 "0.2"; move; circle rad 0.3 "0.3";
445 .CE "3: Circles with increasing radii"
447 The \fBmove\fP command can also take a dimension, which just tells
448 it how many inches to move in the current direction.
450 Ellipses are sized to fit in the rectangular box defined by their
451 axes, and can be resized with \fBwidth\fP and \fBheight\fP like boxes.
453 You can also change the radius of curvature of an arc with \fBrad[ius]\fP
454 (which specifies the radius of the circle of which the arc is a segment).
455 Larger values yield flatter arcs.
458 {arc rad 0.1; move down 0.3 from last arc .center; "0.1"};
460 {arc rad 0.2; move down 0.4 from last arc .center; "0.2"};
462 {arc rad 0.3; move down 0.5 from last arc .center; "0.3"};
464 .CE "4: \fBarc rad\fP with increasing radii"
466 Observe that because an arc is defined as a quarter circle, increasing
467 the radius also increases the size of the arc's bounding box.
472 In place of a dimension specification, you can use the keyword
473 \fBsame\fR. This gives the object the same size as the previous one
474 of its type. As an example, the program
479 box; box wid 1 ht 1; box same; box
488 box; box wid 1 ht 1; box same; box
490 .CE "5: The \fBsame\fP keyword"
494 Generalized Lines and Splines
499 It is possible to specify diagonal lines or arrows by adding multiple \fBup\fP,
500 \fBdown\fP, \fBleft\fP, and \fBright\fP modifiers to the line object.
501 Any of these can have a multiplier. To understand the effects, think
502 of the drawing area as being gridded with standard-sized boxes.
505 # Draw a demonstration up left arrow with grid box overlay
511 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
512 for i = 2 to ($1 / 0.5) do {
513 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
515 move down from last arrow .center;
517 if ( $1 == boxht ) then {
520 sprintf("\fBarrow up left %g\fP", $1)
524 move right 0.1 from last [] .e;
532 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
535 Multi-Segment Line Objects
537 A \[lq]line\[rq] or \[lq]arrow\[rq] object may actually be a path
538 consisting of any number of segments of varying lengths and directions.
539 To describe a path, connect several line or arrow commands with the
543 define zigzag { $1 right 1 then down .5 left 1 then right 1 }
546 .CE "2: \fBline right 1 then down .5 left 1 then right 1\fP"
548 If a path starts with \fBthen\fP, the first segment is assumed to be into
549 the current direction, using the default length.
554 If you start a path with the \fBspline\fP keyword, the path vertices
555 are treated as control points for a spline curve fit.
559 move down 0.2 from last [] .s;
560 "The spline curve..."
561 move right from last [] .e;
564 spline from start of last line right 1 then down .5 left 1 then right 1;
565 "1" at last spline .start + (-0.1, 0);
566 "2" at last spline .start + (1.1, 0);
567 "3" at last spline .end + (-1.1, 0);
568 "4" at last spline .end + (0.1, 0);
570 move down 0.2 from last [] .s;
571 "...with tangents displayed"
574 .CE "3: \fBspline right 1 then down .5 left 1 then right 1\fP"
576 You can describe many natural-looking but irregular curves this
580 [spline right then up then left then down ->;]
581 move down 0.2 from last [] .s;
582 ["\fBspline right then up then left then down ->;\fP"]
583 move right 3 from last [] .se;
584 "\fBspline left then up right then down right ->;\fP"
586 [spline left then up right then down right ->;]
588 .CE "4: Two more spline examples"
590 Note the arrow decorations. Arrowheads can be applied naturally to
591 any path-based object, line or spline. We'll see how in the next
601 All \fBpic\fP implementations support the following font-styling
602 escapes within text objects:
604 Set Roman style (the default)
609 .IP "\efP\ \ \ \ \ \ "
610 Revert to previous style; only works one level deep, does not stack.
612 In the \fBpic\fP implementations that are preprocessors for a
613 toolchain that include \fB[gtn]roff\fP, text objects may also contain
614 \fB[gtn]roff\fP vertical- and horizontal-motion escapes such as \eh or \ev.
615 Troff special glyphs are also available. All \e-escapes will be
616 passed through to the postprocessing stage and have their normal
617 effects. The base font family is set by the \fB[gtn]roff\fP
618 environment at the time the picture is rendered.
620 \fBpic2plot\fP replaces \fB[gtn]roff\fP horizontal- and vertical-motion
621 escapes with \e-escapes of its own. Troff special glyphs are not
622 available, but in most back ends Latin-1 special characters and a
623 square-root radical will be. See the \fBpic2plot\fP documentation for
629 We've already seen that the modifier \fBdashed\fP can change the line
630 style of an object from solid to dashed. GNU \fBgpic\fP permits you to
631 dot or dash ellipses, circles, and arcs (and splines in \*[tx] mode
632 only); some versions of DWB may only permit dashing of lines and
633 boxes. It's possible to change the dash interval by specifying a
634 number after the modifier.
638 box dashed "default";
640 box dashed 0.05 "0.05";
642 box dashed 0.1 "0.1";
644 box dashed 0.15 "0.15";
646 box dashed 0.2 "0.2";
648 .CE "1: Dashed objects"
653 Another available qualifier is \fBdotted\fP. GNU \fBgpic\fP permits
654 you to dot or dash ellipses, circles, and arcs (and splines in \*[tx]
655 mode only); some versions of DWB may only permit dashing of lines and
656 boxes. It too can be suffixed with a number to specify the interval
660 box dotted "default";
662 box dotted 0.05 "0.05";
664 box dotted 0.1 "0.1";
666 box dotted 0.15 "0.15";
668 box dotted 0.2 "0.2";
670 .CE "2: Dotted objects"
675 It is also possible, in GNU \fBgpic\fP only, to modify a box so it has
679 box rad 0.05 "rad 0.05";
681 box rad 0.1 "rad 0.1";
683 box rad 0.15 "rad 0.15";
685 box rad 0.2 "rad 0.2";
687 box rad 0.25 "rad 0.25";
689 .CE "3: \fBbox rad\fP with increasing radius values"
691 Radius values higher than half the minimum box dimension are silently
692 truncated to that value.
697 GNU \fBgpic\fP supports slanted boxes:
700 box wid 1.2 xslanted 0.1 "xslanted 0.1";
702 box wid 1.2 yslanted -0.1 "yslanted -0.1";
704 box wid 1.2 xslanted -0.2 yslanted 0.1 "xslanted -0.2" "yslanted 0.1";
706 .CE "4: Various slanted boxes."
708 The \fBxslanted\fP and \fByslanted\fP attributes specify the x and
709 y\~offset, respectively, of the box's upper right corner from its default
715 Lines and arcs can be decorated as well. Any line or arc (and any
716 spline as well) can be decorated with arrowheads by adding one or more
722 .CE "5: Double-headed line made with \fBline <- ->\fP"
724 In fact, the \fBarrow\fP command is just shorthand for \fBline ->\fP. And
725 there is a double-head modifier <->, so the figure above could have been made
728 Arrowheads have a \fBwidth\fP attribute, the distance across the rear;
729 and a \fBheight\fP attribute, the length of the arrowhead along the shaft.
731 Arrowhead style is controlled by the style variable \fBarrowhead\fP.
732 The DWB and GNU versions interpret it differently. DWB defaults to
733 open arrowheads and an \fBarrowhead\fP value of\~2; the Kernighan
734 paper says a value of\~7 makes solid arrowheads. GNU \fBgpic\fP
735 defaults to solid arrowheads and an \fBarrowhead\fP value of\~1; a
736 value of\~0 produces open arrowheads. Note that solid arrowheads are
737 always filled with the current outline color.
742 It's also possible to change the line thickness of an object (this is
743 a GNU extension, DWB \fBpic\fP doesn't support it).
744 The default thickness of the lines used to draw objects is controlled by the
747 This gives the thickness of lines in points.
748 A negative value means use the default thickness:
749 in \*[tx] output mode, this means use a thickness of 8 milliinches;
750 in \*[tx] output mode with the
752 option, this means use the line thickness specified by
754 lines; in troff output mode, this means use a thickness proportional
755 to the pointsize. A zero value means draw the thinnest possible line
756 supported by the output device. Initially it has a value of -1.
757 There is also a \fBthickness\fP attribute (which can be abbreviated to
758 \fBthick\fP). For example, \fBcircle thickness 1.5\fP would draw a
759 circle using a line with a thickness of 1.5 points. The thickness of
760 lines is not affected by the value of the
762 variable, nor by any width or height given in the
769 The modifier \fBinvis[ible]\fP makes an object entirely invisible. This
770 used to be useful for positioning text in an invisible object that is
771 properly joined to neighboring ones. Newer DWB versions and GNU
772 \fBpic\fP treat stand-alone text in exactly this way.
777 It is possible to fill boxes, circles, and ellipses. The
778 modifier \fBfill[ed]\fP accomplishes this. You can suffix it with a fill
779 value; the default is given by the style variable \fBfillval\fP.
781 DWB \fBpic\fP and \fBgpic\fP have opposite conventions for fill values
782 and different defaults. DWB \fBfillval\fP defaults to 0.3 and smaller
783 values are darker; GNU \fBfillval\fP uses 0 for white and 1 for black.
786 circle fill; move; circle fill 0.4; move; circle fill 0.9;
788 .CE "6: \fBcircle fill; move; circle fill 0.4; move; circle fill 0.9;\fR"
790 GNU \fBgpic\fP makes some additional guarantees. A fill value greater
791 than 1 can also be used: this means fill with the shade of gray that
792 is currently being used for text and lines. Normally this is
793 black, but output devices may provide a mechanism for changing this.
794 The invisible attribute does not affect the filling of objects. Any
795 text associated with a filled object is added after the object
796 has been filled, so that the text is not obscured by the filling.
798 The closed-object modifier \fBsolid\fP is equivalent to \fBfill\fP
799 with the darkest fill value (DWB \fBpic\fP had this capability but
800 mentioned it only in a reference section).
805 As a GNU extension, three additional modifiers are available to specify
806 colored objects. \fBoutline\fP sets the color of the outline, \fBshaded\fP
807 the fill color, and \fBcolor\fP sets both. All three keywords expect a
808 suffix specifying the color. Example:
811 box color "yellow"; arrow color "cyan"; circle shaded "green" outline "black";
813 .CE "7: \fBbox color ""yellow""; arrow color ""cyan""; \
814 circle shaded ""green"" outline ""black"";\fR"
816 Alternative spellings are \fBcolour\fP, \fBcolored\fP, \fBcoloured\fP,
819 Predefined color names for \fI[gtn]roff\/\fP-based \fBpic\fP
820 implementations are defined in the device macro files, for example
821 \f(CWps.tmac\fP; additional colors can be defined with the
822 \fB.defcolor\fP request (see the manual page of GNU \fItroff\/\fP(1)
823 for more details). Currently, color support is not available at all
826 The \fIpic2plot\/\fP(1) carries with its own set of color names,
827 essentially those recognized by the X\~window system with \[lq]grey\[rq]
828 accepted as a variant of \[lq]gray\[rq].
830 \fBpic\fP assumes that at the beginning of a picture both glyph and fill
831 color are set to the default value.
835 More About Text Placement
837 By default, text is centered at the geometric center of the object it is
838 associated with. The modifier \fBljust\fP causes the left end to be
839 at the specified point (which means that the text lies to the right of
840 the specified place!), the modifier \fBrjust\fP puts the right end at
841 the place. The modifiers \fBabove\fP and \fBbelow\fP center the text
842 one half line space in the given direction.
844 Text attributes can be combined:
847 [line up "ljust text" ljust;]
849 [line up "rjust text" rjust;]
851 [arrow 1 "ljust above" ljust above;]
853 [arrow 1 "rjust below" rjust below;]
855 .CE "1: Text attributes"
857 What actually happens is that \fIn\fP text strings are centered in a box
858 that is \fBtextwid\fP wide by \fBtextht\fP high. Both these variables
859 are initially zero (that is \fBpic\fR's way of not making assumptions
860 about \fI[tg]roff\/\fP(1)'s default point size).
862 In GNU \fBgpic\fR, objects can have an
865 This only works if the postprocessor is
867 Any text associated with an object having the
869 attribute is rotated about the center of the object
870 so that it is aligned in the direction from the start point
871 to the end point of the object.
872 Note that this attribute has no effect for objects whose start and
873 end points are coincident.
877 More About Direction Changes
879 We've already seen how to change the direction in which objects are
880 composed from rightwards to downwards. Here are some more
881 illustrative examples:
886 "\fBright; box; arrow; circle; arrow; ellipse\fP";
888 [right; box; arrow; circle; arrow; ellipse;]
890 move down 0.3 from last [] .s;
892 "\fBleft; box; arrow; circle; arrow; ellipse\fP"
894 [left; box; arrow; circle; arrow; ellipse;]
896 # move down 0.3 from last [] .sw;
897 # To re-join this illustrations, delete everything from here down to
898 # the next #-comment, and uncomment the move line above
900 .CE "1: Effects of different motion directions (right and left)"
903 # To re-join this illustrations, delete everything down to here, then
904 # comment out the next `down' line.
905 # Don't forget to re-number the figures following!
908 "\fBdown; box; arrow; circle; arrow; ellipse;\fP"
910 box; arrow; circle; arrow; ellipse;
912 move right 2 from last [] .e;
914 up; box; arrow; circle; arrow; ellipse;
916 "\fBup; box; arrow; circle; arrow; ellipse;\fP"
919 .CE "2: Effects of different motion directions (up and down)"
921 Something that may appear surprising happens if you change directions
925 box; arrow; circle; down; arrow; ellipse
927 .CE "3: \fBbox; arrow; circle; down; arrow; ellipse\fP"
929 You might have expected that program to yield this:
932 box; arrow; circle; move to last circle .s; down; arrow; ellipse
934 .CE "4: More intuitive?"
936 But, in fact, to get Figure \*[SN]3 you have to do this:
944 move to last circle .s;
953 Why is this? Because the exit point for the current direction is
954 already set when you draw the object. The second arrow in Figure
955 \*[SN]2 dropped downwards from the circle's attachment point for an
956 object to be joined to the right.
958 The meaning of the command \fBmove to last circle .s\fP should be obvious.
959 In order to see how it generalizes, we'll need to go into detail on two
960 important topics; locations and object names.
966 The most natural way to name locations in \fBpic\fP is relative to
967 objects. In order to do this, you have to be able you have to be able
968 to name objects. The \fBpic\fP language has rich facilities for this
969 that try to emulate the syntax of English.
972 Naming Objects By Order Of Drawing
974 The simplest (and generally the most useful) way to name an object is
975 with a \fBlast\fP clause. It needs to be followed by an object type
976 name; \fBbox\fP, \fBcircle\fP, \fBellipse\fP, \fBline\fP, \fBarrow\fP,
977 \fBspline\fP, \fB""\fP, or \fB[]\fP (the last type refers to a \fIcomposite
978 object\fP which we'll discuss later). So, for example, the \fBlast
979 circle\fP clause in the program attached to Figure \*[SN]3 refers to the
982 More generally, objects of a given type are implicitly numbered
983 (starting from\~1). You can refer to (say) the third ellipse in the
984 current picture with \fB3rd ellipse\fP, or to the first box as \fB1st
985 box\fP, or to the fifth text string (which isn't an attribute to another
986 object) as \fB5th ""\fP.
988 Objects are also numbered backwards by type from the last one.
989 You can say \fB2nd last box\fP to get the second-to-last box, or
990 \fB3rd last ellipse\fP to get the third-to-last ellipse.
992 In places where \fIn\/\fBth\fR is allowed, \fB`\fIexpr\/\fB'th\fR is
993 also allowed. Note that
995 is a single token: no space is allowed between the
1004 line from `i'th box.nw to `i+1'th box.se
1011 Naming Objects With Labels
1013 You can also specify an object by referring to a label. A label is a
1014 word (which must begin with a capital letter) followed by a colon;
1015 you declare it by placing it immediately before the object drawing command.
1016 For example, the program
1021 A: box "first" "object"
1023 B: ellipse "second" "object"
1025 arrow right at A .r;
1031 declares labels \fBA\fP and \fBB\fP for its first and second objects.
1032 Here's what that looks like:
1035 A: box "first" "object"
1037 B: ellipse "second" "object"
1039 arrow right at A .r;
1041 .CE "1: Example of label use"
1042 The \fBat\fP statement in the fourth line uses the label \fBA\fP (the
1043 behavior of \fBat\fP is explained in the next section). We'll
1044 see later on that labels are most useful for referring to block composite
1047 Labels are not constants but variables (you can view colon as a sort
1048 of assignment). You can say something like \fBA: A + (1,0);\fP
1049 and the effect is to reassign the label \fBA\fR to designate a
1050 position one inch to the right of its old value.
1054 Describing locations
1056 The location of points can be described in many different ways. All these
1057 forms are interchangeable as for as the \fBpic\fP language syntax is
1058 concerned; where you can use one, any of the others that would make
1059 semantic sense are allowed.
1061 The special label \fBHere\fR always refers to the current position.
1064 Absolute Coordinates
1066 The simplest is absolute coordinates in inches; \fBpic\fP uses a
1067 Cartesian system with (0,0) at the lower left corner of the virtual
1068 drawing surface for each picture (that is, X\~increases to the right
1069 and Y\~increases upwards). An absolute location may always be written in the
1070 conventional form as two comma-separated numbers surrounded by
1071 parentheses (and this is recommended for clarity). In contexts where
1072 it creates no ambiguity, the pair of X and Y\~coordinates suffices
1073 without parentheses.
1075 It is a good idea to avoid absolute coordinates, however. They tend
1076 to make picture descriptions difficult to understand and modify.
1077 Instead, there are quite a number of ways to specify locations
1078 relative to \fBpic\fP objects and previous locations.
1080 Another possibility of surprise is the fact that \fBpic\fP crops the
1081 picture to the smallest bounding box before writing it out. For
1082 example, if you have a picture consisting of a small box with its lower
1083 left corner at (2,2) and another small box with its upper right corner
1084 at (5,5), the width and height of the image are both 3\~units and
1085 not\~5. To get the origin at (0,0) included, simply add an invisible
1086 object to the picture, positioning the object's left corner at (0,0).
1089 Locations Relative to Objects
1091 The symbol \fBHere\fP always refers to the position of the last object
1092 drawn or the destination of the last \fBmove\fP.
1094 Alone and unqualified, a \fBlast circle\fP or any other way of
1095 specifying a closed-object or arc location refers as a position to the
1096 geometric center of the object. Unqualified, the name of a line or
1097 spline object refers to the position of the object start.
1099 Also, \fBpic\fP objects have quite a few named locations
1100 associated with them. One of these is the object center, which can be
1101 indicated (redundantly) with the suffix \fB.center\fP (or just \fB.c\fP).
1102 Thus, \fBlast circle \&.center\fP is equivalent to \fBlast
1105 Locations Relative to Closed Objects
1107 Every closed object (box, circle, ellipse, or block composite) also
1108 has eight compass points associated with it;
1111 define dot {circle fill rad 0.02 at $1}
1115 dot(ME.c); "\fB .c\fP" at ME .c ljust;
1116 dot(ME.n); "\fB.n\fP" at ME .n above
1117 dot(ME.ne); "\fB .ne\fP" at ME .ne above
1118 dot(ME.e); "\fB .e\fP" at ME .e ljust
1119 dot(ME.se); "\fB .se\fP" at ME .se below
1120 dot(ME.s); "\fB.s\fP" at ME .s below
1121 dot(ME.sw); "\fB.sw \fP" at ME .sw below
1122 dot(ME.w); "\fB.w \fP" at ME .w rjust
1123 dot(ME.nw); "\fB.nw \fP" at ME .nw above
1125 compass(box wid 1.5 ht 1);
1126 move right from last [] .e;
1127 compass(circle diam 1);
1128 move right from last [] .e;
1129 compass(ellipse wid 1.5 ht 1);
1131 .CE "1: Compass points"
1133 these are the locations where eight compass rays from the geometric center
1134 would intersect the figure. So when we say \fBlast circle .s\fP we are
1135 referring to the south compass point of the last circle drawn. The
1136 explanation of Figure 7.3's program is now complete.
1138 (In case you dislike compass points, the names \fB.top\fP,
1139 \&\fB.bottom\fP, \fB.left\fP and \fB.right\fP are synonyms for \fB.n\fP,
1140 \&\fB.s\fP, \fB.e\fP, and \fB.w\fP respectively; they can even be
1141 abbreviated to \fB.t\fP, \fB.b\fP, \fB.l\fP and \fB.r\fP).
1143 The names \fBcenter\fP, \fBtop\fP, \fBbottom\fP, \fBleft\fP, \fBright\fP,
1144 \fBnorth\fP, \fBsouth\fP, \fBeast\fP, and \fBwest\fP can also be used
1145 (without the leading dot) in a prefix form marked by \fBof\fP; thus,
1146 \fBcenter of last circle\fP and \fBtop of 2nd last ellipse\fP are both
1147 valid object references. Finally, the names \fBleft\fP and \fBright\fP
1148 can be prefixed with \fBupper\fP and \fBlower\fP which both have the
1151 Arc objects also have compass points; they are the compass points of
1154 Non-closed objects (line, arrow, or spline) have compass points too, but
1155 the locations of them are completely arbitrary. In particular, different
1156 \fBpic\fP implementations return different locations.
1158 Locations Relative to Open Objects
1160 Every open object (line, arrow, arc, or spline) has three named
1161 points: \fB.start\fP, \fB.center\fP (or \fB.c\fP), and \fB.end\fP. They
1162 can also be used without leading dots in the \fBof\fP prefix form.
1163 The center of an arc is the center of its circle, but the center of
1164 a line, path, or spline is halfway between its endpoints.
1169 dot(ME.c); "\fB.center\fP" rjust at ME.center + (-0.1, 0.1)
1170 dot(ME.start); "\fB.start\fP" rjust at ME.start + (-0.1, 0.1)
1171 dot(ME.end); "\fB.end\fP" rjust at ME.end + (-0.1, 0.1)
1174 critical(line up right 1);
1175 move right 1 from last [] .e;
1176 critical(arc rad 0.5 cw);
1177 move down 0.5 from 2nd last [] .s;
1178 critical(line right 1 then down .5 left 1 then right 1);
1179 move right 1 from last [] .e;
1180 critical(spline right 1 then up right then left then left 1);
1182 .CE "2: Special points on open objects"
1186 Ways of Composing Positions
1188 Once you have two positions to work with, there are several ways to
1189 combine them to specify new positions.
1191 Vector Sums and Displacements
1193 Positions may be added or subtracted to yield a new position (to be
1194 more precise, you can only add a position and an expression pair; the
1195 latter must be on the right side of the addition or subtraction sign).
1196 The result is the conventional vector sum or difference of coordinates.
1197 For example, \fBlast box .ne + (0.1, 0)\fP is a valid position. This
1198 example illustrates a common use, to define a position slightly offset
1199 from a named one (say, for captioning purposes).
1201 Interpolation Between Positions
1203 A position may be interpolated between any two positions. The syntax
1204 is `\fIfraction\fP \fBof the way between\fP \fIposition1\fP \fBand\fP
1205 \fIposition2\fP'. For example, you can say \fB1/3 of the way between
1206 here and last ellipse .ne\fP. The fraction may be in
1207 numerator/denominator form or may be an ordinary number (values are
1208 \fInot\fP restricted to [0,1]). As an alternative to this verbose
1209 syntax, you can say `\fIfraction\fP \fB<\,\fP\fIposition1\fP \fB,\fP
1210 \fIposition2\/\fP\fB>\fP'; thus, the example could also be written as
1211 \fB1/3 <here, last ellipse>\fP.
1215 P: 1/3 of the way between last arrow .start and last arrow .end;
1216 dot(P); move right 0.1; "P";
1218 .CE "3: \fBP: 1/3 of the way between last arrow .start and last arrow .end\fP"
1220 This facility can be used, for example, to draw double connections.
1225 arrow right at 1/4 <A.e,A.ne>;
1226 arrow left at 1/4 <B.w,B.sw>;
1228 .CE "4: Doubled arrows"
1230 You can get Figure \n[H1]-4 from the following program:
1237 arrow right at 1/4 <A.e,A.ne>;
1238 arrow left at 1/4 <B.w,B.sw>;
1244 Note the use of the short form for interpolating points.
1246 Projections of Points
1248 Given two positions \fIp\fP and \fIq\fP, the position
1249 \fB(\,\fP\fIp\fP\fB,\fP \fIq\fP\fB)\fP has the X\~coordinate of \fIp\fP
1250 and the Y coordinate of \fIq\fP. This can be helpful in placing an
1251 object at one of the corners of the virtual box defined by two other
1255 box invis wid 2 height 1;
1256 dot(last box .ne); "\fB(B,A)\fP is here" ljust at last circle + (0.1, 0.1);
1257 dot(last box .se); "B" ljust at last circle + (0.1, -0.1)
1258 dot(last box .sw); "\fB(A,B)\fP is here" rjust at last circle + (-0.1, -0.1);
1259 dot(last box .nw); "A" ljust at last circle + (-0.1, 0.1)
1261 .CE "5: Using (\fIx\fP, \fIy\fP) composition"
1266 There are four ways to use locations; \fBat\fP, \fBfrom\fP, \fBto\fP,
1267 and \fBwith\fP. All four are object modifiers; that is, you use them
1268 as suffixes to a drawing command.
1270 The \fBat\fP modifier says to draw a closed object or arc with its
1271 center at the following location, or to draw a line/spline/arrow
1272 starting at the following location.
1274 The \fBto\fP modifier can be used alone to specify a move destination.
1275 The \fBfrom\fP modifier can be used alone in the same way as \fBat\fP.
1277 The \fBfrom\fP and \fBto\fP modifiers can be used with a \fBline\fR or
1278 \fBarc\fR command to specify start and end points of the object. In
1279 conjunction with named locations, this offers a very flexible
1280 mechanism for connecting objects. For example, the following program
1288 arc cw from 1/3 of the way \e
1289 between last box .n and last box .ne to last ellipse .n;
1301 arc cw from 1/3 of the way \
1302 between last box .n and last box .ne to last ellipse .n;
1304 .CE "6: A tricky connection specified with English-like syntax"
1306 The \fBwith\fP modifier allows you to identify a named attachment
1307 point of an object (or a position within the object) with another point.
1308 This is very useful for connecting objects in a natural way. For an
1309 example, consider these two programs:
1315 box wid 0.75 ht 0.75;
1317 move down 0.3 from last [] .s 0.1;
1318 "\fBbox wid 0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1320 move from last [].e 1.5
1324 box wid 0.75 ht 0.75 with .sw at last box .se;
1326 move down 0.3 from last [] .s 0.1;
1327 box invisible "\fBbox wid 0.5 ht 0.5;\fP" \
1328 "\fBbox wid 0.75 ht 0.75 with .sw at last box .se;\fP"
1331 .CE "7: Using the \fBwith\fP modifier for attachments"
1336 When drawing lines between circles that don't intersect them at a
1337 compass point, it is useful to be able to shorten a line by the radius
1338 of the circle at either or both ends. Consider the following program:
1344 circle "y" at 1st circle - (0.4, 0.6)
1345 circle "z" at 1st circle + (0.4, -0.6)
1346 arrow from 1st circle to 2nd circle chop
1347 arrow from 2nd circle to 3rd circle chop
1348 arrow from 3rd circle to 1st circle chop
1354 It yields the following:
1358 circle "y" at 1st circle - (0.4, 0.6)
1359 circle "z" at 1st circle + (0.4, -0.6)
1360 arrow from 1st circle to 2nd circle chop
1361 arrow from 2nd circle to 3rd circle chop
1362 arrow from 3rd circle to 1st circle chop
1364 .CE "8: The \fBchop\fR modifier"
1366 Notice that the \fBchop\fR attribute moves arrowheads rather than
1367 stepping on them. By default, the \fBchop\fR modifier shortens both
1368 ends of the line by \fBcirclerad\fR. By suffixing it with a number
1369 you can change the amount of chopping.
1371 If you say \fBline .\|.\|.\& chop \fIr1\fP chop \fIr2\fP\fR with \fIr1\fP
1372 and \fIr2\fP both numbers, you can vary the amount of chopping at both
1373 ends. You can use this in combination with trigonometric functions
1374 to write code that deals with more complex intersections.
1380 There are two different ways to group objects in \fBpic\fP; \fIbrace
1381 grouping\fP and \fIblock composites\fP.
1386 The simpler method is simply to group a set of objects within curly
1387 bracket or brace characters. On exit from this grouping, the current
1388 position and direction are restored to their value when the opening
1389 brace was encountered.
1394 A block composite object is created a series of commands enclosed by
1395 square brackets. The composite can be treated for most purposes like
1396 a single closed object, with the size and shape of its bounding box.
1397 Here is an example. The program fragment
1403 line up 1 at last circle .n;
1404 line down 1 at last circle .s;
1405 line right 1 at last circle .e;
1406 line left 1 at last circle .w;
1407 box dashed with .nw at last circle .se + (0.2, -0.2);
1408 Caption: center of last box;
1414 yields the block in figure \n[H1]-1, which we show both with and
1415 without its attachment points. The block's location becomes the
1421 line up 1 at last circle .n;
1422 line down 1 at last circle .s;
1423 line right 1 at last circle .e;
1424 line left 1 at last circle .w;
1425 box dashed with .nw at last circle .se + (0.2, -0.2);
1426 Caption: center of last box;
1430 compass([junction()]);
1432 .CE "1: A sample composite object"
1434 To refer to one of the composite's attachment points, you can say
1435 (for example) \fBA .s\fP. For purposes of object naming, composites
1436 are a class. You could write \fBlast [] .s\fP as an equivalent
1437 reference, usable anywhere a location is needed. This construction is
1438 very important for putting together large, multi-part diagrams.
1440 Blocks are also a variable-scoping mechanism, like a \fIgroff\/\fP(1)
1441 environment. All variable assignments done inside a block are undone
1442 at the end of it. To get at values within a block, write a name of
1443 the block followed by a dot, followed by the label you
1444 want. For example, we could refer the the center of the box in the
1445 above composite as \fBlast [] .Caption\fP or \fBA.Caption\fP.
1447 This kind of reference to a label can be used in any way any other
1448 location can be. For example, if we added \fB"Hi!" at A.Caption\fP
1449 the result would look like this:
1455 .CE "2: Adding a caption using interior labeling"
1457 You can also use interior labels in either part of a \fBwith\fR
1458 modifier. This means that the example composite could be placed
1459 relative to its caption box by a command containing \fBwith A.Caption
1462 Note that both width and height of the block composite object are always
1469 box wid 0.75 ht 0.75
1471 move down 0.3 from last [].s 0.1
1472 "\fBbox wid -0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1474 move from last [].e 2
1477 [ box wid -0.5 ht 0.5 ]
1478 box wid 0.75 ht 0.75
1480 move down 0.3 from last [].s 0.1
1481 "\fB[box wid -0.5 ht 0.5]; box wid 0.75 ht 0.75\fP"
1484 .CE "3: Composite block objects always have positive width and height"
1486 Blocks may be nested. This means you can use block attachment points
1487 to build up complex diagrams hierarchically, from the inside out.
1488 Note that \fBlast\fP and the other sequential naming mechanisms
1489 don't look inside blocks, so if you have a program that looks
1495 P: [box "foo"; ellipse "bar"];
1497 [box "baz"; ellipse "quxx"]
1500 arrow from 2nd last [];
1506 the arrow in the last line is attached to object \fBP\fP, not
1509 In DWB \fBpic\fP, only references one level deep into enclosed blocks
1510 were permitted. GNU \fBgpic\fP removes this restriction.
1512 The combination of block variable scoping, assignability of labels and
1513 the macro facility that we'll describe later on can be used to
1514 simulate functions with local variables (just wrap the macro body in
1521 There are a number of global style variables in \fBpic\fR that can be used to
1522 change its overall behavior. We've mentioned several of them in
1523 previous sections. They're all described here. For each variable,
1524 the default is given.
1526 center, tab(@), linesize(2);
1530 Style Variable@Default@What It Does
1535 boxht@0.5@Default height of a box
1536 boxwid@0.75@Default width of a box
1537 lineht@0.5@Default length of vertical line
1538 linewid@0.75@Default length of horizontal line
1539 linethick@-1@Default line thickness
1540 arcrad @0.25@Default radius of an arc
1541 circlerad@0.25@Default radius of a circle
1542 ellipseht@0.5@Default height of an ellipse
1543 ellipsewid@0.75@Default width of an ellipse
1544 moveht@0.5@Default length of vertical move
1545 movewid@0.75@Default length of horizontal move
1546 textht@0@Default height of box enclosing a text object
1547 textwid@0@Default width of box enclosing a text object
1548 arrowht@0.1@Length of arrowhead along shaft
1549 arrowwid@0.05@Width of rear of arrowhead
1550 arrowhead@1@Enable/disable arrowhead filling
1551 dashwid@0.05@Interval for dashed lines
1552 maxpswid@8.5@Maximum width of picture
1553 maxpsht@11@Maximum height of picture
1554 scale@1@Unit scale factor
1555 fillval@0.5@Default fill value
1559 Any of these variables can be set with a simple assignment statement.
1563 [boxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;]
1565 .CE "1: \fBboxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;\fP"
1567 In GNU \fBpic\fR, setting the \fBscale\fR variable re-scales all
1568 size-related state variables so that their values remain equivalent in
1571 The command \fBreset\fP resets all style variables to their defaults.
1572 You can give it a list of variable names as arguments (optionally
1573 separated by commas), in which case it resets only those.
1575 State variables retain their values across pictures until reset.
1579 Expressions, Variables, and Assignment
1581 A number is a valid expression, of course (all numbers are stored
1582 internally as floating-point). Decimal-point notation is acceptable;
1583 in GNU \fBgpic\fR, scientific notation in C's `e' format (like
1584 \f(CW5e-2\fP) is accepted.
1586 Anywhere a number is expected, the language also accepts a
1587 variable. Variables may be the built-in style variable described in
1588 the last section, or new variables created by assignment.
1590 DWB \fBpic\fP supports only the ordinary assignment via \fB=\fP, which
1591 defines the variable (on the left side of the equal sign) in the current
1592 block if it is not already defined there, and then changes the value (on
1593 the right side) in the current block. The variable is not visible outside
1594 of the block. This is similar to the C\~programming language where a
1595 variable within a block shadows a variable with the same name outside of
1598 GNU \fBgpic\fP supports an alternate form of assignment using \fB:=\fP.
1599 The variable must already be defined, and the value is assigned to
1600 that variable without creating a variable local to the current block.
1617 You can use the height, width, radius, and x and y coordinates of any
1618 object or corner in expressions. If \fBA\fP is an object label or name,
1619 all the following are valid:
1623 A.x # x coordinate of the center of A
1624 A.ne.y # y coordinate of the northeast corner of A
1625 A.wid # the width of A
1626 A.ht # and its height
1627 2nd last circle.rad # the radius of the 2nd last circle
1632 Note the second expression, showing how to extract a corner coordinate.
1634 Basic arithmetic resembling those of C operators are available; \fB+\fP,
1635 \fB*\fP, \fB-\fP, \fB/\fP, and \fB%\fP. So is \fB^\fP for exponentiation.
1636 Grouping is permitted in the usual way using parentheses. GNU \fBgpic\fP
1637 allows logical operators to appear in expressions; \fB!\&\fP (logical
1638 negation, not factorial), \fB&&\fP, \fB|\||\fP, \fB==\fP, \fB!=\fP,
1639 \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
1641 Various built-in functions are supported: \fBsin(\fIx\fB)\fR,
1642 \fBcos(\fIx\fB)\fR, \fBlog(\fIx\fB)\fR, \fBexp(\fIx\fB)\fR,
1643 \fBsqrt(\fIx\fB)\fR, \fBmax(\fIx\fB,\fIy\fB)\fR,
1644 \fBatan2(\fIx\fB,\fIy\fB)\fR, \fBmin(\fIx\fB,\fIy\fB)\fR,
1645 \fBint(\fIx\fB)\fR, \fBrand()\fP, and \fBsrand()\fP.
1646 Both \fBexp\fP and \fBlog\fP are
1647 base\~10; \fBint\fP does integer truncation; \fBrand()\fP returns a
1648 random number in [0-1), and \fBsrand()\fP sets the seed for
1649 a new sequence of pseudo-random numbers to be returned by \fBrand()\fP
1650 (\fBsrand()\fP is a GNU extension).
1652 GNU \fBgpic\fP also documents a one-argument form or rand,
1653 \fBrand(\fIx\fB)\fR, which returns a random number between 1 and
1654 \fIx\fP, but this is deprecated and may be removed in a future
1657 The function \fBsprintf()\fP behaves like a C \fIsprintf\/\fP(3)
1658 function that only takes %, %e, %f, and %g format strings.
1664 You can define macros in \fBpic\fP, with up to 32 arguments (up to 16
1665 on EBCDIC platforms). This is useful for diagrams with
1666 repetitive parts. In conjunction with the scope rules for block
1667 composites, it effectively gives you the ability to write functions.
1672 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement text \fB}\fP
1676 This defines \fIname\fR as a macro to be replaced by the replacement
1677 text (not including the braces). The macro may be called as
1680 \fIname\fB(\fIarg1, arg2, \|.\|.\|.\& argn\fB)\fR
1684 The arguments (if any) are substituted for tokens \fB$1\fP, \fB$2\fP
1685 \&.\|.\|.\& \fB$n\fP
1686 appearing in the replacement text.
1688 As an example of macro use, consider this:
1695 # Plot a single jumper in a box, $1 is the on-off state.
1698 Outer: box invis wid 0.45 ht 1;
1700 # Count on end ] to reset these
1701 boxwid = Outer.wid * shrinkfactor / 2;
1702 boxht = Outer.ht * shrinkfactor / 2;
1704 box fill (!$1) with .s at center of Outer;
1705 box fill ($1) with .n at center of Outer;
1708 # Plot a block of six jumpers.
1709 define jumperblock {
1717 jwidth = last [].Outer.wid;
1718 jheight = last [].Outer.ht;
1720 box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1722 # Use {} to avoid changing position from last box draw.
1723 # This is necessary so move in any direction works as expected
1724 {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0,-0.2);}
1727 # Sample macro invocations.
1728 jumperblock(1,1,0,0,1,0);
1730 jumperblock(1,0,1,0,1,1);
1738 It yields the following:
1741 # Plot a single jumper in a box, $1 is the on-off state.
1744 Outer: box invis wid 0.45 ht 1;
1746 # Count on end ] to reset these
1747 boxwid = Outer.wid * shrinkfactor / 2;
1748 boxht = Outer.ht * shrinkfactor / 2;
1750 box fill (!$1) with .s at center of Outer;
1751 box fill ($1) with .n at center of Outer;
1754 # Plot a block of six jumpers
1755 define jumperblock {
1763 jwidth = last [].Outer.wid;
1764 jheight = last [].Outer.ht;
1766 box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1768 # Use {} to avoid changing position from last box draw.
1769 # This is necessary so move in any direction works as expected
1770 {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0,-0.2);}
1773 # Sample macro invocations
1774 jumperblock(1,1,0,0,1,0);
1776 jumperblock(1,0,1,0,1,1);
1778 .CE "1: Sample use of a macro"
1780 This macro example illustrates how you can combine [], brace grouping,
1781 and variable assignment to write true functions.
1783 One detail the example above does not illustrate is the fact that
1784 macro argument parsing is not token-oriented. If you call
1785 \fBjumper(\ 1\ )\fP, the value of $1 is \fB"\ 1\ "\fP. You could
1786 even call \fBjumper(big\ string)\fP to give $1 the value
1787 \fB"big\ string"\fP.
1789 If you want to pass in a coordinate pair, you can avoid getting
1790 tripped up by the comma by wrapping the pair in parentheses.
1792 Macros persist through pictures. To undefine a macro, say \fBundef\fP
1793 \fIname\fR; for example,
1795 \f(CWundef jumper\fP
1796 \f(CWundef jumperblock\fP
1799 would undefine the two macros in the jumper block example.
1803 Import/Export Commands
1805 Commands that import or export data between \fBpic\fR and its
1806 environment are described here.
1809 File and Table Insertion
1813 \f(CWcopy\fP \fIfilename\fR
1816 inserts the contents of \fIfilename\fR in the \fBpic\fP input stream.
1817 Any \fB.PS\fP/\fB.PE\fP pair in the file is ignored. You
1818 can use this to include pre-generated images.
1820 A variant of this statement replicates the \fBcopy thru\fP feature of
1821 \fIgrap\/\fP(1). The call
1823 \f(CWcopy\fP \fIfilename\fR \f(CWthru\fP \fImacro\fP
1826 calls \fImacro\fP (which may be either a name or replacement text)
1827 on the arguments obtained by breaking each line of the file into
1828 blank-separated fields. The macro may have up to 9\~arguments. The
1829 replacement text may be delimited by braces or by a pair of instances
1830 of any character not appearing in the rest of the text.
1834 \f(CWcopy\fP \f(CWthru\fP \fImacro\fP
1837 omitting the filename, lines to be parsed are taken from the input
1838 source up to the next \fB.PE\fP.
1840 In either of the last two \fBcopy\fP commands, GNU \fBgpic\fP permits a
1841 trailing `\fBuntil\fP \fIword\/\fP' clause to be added which terminates
1842 the copy when the first word matches the argument (the default
1843 behavior is therefore equivalent to \fBuntil .PE\fP).
1845 Accordingly, the command
1852 copy thru % circle at ($1,$2) % until "END"
1884 The command \fBprint\fR accepts any number of arguments, concatenates
1885 their output forms, and writes the result to standard error. Each
1886 argument must be an expression, a position, or a text string.
1889 Escape to Post-Processor
1893 \fBcommand\fR \fIarg\fR\|.\|.\|.
1896 \fBpic\fP concatenates the arguments and pass them through as a line
1897 to troff or \*[tx]. Each
1899 must be an expression, a position, or text.
1900 This has a similar effect to a line beginning with
1904 but allows the values of variables to be passed through.
1913 command ".ds string x is " x "."
1928 Executing Shell Commands
1932 \f(CWsh\fP \f(CW{\fP \fIanything.\|.\|.\fP \f(CW}\fP
1935 macro-expands the text in braces, then executes it as a shell command.
1936 This could be used to generate images or data tables for later
1937 inclusion. The delimiters shown as {} here may also be two copies of
1938 any one character not present in the shell command text. In either
1939 case, the body may contain balanced {} pairs. Strings in the body
1940 may contain balanced or unbalanced braces in any case.
1944 Control-flow constructs
1946 The \fBpic\fP language provides conditionals and looping. For
1952 for i = 0 to 2 * pi by 0.1 do {
1954 "." at (i/2, sin(i)/2);
1955 ":" at (i/2, cos(i)/2);
1965 for i = 0 to 2 * pi by 0.1 do {
1967 "." at (i/2, sin(i)/2);
1968 ":" at (i/2, cos(i)/2);
1971 .CE "1: Plotting with a \fBfor\fP loop"
1973 The syntax of the \fBfor\fP statement is:
1975 \fBfor\fR \fIvariable\fR \fB=\fR \fIexpr1\/\fR \fBto\fR \fIexpr2\/\fR \
1976 [\fBby\fR [\fB*\fR]\fIexpr3\/\fR] \fBdo\fR \fIX\fR \fIbody\fR \fIX\fR
1978 The semantics are as follows: Set
1983 is less than or equal to
1993 is not given, increment
2002 is multiplied instead by
2006 can be negative for the additive case;
2008 is then tested whether it is greater than or equal to
2010 For the multiplicative case,
2012 must be greater than zero.
2013 If the constraints aren't met, the loop isn't executed.
2015 can be any character not occurring in
2016 \fIbody\fR; or the two \fIX\/\fPs may be paired braces (as in the
2019 The syntax of the \fBif\fP statement is as follows:
2021 \fBif\fR \fIexpr\fR \fBthen\fR \fIX\fR \fIif-true\fR \fIX\fR \
2022 [\fBelse\fR \fIY\fR \fIif-false\fR \fIY\/\fR]
2024 Its semantics are as follows: Evaluate
2026 if it is non-zero then do
2031 can be any character not occurring in
2034 can be any character not occurring in
2037 Eithe or both of the
2041 pairs may instead be balanced pairs of
2042 braces ({ and\~}) as in the \fBsh\fR command. In either case, the
2043 \fIif-true\fR may contain balanced pairs of braces. None of these
2044 delimiters are seen inside strings.
2046 All the usual relational operators my be used in conditional expressions;
2047 \fB!\&\fP (logical negation, not factorial), \fB&&\fP, \fB|\||\fP, \fB==\fP,
2048 \fB!=\fP, \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
2050 String comparison is also supported using \fB==\fP and \fB!=\fP. String
2051 comparisons may need to be parenthesized to avoid syntactic
2056 Interface To [gt]roff
2058 The output of \fBpic\fP is \fB[gt]roff\fP drawing commands. The GNU
2059 \fIgpic\/\fP(1) command warns that it relies on drawing extensions
2060 present in \fIgroff\/\fP(1) that are not present in \fItroff\/\fP(1).
2065 The DWB \fIpic\/\fP(1) program accepts one or two arguments to
2066 \&\fB.PS\fP, which is interpreted as a width and height in inches to
2067 which the results of \fIpic\/\fP(1) should be scaled (width and height
2068 scale independently). If there is only one argument, it is
2069 interpreted as a width to scale the picture to, and height is
2070 scaled by the same proportion.
2072 GNU \fBgpic\fP is less general; it accepts a single width to scale
2073 to, or a zero width and a maximum height to scale to. With
2074 two non-zero arguments, it scales to the maximum height.
2077 How Scaling is Handled
2079 When \fBpic\fP processes a picture description on input, it passes
2080 \fB.PS\fP and \fB.PE\fP through to the postprocessor. The \fB.PS\fP
2081 gets decorated with two numeric arguments which are the X and
2082 Y\~dimensions of the picture in inches. The post-processor can use
2083 these to reserve space for the picture and center it.
2085 The GNU incarnation of the \fBms\fP macro package, for example, includes
2086 the following definitions:
2095 \&.ie \e\en[.$]<2 .@error bad arguments to PS (not preprocessed with pic?)
2097 \&. ds@need (u;\e\e$1)+1v
2098 \&. in +(u;\e\en[.l]-\e\en[.i]-\e\e$2/2>?0)
2103 \&.sp \e\en[DD]u+.5m
2111 Equivalent definition is supplied by GNU \fIpic\/\fP(1) if you use
2112 the \-mpic option; this should make it usable with macro pages other
2115 If \fB.PF\fP is used instead of \fB.PE\fP, the \fBtroff\fP position is
2116 restored to what it was at the picture start (Kernighan notes that
2117 the\~F stands for \[lq]flyback\[rq]).
2121 \&\fB.PS <\,\fP\fIfile\fP
2124 causes the contents of \fIfile\fP to replace the \fB.PS\fP line. This
2125 feature is deprecated; use `\fBcopy\fP \fIfile\fR' instead).
2128 PIC and [gt]roff commands
2130 By default, input lines that begin with a period are passed to the
2131 postprocessor, embedded at the corresponding point in the output.
2132 Messing with horizontal or vertical spacing is an obvious recipe for
2133 bugs, but point size and font changes are usually safe.
2135 Point sizes and font changes are also safe within text strings, as
2136 long as they are undone before the end of string.
2138 The state of \fB[gt]roff\fP's fill mode is preserved across pictures.
2143 The Kernighan paper notes that there is a subtle problem with
2144 complicated equations inside \fBpic\fR pictures; they come out wrong if
2145 \fIeqn\/\fP(1) has to leave extra vertical space for the equation.
2146 If your equation involves more than subscripts and superscripts, you
2147 must add to the beginning of each equation the extra information
2148 \fBspace\~0\fP. He gives the following example:
2153 box "$space 0 {H( omega )} over {1 - H( omega )}$"
2164 box "@space 0 {H( omega )} over {1 - H( omega )}@"
2167 .CE "1: Equations within pictures"
2170 Absolute Positioning of Pictures
2172 A \fBpic\fP picture is positioned vertically by troff at the current
2173 position. The topmost position possible on a page is not the paper edge
2174 but a position which is one baseline lower so that the first row of glyphs
2175 is visible. To make a picture really start at the paper edge you have
2176 to make the baseline-to-baseline distance zero, this is, you must set the
2177 vertical spacing to\~0 (using \fB.vs\fP) before starting the picture.
2184 \*[tx] mode is enabled by the
2187 In \*[tx] mode, pic defines a vbox called
2189 for each picture; the name can be changed with the pseudo-variable
2191 (which is actually a specially parsed command).
2192 You must yourself print that vbox using, for example, the command
2196 \ecenterline{\ebox\egraph}
2199 Actually, since the vbox has a height of zero (it is defined with \evtop)
2200 this produces slightly more vertical space above the picture than
2205 \ecenterline{\eraise 1em\ebox\egraph}
2210 To make the vbox having a positive height and a depth of zero (as used
2211 e.g.\& by \*(lx's \f(CW\%graphics.sty\fP), define the following macro in
2217 \evbox{\eunvbox\ecsname #1\eendcsname\ekern 0pt}}
2222 Now you can simply say
2224 instead of \ebox\egraph.
2226 You must use a \*[tx] driver that supports the
2228 specials, version\~2.
2230 Lines beginning with
2232 are passed through transparently; a
2234 is added to the end of the line to avoid unwanted spaces.
2235 You can safely use this feature to change fonts or to
2236 change the value of \fB\ebaselineskip\fP.
2237 Anything else may well produce undesirable results; use at your own risk.
2238 Lines beginning with a period are not given any special treatment.
2240 The \*[tx] mode of \fIpic\/\fP(1) does \fInot\fP translate \fBtroff\fP
2241 font and size changes included in text strings!
2243 Here an example how to use \fBfigname\fP.
2257 \ecenterline{\ebox\efoo \ehss \ebox\ebar}
2262 Use this feature sparsingly and only if really needed:
2263 A different name means a new box register in \*[tx], and the maximum number
2264 of box registers is only 256.
2265 Also be careful not to use a predefined \*[tx] or \*[lx] macro name as
2266 an argument to \fBfigname\fP since this inevitably causes an error.
2272 GNU \fIgpic\/\fP(1) has a command
2274 \fBplot\fR \fIexpr\fR [\fB"\fItext\fB"\fR]
2276 This is a text object which is constructed by using
2278 as a format string for sprintf
2283 is omitted a format string of \fB"%g"\fP is used.
2284 Attributes can be specified in the same way as for a normal text
2286 Be very careful that you specify an appropriate format string;
2287 \fBpic\fP does only very limited checking of the string.
2288 This is deprecated in favour of
2293 Some Larger Examples
2295 Here are a few larger examples, with complete source code.
2296 One of our earlier examples is generated in an instructive way using a
2304 # Draw a demonstration up left arrow with grid box overlay
2310 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2311 for i = 2 to ($1 / 0.5) do
2313 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2315 move down from last arrow .center;
2317 if ( $1 == boxht ) \e
2318 then { "\efBline up left\efP" } \e
2319 else { sprintf("\efBarrow up left %g\efP", $1) };
2322 move right 0.1 from last [] .e;
2337 # Draw a demonstration up left arrow with grid box overlay
2343 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2344 for i = 2 to ($1 / 0.5) do
2346 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2348 move down from last arrow .center;
2350 if ( $1 == boxht ) \
2351 then { "\fBline up left\fP" } \
2352 else { sprintf("\fBarrow up left %g\fP", $1) };
2355 move right 0.1 from last [] .e;
2363 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
2365 Here's an example concocted to demonstrate layout of a large,
2366 multiple-part pattern:
2373 define filter {box ht 0.25 rad 0.125}
2377 box "\efBms\efR" "sources";
2379 box "\efBHTML\efR" "sources";
2381 box "\efBlinuxdoc-sgml\efP" "sources" wid 1.5;
2383 box "\efBTexinfo\efP" "sources";
2385 line down from 1st box .s lineht;
2387 line down from 2nd box .s; filter "\efBhtml2ms\efP";
2389 line down from 3rd box .s; filter "\efBformat\efP";
2391 line down from 4th box .s; filter "\efBtexi2roff\efP";
2394 move down 1 from last [] .s;
2395 Anchor: box wid 1 ht 0.75 "\efBms\efR" "intermediate" "form";
2396 arrow from Top.A.end to Anchor.nw;
2397 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2398 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2399 arrow from Top.D.end to Anchor.ne
2403 line down left then down ->;
2404 filter "\efBpic\efP";
2406 filter "\efBeqn\efP";
2408 filter "\efBtbl\efP";
2410 filter "\efBgroff\efP";
2416 line down right then down ->;
2417 A: filter dotted "\efBpic2img\efP";
2419 B: filter dotted "\efBeqn2html\efP";
2421 C: filter dotted "\efBtbl2html\efP";
2423 filter "\efBms2html\efP";
2427 # Nonexistence caption
2428 box dashed wid 1 at B + (2,0) "These tools" "don't yet exist";
2429 line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2430 line chop 0 chop 0.1 dashed from last box .w to B.e ->;
2431 line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2441 define filter {box ht 0.25 rad 0.125}
2445 box "\fBms\fR" "sources";
2447 box "\fBHTML\fR" "sources";
2449 box "\fBlinuxdoc-sgml\fP" "sources" wid 1.5;
2451 box "\fBTexinfo\fP" "sources";
2453 line down from 1st box .s lineht;
2455 line down from 2nd box .s; filter "\fBhtml2ms\fP";
2457 line down from 3rd box .s; filter "\fBformat\fP";
2459 line down from 4th box .s; filter "\fBtexi2roff\fP";
2462 move down 1 from last [] .s;
2463 Anchor: box wid 1 ht 0.75 "\fBms\fR" "intermediate" "form";
2464 arrow from Top.A.end to Anchor.nw;
2465 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2466 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2467 arrow from Top.D.end to Anchor.ne
2471 line down left then down ->;
2478 filter "\fBgroff\fP";
2484 line down right then down ->;
2485 A: filter dotted "\fBpic2img\fP";
2487 B: filter dotted "\fBeqn2html\fP";
2489 C: filter dotted "\fBtbl2html\fP";
2491 filter "\fBms2html\fP";
2495 # Nonexistence caption
2496 box dashed wid 1 at B + (2,0) "These tools" "don't yet exist";
2497 line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2498 line chop 0 chop 0.1 dashed from last box .w to B.e ->;
2499 line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2502 .CE "2: Hypothetical production flow for dual-mode publishing"
2506 # a three-dimensional block
2508 # tblock(<width>, <height>, <text>)
2512 color "gold" outlined "black" \
2513 xslanted 0 yslanted 0 \
2516 color "yellow" outlined "black" \
2517 xslanted .1 yslanted 0 \
2518 with .sw at last box .nw;
2520 color "goldenrod" outlined "black" \
2521 xslanted 0 yslanted .1 \
2522 with .nw at 2nd last box .ne;
2525 tblock(1, .5, "Master" "1");
2527 tblock(.5, 1, "Slave");
2529 .CE "3: Three-dimensional Boxes"
2531 Here the source code for figure \n[H1]-3:
2536 # a three-dimensional block
2538 # tblock(<width>, <height>, <text>)
2542 color "gold" outlined "black" \e
2543 xslanted 0 yslanted 0 \e
2546 color "yellow" outlined "black" \e
2547 xslanted .1 yslanted 0 \e
2548 with .sw at last box .nw;
2550 color "goldenrod" outlined "black" \e
2551 xslanted 0 yslanted .1 \e
2552 with .nw at 2nd last box .ne;
2555 tblock(1, .5, "Master" "1");
2557 tblock(.5, 1, "Slave");
2568 This is an annotated grammar of \fBpic\fP.
2573 In general, \fBpic\fP is a free-format, token-oriented language that
2574 ignores whitespace outside strings. But certain lines and contructs
2575 are specially interpreted at the lexical level:
2577 A comment begins with \fB#\fP and continues to \fB\en\fP (comments may
2578 also follow text in a line). A line beginning with a period or
2579 backslash may be interpreted as text to be passed through to the
2580 post-processor, depending on command-line options. An end-of-line
2581 backslash is interpreted as a request to continue the line; the
2582 backslash and following newline are ignored.
2585 Here are the grammar terminals:
2588 .IP \s[-1]NUMBER\s[0]
2589 A floating point numeric constant. May contain a decimal point or be
2590 expressed in scientific notation in the style of \fIprintf\/\fP(3)'s %e
2591 escape. A trailing `i' or `I' (indicating the unit `inch') is ignored.
2593 A string enclosed in double quotes. A double quote within \s[-1]TEXT\s[0]
2594 must be preceded by a backslash. Instead of \s[-1]TEXT\s[0] you can use
2597 sprintf ( TEXT [, <expr> ...] )
2601 except after the `until' and `last' keywords, and after all ordinal
2602 keywords (`th' and friends).
2603 .IP \s[-1]VARIABLE\s[0]
2604 A string starting with a character from the set [a-z], optionally
2605 followed by one or more characters of the set [a-zA-Z0-9_].
2606 (Values of variables are preserved across pictures.)
2607 .IP \s[-1]LABEL\s[0]
2608 A string starting with a character from the set [A-Z], optionally
2609 followed by one or more characters of the set [a-zA-Z0-9_].
2610 .IP \s[-1]COMMAND-LINE\s[0]
2611 A line starting with a command character (`.' in groff mode, `\e' in
2613 .IP \s[-1]BALANCED-TEXT\s[0]
2614 A string either enclosed by `{' and `}' or with \fIX\fP and \fIX\fP,
2615 where \fIX\fP doesn't occur in the string.
2616 .IP \s[-1]BALANCED-BODY\s[0]
2617 Delimiters as in \s[-1]BALANCED-TEXT\s[0]; the body is interpreted as
2618 `\fB\[la]command\[ra].\|.\|.\fP'.
2619 .IP \s[-1]FILENAME\s[0]
2620 The name of a file. This has the same semantics as \s[-1]TEXT\s[0].
2621 .IP \s[-1]MACRONAME\s[0]
2622 Either \s[-1]VARIABLE\s[0] or \s[-1]LABEL\s[0].
2628 Tokens not enclosed in \[la]\|\[ra] are literals, except:
2630 \fB\en\fP is a newline.
2632 Three dots is a suffix meaning `replace with 0 or more repetitions
2633 of the preceding element(s).
2635 An enclosure in square brackets has its usual meaning of `this clause is
2638 Square-bracket-enclosed portions within tokens are optional. Thus,
2639 `h\^[eigh]\^t' matches either `height' or `ht'.
2641 If one of these special tokens has to be referred to literally, it is
2642 surrounded with single quotes.
2644 The top-level \fBpic\fP object is a picture.
2648 .PS [NUMBER [NUMBER]]\en
2654 The arguments, if present, represent the width and height of the picture,
2655 causing \fBpic\fR to attempt to scale it to the given dimensions in
2656 inches. In no case, however, the X and Y\~dimensions of the
2657 picture exceed the values of the style variables \fBmaxpswid\fP and
2658 \fBmaxpsheight\fP (which default to the normal 8.5\^i by 11\^i page size).
2660 If the ending `.PE' is replaced by `.PF', the page vertical position is
2661 restored to its value at the time `.PS' was encountered. Another
2662 alternate form of invocation is `.PS\ <\s[-1]FILENAME\s[0]', which
2663 replaces the `.PS' line with a file to be interpreted by \fBpic\fR (but
2664 this feature is deprecated).
2666 The `.PS', `.PE', and `.PF' macros to perform centering and scaling are
2667 normally supplied by the post-processor.
2669 In the following, either `|' or a new line starts an alternative.
2680 <primitive> [<attribute>]
2681 LABEL : [;] <command>
2682 LABEL : [;] <command> [<position>]
2684 VARIABLE [:] = <any-expr>
2686 up | down | left | right
2688 command <print-arg> ...
2689 print <print-arg> ...
2692 copy [FILENAME] thru MACRONAME [until TEXT]
2693 copy [FILENAME] thru BALANCED-BODY [until TEXT]
2694 for VARIABLE = <expr> to <expr> [by [*] <expr>] do BALANCED-BODY
2695 if <any-expr> then BALANCED-BODY [else BALANCED-BODY]
2696 reset [VARIABLE [[,] VARIABLE ...]]
2708 The current position and direction are saved on entry to a `{\ .\|.\|.\ }'
2709 construction and restored on exit from it.
2711 Note that in `if' constructions, newlines can only occur in
2712 \s[-1]BALANCED-BODY\s[0]. This means that
2722 fails. You have to use the braces on the same line as the keywords:
2733 This restriction doesn't hold for the body after the `do' in a `for'
2736 At the beginning of each picture, `figname' is reset to the vbox name
2737 `graph'; this command has only a meaning in \*[tx] mode. While the grammar
2738 rules allow digits and the underscore in the value of `figname', \*[tx]
2739 normally accepts uppercase and lowercase letters only as box names
2740 (you have to use `\ecsname' if you really need to circumvent this
2747 <any-expr> <logical-op> <any-expr>
2765 Logical operators are handled specially by \fBpic\fP since they can
2766 deal with text strings also. \fBpic\fP uses \%\fIstrcmp\/\fP(3) to test
2767 for equality of strings; an empty string is considered as `false' for
2772 box \fR# closed object \[em] rectangle\fP
2773 circle \fR# closed object \[em] circle\fP
2774 ellipse \fR# closed object \[em] ellipse\fP
2775 arc \fR# open object \[em] quarter-circle\fP
2776 line \fR# open object \[em] line\fP
2777 arrow \fR# open object \[em] line with arrowhead\fP
2778 spline \fR# open object \[em] spline curve\fP
2780 TEXT TEXT ... \fR# text within invisible box\fP
2781 plot <expr> TEXT \fR# formatted text\fP
2782 '[' <command> ... ']'
2786 Drawn objects within `[\ .\|.\|.\ ]' are treated as a single composite
2787 object with a rectangular shape (that of the bounding box of all the
2788 elements). Variable and label assignments within a block are local to
2789 the block. Current direction of motion is restored to the value at start
2790 of block upon exit. Position is \fInot\fR restored (unlike `{\ }');
2791 instead, the current position becomes the exit position for the current
2792 direction on the block's bounding box.
2796 h[eigh]t <expr> \fR# set height of closed figure \fP
2797 wid[th] <expr> \fR# set width of closed figure \fP
2798 rad[ius] <expr> \fR# set radius of circle/arc \fP
2799 diam[eter] <expr> \fR# set diameter of circle/arc \fP
2800 up [<expr>] \fR# move up \fP
2801 down [<expr>] \fR# move down \fP
2802 left [<expr>] \fR# move left \fP
2803 right [<expr>] \fR# move right \fP
2804 from <position> \fR# set from position of open figure\fP
2805 to <position> \fR# set to position of open figure\fP
2806 at <position> \fR# set center of open figure\fP
2807 with <path> \fR# fix corner/named point at specified location\fP
2808 with <position> \fR# fix position of object at specified location\fP
2809 by <expr-pair> \fR# set object's attachment point\fP
2810 then \fR# sequential segment composition\fP
2811 dotted [<expr>] \fR# set dotted line style\fP
2812 dashed [<expr>] \fR# set dashed line style\fP
2813 thick[ness] <expr> \fR# set thickness of lines\fP
2814 chop [<expr>] \fR# chop end(s) of segment\fP
2815 '->' | '<-' | '<->' \fR# decorate with arrows\fP
2816 invis[ible] \fR# make primitive invisible\fP
2817 solid \fR# make closed figure solid\fP
2818 fill[ed] [<expr>] \fR# set fill density for figure\fP
2819 xscaled <expr> \fR# slant box into x direction\fP
2820 yscaled <expr> \fR# slant box into y direction\fP
2821 colo[u]r[ed] TEXT \fR# set fill and outline color for figure\fP
2822 outline[d] TEXT \fR# set outline color for figure\fP
2823 shaded TEXT \fR# set fill color for figure\fP
2824 same \fR# copy size of previous object\fP
2825 cw | ccw \fR# set orientation of curves\fP
2826 ljust | rjust \fR# adjust text horizontally\fP
2827 above | below \fR# adjust text vertically\fP
2828 aligned \fR# align parallel to object\fP
2829 TEXT TEXT ... \fR# text within object\fP
2830 <expr> \fR# motion in the current direction\fR
2834 Missing attributes are supplied from defaults; inappropriate ones are
2835 silently ignored. For lines, splines, and arcs, height and width
2836 refer to arrowhead size.
2838 The `at' primitive sets the center of the current object. The
2839 `with' attribute fixes the specified feature of the given object
2840 to a specified location. (Note that `with' is incorrectly described
2841 in the Kernighan paper.)
2843 The `by' primitive is not documented in the tutorial portion of
2844 the Kernighan paper, and should probably be considered unreliable.
2846 The primitive `arrow' is a synonym for `line\ ->'.
2848 Text is normally an attribute of some object, in which case successive
2849 strings are vertically stacked and centered on the object's center by
2850 default. Standalone text is treated as though placed in an invisible
2853 A text item consists of a string or sprintf-expression, optionally
2854 followed by positioning information. Text (or strings specified with
2855 `sprintf') may contain font changes, size changes, and local
2856 motions, provided those changes are undone before the end of the current
2857 item. Text may also contain \e-escapes denoting special characters.
2858 The base font and specific set of escapes supported is implementation
2859 dependent, but supported escapes always include the following:
2861 Set Roman style (the default)
2866 .IP "\efP\ \ \ \ \ \ "
2867 Revert to previous style; only works one level deep, does not stack.
2869 Color names are dependent on the \gBpic\fR implementation, but in
2870 all modern versions color names recognized by the X\~window system are
2873 A position is an (x,y) coordinate pair. There are lots of different
2874 ways to specify positions:
2878 <position-not-place>
2885 <position-not-place> ::=
2887 <position> + <expr-pair>
2888 <position> - <expr-pair>
2889 ( <position> , <position> )
2890 <expr> [of the way] between <position> and <position>
2891 <expr> '<' <position> , <position> '>'
2906 <corner> [of] <label>
2921 .ne | .se | .nw | .sw
2922 .c[enter] | .start | .end
2923 .t[op] | .b[ot[tom]] | .l[eft] | .r[ight]
2924 left | right | <top-of> | <bottom-of>
2925 <north-of> | <south-of> | <east-of> | <west-of>
2926 <center-of> | <start-of> | <end-of>
2927 upper left | lower left | upper right | lower right
2932 <\,\f(CIxxx\/\fP-of> ::=
2933 \f(CIxxx\fP \fR# followed by `of'\fP
2939 <ordinal> <object-type>
2940 [<ordinal>] last <object-type>
2947 INT st | INT nd | INT rd
2966 As Kernighan notes, \[lq]since barbarisms like \fB1th\fP and \fB3th\fP are
2967 barbaric, synonyms like \fB1st\fP and \fB3rd\fP are accepted as well.\[rq]
2968 Objects of a given type are numbered from 1 upwards in order of
2969 declaration; the \fBlast\fP modifier counts backwards.
2971 The \[lq]'th\[rq] form (which allows you to select a previous object with
2972 an expression, as opposed to a numeric literal) is not documented in DWB's
2975 The \[la]\,\fIxxx\/\fP-of\|\[ra] rule is special: The lexical parser checks whether
2976 \fIxxx\fP is followed by the token `of' without eliminating it so that
2977 the grammar parser can still see `of'. Valid examples of specifying a
2978 place with corner and label are thus
2995 both cause a syntax error. (DWB \fBpic\fP also allows the weird form
2998 Here the special rules for the `with' keyword using a path:
3003 ( <relative-path> , <relative-path> )
3010 . LABEL [. LABEL ...] [<corner>]
3014 The following style variables control output:
3016 center tab(@), linesize(2);
3020 Style Variable@Default@What It Does
3025 boxht@0.5@Default height of a box
3026 boxwid@0.75@Default height of a box
3027 lineht@0.5@Default length of vertical line
3028 linewid@0.75@Default length of horizontal line
3029 arcrad @0.25@Default radius of an arc
3030 circlerad@0.25@Default radius of a circle
3031 ellipseht@0.5@Default height of an ellipse
3032 ellipsewid@0.75@Default width of an ellipse
3033 moveht@0.5@Default length of vertical move
3034 movewid@0.75@Default length of horizontal move
3035 textht@0@Default height of box enclosing a text object
3036 textwid@0@Default width of box enclosing a text object
3037 arrowht@0.1@Length of arrowhead along shaft
3038 arrowwid@0.05@Width of rear of arrowhead
3039 arrowhead@1@Enable/disable arrowhead filling
3040 dashwid@0.05@Interval for dashed lines
3041 maxpswid@8.5@Maximum width of picture
3042 maxpsht@11@Maximum height of picture
3043 scale@1@Unit scale factor
3044 fillval@0.5@Default fill value
3048 Any of these can be set by assignment, or reset using the \fBreset\fP
3049 statement. Style variables assigned within `[\ ]' blocks are restored to
3050 their beginning-of-block value on exit; top-level assignments persist
3051 across pictures. Dimensions are divided by \fBscale\fR on output.
3053 All \fBpic\fP expressions are evaluated in floating point; units
3054 are always inches (a trailing `i' or `I' is ignored). Expressions have
3055 the following simple grammar, with semantics very similar to
3062 <place> <place-attribute>
3067 <func1> ( <any-expr> )
3068 <func2> ( <any-expr> , <any-expr> )
3075 .x | .y | .h[eigh]t | .wid[th] | .rad
3081 + | - | * | / | % | ^ | '<' | '>' | '<=' | '>='
3087 sin | cos | log | exp | sqrt | int | rand | srand
3097 Both \fBexp\fP and \fBlog\fP are base 10; \fBint\fP does integer
3098 truncation; and \fBrand()\fP returns a random number in [0-1).
3100 There are \fBdefine\fP and \fBundef\fR statements which are not part
3101 of the grammar (they behave as pre-processor macros to the language).
3102 These may be used to define pseudo-functions.
3105 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement-text\fP \fB}\fP
3109 This defines \fIname\fR as a macro to be replaced by the replacement
3110 text (not including the braces). The macro may be called as
3113 \fIname\/\fB(\,\fIarg1, arg2, .\|.\|., argn\fB\/)\fR
3117 The arguments (if any) are substituted for tokens $1, $2 .\|.\|.\& $n
3118 appearing in the replacement text. To undefine a macro, say \fBundef\fP
3119 \fIname\fR, specifying the name to be undefined.
3124 History and Acknowledgements
3126 Original \fBpic\fP was written to go with Joseph Ossanna's original
3127 \fItroff\/\fP(1) by Brian Kernighan, and later re-written by Kernighan
3128 with substantial enhancements (apparently as part of the evolution of
3129 \fItroff\/\fP(1) into \fIditroff\/\fP(1) to generate
3130 device-independent output).
3132 The language had been inspired by some earlier graphics languages
3133 including \fBideal\fP and \fBgrap\fP. Kernighan credits Chris van Wyk
3134 (the designer of \fBideal\fP) with many of the ideas that went into
3137 .\" the original definitions of EQ and EN cause insertion of vertical
3138 .\" space which is not appropriate here
3146 The \fBpic\fP language was originally described by Brian Kernighan in
3147 Bell Labs Computing Science Technical Report #116 (you can obtain a
3148 PostScript copy of the revised version, [1], by sending a mail message to
3149 \fInetlib@research.att.com\fP with a body of `send 116 from
3150 research/cstr'). There have been two revisions, in 1984 and 1991.
3152 The document you are reading effectively subsumes Kernighan's
3153 description; it was written to fill in lacun\[ae] in the exposition and
3154 integrate in descriptions of the GNU \fIgpic\/\fP(1) and
3155 \fIpic2plot\/\fP(1) features.
3157 The GNU \fBgpic\fR implementation was written by James Clark
3158 \[la]\,\fIjjc@jclark.com\/\fP\[ra]. It is currently maintained by Werner
3159 Lemberg \[la]\,\fIwl@gnu.org\/\fP\[ra].
3161 The GNU \fBpic2plot\fR implementation is based on James Clark's parser
3162 code and maintained by Robert Maier, principal author of \fBplotutils\fP.
3168 Kernighan, B. W. \fBPIC \[em] A Graphics Language for Typesetting
3169 (Revised User Manual)\fP. Bell Labs Computing Science Technical Report
3170 #116, December 1991.
3172 Van Wyk, C. J. \fBA high-level language for specifying pictures\fP.
3173 \fIACM Transactions On Graphics\fP 1,2 (1982) 163-182.