1 .\" Copyright (C) 2006-2020 Free Software Foundation, Inc.
2 .\" Written by Eric S. Raymond <esr@thyrsus.com>
4 .\" This file is part of groff.
6 .\" groff is free software; you can redistribute it and/or modify it under
7 .\" the terms of the GNU General Public License as published by the Free
8 .\" Software Foundation, either version 3 of the License, or
9 .\" (at your option) any later version.
11 .\" groff is distributed in the hope that it will be useful, but WITHOUT ANY
12 .\" WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 .\" FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 .\" You should have received a copy of the GNU General Public License
17 .\" along with this program. If not, see <http://www.gnu.org/licenses/>.
19 .\" For tolerably obvious reason, this needs to be processed through PIC.
20 .\" It also needs to be processed through TBL and EQN. Use "groff -p -e -t".
21 .\" There is no hope that this will ever look right under nroff.
23 .\" Comments beginning with %% are cut lines so portions of this
24 .\" document can be automatically extracted. %%TUTORIAL%% begins the
25 .\" tutorial part; %%REFERENCE%% the reference part. %%POSTLUDE%% the
26 .\" bibliography and end matter after the reference part.
28 .\" This document was written for free use and redistribution by
29 .\" Eric S. Raymond <esr@thyrsus.com> in August 1995. It has been put
30 .\" under the GPL in March 2006.
34 .\" Set a proper TeX and LaTeX
36 . ds tx T\h'-.1667m'\v'.224m'E\v'-.224m'\h'-.125m'X\"
37 . ds lx L\h'-0.36m'\v'-0.22v'\s-2A\s0\h'-0.15m'\v'0.22v'\*(tx\"
44 .\" Centered caption for figure. Assumes previous .KS
52 .\" Definitions end here
56 Making Pictures With GNU PIC
60 \[la]\fIesr@snark.thyrsus.com\fP\[ra]
62 The \fBpic\fP language is a \fBtroff\fP extension that makes it easy
63 to create and alter box-and-arrow diagrams of the kind frequently used
64 in technical papers and textbooks.
65 This paper is both an introduction to and reference for \fIgpic\/\fP(1),
66 the implementation distributed by the Free Software Foundation for use
67 with \fIgroff\/\fP(1).
68 It also catalogs other implementations and explains the differences
80 The \fBpic\fP language provides an easy way to write procedural
81 box-and-arrow diagrams to be included in \fBtroff\fP documents.
82 The language is sufficiently flexible to be quite useful for state
83 charts, Petri-net diagrams, flow charts, simple circuit schematics,
84 jumper layouts, and other kinds of illustration involving repetitive
85 uses of simple geometric forms and splines.
86 Because these descriptions are procedural and object-based, they are
87 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.
92 The \fIgpic\/\fP(1) implementation is for use with the \fIgroff\/\fP(1)
93 implementation of \fBtroff\fP.
94 The \fIpic2plot\/\fP(1) implementation runs standalone and is part of
95 the \fBplotutils\fR package.
96 Because both implementations are widely available in source form for
97 free, they are good bets for writing very portable documentation.
102 The original 1984 pre-\fIditroff\/\fP(1) version of \fBpic\fP is long
104 The rewritten 1991 version is still available as part of the
105 Documenter's Work Bench module of System V.
107 Where differences between Documenter's Work Bench (1991) \fBpic\fP and GNU
108 \fBpic\fP need to be described, original \fBpic\fP is referred to as
110 Details on the history of the program are given at the end of this
113 The \fBpic2plot\fR program does not require the rest of the
114 \fIgroff\/\fP(1) toolchain to render graphics.
115 It can display \fBpic\fR diagrams in an X\~window, or generate output
116 plots in a large number of other formats.
117 These formats include: PNG, PBM, PGM, PPM, GIF, SVG, Adobe Illustrator
118 format, idraw-editable Postscript, the WebCGM format for Web-based
119 vector graphics, the format used by the \fBxfig\fP drawing editor, the
120 Hewlett-Packard PCL\~5 printer language, the Hewlett-Packard Graphics
121 Language (by default, HP-GL/2), the ReGIS (remote graphics instruction
122 set) format developed by DEC, Tektronix format, and device-independent
123 GNU graphics metafile format.
125 In this document, \fIgpic\/\fP(1) and \fIpic2plot\/\fP(1) extensions are
132 Every \fBpic\fP description is a little program describing drawing
134 The \fB[gtn]roff\fP-dependent versions compile the program by
135 \fIpic\/\fP(1) into \fIgtroff\/\fP(1) macros; the \fIpic2plot\/\fP(1)
136 implementation uses a plotting library to draw the picture directly.
137 Programs that process or display
138 \fIgtroff\/\fP(1) output need not know or care that parts of the image
139 began life as \fBpic\fP descriptions.
141 The \fIpic\/\fP(1) program tries to translate anything between \fB.PS\fP
142 and \fB.PE\fP markers, and passes through everything else.
143 The normal definitions of \fB.PS\fP and \fB.PE\fP in the \fIms\fP macro
144 package and elsewhere have also the side-effect of centering the
145 \fBpic\fP output on the page.
151 If you make a mistake in \fBpic\fP input such that the program cannot
152 interpret what you mean,
153 \fIgpic\/\fP(1) issues a diagnostic message in the format prescribed by
154 the GNU Coding Standards.
156 A typical error message looks like
161 pic:\fIfile\fP:\fInnn\fP: syntax error before \[aq]\fItoken\fP\[aq]
162 pic:\fIfile\fP:\fInnn\fP: giving up on this picture
170 is the name of the file being processed,
172 is a line number within that file,
175 is a symbol in the \fBpic\fP language
186 Pictures are described procedurally, as collections of objects
187 connected by motions.
188 Normally, \fBpic\fP tries to string together objects left-to-right in
189 the sequence they are described, joining them at visually natural
191 Here is an example illustrating the flow of data in \fBpic\fP
197 box width 0.6 "\fIgpic\/\fP(1)"
199 box width 1.1 "\fIgtbl\/\fP(1) or \fIgeqn\/\fP(1)" "(optional)" dashed;
201 box width 0.6 "\fIgtroff\/\fP(1)";
205 .CE "1: Flow of \fBpic\fP data"
207 This was produced from the following \fBpic\fP program:
216 box width 0.6 "\efIgpic\e/\efP(1)"
218 box width 1.1 "\efIgtbl\e/\efP(1) or \efIgeqn\e/\efP(1)" "(optional)" dashed;
220 box width 0.6 "\efIgtroff\e/\efP(1)";
228 This little program illustrates several \fBpic\fP basics.
229 Firstly, we see how to invoke three object types; ellipses, arrows, and
231 We see how to declare text lines to go within an object (and that text
232 can have font changes in it).
233 We see how to change the line style of an object from solid (the
235 And we see that a box can be made wider than its default size to
236 accommodate more text (we'll discuss this facility in detail in the next
239 We also get to see \fBpic\fP's simple syntax.
240 Statements are ended by newlines or semicolons.
241 String quotes are required around all text arguments, whether or not
243 In general, the order of command arguments and modifiers like \[lq]width
244 1.2\[rq] or \[lq]dashed\[rq] doesn't matter, except that the order of
245 text arguments is significant.
247 Here are all but one of the basic \fBpic\fP objects at their default sizes:
260 arc; down; move; "arc"
262 .CE "2: Basic \fBpic\fP objects"
264 The missing simple object type is a \fIspline\fP.
265 There is also a way to collect objects into \fIblock composites\fP which
266 allows you to treat the whole group as a single object (resembling a
267 box) for many purposes.
268 We'll describe both of these later on.
270 The box, ellipse, circle, and block composite objects are \fIclosed\/\fR;
271 lines, arrows, arcs and splines are \fIopen\fP.
272 This distinction is often important in explaining command modifiers.
274 Figure \n[H1]-2 was produced by the following \fBpic\fP program,
275 which introduces some more basic concepts:
290 arc; down; move; "arc"
296 The first thing to notice is the \fImove\fP command, which moves a
297 default distance (1/2 inch) in the current movement direction.
299 Secondly, see how we can also decorate lines and arrows with text.
300 The line and arrow commands each take two arguments here, specifying
301 text to go above and below the object.
302 If you wonder why one argument would not do, contemplate the output of
308 .CE "3: Text centered on an arrow"
310 When a command takes one text string, \fBpic\fP tries to place it at
311 the object's geometric center.
312 As you add more strings, \fBpic\fP treats them as a vertical block to be
321 line "1" "2" "3" "4";
322 line "1" "2" "3" "4" "5";
327 for example, gives you this:
334 line "1" "2" "3" "4";
335 line "1" "2" "3" "4" "5";
338 .CE "4: Effects of multiple text arguments"
340 The last line of Figure 3-2's program, `\fBarc; down; move;
341 "arc"\fP', describing the captioned arc, introduces several new ideas.
342 Firstly, we see how to change the direction in which objects are
344 Had we written \fBarc; move; "arc"\fP, omitting \fBdown\fP the caption
345 would have been joined to the top of the arc, like this:
350 .CE "5: Result of \fBarc; move; ""arc""\fP"
352 This is because drawing an arc changes the default direction to the
353 one its exit end points at.
354 To reinforce this point, consider:
359 .CE "6: Result of \fBarc cw; move; ""arc""\fP"
361 All we've done differently here is specify \[lq]cw\[rq] for a clockwise arc
362 (\[lq]ccw\[rq] specifies counter-clockwise direction).
363 Observe how it changes the default direction to down, rather than up.
365 Another good way to see this via with the following program:
369 line; arc; arc cw; line
377 line; arc; arc cw; line;
379 .CE "7: Result of \fBline; arc; arc cw; line\fP"
381 Notice that we did not have to specify \[lq]up\[rq] for the second arc to be
382 joined to the end of the first.
384 Finally, observe that a string, alone, is treated as text to be
385 surrounded by an invisible box of a size either specified by width
386 and height attributes or by the defaults \fBtextwid\fR and
388 Both are initially zero (because we don't know the default font size).
394 Sizes are specified in inches.
395 If you don't like inches, it's possible to set a global style variable
396 \fBscale\fP that changes the unit.
397 Setting \fBscale = 2.54\fP effectively changes the internal unit to
398 centimeters (all other size variable values are scaled correspondingly).
401 Default Sizes of Objects
403 Here are the default sizes for \fBpic\fP objects:
405 center, tab(@), linesize(2);
414 box@0.75" wide by 0.5" high
416 ellipse@0.75" wide by 0.5" high
424 The simplest way to think about these defaults is that they make the
425 other basic objects fit snugly into a default-sized box.
427 \fIpic2plot\/\fP(1) does not necessarily emit a physical inch for
428 each virtual inch in its drawing coordinate system.
429 Instead, it draws on a canvas 8\~virtual inches by 8\~virtual inches
431 If its output page size is \[lq]letter\[rq], these virtual inches will
433 Specifying a different page size (such as, say, \[lq]a4\[rq]) will scale
434 virtual inches so they are output as one eighth of the page width.
435 Also, \fIpic2plot\/\fP(1) centers all images by default, though the
436 \fB\-n\fP option can be used to prevent this.
439 Objects Do Not Stretch!
441 Text is rendered in the current font with normal troff line spacing.
442 Boxes, circles, and ellipses do \fInot\fP automatically resize to fit
444 Thus, if you say \fBbox "this text far too long for a default box"\fP
448 box "this text is far too long for a default box"
450 .CE "1: Boxes do not automatically resize"
452 which is probably not the effect you want.
457 To change the box size, you can specify a box width with the \[lq]width\[rq]
461 box width 3 "this text is far too long for a default box"
463 .CE "2: Result of \fBbox width 3 ""text far too long""\fP"
465 This modifier takes a dimension in inches.
466 There is also a \[lq]height\[rq] modifier that changes a box's height.
467 The \fBwidth\fP keyword may be abbreviated to \fBwid\fP; the
468 \fBheight\fP keyword to \fBht\fP.
471 Resizing Other Object Types
473 To change the size of a circle, give it a \fBrad[ius]\fP or
474 \fBdiam[eter]\fP modifier; this changes the radius or diameter of the
475 circle, according to the numeric argument that follows.
478 {circle rad 0.1; move down 0.2 from last circle .s; "0.1"};
479 move; circle rad 0.2 "0.2"; move; circle rad 0.3 "0.3";
481 .CE "3: Circles with increasing radii"
483 The \fBmove\fP command can also take a dimension, which just tells
484 it how many inches to move in the current direction.
486 Ellipses are sized to fit in the rectangular box defined by their
487 axes, and can be resized with \fBwidth\fP and \fBheight\fP like boxes.
489 You can also change the radius of curvature of an arc with \fBrad[ius]\fP
490 (which specifies the radius of the circle of which the arc is a segment).
491 Larger values yield flatter arcs.
494 {arc rad 0.1; move down 0.3 from last arc .center; "0.1"};
496 {arc rad 0.2; move down 0.4 from last arc .center; "0.2"};
498 {arc rad 0.3; move down 0.5 from last arc .center; "0.3"};
500 .CE "4: \fBarc rad\fP with increasing radii"
502 Observe that because an arc is defined as a quarter circle, increasing
503 the radius also increases the size of the arc's bounding box.
508 In place of a dimension specification, you can use the keyword
510 This gives the object the same size as the previous one
512 As an example, the program
517 box; box wid 1 ht 1; box same; box
526 box; box wid 1 ht 1; box same; box
528 .CE "5: The \fBsame\fP keyword"
532 Generalized Lines and Splines
537 It is possible to specify diagonal lines or arrows by adding multiple \fBup\fP,
538 \fBdown\fP, \fBleft\fP, and \fBright\fP modifiers to the line object.
539 Any of these can have a multiplier.
540 To understand the effects, think of the drawing area as being gridded
541 with standard-sized boxes.
544 # Draw a demonstration up left arrow with grid box overlay
550 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
551 for i = 2 to ($1 / 0.5) do {
552 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
554 move down from last arrow .center;
556 sprintf("\fBarrow up left %g\fP", $1)
559 move right 0.1 from last [] .e;
567 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
570 Multi-Segment Line Objects
572 A \[lq]line\[rq] or \[lq]arrow\[rq] object may actually be a path
573 consisting of any number of segments of varying lengths and directions.
574 To describe a path, connect several line or arrow commands with the
578 define zigzag { $1 right 1 then down .5 left 1 then right 1 }
581 .CE "2: \fBline right 1 then down .5 left 1 then right 1\fP"
583 If a path starts with \fBthen\fP, the first segment is assumed to be into
584 the current direction, using the default length.
589 If you start a path with the \fBspline\fP keyword, the path vertices
590 are treated as control points for a spline curve fit.
594 move down 0.2 from last [] .s;
595 "The spline curve..."
596 move right from last [] .e;
599 spline from start of last line right 1 then down .5 left 1 then right 1;
600 "1" at last spline .start + (-0.1, 0);
601 "2" at last spline .start + (1.1, 0);
602 "3" at last spline .end + (-1.1, 0);
603 "4" at last spline .end + (0.1, 0);
605 move down 0.2 from last [] .s;
606 "...with tangents displayed"
609 .CE "3: \fBspline right 1 then down .5 left 1 then right 1\fP"
611 You can describe many natural-looking but irregular curves this
616 [spline right then up then left then down ->;]
617 move down 0.2 from last [] .s;
618 ["\fBspline right then up then left then down ->;\fP"]
619 move right 3 from last [] .se;
620 "\fBspline left then up right then down right ->;\fP"
622 [spline left then up right then down right ->;]
624 .CE "4: Two more spline examples"
626 Note the arrow decorations.
627 Arrowheads can be applied naturally to any path-based object, line or
629 We'll see how in the next section.
638 All \fBpic\fP implementations support the following font-styling
639 escapes within text objects:
640 .IP "\efR, \ef1" \w'\efR,\~\ef3'u+2n
641 Set Roman style (the default)
647 Revert to previous style; only works one level deep, does not stack.
649 In the \fBpic\fP implementations that are preprocessors for a
650 toolchain that include \fB[gtn]roff\fP, text objects may also contain
651 \fB[gtn]roff\fP vertical- and horizontal-motion escapes such as \eh or \ev.
652 Troff special glyphs are also available.
653 All \e-escapes will be passed through to the postprocessing stage and
654 have their normal effects.
655 The base font family is set by the \fB[gtn]roff\fP environment at the
656 time the picture is rendered.
658 \fBpic2plot\fP replaces \fB[gtn]roff\fP horizontal- and vertical-motion
659 escapes with \e-escapes of its own.
660 Troff special glyphs are not available, but in most back ends Latin-1
661 special characters and a square-root radical will be.
662 See the \fBpic2plot\fP documentation for full details.
667 We've already seen that the modifier \fBdashed\fP can change the line
668 style of an object from solid to dashed.
669 GNU \fBgpic\fP permits you to dot or dash ellipses, circles, and arcs
670 (and splines in \*[tx] mode only); some versions of DWB may only permit
671 dashing of lines and boxes.
672 It's possible to change the dash interval by specifying a
673 number after the modifier.
677 box dashed "default";
679 box dashed 0.05 "0.05";
681 box dashed 0.1 "0.1";
683 box dashed 0.15 "0.15";
685 box dashed 0.2 "0.2";
687 .CE "1: Dashed objects"
692 Another available qualifier is \fBdotted\fP.
693 GNU \fBgpic\fP permits you to dot or dash ellipses, circles, and arcs
694 (and splines in \*[tx] mode only); some versions of DWB may only permit
695 dashing of lines and boxes.
696 It too can be suffixed with a number to specify the interval between
700 box dotted "default";
702 box dotted 0.05 "0.05";
704 box dotted 0.1 "0.1";
706 box dotted 0.15 "0.15";
708 box dotted 0.2 "0.2";
710 .CE "2: Dotted objects"
715 It is also possible, in GNU \fBgpic\fP only, to modify a box so it has
719 box rad 0.05 "rad 0.05";
721 box rad 0.1 "rad 0.1";
723 box rad 0.15 "rad 0.15";
725 box rad 0.2 "rad 0.2";
727 box rad 0.25 "rad 0.25";
729 .CE "3: \fBbox rad\fP with increasing radius values"
731 Radius values higher than half the minimum box dimension are silently
732 truncated to that value.
737 GNU \fBgpic\fP supports slanted boxes:
740 box wid 1.2 xslanted 0.1 "xslanted 0.1";
742 box wid 1.2 yslanted -0.1 "yslanted -0.1";
744 box wid 1.2 xslanted -0.2 yslanted 0.1 "xslanted -0.2" "yslanted 0.1";
746 .CE "4: Various slanted boxes."
748 The \fBxslanted\fP and \fByslanted\fP attributes specify the x and
749 y\~offset, respectively, of the box's upper right corner from its default
755 Lines and arcs can be decorated as well.
756 Any line or arc (and any spline as well) can be decorated with
757 arrowheads by adding one or more as modifiers:
762 .CE "5: Double-headed line made with \fBline <- ->\fP"
764 In fact, the \fBarrow\fP command is just shorthand for \fBline ->\fP.
765 And there is a double-head modifier <->, so the figure above could have
766 been made with \fBline <->\fP.
768 Arrowheads have a \fBwidth\fP attribute, the distance across the rear;
769 and a \fBheight\fP attribute, the length of the arrowhead along the shaft.
771 Arrowhead style is controlled by the style variable \fBarrowhead\fP.
772 The DWB and GNU versions interpret it differently.
773 DWB defaults to open arrowheads and an \fBarrowhead\fP value of\~2; the
774 Kernighan paper says a value of\~7 makes solid arrowheads.
775 GNU \fBgpic\fP defaults to solid arrowheads and an \fBarrowhead\fP value
776 of\~1; a value of\~0 produces open arrowheads.
777 Note that solid arrowheads are always filled with the current outline
783 It's also possible to change the line thickness of an object (this is
784 a GNU extension, DWB \fBpic\fP doesn't support it).
785 The default thickness of the lines used to draw objects is controlled by the
788 This gives the thickness of lines in points.
789 A negative value means use the default thickness:
790 in \*[tx] output mode, this means use a thickness of 8 milliinches;
791 in \*[tx] output mode with the
793 option, this means use the line thickness specified by
795 lines; in troff output mode, this means use a thickness proportional
797 A zero value means draw the thinnest possible line supported by the
799 Initially it has a value of -1.
800 There is also a \fBthickness\fP attribute (which can be abbreviated to
802 For example, \fBcircle thickness 1.5\fP would draw a circle using a line
803 with a thickness of 1.5 points.
804 The thickness of lines is not affected by the value of the
806 variable, nor by any width or height given in the
813 The modifier \fBinvis[ible]\fP makes an object entirely invisible.
814 This used to be useful for positioning text in an invisible object that
815 is properly joined to neighboring ones.
816 Newer DWB versions and GNU \fBpic\fP treat stand-alone text in exactly
822 It is possible to fill boxes, circles, and ellipses.
823 The modifier \fBfill[ed]\fP accomplishes this.
824 You can suffix it with a fill value; the default is given by the style
825 variable \fBfillval\fP.
827 DWB \fBpic\fP and \fBgpic\fP have opposite conventions for fill values
828 and different defaults.
829 DWB \fBfillval\fP defaults to 0.3 and smaller values are darker; GNU
830 \fBfillval\fP uses 0 for white and 1 for black.
833 circle fill; move; circle fill 0.4; move; circle fill 0.9;
835 .CE "6: \fBcircle fill; move; circle fill 0.4; move; circle fill 0.9;\fR"
837 GNU \fBgpic\fP makes some additional guarantees.
838 A fill value greater than 1 can also be used: this means fill with the
839 shade of gray that is currently being used for text and lines.
840 Normally this is black, but output devices may provide a mechanism for
842 The invisible attribute does not affect the filling of objects.
843 Any text associated with a filled object is added after the object has
844 been filled, so that the text is not obscured by the filling.
849 As a GNU extension, three additional modifiers are available to specify
851 \fBoutline\fP sets the color of the outline, \fBshaded\fP the fill
852 color, and \fBcolor\fP sets both.
853 All three keywords expect a suffix specifying the color.
857 box color "yellow"; arrow color "cyan"; circle shaded "green" outline "black";
859 .CE "7: \fBbox color ""yellow""; arrow color ""cyan""; \
860 circle shaded ""green"" outline ""black"";\fR"
862 Alternative spellings are \fBcolour\fP, \fBcolored\fP, \fBcoloured\fP,
865 Predefined color names for \fI[gtn]roff\/\fP-based \fBpic\fP
866 implementations are defined in the device macro files, for example
867 \f(CWps.tmac\fP; additional colors can be defined with the
868 \fB.defcolor\fP request (see the manual page of GNU \fItroff\/\fP(1)
870 Currently, color support is not available at all in \*[tx] mode.
872 The \fIpic2plot\/\fP(1) carries with its own set of color names,
873 essentially those recognized by the X\~window system with \[lq]grey\[rq]
874 accepted as a variant of \[lq]gray\[rq].
876 \fBpic\fP assumes that at the beginning of a picture both glyph and fill
877 color are set to the default value.
881 More About Text Placement
883 By default, text is centered at the geometric center of the object it is
885 The modifier \fBljust\fP causes the left end to be at the specified
886 point (which means that the text lies to the right of the specified
887 place!), the modifier \fBrjust\fP puts the right end at the place.
888 The modifiers \fBabove\fP and \fBbelow\fP center the text one half line
889 space in the given direction.
891 Text attributes can be combined:
894 [line up "ljust text" ljust;]
896 [line up "rjust text" rjust;]
898 [arrow 1 "ljust above" ljust above;]
900 [arrow 1 "rjust below" rjust below;]
902 .CE "1: Text attributes"
904 What actually happens is that \fIn\fP text strings are centered in a box
905 that is \fBtextwid\fP wide by \fBtextht\fP high.
906 Both these variables are initially zero (that is \fBpic\fR's way of not
907 making assumptions about \fI[tg]roff\/\fP(1)'s default point size).
909 In GNU \fBgpic\fR, objects can have an
912 This only works if the postprocessor is
913 \fBgrops\fP or \fBgropdf\fP.
914 Any text associated with an object having the
916 attribute is rotated about the center of the object
917 so that it is aligned in the direction from the start point
918 to the end point of the object.
919 Note that this attribute has no effect for objects whose start and
920 end points are coincident.
924 More About Direction Changes
926 We've already seen how to change the direction in which objects are
927 composed from rightwards to downwards.
928 Here are some more illustrative examples:
933 "\fBright; box; arrow; circle; arrow; ellipse\fP";
935 [right; box; arrow; circle; arrow; ellipse;]
937 move down 0.3 from last [] .s;
939 "\fBleft; box; arrow; circle; arrow; ellipse\fP"
941 [left; box; arrow; circle; arrow; ellipse;]
943 # move down 0.3 from last [] .sw;
944 # To re-join this illustrations, delete everything from here down to
945 # the next #-comment, and uncomment the move line above
947 .CE "1: Effects of different motion directions (right and left)"
950 # To re-join this illustrations, delete everything down to here, then
951 # comment out the next `down' line.
952 # Don't forget to re-number the figures following!
955 "\fBdown; box; arrow; circle; arrow; ellipse;\fP"
957 box; arrow; circle; arrow; ellipse;
959 move right 2 from last [] .e;
961 up; box; arrow; circle; arrow; ellipse;
963 "\fBup; box; arrow; circle; arrow; ellipse;\fP"
966 .CE "2: Effects of different motion directions (up and down)"
968 Something that may appear surprising happens if you change directions
972 box; arrow; circle; down; arrow; ellipse
974 .CE "3: \fBbox; arrow; circle; down; arrow; ellipse\fP"
976 You might have expected that program to yield this:
979 box; arrow; circle; move to last circle .s; down; arrow; ellipse
981 .CE "4: More intuitive?"
983 But, in fact, to get Figure \*[SN]3 you have to do this:
991 move to last circle .s;
1001 Because the exit point for the current direction is already set when you
1003 The second arrow in Figure \*[SN]2 dropped downwards from the circle's
1004 attachment point for an
1005 object to be joined to the right.
1007 The meaning of the command \fBmove to last circle \&.s\fP should be
1009 In order to see how it generalizes, we'll need to go into detail on two
1010 important topics; locations and object names.
1016 The most natural way to name locations in \fBpic\fP is relative to
1018 In order to do this, you have to be able to name
1020 The \fBpic\fP language has rich facilities for this that try to emulate
1021 the syntax of English.
1024 Naming Objects By Order Of Drawing
1026 The simplest (and generally the most useful) way to name an object is
1027 with a \fBlast\fP clause.
1028 It needs to be followed by an object type name; \fBbox\fP, \fBcircle\fP,
1029 \fBellipse\fP, \fBline\fP, \fBarrow\fP, \fBspline\fP, \fB""\fP, or
1030 \fB[]\fP (the last type refers to a \fIcomposite object\fP which we'll
1032 So, for example, the \fBlast circle\fP clause in the program attached to
1033 Figure \*[SN]3 refers to the last circle drawn.
1035 More generally, objects of a given type are implicitly numbered
1037 You can refer to (say) the third ellipse in the current picture with
1038 \fB3rd ellipse\fP, or to the first box as \fB1st box\fP, or to the fifth
1039 text string (which isn't an attribute to another object) as \fB5th
1042 Objects are also numbered backwards by type from the last one.
1043 You can say \fB2nd last box\fP to get the second-to-last box, or
1044 \fB3rd last ellipse\fP to get the third-to-last ellipse.
1046 In places where \fIn\/\fBth\fR is allowed, \fB`\fIexpr\/\fB'th\fR is
1050 is a single token: no space is allowed between the
1059 line from `i'th box.nw to `i+1'th box.se
1066 Naming Objects With Labels
1068 You can also specify an object by referring to a label.
1069 A label is a word (which must begin with a capital letter) followed by a
1070 colon; you declare it by placing it immediately before the object
1072 For example, the program
1077 A: box "first" "object"
1079 B: ellipse "second" "object"
1081 arrow right at A .r;
1087 declares labels \fBA\fP and \fBB\fP for its first and second objects.
1088 Here's what that looks like:
1091 A: box "first" "object"
1093 B: ellipse "second" "object"
1095 arrow right at A .r;
1097 .CE "1: Example of label use"
1098 The \fBat\fP statement in the fourth line uses the label \fBA\fP (the
1099 behavior of \fBat\fP is explained in the next section).
1100 We'll see later on that labels are most useful for referring to block
1103 Labels are not constants but variables (you can view colon as a sort
1105 You can say something like \fBA: A + (1,0);\fP and the effect is to
1106 reassign the label \fBA\fR to designate a position one inch to the right
1111 Describing locations
1113 The location of points can be described in many different ways.
1114 All these forms are interchangeable as for as the \fBpic\fP language
1115 syntax is concerned; where you can use one, any of the others that would
1116 make semantic sense are allowed.
1118 The special label \fBHere\fR always refers to the current position.
1121 Absolute Coordinates
1123 The simplest is absolute coordinates in inches; \fBpic\fP uses a
1124 Cartesian system with (0,0) at the lower left corner of the virtual
1125 drawing surface for each picture (that is, X\~increases to the right
1126 and Y\~increases upwards).
1127 An absolute location may always be written in the conventional form as
1128 two comma-separated numbers surrounded by parentheses (and this is
1129 recommended for clarity).
1130 In contexts where it creates no ambiguity, the pair of X and
1131 Y\~coordinates suffices without parentheses.
1133 It is a good idea to avoid absolute coordinates, however.
1134 They tend to make picture descriptions difficult to understand and
1136 Instead, there are quite a number of ways to specify locations
1137 relative to \fBpic\fP objects and previous locations.
1139 Another possibility of surprise is the fact that \fBpic\fP crops the
1140 picture to the smallest bounding box before writing it out.
1141 For example, if you have a picture consisting of a small box with its
1142 lower left corner at (2,2) and another small box with its upper right
1143 corner at (5,5), the width and height of the image are both 3\~units and
1145 To get the origin at (0,0) included, simply add an invisible object to
1146 the picture, positioning the object's left corner at (0,0).
1149 Locations Relative to Objects
1151 The symbol \fBHere\fP always refers to the position of the last object
1152 drawn or the destination of the last \fBmove\fP.
1154 Alone and unqualified, a \fBlast circle\fP or any other way of
1155 specifying a closed-object or arc location refers as a position to the
1156 geometric center of the object.
1157 Unqualified, the name of a line or spline object refers to the position
1158 of the object start.
1160 Also, \fBpic\fP objects have quite a few named locations
1161 associated with them.
1162 One of these is the object center, which can be indicated (redundantly)
1163 with the suffix \fB.center\fP (or just \fB.c\fP).
1164 Thus, \fBlast circle \&.center\fP is equivalent to \fBlast
1167 Locations Relative to Closed Objects
1169 Every closed object (box, circle, ellipse, or block composite) also
1170 has eight compass points associated with it;
1173 define dot {circle fill rad 0.02 at $1}
1177 dot(ME.c); "\fB .c\fP" at ME .c ljust;
1178 dot(ME.n); "\fB.n\fP" at ME .n above
1179 dot(ME.ne); "\fB .ne\fP" at ME .ne above
1180 dot(ME.e); "\fB .e\fP" at ME .e ljust
1181 dot(ME.se); "\fB .se\fP" at ME .se below
1182 dot(ME.s); "\fB.s\fP" at ME .s below
1183 dot(ME.sw); "\fB.sw \fP" at ME .sw below
1184 dot(ME.w); "\fB.w \fP" at ME .w rjust
1185 dot(ME.nw); "\fB.nw \fP" at ME .nw above
1187 compass(box wid 1.5 ht 1);
1188 move right from last [] .e;
1189 compass(circle diam 1);
1190 move right from last [] .e;
1191 compass(ellipse wid 1.5 ht 1);
1193 .CE "1: Compass points"
1195 these are the locations where eight compass rays from the geometric center
1196 would intersect the figure.
1197 So when we say \fBlast circle \&.s\fP we are referring to the south
1198 compass point of the last circle drawn.
1199 The explanation of Figure 8-3's program is now complete.
1201 (In case you dislike compass points, the names \fB.top\fP,
1202 \&\fB.bottom\fP, \fB.left\fP and \fB.right\fP are synonyms for \fB.n\fP,
1203 \&\fB.s\fP, \fB.e\fP, and \fB.w\fP respectively; they can even be
1204 abbreviated to \fB.t\fP, \fB.b\fP, \fB.l\fP and \fB.r\fP).
1206 The names \fBcenter\fP, \fBtop\fP, \fBbottom\fP, \fBleft\fP, \fBright\fP,
1207 \fBnorth\fP, \fBsouth\fP, \fBeast\fP, and \fBwest\fP can also be used
1208 (without the leading dot) in a prefix form marked by \fBof\fP; thus,
1209 \fBcenter of last circle\fP and \fBtop of 2nd last ellipse\fP are both
1210 valid object references.
1211 Finally, the names \fBleft\fP and \fBright\fP can be prefixed with
1212 \fBupper\fP and \fBlower\fP which both have the obvious meaning.
1214 Arc objects also have compass points; they are the compass points of
1217 Non-closed objects (line, arrow, or spline) have compass points too, but
1218 the locations of them are completely arbitrary.
1219 In particular, different \fBpic\fP implementations return different
1222 Locations Relative to Open Objects
1224 Every open object (line, arrow, arc, or spline) has three named
1225 points: \fB.start\fP, \fB.center\fP (or \fB.c\fP), and \fB.end\fP.
1226 They can also be used without leading dots in the \fBof\fP prefix form.
1227 The center of an arc is the center of its circle, but the center of
1228 a line, path, or spline is halfway between its endpoints.
1233 dot(ME.c); "\fB.center\fP" rjust at ME.center + (-0.1, 0.1)
1234 dot(ME.start); "\fB.start\fP" rjust at ME.start + (-0.1, 0.1)
1235 dot(ME.end); "\fB.end\fP" rjust at ME.end + (-0.1, 0.1)
1238 critical(line up right 1);
1239 move right 1 from last [] .e;
1240 critical(arc rad 0.5 cw);
1241 move down 0.5 from 2nd last [] .s;
1242 critical(line right 1 then down .5 left 1 then right 1);
1243 move right 1 from last [] .e;
1244 critical(spline right 1 then up right then left then left 1);
1246 .CE "2: Special points on open objects"
1250 Ways of Composing Positions
1252 Once you have two positions to work with, there are several ways to
1253 combine them to specify new positions.
1255 Vector Sums and Displacements
1257 Positions may be added or subtracted to yield a new position (to be
1258 more precise, you can only add a position and an expression pair; the
1259 latter must be on the right side of the addition or subtraction sign).
1260 The result is the conventional vector sum or difference of coordinates.
1261 For example, \fBlast box \&.ne + (0.1, 0)\fP is a valid position.
1262 This example illustrates a common use, to define a position slightly
1263 offset from a named one (say, for captioning purposes).
1265 Interpolation Between Positions
1267 A position may be interpolated between any two positions.
1268 The syntax is `\fIfraction\fP \fBof the way between\fP \fIposition1\fP
1269 \fBand\fP \fIposition2\fP'.
1270 For example, you can say \fB1/3 of the way between Here and last ellipse
1272 The fraction may be in numerator/denominator form or may be an ordinary
1273 number (values are \fInot\fP restricted to [0,1]).
1274 As an alternative to this verbose syntax, you can say `\fIfraction\fP
1275 \fB<\,\fP\fIposition1\fP \fB,\fP \fIposition2\/\fP\fB>\fP'; thus, the
1276 example could also be written as \fB1/3 <Here, last ellipse>\fP.
1280 P: 1/3 of the way between last arrow .start and last arrow .end;
1281 dot(P); move right 0.1; "P";
1283 .CE "3: \fBP: 1/3 of the way between last arrow .start and last arrow .end\fP"
1285 This facility can be used, for example, to draw double connections.
1290 arrow right at 1/4 <A.e,A.ne>;
1291 arrow left at 1/4 <B.w,B.sw>;
1293 .CE "4: Doubled arrows"
1295 You can get Figure \n[H1]-4 from the following program:
1302 arrow right at 1/4 <A.e,A.ne>;
1303 arrow left at 1/4 <B.w,B.sw>;
1309 Note the use of the short form for interpolating points.
1311 Projections of Points
1313 Given two positions \fIp\fP and \fIq\fP, the position
1314 \fB(\,\fP\fIp\fP\fB,\fP \fIq\fP\fB)\fP has the X\~coordinate of \fIp\fP
1315 and the Y coordinate of \fIq\fP.
1316 This can be helpful in placing an object at one of the corners of the
1317 virtual box defined by two other objects.
1320 box invis wid 2 height 1;
1321 dot(last box .ne); "\fB(B,A)\fP is here" ljust at last circle + (0.1, 0.1);
1322 dot(last box .se); "B" ljust at last circle + (0.1, -0.1)
1323 dot(last box .sw); "\fB(A,B)\fP is here" rjust at last circle + (-0.1, -0.1);
1324 dot(last box .nw); "A" ljust at last circle + (-0.1, 0.1)
1326 .CE "5: Using (\fIx\fP, \fIy\fP) composition"
1331 There are four ways to use locations; \fBat\fP, \fBfrom\fP, \fBto\fP,
1333 All four are object modifiers; that is, you use them as suffixes to a
1336 The \fBat\fP modifier says to draw a closed object or arc with its
1337 center at the following location, or to draw a line/spline/arrow
1338 starting at the following location.
1340 The \fBto\fP modifier can be used alone to specify a move destination.
1341 The \fBfrom\fP modifier can be used alone in the same way as \fBat\fP.
1343 The \fBfrom\fP and \fBto\fP modifiers can be used with a \fBline\fR or
1344 \fBarc\fR command to specify start and end points of the object.
1345 In conjunction with named locations, this offers a very flexible
1346 mechanism for connecting objects.
1347 For example, the following program
1355 arc cw from 1/3 of the way \e
1356 between last box .n and last box .ne to last ellipse .n;
1368 arc cw from 1/3 of the way \
1369 between last box .n and last box .ne to last ellipse .n;
1371 .CE "6: A tricky connection specified with English-like syntax"
1373 The \fBwith\fP modifier allows you to identify a named attachment
1374 point of an object (or a position within the object) with another point.
1375 This is very useful for connecting objects in a natural way.
1376 For an example, consider these two programs:
1382 box wid 0.75 ht 0.75;
1384 move 0.1 down 0.3 from last [] .s;
1385 "\fBbox wid 0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1387 move from last [].e 1.5
1391 box wid 0.75 ht 0.75 with .sw at last box .se;
1393 move 0.1 down 0.3 from last [] .s;
1394 box invisible "\fBbox wid 0.5 ht 0.5;\fP" \
1395 "\fBbox wid 0.75 ht 0.75 with .sw at last box .se;\fP"
1398 .CE "7: Using the \fBwith\fP modifier for attachments"
1403 When drawing lines between circles that don't intersect them at a
1404 compass point, it is useful to be able to shorten a line by the radius
1405 of the circle at either or both ends.
1406 Consider the following program:
1412 circle "y" at 1st circle - (0.4, 0.6)
1413 circle "z" at 1st circle + (0.4, -0.6)
1414 arrow from 1st circle to 2nd circle chop
1415 arrow from 2nd circle to 3rd circle chop
1416 arrow from 3rd circle to 1st circle chop
1422 It yields the following:
1426 circle "y" at 1st circle - (0.4, 0.6)
1427 circle "z" at 1st circle + (0.4, -0.6)
1428 arrow from 1st circle to 2nd circle chop
1429 arrow from 2nd circle to 3rd circle chop
1430 arrow from 3rd circle to 1st circle chop
1432 .CE "8: The \fBchop\fR modifier"
1434 Notice that the \fBchop\fR attribute moves arrowheads rather than
1436 By default, the \fBchop\fR modifier shortens both ends of the line by
1438 By suffixing it with a number you can change the amount of chopping.
1440 If you say \fBline \&.\|.\|.\& chop \fIr1\fP chop \fIr2\fP\fR with
1441 \fIr1\fP and \fIr2\fP both numbers, you can vary the amount of chopping
1443 You can use this in combination with trigonometric functions to write
1444 code that deals with more complex intersections.
1450 There are two different ways to group objects in \fBpic\fP; \fIbrace
1451 grouping\fP and \fIblock composites\fP.
1456 The simpler method is simply to group a set of objects within curly
1457 bracket or brace characters.
1458 On exit from this grouping, the current position and direction are
1459 restored to their value when the opening brace was encountered.
1464 A block composite object is created a series of commands enclosed by
1466 The composite can be treated for most purposes like a single closed
1467 object, with the size and shape of its bounding box.
1469 The program fragment
1475 line up 1 at last circle .n;
1476 line down 1 at last circle .s;
1477 line right 1 at last circle .e;
1478 line left 1 at last circle .w;
1479 box dashed with .nw at last circle .se + (0.2, -0.2);
1480 Caption: center of last box;
1486 yields the block in figure \n[H1]-1, which we show both with and
1487 without its attachment points.
1488 The block's location becomes the value of \fBA\fP.
1493 line up 1 at last circle .n;
1494 line down 1 at last circle .s;
1495 line right 1 at last circle .e;
1496 line left 1 at last circle .w;
1497 box dashed with .nw at last circle .se + (0.2, -0.2);
1498 Caption: center of last box;
1502 compass([junction()]);
1504 .CE "1: A sample composite object"
1506 To refer to one of the composite's attachment points, you can say
1507 (for example) \fBA \&.s\fP.
1508 For purposes of object naming, composites are a class.
1509 You could write \fBlast [] \&.s\fP as an equivalent reference, usable
1510 anywhere a location is needed.
1511 This construction is very important for putting together large,
1512 multi-part diagrams.
1514 Blocks are also a variable-scoping mechanism, like a \fIgroff\/\fP(1)
1516 All variable assignments done inside a block are undone at the end of it.
1517 To get at values within a block, write a name of the block followed by a
1518 dot, followed by the label you want.
1519 For example, we could refer the center of the box in the above composite as
1520 \fBlast [] \&.Caption\fP or \fBA.Caption\fP.
1522 This kind of reference to a label can be used in any way any other
1524 For example, if we added \fB"Hi!" at A.Caption\fP
1525 the result would look like this:
1531 .CE "2: Adding a caption using interior labeling"
1533 You can also use interior labels in either part of a \fBwith\fR
1535 This means that the example composite could be placed relative to its
1536 caption box by a command containing \fBwith A.Caption at\fP.
1538 Note that both width and height of the block composite object are always
1545 box wid 0.75 ht 0.75
1547 move 0.1 down 0.3 from last [].s
1548 "\fBbox wid -0.5 ht 0.5; box wid 0.75 ht 0.75\fP"
1550 move from last [].e 2
1553 [ box wid -0.5 ht 0.5 ]
1554 box wid 0.75 ht 0.75
1556 move 0.1 down 0.3 from last [].s
1557 "\fB[box wid -0.5 ht 0.5]; box wid 0.75 ht 0.75\fP"
1560 .CE "3: Composite block objects always have positive width and height"
1562 Blocks may be nested.
1563 This means you can use block attachment points to build up complex
1564 diagrams hierarchically, from the inside out.
1565 Note that \fBlast\fP and the other sequential naming mechanisms
1566 don't look inside blocks, so if you have a program that looks
1572 P: [box "foo"; ellipse "bar"];
1574 [box "baz"; ellipse "quxx"]
1577 arrow from 2nd last [];
1583 the arrow in the last line is attached to object \fBP\fP, not
1586 In DWB \fBpic\fP, only references one level deep into enclosed blocks
1588 GNU \fBgpic\fP removes this restriction.
1590 The combination of block variable scoping, assignability of labels and
1591 the macro facility that we'll describe later on can be used to
1592 simulate functions with local variables (just wrap the macro body in
1599 There are a number of global style variables in \fBpic\fR that can be used to
1600 change its overall behavior.
1601 We've mentioned several of them in previous sections.
1602 They're all described here.
1603 For each variable, the default is given.
1605 center, tab(@), linesize(2);
1609 Style Variable@Default@What It Does
1614 boxht@0.5@Default height of a box
1615 boxwid@0.75@Default width of a box
1616 lineht@0.5@Default length of vertical line
1617 linewid@0.75@Default length of horizontal line
1618 linethick@-1@Default line thickness
1619 arcrad @0.25@Default radius of an arc
1620 circlerad@0.25@Default radius of a circle
1621 ellipseht@0.5@Default height of an ellipse
1622 ellipsewid@0.75@Default width of an ellipse
1623 moveht@0.5@Default length of vertical move
1624 movewid@0.75@Default length of horizontal move
1625 textht@0@Default height of box enclosing a text object
1626 textwid@0@Default width of box enclosing a text object
1627 arrowht@0.1@Length of arrowhead along shaft
1628 arrowwid@0.05@Width of rear of arrowhead
1629 arrowhead@1@Enable/disable arrowhead filling
1630 dashwid@0.05@Interval for dashed lines
1631 maxpswid@8.5@Maximum width of picture
1632 maxpsht@11@Maximum height of picture
1633 scale@1@Unit scale factor
1634 fillval@0.5@Default fill value
1638 Any of these variables can be set with a simple assignment statement.
1642 [boxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;]
1644 .CE "1: \fBboxht=1; boxwid=0.3; movewid=0.2; box; move; box; move; box; move; box;\fP"
1646 In GNU \fBpic\fR, setting the \fBscale\fR variable re-scales all
1647 size-related state variables so that their values remain equivalent in
1650 The command \fBreset\fP resets all style variables to their defaults.
1651 You can give it a list of variable names as arguments (optionally
1652 separated by commas), in which case it resets only those.
1654 State variables retain their values across pictures until reset.
1658 Expressions, Variables, and Assignment
1660 A number is a valid expression, of course (all numbers are stored
1661 internally as floating-point).
1662 Decimal-point notation is acceptable;
1663 in GNU \fBgpic\fR, scientific notation in C's `e' format (like
1664 \f(CW5e-2\fP) is accepted.
1666 Anywhere a number is expected, the language also accepts a
1668 Variables may be the built-in style variable described in the last
1669 section, or new variables created by assignment.
1671 DWB \fBpic\fP supports only the ordinary assignment via \fB=\fP, which
1672 defines the variable (on the left side of the equal sign) in the current
1673 block if it is not already defined there, and then changes the value (on
1674 the right side) in the current block.
1675 The variable is not visible outside of the block.
1676 This is similar to the C\~programming language where a variable within a
1677 block shadows a variable with the same name outside of the block.
1679 GNU \fBgpic\fP supports an alternate form of assignment using \fB:=\fP.
1680 The variable must already be defined, and the value is assigned to
1681 that variable without creating a variable local to the current block.
1698 You can use the height, width, radius, and x and y coordinates of any
1699 object or corner in expressions.
1700 If \fBA\fP is an object label or name, all the following are valid:
1704 A.x # x coordinate of the center of A
1705 A.ne.y # y coordinate of the northeast corner of A
1706 A.wid # the width of A
1707 A.ht # and its height
1708 2nd last circle.rad # the radius of the 2nd last circle
1713 Note the second expression, showing how to extract a corner coordinate.
1715 Basic arithmetic resembling those of C operators are available; \fB+\fP,
1716 \fB*\fP, \fB-\fP, \fB/\fP, and \fB%\fP.
1717 So is \fB^\fP for exponentiation.
1718 Grouping is permitted in the usual way using parentheses.
1719 GNU \fBgpic\fP allows logical operators to appear in expressions;
1720 \fB!\&\fP (logical negation, not factorial), \fB&&\fP, \fB|\||\fP,
1721 \fB==\fP, \fB!=\fP, \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
1723 Various built-in functions are supported: \fBsin(\fIx\fB)\fR,
1724 \fBcos(\fIx\fB)\fR, \fBlog(\fIx\fB)\fR, \fBexp(\fIx\fB)\fR,
1725 \fBsqrt(\fIx\fB)\fR, \fBmax(\fIx\fB,\fIy\fB)\fR,
1726 \fBatan2(\fIx\fB,\fIy\fB)\fR, \fBmin(\fIx\fB,\fIy\fB)\fR,
1727 \fBint(\fIx\fB)\fR, \fBrand()\fP, and \fBsrand()\fP.
1728 Both \fBexp\fP and \fBlog\fP are
1729 base\~10; \fBint\fP does integer truncation; \fBrand()\fP returns a
1730 random number in [0-1), and \fBsrand()\fP sets the seed for
1731 a new sequence of pseudo-random numbers to be returned by \fBrand()\fP
1732 (\fBsrand()\fP is a GNU extension).
1734 GNU \fBgpic\fP also documents a one-argument form or rand,
1735 \fBrand(\fIx\fB)\fR, which returns a random number between 1 and
1736 \fIx\fP, but this is deprecated and may be removed in a future
1739 The function \fBsprintf()\fP behaves like a C \fIsprintf\/\fP(3)
1740 function that only takes %%, %e, %E, %f, %g, and %G conversion
1747 You can define macros in \fBpic\fP, with up to 32 arguments (up to 16
1748 on EBCDIC platforms).
1749 This is useful for diagrams with repetitive parts.
1750 In conjunction with the scope rules for block composites, it effectively
1751 gives you the ability to write functions.
1756 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement text \fB}\fP
1760 This defines \fIname\fR as a macro to be replaced by the replacement
1761 text (not including the braces).
1762 The macro may be called as
1765 \fIname\fB(\fIarg1, arg2, \|.\|.\|.\& argn\fB)\fR
1769 The arguments (if any) are substituted for tokens \fB$1\fP, \fB$2\fP
1770 \&.\|.\|.\& \fB$n\fP
1771 appearing in the replacement text.
1773 As an example of macro use, consider this:
1780 # Plot a single jumper in a box, $1 is the on-off state.
1783 Outer: box invis wid 0.45 ht 1;
1785 # Count on end ] to reset these
1786 boxwid = Outer.wid * shrinkfactor / 2;
1787 boxht = Outer.ht * shrinkfactor / 2;
1789 box fill (!$1) with .s at center of Outer;
1790 box fill ($1) with .n at center of Outer;
1793 # Plot a block of six jumpers.
1794 define jumperblock {
1802 jwidth = last [].Outer.wid;
1803 jheight = last [].Outer.ht;
1805 box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1807 # Use {} to avoid changing position from last box draw.
1808 # This is necessary so move in any direction works as expected
1809 {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0,-0.2);}
1812 # Sample macro invocations.
1813 jumperblock(1,1,0,0,1,0);
1815 jumperblock(1,0,1,0,1,1);
1823 It yields the following:
1826 # Plot a single jumper in a box, $1 is the on-off state.
1829 Outer: box invis wid 0.45 ht 1;
1831 # Count on end ] to reset these
1832 boxwid = Outer.wid * shrinkfactor / 2;
1833 boxht = Outer.ht * shrinkfactor / 2;
1835 box fill (!$1) with .s at center of Outer;
1836 box fill ($1) with .n at center of Outer;
1839 # Plot a block of six jumpers
1840 define jumperblock {
1848 jwidth = last [].Outer.wid;
1849 jheight = last [].Outer.ht;
1851 box with .nw at 6th last [].nw wid 6*jwidth ht jheight;
1853 # Use {} to avoid changing position from last box draw.
1854 # This is necessary so move in any direction works as expected
1855 {"Jumpers in state $1$2$3$4$5$6" at last box .s + (0,-0.2);}
1858 # Sample macro invocations
1859 jumperblock(1,1,0,0,1,0);
1861 jumperblock(1,0,1,0,1,1);
1863 .CE "1: Sample use of a macro"
1865 This macro example illustrates how you can combine [], brace grouping,
1866 and variable assignment to write true functions.
1868 One detail the example above does not illustrate is the fact that
1869 macro argument parsing is not token-oriented.
1870 If you call \fBjumper(\~1\~)\fP, the value of $1 is \fB"\~1\~"\fP.
1871 You could even call \fBjumper(big\~string)\fP to give $1 the value
1872 \fB"big\~string"\fP.
1874 If you want to pass in a coordinate pair, you can avoid getting
1875 tripped up by the comma by wrapping the pair in parentheses.
1877 Macros persist through pictures.
1878 To undefine a macro, say \fBundef\fP \fIname\fR; for example,
1880 \f(CWundef jumper\fP
1881 \f(CWundef jumperblock\fP
1884 would undefine the two macros in the jumper block example.
1888 Import/Export Commands
1890 Commands that import or export data between \fBpic\fR and its
1891 environment are described here.
1894 File and Table Insertion
1898 \f(CWcopy\fP \fIfilename\fR
1901 inserts the contents of \fIfilename\fR in the \fBpic\fP input stream.
1902 Any \fB.PS\fP/\fB.PE\fP pair in the file is ignored.
1903 You can use this to include pre-generated images.
1905 A variant of this statement replicates the \fBcopy thru\fP feature of
1909 \f(CWcopy\fP \fIfilename\fR \f(CWthru\fP \fImacro\fP
1912 calls \fImacro\fP (which may be either a name or replacement text)
1913 on the arguments obtained by breaking each line of the file into
1914 blank-separated fields.
1915 The macro may have up to 9\~arguments.
1916 The replacement text may be delimited by braces or by a pair of
1917 instances of any character not appearing in the rest of the text.
1921 \f(CWcopy\fP \f(CWthru\fP \fImacro\fP
1924 omitting the filename, lines to be parsed are taken from the input
1925 source up to the next \fB.PE\fP.
1927 In either of the last two \fBcopy\fP commands, GNU \fBgpic\fP permits a
1928 trailing `\fBuntil\fP \fIword\/\fP' clause to be added which terminates
1929 the copy when the first word matches the argument (the default
1930 behavior is therefore equivalent to \fBuntil \&.PE\fP).
1932 Accordingly, the command
1939 copy thru % circle at ($1,$2) % until "END"
1971 The command \fBprint\fR accepts any number of arguments, concatenates
1972 their output forms, and writes the result to standard error.
1973 Each argument must be an expression, a position, or a text string.
1976 Escape to Post-Processor
1980 \fBcommand\fR \fIarg\fR\|.\|.\|.
1983 \fBpic\fP concatenates the arguments and pass them through as a line
1987 must be an expression, a position, or text.
1988 This has a similar effect to a line beginning with
1992 but allows the values of variables to be passed through.
2001 command ".ds string x is " x "."
2016 Executing Shell Commands
2020 \f(CWsh\fP \f(CW{\fP \fIanything.\|.\|.\fP \f(CW}\fP
2023 macro-expands the text in braces, then executes it as a shell command.
2024 This could be used to generate images or data tables for later
2026 The delimiters shown as {} here may also be two copies of any one
2027 character not present in the shell command text.
2028 In either case, the body may contain balanced {} pairs.
2029 Strings in the body may contain balanced or unbalanced braces in any
2034 Control-flow constructs
2036 The \fBpic\fP language provides conditionals and looping.
2042 for i = 0 to 2 * pi by 0.1 do {
2044 "." at (i/2, sin(i)/2);
2045 ":" at (i/2, cos(i)/2);
2055 for i = 0 to 2 * pi by 0.1 do {
2057 "." at (i/2, sin(i)/2);
2058 ":" at (i/2, cos(i)/2);
2061 .CE "1: Plotting with a \fBfor\fP loop"
2063 The syntax of the \fBfor\fP statement is:
2065 \fBfor\fR \fIvariable\fR \fB=\fR \fIexpr1\/\fR \fBto\fR \fIexpr2\/\fR \
2066 [\fBby\fR [\fB*\fR]\fIexpr3\/\fR] \fBdo\fR \fIX\fR \fIbody\fR \fIX\fR
2068 The semantics are as follows: Set
2073 is less than or equal to
2083 is not given, increment
2092 is multiplied instead by
2096 can be negative for the additive case;
2098 is then tested whether it is greater than or equal to
2100 For the multiplicative case,
2102 must be greater than zero.
2103 If the constraints aren't met, the loop isn't executed.
2105 can be any character not occurring in
2106 \fIbody\fR; or the two \fIX\/\fPs may be paired braces (as in the
2109 The syntax of the \fBif\fP statement is as follows:
2111 \fBif\fR \fIexpr\fR \fBthen\fR \fIX\fR \fIif-true\fR \fIX\fR \
2112 [\fBelse\fR \fIY\fR \fIif-false\fR \fIY\/\fR]
2114 Its semantics are as follows: Evaluate
2116 if it is non-zero then do
2121 can be any character not occurring in
2124 can be any character not occurring in
2127 Eithe or both of the
2131 pairs may instead be balanced pairs of
2132 braces ({ and\~}) as in the \fBsh\fR command.
2133 In either case, the \fIif-true\fR may contain balanced pairs of braces.
2134 None of these delimiters are seen inside strings.
2136 All the usual relational operators my be used in conditional expressions;
2137 \fB!\&\fP (logical negation, not factorial), \fB&&\fP, \fB|\||\fP, \fB==\fP,
2138 \fB!=\fP, \fB>=\fP, \fB<=\fP, \fB<\fP, \fB>\fP.
2140 String comparison is also supported using \fB==\fP and \fB!=\fP.
2141 String comparisons may need to be parenthesized to avoid syntactic
2146 Interface To [gt]roff
2148 The output of \fBpic\fP is \fB[gt]roff\fP drawing commands.
2149 The GNU \fIgpic\/\fP(1) command warns that it relies on drawing
2150 extensions present in \fIgroff\/\fP(1) that are not present in
2156 The DWB \fIpic\/\fP(1) program accepts one or two arguments to
2157 \&\fB.PS\fP, which is interpreted as a width and height in inches to
2158 which the results of \fIpic\/\fP(1) should be scaled (width and height
2159 scale independently).
2160 If there is only one argument, it is interpreted as a width to scale the
2161 picture to, and height is scaled by the same proportion.
2163 GNU \fBgpic\fP is less general; it accepts a single width to scale
2164 to, or a zero width and a maximum height to scale to.
2165 With two non-zero arguments, it scales to the maximum height.
2168 How Scaling is Handled
2170 When \fBpic\fP processes a picture description on input, it passes
2171 \fB.PS\fP, \fB.PE\fP, and \fB.PF\fP through to the postprocessor.
2172 The \fB.PS\fP gets decorated with two numeric arguments which are the X
2173 and Y\~dimensions of the picture in inches.
2174 The post-processor can use these to reserve space for the picture and
2177 The GNU incarnation of the \fBms\fP macro package, for example, includes
2178 the following definitions:
2187 \&.ie \e\en[.$]<2 .@error bad arguments to PS (not preprocessed with pic?)
2189 \&. ds@need (u;\e\e$1)+1v
2190 \&. in +(u;\e\en[.l]-\e\en[.i]-\e\e$2/2>?0)
2195 \&.sp \e\en[DD]u+.5m
2203 Equivalent definitions of these and of \fB.PF\fP are supplied by GNU
2204 \fIpic\/\fP(1) if you use the \-mpic option; this should make it usable
2205 with macro pages other than \fIms\/\fR(1).
2207 If \fB.PF\fP is used instead of \fB.PE\fP, the \fBtroff\fP position is
2208 restored to what it was at the picture start (Kernighan notes that
2209 the\~F stands for \[lq]flyback\[rq]).
2213 \&\fB.PS <\,\fP\fIfile\fP
2216 causes the contents of \fIfile\fP to replace the \fB.PS\fP line.
2217 This feature is deprecated; use `\fBcopy\fP \fIfile\fR' instead.
2220 PIC and [gt]roff commands
2222 By default, input lines that begin with a period are passed to the
2223 postprocessor, embedded at the corresponding point in the output.
2224 Messing with horizontal or vertical spacing is an obvious recipe for
2225 bugs, but point size and font changes are usually safe.
2227 Point sizes and font changes are also safe within text strings, as
2228 long as they are undone before the end of string.
2230 The enablement of output line filling by \fB[gt]roff\fP is preserved
2236 The Kernighan paper notes that there is a subtle problem with
2237 complicated equations inside \fBpic\fR pictures; they come out wrong if
2238 \fIeqn\/\fP(1) has to leave extra vertical space for the equation.
2239 If your equation involves more than subscripts and superscripts, you
2240 must add to the beginning of each equation the extra information
2242 He gives the following example:
2247 box "$space 0 {H( omega )} over {1 - H( omega )}$"
2258 box "@space 0 {H( omega )} over {1 - H( omega )}@"
2261 .CE "1: Equations within pictures"
2264 Absolute Positioning of Pictures
2266 A \fBpic\fP picture is positioned vertically by troff at the current
2268 The topmost position possible on a page is not the paper edge
2269 but a position which is one baseline lower so that the first row of glyphs
2271 To make a picture really start at the paper edge you have to make the
2272 baseline-to-baseline distance zero, this is, you must set the vertical
2273 spacing to\~0 (using \fB.vs\fP) before starting the picture.
2280 \*[tx] mode is enabled by the
2283 In \*[tx] mode, pic defines a vbox called
2285 for each picture; the name can be changed with the pseudo-variable
2287 (which is actually a specially parsed command).
2288 You must yourself print that vbox using, for example, the command
2292 \ecenterline{\ebox\egraph}
2295 Actually, since the vbox has a height of zero (it is defined with \evtop)
2296 this produces slightly more vertical space above the picture than
2301 \ecenterline{\eraise 1em\ebox\egraph}
2306 To make the vbox having a positive height and a depth of zero (as used
2307 e.g.\& by \*(lx's \f(CW\%graphics.sty\fP), define the following macro in
2313 \evbox{\eunvbox\ecsname #1\eendcsname\ekern 0pt}}
2318 Now you can simply say
2320 instead of \ebox\egraph.
2322 You must use a \*[tx] driver that supports the
2324 specials, version\~2.
2326 Lines beginning with
2328 are passed through transparently; a
2330 is added to the end of the line to avoid unwanted spaces.
2331 You can safely use this feature to change fonts or to
2332 change the value of \fB\ebaselineskip\fP.
2333 Anything else may well produce undesirable results; use at your own risk.
2334 Lines beginning with a period are not given any special treatment.
2336 The \*[tx] mode of \fIpic\/\fP(1) does \fInot\fP translate \fBtroff\fP
2337 font and size changes included in text strings!
2339 Here an example how to use \fBfigname\fP.
2353 \ecenterline{\ebox\efoo \ehss \ebox\ebar}
2358 Use this feature sparsingly and only if really needed:
2359 A different name means a new box register in \*[tx], and the maximum number
2360 of box registers is only 256.
2361 Also be careful not to use a predefined \*[tx] or \*[lx] macro name as
2362 an argument to \fBfigname\fP since this inevitably causes an error.
2368 GNU \fIgpic\/\fP(1) has a command
2370 \fBplot\fR \fIexpr\fR [\fB"\fItext\fB"\fR]
2372 This is a text object which is constructed by using
2374 as a format string for sprintf
2379 is omitted a format string of \fB"%g"\fP is used.
2380 Attributes can be specified in the same way as for a normal text
2382 Be very careful that you specify an appropriate format string;
2383 \fBpic\fP does only very limited checking of the string.
2384 This is deprecated in favour of
2389 Some Larger Examples
2391 Here are a few larger examples, with complete source code.
2392 One of our earlier examples is generated in an instructive way using a
2400 # Draw a demonstration up left arrow with grid box overlay
2406 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2407 for i = 2 to ($1 / 0.5) do
2409 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2411 move down from last arrow .center;
2413 sprintf("\efBarrow up left %g\efP", $1)
2416 move right 0.1 from last [] .e;
2431 # Draw a demonstration up left arrow with grid box overlay
2437 box wid 0.5 ht 0.5 dotted with .nw at last arrow .end;
2438 for i = 2 to ($1 / 0.5) do {
2439 box wid 0.5 ht 0.5 dotted with .sw at last box .se;
2441 move down from last arrow .center;
2443 sprintf("\fBarrow up left %g\fP", $1)
2446 move right 0.1 from last [] .e;
2454 .CE "1: Diagonal arrows (dotted boxes show the implied 0.5-inch grid)"
2456 Here's an example concocted to demonstrate layout of a large,
2457 multiple-part pattern:
2464 define filter {box ht 0.25 rad 0.125}
2468 box "\efBms\efR" "sources";
2470 box "\efBHTML\efR" "sources";
2472 box "\efBlinuxdoc-sgml\efP" "sources" wid 1.5;
2474 box "\efBTexinfo\efP" "sources";
2476 line down from 1st box .s lineht;
2478 line down from 2nd box .s; filter "\efBhtml2ms\efP";
2480 line down from 3rd box .s; filter "\efBformat\efP";
2482 line down from 4th box .s; filter "\efBtexi2roff\efP";
2485 move down 1 from last [] .s;
2486 Anchor: box wid 1 ht 0.75 "\efBms\efR" "intermediate" "form";
2487 arrow from Top.A.end to Anchor.nw;
2488 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2489 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2490 arrow from Top.D.end to Anchor.ne
2494 line down left then down ->;
2495 filter "\efBpic\efP";
2497 filter "\efBeqn\efP";
2499 filter "\efBtbl\efP";
2501 filter "\efBgroff\efP";
2507 line down right then down ->;
2508 A: filter dotted "\efBpic2img\efP";
2510 B: filter dotted "\efBeqn2html\efP";
2512 C: filter dotted "\efBtbl2html\efP";
2514 filter "\efBms2html\efP";
2518 # Nonexistence caption
2519 box dashed wid 1 at B + (2,0) "These tools" "don't yet exist";
2520 line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2521 line chop 0 chop 0.1 dashed from last box .w to B.e ->;
2522 line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2532 define filter {box ht 0.25 rad 0.125}
2536 box "\fBms\fR" "sources";
2538 box "\fBHTML\fR" "sources";
2540 box "\fBlinuxdoc-sgml\fP" "sources" wid 1.5;
2542 box "\fBTexinfo\fP" "sources";
2544 line down from 1st box .s lineht;
2546 line down from 2nd box .s; filter "\fBhtml2ms\fP";
2548 line down from 3rd box .s; filter "\fBformat\fP";
2550 line down from 4th box .s; filter "\fBtexi2roff\fP";
2553 move down 1 from last [] .s;
2554 Anchor: box wid 1 ht 0.75 "\fBms\fR" "intermediate" "form";
2555 arrow from Top.A.end to Anchor.nw;
2556 arrow from Top.B.end to 1/3 of the way between Anchor.nw and Anchor.ne;
2557 arrow from Top.C.end to 2/3 of the way between Anchor.nw and Anchor.ne;
2558 arrow from Top.D.end to Anchor.ne
2562 line down left then down ->;
2569 filter "\fBgroff\fP";
2575 line down right then down ->;
2576 A: filter dotted "\fBpic2img\fP";
2578 B: filter dotted "\fBeqn2html\fP";
2580 C: filter dotted "\fBtbl2html\fP";
2582 filter "\fBms2html\fP";
2586 # Nonexistence caption
2587 box dashed wid 1 at B + (2,0) "These tools" "don't yet exist";
2588 line chop 0 chop 0.1 dashed from last box .nw to A.e ->;
2589 line chop 0 chop 0.1 dashed from last box .w to B.e ->;
2590 line chop 0 chop 0.1 dashed from last box .sw to C.e ->;
2593 .CE "2: Hypothetical production flow for dual-mode publishing"
2597 # a three-dimensional block
2599 # tblock(<width>, <height>, <text>)
2603 color "gold" outlined "black" \
2604 xslanted 0 yslanted 0 \
2607 color "yellow" outlined "black" \
2608 xslanted .1 yslanted 0 \
2609 with .sw at last box .nw;
2611 color "goldenrod" outlined "black" \
2612 xslanted 0 yslanted .1 \
2613 with .nw at 2nd last box .ne;
2616 tblock(1, .5, "Master" "1");
2618 tblock(.5, 1, "Slave");
2620 .CE "3: Three-dimensional Boxes"
2622 Here the source code for figure \n[H1]-3:
2627 # a three-dimensional block
2629 # tblock(<width>, <height>, <text>)
2633 color "gold" outlined "black" \e
2634 xslanted 0 yslanted 0 \e
2637 color "yellow" outlined "black" \e
2638 xslanted .1 yslanted 0 \e
2639 with .sw at last box .nw;
2641 color "goldenrod" outlined "black" \e
2642 xslanted 0 yslanted .1 \e
2643 with .nw at 2nd last box .ne;
2646 tblock(1, .5, "Master" "1");
2648 tblock(.5, 1, "Slave");
2659 This is an annotated grammar of \fBpic\fP.
2664 In general, \fBpic\fP is a free-format, token-oriented language that
2665 ignores whitespace outside strings.
2666 But certain lines and constructs are specially interpreted at the
2669 A comment begins with \fB#\fP and continues to \fB\en\fP (comments may
2670 also follow text in a line).
2671 A line beginning with a period or backslash may be interpreted as text
2672 to be passed through to the post-processor, depending on command-line
2674 An end-of-line backslash is interpreted as a request to continue the
2675 line; the backslash and following newline are ignored.
2678 Here are the grammar terminals:
2681 .IP \s[-1]NUMBER\s[0]
2682 A floating point numeric constant.
2683 May contain a decimal point or be expressed in scientific notation in
2684 the style of \fIprintf\/\fP(3)'s %e escape.
2685 A trailing `i' or `I' (indicating the unit `inch') is ignored.
2687 A string enclosed in double quotes.
2688 A double quote within \s[-1]TEXT\s[0] must be preceded by a backslash.
2689 Instead of \s[-1]TEXT\s[0] you can use
2692 sprintf ( TEXT [, <expr> ...] )
2696 except after the `until' and `last' keywords, and after all ordinal
2697 keywords (`th' and friends).
2698 .IP \s[-1]VARIABLE\s[0]
2699 A string starting with a character from the set [a-z], optionally
2700 followed by one or more characters of the set [a-zA-Z0-9_].
2701 (Values of variables are preserved across pictures.)
2702 .IP \s[-1]LABEL\s[0]
2703 A string starting with a character from the set [A-Z], optionally
2704 followed by one or more characters of the set [a-zA-Z0-9_].
2705 .IP \s[-1]COMMAND-LINE\s[0]
2706 A line starting with a command character (`.' in groff mode, `\e' in
2708 .IP \s[-1]BALANCED-TEXT\s[0]
2709 A string either enclosed by `{' and `}' or with \fIX\fP and \fIX\fP,
2710 where \fIX\fP doesn't occur in the string.
2711 .IP \s[-1]BALANCED-BODY\s[0]
2712 Delimiters as in \s[-1]BALANCED-TEXT\s[0]; the body is interpreted as
2713 `\fB\[la]command\[ra].\|.\|.\fP'.
2714 .IP \s[-1]FILENAME\s[0]
2716 This has the same semantics as \s[-1]TEXT\s[0].
2717 .IP \s[-1]MACRONAME\s[0]
2718 Either \s[-1]VARIABLE\s[0] or \s[-1]LABEL\s[0].
2724 Tokens not enclosed in \[la]\|\[ra] are literals, except:
2726 \fB\en\fP is a newline.
2728 Three dots is a suffix meaning `replace with 0 or more repetitions
2729 of the preceding element(s).
2731 An enclosure in square brackets has its usual meaning of `this clause is
2734 Square-bracket-enclosed portions within tokens are optional.
2735 Thus, `h\^[eigh]\^t' matches either `height' or `ht'.
2737 If one of these special tokens has to be referred to literally, it is
2738 surrounded with single quotes.
2740 The top-level \fBpic\fP object is a picture.
2744 .PS [NUMBER [NUMBER]]\en
2750 The arguments, if present, represent the width and height of the picture,
2751 causing \fBpic\fR to attempt to scale it to the given dimensions in
2753 In no case, however, the X and Y\~dimensions of the picture exceed the
2754 values of the style variables \fBmaxpswid\fP and \fBmaxpsheight\fP
2755 (which default to the normal 8.5\^i by 11\^i page size).
2757 If the ending `.PE' is replaced by `.PF', the page vertical position is
2758 restored to its value at the time `.PS' was encountered.
2759 Another alternate form of invocation is `.PS\~<\s[-1]FILENAME\s[0]',
2760 which replaces the `.PS' line with a file to be interpreted by \fBpic\fR
2761 (but this feature is deprecated).
2763 The `.PS', `.PE', and `.PF' macros to perform centering and scaling are
2764 normally supplied by the post-processor.
2766 In the following, either `|' or a new line starts an alternative.
2777 <primitive> [<attribute>]
2778 LABEL : [;] <command>
2779 LABEL : [;] <command> [<position>]
2781 VARIABLE [:] = <any-expr>
2783 up | down | left | right
2785 command <print-arg> ...
2786 print <print-arg> ...
2789 copy [FILENAME] thru MACRONAME [until TEXT]
2790 copy [FILENAME] thru BALANCED-BODY [until TEXT]
2791 for VARIABLE = <expr> to <expr> [by [*] <expr>] do BALANCED-BODY
2792 if <any-expr> then BALANCED-BODY [else BALANCED-BODY]
2793 reset [VARIABLE [[,] VARIABLE ...]]
2805 The current position and direction are saved on entry to a
2806 `{\~.\|.\|.\~}' construction and restored on exit from it.
2808 Note that in `if' constructions, newlines can only occur in
2809 \s[-1]BALANCED-BODY\s[0].
2821 You have to use the braces on the same line as the keywords:
2832 This restriction doesn't hold for the body after the `do' in a `for'
2835 At the beginning of each picture, `figname' is reset to the vbox name
2836 `graph'; this command has only a meaning in \*[tx] mode.
2837 While the grammar rules allow digits and the underscore in the value of
2838 `figname', \*[tx] normally accepts uppercase and lowercase letters only
2839 as box names (you have to use `\ecsname' if you really need to
2840 circumvent this limitation).
2846 <any-expr> <logical-op> <any-expr>
2864 Logical operators are handled specially by \fBpic\fP since they can
2865 deal with text strings also.
2866 \fBpic\fP uses \%\fIstrcmp\/\fP(3) to test for equality of strings; an
2867 empty string is considered as `false' for `&&' and `|\||'.
2871 box \fR# closed object \[em] rectangle\fP
2872 circle \fR# closed object \[em] circle\fP
2873 ellipse \fR# closed object \[em] ellipse\fP
2874 arc \fR# open object \[em] quarter-circle\fP
2875 line \fR# open object \[em] line\fP
2876 arrow \fR# open object \[em] line with arrowhead\fP
2877 spline \fR# open object \[em] spline curve\fP
2879 TEXT TEXT ... \fR# text within invisible box\fP
2880 plot <expr> TEXT \fR# formatted text\fP
2881 '[' <command> ... ']'
2885 Drawn objects within `[\~.\|.\|.\~]' are treated as a single composite
2886 object with a rectangular shape (that of the bounding box of all the
2888 Variable and label assignments within a block are local to the block.
2889 Current direction of motion is restored to the value at start of block
2891 Position is \fInot\fR restored (unlike `{\~}');
2892 instead, the current position becomes the exit position for the current
2893 direction on the block's bounding box.
2897 h[eigh]t <expr> \fR# set height of closed figure\fP
2898 wid[th] <expr> \fR# set width of closed figure\fP
2899 rad[ius] <expr> \fR# set radius of circle/arc\fP
2900 diam[eter] <expr> \fR# set diameter of circle/arc\fP
2901 up [<expr>] \fR# move up\fP
2902 down [<expr>] \fR# move down\fP
2903 left [<expr>] \fR# move left\fP
2904 right [<expr>] \fR# move right\fP
2905 from <position> \fR# set from position of open figure\fP
2906 to <position> \fR# set to position of open figure\fP
2907 at <position> \fR# set center of open figure\fP
2908 with <path> \fR# fix corner/named point at specified location\fP
2909 with <position> \fR# fix position of object at specified location\fP
2910 by <expr-pair> \fR# set object's attachment point\fP
2911 then \fR# sequential segment composition\fP
2912 dotted [<expr>] \fR# set dotted line style\fP
2913 dashed [<expr>] \fR# set dashed line style\fP
2914 thick[ness] <expr> \fR# set thickness of lines\fP
2915 chop [<expr>] \fR# chop end(s) of segment\fP
2916 '->' | '<-' | '<->' \fR# decorate with arrows\fP
2917 invis[ible] \fR# make primitive invisible\fP
2918 solid \fR# set solid line style\fP
2919 fill[ed] [<expr>] \fR# fill closed figure with optional density\fP
2920 xscaled <expr> \fR# slant box into x direction\fP
2921 yscaled <expr> \fR# slant box into y direction\fP
2922 colo[u]r[ed] TEXT \fR# set fill and outline color for figure\fP
2923 outline[d] TEXT \fR# set outline color for figure\fP
2924 shaded TEXT \fR# set fill color for figure\fP
2925 same \fR# copy size of previous object\fP
2926 cw | ccw \fR# set orientation of curves\fP
2927 ljust | rjust \fR# adjust text horizontally\fP
2928 above | below \fR# adjust text vertically\fP
2929 aligned \fR# align parallel to object\fP
2930 TEXT TEXT ... \fR# text within object\fP
2931 <expr> \fR# motion in the current direction\fR
2935 Missing attributes are supplied from defaults; inappropriate ones are
2937 For lines, splines, and arcs, height and width refer to arrowhead size.
2939 The `at' primitive sets the center of the current object.
2940 The `with' attribute fixes the specified feature of the given object to
2941 a specified location.
2942 (Note that `with' is incorrectly described in the Kernighan paper.)
2944 The `by' primitive is not documented in the tutorial portion of
2945 the Kernighan paper, and should probably be considered unreliable.
2947 The primitive `arrow' is a synonym for `line\~->'.
2949 Text is normally an attribute of some object, in which case successive
2950 strings are vertically stacked and centered on the object's center by
2952 Standalone text is treated as though placed in an invisible box.
2954 A text item consists of a string or sprintf-expression, optionally
2955 followed by positioning information.
2956 Text (or strings specified with `sprintf') may contain font changes,
2957 size changes, and local motions, provided those changes are undone
2958 before the end of the current item.
2959 Text may also contain \e-escapes denoting special characters.
2960 The base font and specific set of escapes supported is implementation
2961 dependent, but supported escapes always include the following:
2962 .IP "\efR, \ef1" \w'\efR,\~\ef3'u+2n
2963 Set Roman style (the default)
2969 Revert to previous style; only works one level deep, does not stack.
2971 Color names are dependent on the \gBpic\fR implementation, but in
2972 all modern versions color names recognized by the X\~window system are
2975 A position is an (x,y) coordinate pair.
2976 There are lots of different ways to specify positions:
2980 <position-not-place>
2987 <position-not-place> ::=
2989 <position> + <expr-pair>
2990 <position> - <expr-pair>
2991 ( <position> , <position> )
2992 <expr> [of the way] between <position> and <position>
2993 <expr> '<' <position> , <position> '>'
3008 <corner> [of] <label>
3023 .ne | .se | .nw | .sw
3024 .c[enter] | .start | .end
3025 .t[op] | .b[ot[tom]] | .l[eft] | .r[ight]
3026 left | right | <top-of> | <bottom-of>
3027 <north-of> | <south-of> | <east-of> | <west-of>
3028 <center-of> | <start-of> | <end-of>
3029 upper left | lower left | upper right | lower right
3034 <\,\f(CIxxx\/\fP-of> ::=
3035 \f(CIxxx\fP \fR# followed by `of'\fP
3041 <ordinal> <object-type>
3042 [<ordinal>] last <object-type>
3049 INT st | INT nd | INT rd
3068 As Kernighan notes, \[lq]since barbarisms like \fB1th\fP and \fB3th\fP are
3069 barbaric, synonyms like \fB1st\fP and \fB3rd\fP are accepted as well.\[rq]
3070 Objects of a given type are numbered from 1 upwards in order of
3071 declaration; the \fBlast\fP modifier counts backwards.
3073 The \[lq]'th\[rq] form (which allows you to select a previous object with
3074 an expression, as opposed to a numeric literal) is not documented in DWB's
3077 The \[la]\,\fIxxx\/\fP-of\|\[ra] rule is special: The lexical parser checks whether
3078 \fIxxx\fP is followed by the token `of' without eliminating it so that
3079 the grammar parser can still see `of'.
3080 Valid examples of specifying a place with corner and label are thus
3097 both cause a syntax error.
3098 (DWB \fBpic\fP also allows the weird form `A\~north\~of'.)
3100 Here the special rules for the `with' keyword using a path:
3105 ( <relative-path> , <relative-path> )
3112 . LABEL [. LABEL ...] [<corner>]
3116 The following style variables control output:
3118 center tab(@), linesize(2);
3122 Style Variable@Default@What It Does
3127 boxht@0.5@Default height of a box
3128 boxwid@0.75@Default width of a box
3129 lineht@0.5@Default length of vertical line
3130 linewid@0.75@Default length of horizontal line
3131 arcrad @0.25@Default radius of an arc
3132 circlerad@0.25@Default radius of a circle
3133 ellipseht@0.5@Default height of an ellipse
3134 ellipsewid@0.75@Default width of an ellipse
3135 moveht@0.5@Default length of vertical move
3136 movewid@0.75@Default length of horizontal move
3137 textht@0@Default height of box enclosing a text object
3138 textwid@0@Default width of box enclosing a text object
3139 arrowht@0.1@Length of arrowhead along shaft
3140 arrowwid@0.05@Width of rear of arrowhead
3141 arrowhead@1@Enable/disable arrowhead filling
3142 dashwid@0.05@Interval for dashed lines
3143 maxpswid@8.5@Maximum width of picture
3144 maxpsht@11@Maximum height of picture
3145 scale@1@Unit scale factor
3146 fillval@0.5@Default fill value
3150 Any of these can be set by assignment, or reset using the \fBreset\fP
3152 Style variables assigned within `[\~]' blocks are restored to their
3153 beginning-of-block value on exit; top-level assignments persist across
3155 Dimensions are divided by \fBscale\fR on output.
3157 All \fBpic\fP expressions are evaluated in floating point; units
3158 are always inches (a trailing `i' or `I' is ignored).
3159 Expressions have the following simple grammar, with semantics very
3160 similar to C\~expressions:
3166 <place> <place-attribute>
3171 <func1> ( <any-expr> )
3172 <func2> ( <any-expr> , <any-expr> )
3179 .x | .y | .h[eigh]t | .wid[th] | .rad
3185 + | - | * | / | % | ^ | '<' | '>' | '<=' | '>='
3191 sin | cos | log | exp | sqrt | int | rand | srand
3201 Both \fBexp\fP and \fBlog\fP are base 10; \fBint\fP does integer
3202 truncation; and \fBrand()\fP returns a random number in [0-1).
3204 There are \fBdefine\fP and \fBundef\fR statements which are not part
3205 of the grammar (they behave as pre-processor macros to the language).
3206 These may be used to define pseudo-functions.
3209 \fBdefine\fP \fIname\fP \fB{\fP \fIreplacement-text\fP \fB}\fP
3213 This defines \fIname\fR as a macro to be replaced by the replacement
3214 text (not including the braces).
3215 The macro may be called as
3218 \fIname\/\fB(\,\fIarg1, arg2, .\|.\|., argn\fB\/)\fR
3222 The arguments (if any) are substituted for tokens $1, $2 \&.\|.\|.\& $n
3223 appearing in the replacement text.
3224 To undefine a macro, say \fBundef\fP \fIname\fR, specifying the name to
3230 History and Acknowledgements
3232 Original \fBpic\fP was written to go with Joseph Ossanna's original
3233 \fItroff\/\fP(1) by Brian Kernighan, and later re-written by Kernighan
3234 with substantial enhancements (apparently as part of the evolution of
3235 \fItroff\/\fP(1) into \fIditroff\/\fP(1) to generate
3236 device-independent output).
3238 The language had been inspired by some earlier graphics languages
3239 including \fBideal\fP and \fBgrap\fP.
3240 Kernighan credits Chris van Wyk (the designer of \fBideal\fP) with many
3241 of the ideas that went into
3244 .\" the original definitions of EQ and EN cause insertion of vertical
3245 .\" space which is not appropriate here
3253 The \fBpic\fP language was originally described by Brian Kernighan in
3254 Bell Labs Computing Science Technical Report #116 (you can obtain a
3255 PostScript copy of the revised version, [1], by sending a mail message to
3256 \fInetlib@research.att.com\fP with a body of `send 116 from
3258 There have been two revisions, in 1984 and 1991.
3260 The document you are reading effectively subsumes Kernighan's
3261 description; it was written to fill in lacun\[ae] in the exposition and
3262 integrate in descriptions of the GNU \fIgpic\/\fP(1) and
3263 \fIpic2plot\/\fP(1) features.
3265 The GNU \fBgpic\fR implementation was written by James Clark
3266 \[la]\,\fIjjc@jclark.com\/\fP\[ra].
3268 The GNU \fBpic2plot\fR implementation is based on James Clark's parser
3269 code and maintained by Robert Maier, principal author of \fBplotutils\fP.
3276 \fBPIC \[em] A Graphics Language for Typesetting
3277 (Revised User Manual)\fP.
3278 Bell Labs Computing Science Technical Report #116, December 1991.
3281 \fBA high-level language for specifying pictures\fP.
3282 \fIACM Transactions On Graphics\fP 1,2 (1982) 163-182.
3284 .\" Local Variables:
3287 .\" vim: filetype=groff: