pic(1)

๐Ÿ’– pic(1) โ€” General Commands Manual ๐Ÿ’–

okay bestie, buckle up, this is pic from the groff family and honestly? it's giving iconic preprocessor energy. let's get into it ๐ŸŒธ


โœจ NAME โœจ

pic โ€” compile pictures for troff or TeX ๐ŸŽจ


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

pic [-CnSU] [file ...]

pic -t [-cCSUz] [file ...]

pic --help

pic -v

pic --version

๐ŸŒˆ DESCRIPTION ๐ŸŒˆ

The GNU implementation of pic is part of the groff(1) document formatting system. No cap. pic is a troff(1) preprocessor that translates descriptions of diagrammatic pictures embedded in roff(7) or TeX input into the language understood by TeX or troff. Basically it's the translator bestie between your vibes and your formatter. ๐Ÿ’…

It copies each file's contents to the standard output stream, translating each picture between lines starting with .PS and any of .PE, .PF, or .PY. End a pic picture with .PE to leave the drawing position at the bottom of the picture, and with .PF or .PY to leave it at the top. Choose wisely, that's the whole plot twist. ๐Ÿ‘‘

Normally, pic is not executed directly by the user, but invoked by specifying the -p option to groff(1). So like, it's the backstage crew, not the main character. If no file operands are present, or if file is -, pic reads the standard input stream.

It is the user's responsibility to provide appropriate definitions of the PS, PE, and one or both of the PF and PY macros. When a macro package does not supply these, obtain simple definitions with the groff option -mpic; these horizontally center each picture. ๐ŸŽ€

GNU pic supports PY as a synonym of PF to work around a name space collision with the mm macro package, which defines PF as a page footer management macro. Use PF preferentially unless a similar problem faces your document. ikyk. ๐Ÿซถ


๐Ÿ’… OPTIONS ๐Ÿ’…

--help displays a usage message, while -v and --version show version information; all exit afterward. bye bestie ๐Ÿ‘‹

  • -c โ€” Be more compatible with tpic; implies -t. Lines beginning with \ are not passed through transparently. Lines beginning with . are passed through with the initial . changed to \. GNU pic gives a line beginning with .ps special treatment: it takes an optional integer argument specifying the line thickness (pen size) in milliinches, a missing argument restores the previous line thickness, and the default line thickness is 8 milliinches. The line thickness thus specified takes effect only when a non-negative line thickness has not been specified by use of the thickness attribute or by setting the linethick variable. lowkey a lot, but okay. โœจ
  • -C โ€” Recognize .PS, .PE, .PF, and .PY even when followed by a character other than space or newline. loose vibes only fr fr.
  • -n โ€” Don't use groff extensions to the troff drawing commands. Specify this option if a postprocessor you're using doesn't support these extensions, described in groff_out(5). This option also causes pic not to use zero-length lines to draw dots in troff mode.
  • -S โ€” Enable safer mode and ignore any subsequent -U option. In safer mode, pic ignores sh commands, which can be useful when operating on untrustworthy input. pic operates in safer mode by default. protective queen behavior ๐Ÿ’–
  • -t โ€” Produce TeX output.
  • -U โ€” Operate in unsafe mode; sh commands are interpreted.
  • -z โ€” In TeX mode, draw dots using zero-length lines.
โš ๏ธ okay listen: -U is unsafe mode. sh commands get interpreted. Do NOT just vibe with untrusted input, bestie. -S is the safe default for a reason. ๐Ÿ™ˆ

The following options supported by other versions of pic are ignored. literally ignored. they simply do not get a reaction from us. ๐Ÿ’€

  • -D โ€” Draw all lines using the \D escape sequence. GNU pic always does this.
  • -T dev โ€” Generate output for the troff device dev. This option is unnecessary in GNU pic because the troff it generates is device-independent.

๐Ÿงš USAGE ๐Ÿงš

This section primarily discusses the differences between GNU pic and the Eighth Edition Unix version of AT&T pic (1985). Many of these differences also apply to later versions of AT&T pic.

๐ŸŒธ TeX mode ๐ŸŒธ

TeX-compatible output is produced when the -t option is specified. You must use a TeX driver that supports tpic version 2 specials. (tpic was a fork of AT&T pic by Tim Morgan of the University of California at Irvine that diverged from its source around 1984. It is best known today for lending its name to a group of \special commands it produced for TeX.) history class but make it cute ๐Ÿ“š

Lines beginning with \ are passed through unaltered except for a % suffix to avoid unwanted spaces. Use this feature to change fonts or the value of \baselineskip. Other applications may produce undesirable results; use at your own risk. ๐Ÿซฃ

By default, lines beginning with a dot are not treated speciallyโ€”but see the -c option.

In TeX mode, pic defines a vbox called \graph for each picture. Use GNU pic's figname command to change the name of the vbox. You must print that vbox yourself using the command

\centerline{\box\graph}

for instance. Since the vbox has a height of zeroโ€”it is defined with \vtopโ€”this produces slightly more vertical space above the picture than below it;

\centerline{\raise 1em\box\graph}

would avoid this. To give the vbox a positive height and a depth of zero (as used by LaTeX's graphics.sty, for example), define the following macro in your document.

\def\gpicbox#1{%
  \vbox{\unvbox\csname #1\endcsname\kern 0pt}}

You can then simply say \gpicbox{graph} instead of \box\graph. slay. ๐Ÿ’…

๐Ÿ‘‘ Commands ๐Ÿ‘‘

Several commands new to GNU pic accept delimiters, shown in their synopses as braces { }. Nesting of braces is supported. Any other characters (except a space, tab, or newline) may be used as alternative delimiters, in which case the members of a given pair must be identical. GNU pic recognizes double-quoted strings within delimiters of either kind; such strings may contain the delimiter character or unbalanced braces. giving flexible and forgiving โœจ

  • for variable = expr1 to expr2 [by [*]expr3] do X body X โ€” Set variable to expr1. While the value of variable is less than or equal to expr2, do body and increment variable by expr3; if by is not given, increment variable by 1. expr3 can be negative, in which case variable is then tested whether it is greater than or equal to expr2. A * prefix on variable multiplies it by expr3 (which must be greater than zero) at each iteration rather than incrementing it. If the range constraint on expr3 isn't met, the loop does not execute. X can be any character not in body. ๐Ÿ”
  • if expr then X if-true X [else Y if-false Y] โ€” Evaluate expr; if it is non-zero then do if-true, otherwise do if-false. X can be any character not in if-true. Y can be any character not in if-false.
  • print arg ... โ€” Catenate and write arguments to the standard error stream followed by a newline. Each arg must be an expression, a position, or text. This feature is useful for debugging. ur little printf detective ๐Ÿ”
  • command arg ... โ€” Catenate arguments and pass them as a line to troff or TeX. Each arg must be an expression, a position, or text. command allows the values of pic variables to be passed to the formatter. Thus,
.PS
x = 14
command ".ds string x is " x "."
.PE
\*[string]

produces

x is 14.

when formatted with troff. periodt. ๐Ÿ’–

  • sh X command X โ€” Pass command to a shell via system(3). Ignored if -U option not specified. (so yep, no -U means no shell, she's not listening ๐Ÿ™…โ€โ™€๏ธ)
  • copy "filename" โ€” Include filename at this point in the file.
  • copy ["filename"] thru X body X [until "word"]
  • copy ["filename"] thru macro [until "word"]

This construct does body once for each line of filename; the line is split into blank-delimited words, and occurrences of $i in body, for i between 1 and 9, are replaced by the i-th word of the line. If filename is not given, lines are taken from the current input up to .PE. If an until clause is specified, GNU pic reads lines only until encountering one beginning with word; which it then discards. X can be any character not in body. For example,

.PS
copy thru % circle at ($1,$2) % until "END"
1 2
3 4
5 6
END
box
.PE

and

.PS
circle at (1,2)
circle at (3,4)
circle at (5,6)
box
.PE

are equivalent. The commands to be performed for each line can also be taken from a macro defined earlier by giving the name of the macro as the argument to thru. The argument after thru is looked up as a macro name first; if not defined, its first character is interpreted as a delimiter. truly genius behavior โœจ

  • reset
  • reset pvar1[,] pvar2 ...

Reset predefined variables pvar1, pvar2 ... to their default values; if no arguments are given, reset all predefined variables to their default values. Variable names may be separated by commas, spaces, or both. Assigning a value to scale also causes all predefined variables that control dimensions to be reset to their default values times the new value of scale. factory reset but make it diagram-core ๐ŸŽ€

  • plot expr ["text"] โ€” Create a text object by using text as a format string for sprintf(3) with an argument of expr. If text is omitted, "%g" is implied. Attributes can be specified in the same way as for a normal text object.
โš ๏ธ Caution: be very careful that you specify an appropriate format string in text; pic's validation of it is limited. plot is deprecated in favour of sprintf. yes bestie, deprecated. it's giving vintage, not giving recommended. ๐Ÿ’€
  • var := expr โ€” Update an existing variable. var must already be defined, and expr is assigned to var without creating a variable local to the current block. (By contrast, = defines var in the current block if it is not already defined there, and then changes the value in the current block only.) For example,
.PS
x = 3
y = 3
[
x := 5
y = 5
]
print x   y
.PE

writes

5 3

to the standard error stream. the way := and = differ is the whole tea โ˜•

๐Ÿฆ‹ Expressions ๐Ÿฆ‹

The syntax for expressions has been significantly extended. glow up fr fr ๐ŸŒŸ

  • x ^ y (exponentiation)
  • sin(x)
  • cos(x)
  • atan2(y, x)
  • log(x) (base 10)
  • exp(x) (base 10, i.e. 10^x)
  • sqrt(x)
  • int(x)
  • rand() (return a random number between 0 and 1)
  • rand(x) (return a random number between 1 and x; deprecated)
  • srand(x) (set the random number seed)
  • max(e1, e2)
  • min(e1, e2)
  • !e
  • e1 && e2
  • e1 || e2
  • e1 == e2
  • e1 != e2
  • e1 >= e2
  • e1 > e2
  • e1 <= e2
  • e1 < e2
  • "str1" == "str2"
  • "str1" != "str2"

String comparison expressions must be parenthesised in some contexts to avoid ambiguity. so like, when in doubt, add the parentheses bestie ๐Ÿซถ

Other changes โœจ

Okay so this is where it gets juicy. Lemme walk you through all the extra little treats.

  • A bare expression, expr, is totally acceptable as an attribute โ€” it's the same thing as dir expr, where <italic>dir</italic> is whatever direction you're currently facing. So like, line 2i draws a line 2 inches long in the current direction. The i (or I) character gets straight up ignored; if you wanna use another measurement unit, just set the scale variable to something appropriate. ๐Ÿ’–

The maximum width and the maximum height of your picture come from the maxpswid and maxpsht variables. Initially? They're 8.5 and 11. Respectively. Periodt.

Scientific notation is allowed for numbers, so yes you can literally write x = 5e-2. Slay.

Text attributes can be compounded, bestie. For example, "foo" above ljust is valid. Iconic.

There is no limit to how deep you can nest blocks. Like, go feral. For example,

[A: [B: [C: box ]]] with .A.B.C.sw at 1,2
circle at last [].A.B.C

is acceptable. ๐Ÿ’…

Arcs have compass points determined by the circle of which the arc is a part.

Circles, ellipses, and arcs can be dotted or dashed. And in TeX mode? Splines can be dotted or dashed too. ๐ŸŒธ

Boxes can have rounded corners! The rad attribute specifies the radius of the quarter-circles at each corner. If no rad or diam attribute is given, a radius of boxrad is used. Initially, boxrad has a value of 0. And yes โ€” a box with rounded corners can be dotted or dashed.

Boxes can also have slanted sides, which generalizes them from rectangles to parallelograms. The xslanted and yslanted attributes specify the x and y offsets of the box's upper right corner from its default position.

The .PS line accepts a second argument specifying a maximum height for the picture. If a width of zero is specified, it is ignored when computing the scaling factor for the picture. GNU pic always scales a picture by the same amount vertically and horizontally. > This differs from DWB 2.0 pic, which may change the picture's aspect ratio if a height is specified. (so, heads up!)

Every text object has an associated invisible box that determines its compass points and implicit motion. The dimensions of that box are taken from its width and height attributes. If the width attribute isn't supplied, the value of textwid is assumed. If the height attribute isn't supplied, the height defaults to the number of text strings associated with the object times textht. Initially, textwid and textht have values of 0.

In (almost all) places where a quoted text string can be used, an expression of the form

sprintf("format", arg, ...)

can be used instead; it transforms its arguments per format, which should be a string as described in printf(3), and appropriate to the quantity of arguments supplied. GNU pic supports only the conversion specifiers e, E, f, g, G, and %, the modifiers #, -, +, and ` [space]), a minimum field width, and an optional precision. Don't ask for more, bestie, that's the whole menu. ๐Ÿ“

The thickness of the lines used to draw objects is controlled by the linethick variable, which is measured in points. A negative value indicates the default thickness. In TeX output mode when the -c option is not given, this means 8 milliinches. In troff and TeX -c output modes, the default thickness corresponds to the type size. (Thus, if the type size is 10 points, a line is 10 points thick.) A linethick value of zero draws the thinnest possible line supported by the output device. Initially, linethick has a value of -1. A thick[ness] attribute is also available. For example, circle thickness 1.5 draws a circle with a line thickness of 1.5 points. The thickness of lines is not affected by the value of the scale variable, nor by the width or height given in the .PS line.

Boxes (including boxes with rounded corners or slanted sides), circles, and ellipses can be filled by giving them an attribute of fill[ed], which takes an optional expression argument with a value between 0 and 1; 0 fills it with white, 1 with black, and values in between with a proportionally gray shade. A value greater than 1 is interpreted as the shade of gray that is being used for text and lines. Normally this is black, but output devices may provide a mechanism for changing this. Without an argument, the value of the variable fillval is used. Initially, fillval has a value of 0.5. The invisible attribute does not affect the filling of objects. Text associated with a filled object is added after the object is filled, so that the text is not obscured by the filling. ๐Ÿ™ˆ

Additional modifiers are available to draw colored objects: outline[d] sets the color of the outline, shaded the fill color, and colo[u]r[ed] sets both. All expect a subsequent string argument specifying the color.

circle shaded "green" outline "black"
Color is not yet supported in TeX mode.

Device macro files like ps.tmac declare color names; you can define additional ones with the defcolor request (see groff(7)). pic assumes at the beginning of each picture that the stroke and fill colors are set to the device defaults.

To change the name of the vbox in TeX mode, set the pseudo-variable figname (which is actually a specially parsed command) within a picture. For example,

.PS
figname = foobar;
circle "dig here";
.PE

makes the picture available in the box \foobar.

Arrow heads are drawn as solid triangles if the variable arrowhead is non-zero and either TeX mode is enabled or the -n option is not used. Initially, arrowhead has a value of 1. Solid arrow heads are always filled with the current outline (stroke) color.

The troff output of pic is device-independent. The -T option is therefore redundant. Except where noted, all measurements and dimensions use inches implicitly; they are never interpreted as troff basic units.

Objects can have an aligned attribute, but it is supported only by the grops(1) and gropdf(1) output drivers. Any text associated with an aligned object is rotated about the object's center such that it is oriented along a line connecting the start and end points of the object. aligned has no effect on objects whose start and end points are coincident.

In places where nth is allowed, `expr'th is also allowed. The `'th is a single token: no space is allowed between the apostrophe and the th. Consider the following example.

for i = 1 to 4 do {
   box
   move right 0.5
}
for i = 1 to 3 do {
   arrow from `i'th box.ne to `i+1'th box.sw
}

Arbitrary polygons can be drawn using the polygon keyword followed by a series of n-1 line segments, where n is the number of edges of the polygon. This allows GNU troff to interpret the line segments as a complete object such that the filled and shaded attributes may be used. The last user-specified line segment determines the polygon's final drawing position and direction. For example, draw and fill a triangle with the following.

polygon up 1 then right 1 down 0.5 fill 0.5

Two reference point suffixes permit the positioning of drawing elements relative to a polygon. .vertex expr locates the vertices, and .midpoint expr for locating the midpoints of edges. GNU pic numbers vertices and midpoints in drawing order starting from 1. You can abbreviate .vertex as .v or .ver, and .midpoint as .mid.

For example,

arrow down
polygon up 0.5 right 1 \
then down 0.5 right 1 \
then down 0.5 left 1 \
with .v2 at last line.end
arrow down from last polygon.v4

creates and correctly places a flowchart decision diamond. ๐Ÿ‘‘

.center (.c) is also available, but compass points do not work as expected and should not be used with polygons. (she's not like other girls, she doesn't play nice)


Converting pic to other image formats ๐Ÿฆ‹

Wanna make a stand-alone graphics file from a pic file? First, compose the picture. Bracket your pic code with .PS and .PE tokens. groff requests that don't produce formatted output may precede .PS, but format no text, not even any injected by a macro package, which may include a page number even on the first page, as mm does by default. Consider writing a "raw" roff document that uses no macro package. Ngl, that's the move.

Next, convert the roff/pic input into the desired format. groff distributes a simple utility, pic2graph(1), for this purpose. Other possibilities exist, particularly if you first transform your picture into PostScript format with groff -T ps. However, such a PostScript file lacks bounding box information; roff formatters produce page-sized output. Several tools with names beginning psto or ps2 exist that can infer the bounding box and perform a format conversion. One of these is the PostScript interpreter Ghostscript (gs(1)), which exposes format converters via its -sDEVICE= option. gs --help lists available devices.

Alternatively, produce a PDF with groff -T pdf; gropdf(1)'s -p option sets the MediaBox of the file.

The Encapsulated PostScript File (EPS) format is still sometimes seen. The aforementioned Ghostscript offers ps2epsi(1), and a standalone package and command ps2eps(1) is also available.

For raster image formats, use pstopnm(1); the resulting pnm(5) file can be then converted to virtually any image format using the netpbm tools. ๐ŸŒˆ

GNU plotutils offers a pic2plot(1) utility for converting pic input to a wide variety of other image formats, including SVG. So many options, we love versatility. ๐Ÿ’…


Exit status ๐Ÿ’–

pic exits with status 0 on successful operation, status 2 if the program cannot interpret its command-line arguments, and status 1 if it encounters an error during operation. Simple as that.


Files ๐Ÿ“

  • /usr/share/groff/1.24.1/tmac/pic.tmac โ€” offers simple definitions of the PS, PE, PF, and PY macros. Load it with the mso request when eschewing a full-service macro package, or using one that doesn't supply its own definitions for them.

Caveats ๐ŸŽ€

The spacing of dots and dashes in broken lines scales with other graphics, and is configurable. For example,

line from 0,0 to 100,0 dotted 5

spaces the dots in a dotted line 5 units apart. The spacing of dashes can be set the same way. The dashwid variable sets the length of dashes. Little config queen. โœจ


Bugs ๐Ÿ’€

Characters that are invalid as input to GNU troff (see the groff Texinfo manual or groff_char(7) for a list) are rejected even in TeX mode.

Research Tenth Edition Unix pic's fillval interprets 0 as black and 1 as white, incompatibly with GNU pic. ๐Ÿ˜ญ Chaos.

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

Omg okay so if you wanna go deeper on pic (and bestie, you should, it's giving scholarship), here's the reading list ๐Ÿ’–

  • /usr/share/doc/groff-base/pic.ps.gz โ€” โ€œMaking Pictures with GNU picโ€, by Eric S. Raymond. And listen: this file, plus its source, pic.ms, is literally part of the groff distribution, so it's right there on your system, no cap ๐ŸŒˆ
  • โ€œPICโ€”A Graphics Language for Typesetting: User Manualโ€, by Brian W. Kernighan, 1984 (revised 1991), AT&T Bell Laboratories Computing Science Technical Report No. 116. The original original, the blueprint, the mother of all pic docs ๐Ÿ‘‘
  • ps2eps is available from CTAN mirrors, e.g., ftp://ftp.dante.de/tex-archive/support/ps2eps/. Go get it bestie, it's free โœจ
  • W. Richard Stevens, Turning PIC into HTML ๐Ÿฆ‹
  • W. Richard Stevens, Examples of pic Macros ๐Ÿ“

And the whole friend group, the cross-referenced icons themselves:


groff 1.24.1 ยท 2026-04-22 ยท that's the whole pic(1) page bestie, we did it, we ATE ๐Ÿ’…โœจ no notes, go draw some diagrams, and remember: every picture starts with a .PS and ends with a .PE, iykyk ๐ŸŽ€๐Ÿ’œ

๐Ÿ“ฆ where this page comes from