# pic - man(1) - [phpMan]

> **TLDR:** Picture preprocessor for the groff (GNU Troff) document formatting system.
>
- Process input with pictures, saving the output for future typesetting with groff to PostScript:
  `pic {{path/to/input.pic}} > {{path/to/output.roff}}`
- Typeset input with pictures to PDF using the [me] macro package:
  `pic -T {{pdf}} {{path/to/input.pic}} | groff -{{me}} -T {{pdf}} > {{path/to/output.pdf}}`

*Source: tldr-pages*

---

[_pic_(1)](https://www.chedong.com/phpMan.php/man/pic/1/markdown)                                 General Commands Manual                                [_pic_(1)](https://www.chedong.com/phpMan.php/man/pic/1/markdown)

## 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)](https://www.chedong.com/phpMan.php/man/groff/1/markdown) document formatting system.  _pic_ is a
       [_troff_(1)](https://www.chedong.com/phpMan.php/man/troff/1/markdown) preprocessor that translates  descriptions  of  diagrammatic  pictures  embedded  in
       [_roff_(7)](https://www.chedong.com/phpMan.php/man/roff/7/markdown)  or TeX input files into the language understood by TeX or _troff_.  It copies the con‐
       tents of each _file_ to the standard output stream, except that lines between **.PS  **and  any  of
       **.PE**, **.PF**, or **.PY **are interpreted as picture descriptions in the _pic_ language.  End a _pic_ pic‐
       ture with **.PE **to leave the drawing position at the bottom of the picture, and with **.PF **or **.PY**
       to  leave  it at the top.  Normally, _pic_ is not executed directly by the user, but invoked by
       specifying the **-p **option to [_groff_(1)](https://www.chedong.com/phpMan.php/man/groff/1/markdown).  If no _file_ operands are given on the command line,  or
       if _file_ is “**-**”, the standard input stream is read.

       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 def‐
       initions with the _groff_ option **-mpic**; these will 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 un‐
       less a similar problem faces your document.

## Options
       **--help  **displays  a  usage message, while **-v **and **--version **show version information; all exit
       afterward.

### -c      -t
              through  transparently.   Lines beginning with **. **are passed through with the initial **.**
              changed to **\**.  A line beginning with **.ps **is given special treatment: it takes  an  op‐
              tional  integer  argument  specifying  the line thickness (pen size) in milliinches; a
              missing argument restores the previous line thickness; the default line  thickness  is
              8  milliinches.   The line thickness thus specified takes effect only when a non-nega‐
              tive line thickness has not been specified by use of the  **thickness  **attribute  or  by
              setting the **linethick **variable.

### -C     
              newline.

### -n     
              postprocessor  you're  using  doesn't   support   these   extensions,   described   in
              [_groff_out_(5)](https://www.chedong.com/phpMan.php/man/groffout/5/markdown).   This  option also causes _pic_ not to use zero-length lines to draw dots
              in _troff_ mode.

### -S     
              useful when operating on untrustworthy input.

### -t     

### -U     

### -z     

       The following options supported by other versions of _pic_ are ignored.

### -D     

### -T _
              put generated by GNU _pic_ is device-independent.

## Usage
       This  section  primarily discusses the differences between GNU _pic_ and the Eighth Edition Re‐
       search Unix version of AT&T _pic_ (1985).  Many of these differences also apply to  later  ver‐
       sions 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.)

       Lines  beginning with **\ **are passed through transparently; a **% **is added to the end of the line
       to avoid unwanted spaces.  You can safely use this feature to change fonts or  the  value  of
       **\baselineskip**.  Anything else may well 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_ will define 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 will  pro‐
       duce 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**.

### 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 identi‐
       cal.  Strings are recognized within delimiters of either kind; they may contain the delimiter
       character or unbalanced braces.

       **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.  If
              _expr3_ is prefixed by *** **then _variable_ will instead be multiplied by _expr3_.   The  value
              of  _expr3_ can be negative for the additive case; _variable_ is then tested whether it is
              greater than or equal to _expr2_.  For the multiplicative case, _expr3_  must  be  greater
              than  zero.   If  the  constraints  aren't met, the loop isn't executed.  _X_ can be any
              character not occurring 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 occurring in _if-true_.  _Y_ can be any character not occurring in _if-false_.

       **print _**arg_ ...
              Concatenate and write arguments to the standard error stream followed  by  a  newline.
              Each _arg_ must be an expression, a position, or text.  This is useful for debugging.

       **command _**arg_ ...
              Concatenate  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.  For example,
                     .PS
                     x = 14
                     command ".ds string x is " x "."
                     .PE
                     \*[string]
              produces
                     x is 14.
              when formatted with _troff_.

       **sh _**X_ _command_ _X_
              Pass _command_ to a shell.

       **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, lines will be read only until a
              line the first word of which is _word_; that line will then be discarded.  _X_ can be  any
              character not occurring 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.

### 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**.

       **plot _**expr_ [**"_**text_**"**]
              This is a text object which is constructed by  using  _text_  as  a  format  string  for
              sprintf with an argument of _expr_.  If _text_ is omitted a format string of **"%g" **is used.
              Attributes  can  be  specified  in  the same way as for a normal text object.  Be very
              careful that you specify an appropriate format string;  _pic_  does  only  very  limited
              checking of the string.  This is deprecated in favour of **sprintf**.

       _var_ **:= _**expr_
              This  syntax  resembles variable assignment with **= **except that _var_ must already be de‐
              fined, and _expr_ will be assigned to _var_ without creating a variable local to the  cur‐
              rent block.  (By contrast, **= **defines _var_ in the current block if it is not already de‐
              fined 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.

### Expressions
       The syntax for expressions has been significantly extended.

       _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.

### Other changes
       A  bare  expression, _expr_, is acceptable as an attribute; it is equivalent to _dir_ _expr_, where
       _dir_ is the current direction.  For example

              **line 2i**

       means draw a line 2 inches long in the current direction.  The ‘i’ (or ‘I’) character is  ig‐
       nored; to use another measurement unit, set the _scale_ variable to an appropriate value.

       The  maximum  width and height of the picture are taken from the variables **maxpswid **and **maxp‐**
       **sht**.  Initially, these have values 8.5 and 11.

       Scientific notation is allowed for numbers.  For example

              **x = 5e-2**

       Text attributes can be compounded.  For example,

              **"foo" above ljust**

       is valid.

       There is no limit to the depth to which blocks can be examined.  For example,

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

       is acceptable.

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

       Circles, ellipses, and arcs can be dotted or dashed.  In TeX mode splines can  be  dotted  or
       dashed also.

       Boxes  can  have rounded corners.  The **rad **attribute specifies the radius of the quarter-cir‐
       cles at each corner.  If no **rad **or **diam **attribute is given, a radius of **boxrad **is used.  Ini‐
       tially, **boxrad **has a value of 0.  A box with rounded corners can be dotted or dashed.

       Boxes can have slanted sides.  This effectively changes the shape of a box from  a  rectangle
       to an arbitrary parallelogram.  The **xslanted **and **yslanted **attributes specify the x and y off‐
       set of the box's upper right corner from its default position.

       The  **.PS **line can have a second argument specifying a maximum height for the picture.  If the
       width of zero is specified the width will be ignored in computing the scaling factor for  the
       picture.   GNU _pic_ will always scale a picture by the same amount vertically as well as hori‐
       zontally.  This is different from DWB 2.0 _pic_ which may scale a picture by a different amount
       vertically than horizontally if a height is specified.

       Each text object has an invisible box associated with it.  The compass points of a  text  ob‐
       ject  are determined by this box.  The implicit motion associated with the object is also de‐
       termined by this box.  The dimensions of this box are taken from the width and height attrib‐
       utes; if the width attribute is not supplied then the width will be taken to be  **textwid**;  if
       the  height  attribute is not supplied then the height will be taken to be the number of text
       strings associated with the object times **textht**.  Initially, **textwid **and **textht **have a  value
       of 0.

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

              **sprintf("_**format_**", _**arg_**, **...**)**

       can also be used; this will produce the arguments formatted according to _format_, which should
       be a string as described in [_printf_(3)](https://www.chedong.com/phpMan.php/man/printf/3/markdown) appropriate for the number of arguments supplied.  Only
       the  modifiers “**#**”, “**-**”, “**+**”, and “ ” [space]), a minimum field width, an optional precision,
       and the conversion specifiers **%e**, **%E**, **%f**, **%g**, **%G**, and **%% **are supported.

       The thickness of the lines used to draw objects is  controlled  by  the  **linethick  **variable.
       This  gives  the thickness of lines in points.  A negative value means use the default thick‐
       ness: in TeX output mode, this means use a thickness of 8 milliinches;  in  TeX  output  mode
       with the **-c **option, this means use the line thickness specified by **.ps **lines; in _troff_ output
       mode,  this means use a thickness proportional to the pointsize.  A zero value means draw the
       thinnest possible line supported by the output device.  Initially, it  has  a  value  of  -1.
       There is also a **thick**[**ness**] attribute.  For example,

              **circle thickness 1.5**

       would  draw  a circle using a line with a 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**].  This takes an optional argument  of  an  ex‐
       pression with a value between 0 and 1; 0 will fill it with white, 1 with black, values in be‐
       tween  with a proportionally gray shade.  A value greater than 1 can also be used: this means
       fill with the shade of gray that is currently being used for text and lines.   Normally  this
       will  be black, but output devices may provide a mechanism for changing this.  Without an ar‐
       gument, then the value of the variable **fillval **will be used.  Initially, this has a value  of
       0.5.   The  invisible  attribute does not affect the filling of objects.  Any text associated
       with a filled object will be added after the object has been filled, so that  the  text  will
       not be 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)](https://www.chedong.com/phpMan.php/man/groff/7/markdown)).

       To  change  the name of the vbox in TeX mode, set the pseudo-variable **figname **(which is actu‐
       ally a specially parsed command) within a picture.  Example:

              **.PS**
              **figname = foobar;**
              **...**
              **.PE**

       The picture is then available in the box **\foobar**.

       _pic_ assumes that at the beginning of a picture both glyph and fill color are set to  the  de‐
       fault value.

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

       The _troff_ output of _pic_ is device-independent.  The **-T **option is  therefore  redundant.   All
       numbers  are  taken  to  be  in  inches; numbers are never interpreted to be in _troff_ machine
       units.

       Objects can have an **aligned **attribute.  This will only work if the postprocessor is  [_grops_(1)](https://www.chedong.com/phpMan.php/man/grops/1/markdown)
       or  [_gropdf_(1)](https://www.chedong.com/phpMan.php/man/gropdf/1/markdown).   Any  text associated with an object having the **aligned **attribute will be ro‐
       tated about the center of the object so that it is aligned in the direction  from  the  start
       point  to  the  end point of the object.  This attribute will have no effect on objects whose
       start and end points are coincident.

       In places where _n_**th **is allowed, **'_**expr_**'th **is also allowed.  “**'th**“ is a single token: no  space
       is allowed between the apostrophe and the “**th**”.  For example,

              for i = 1 to 4 do {
                 line from 'i'th box.nw to 'i+1'th box.se
              }

## Conversion
       To  obtain  a stand-alone picture from a _pic_ file, enclose your _pic_ code with **.PS **and **.PE **re‐
       quests; _roff_ configuration commands may be added at the beginning of the file,  but  no  _roff_
       text.

       It is necessary to feed this file into _groff_ without adding any page information, so you must
       check which **.PS **and **.PE **requests are actually called.  For example, the _mm_ macro package adds
       a  page  number,  which  is very annoying.  At the moment, calling standard _groff_ without any
       macro package works.  Alternatively, you can define your own requests, e.g., to do nothing:

              .de PS
              ..
              .de PE
              ..

       _groff_ itself does not provide direct conversion into other graphics file formats.  But  there
       are  lots  of possibilities if you first transform your picture into PostScript® format using
       the _groff_ option **-Tps**.  Since this _ps_-file lacks BoundingBox information it is not very  use‐
       ful  by  itself,  but it may be fed into other conversion programs, usually named **ps2_**other_ or
       **psto_**other_ or the like.  Moreover, the PostScript interpreter Ghostscript ([_gs_(1)](https://www.chedong.com/phpMan.php/man/gs/1/markdown)) has built-in
       graphics conversion devices that are called with the option

              **gs -sDEVICE=_**<devname>_

       Call

              **gs --help**

       for a list of the available devices.

       An alternative may be to use the **-Tpdf **option to convert your picture directly into **PDF  **for‐
       mat.   The  MediaBox  of  the  file produced can be controlled by passing a **-P-p **papersize to
       _groff_.

       As the Encapsulated PostScript File Format **EPS **is getting more and more  important,  and  the
       conversion  wasn't regarded trivial in the past you might be interested to know that there is
       a conversion tool named _ps2eps_ which does the right job.  It is much  better  than  the  tool
       _ps2epsi_ packaged with _gs_.

       For  bitmapped  graphic  formats, you should use _pstopnm_; the resulting (intermediate) [_pnm_(5)](https://www.chedong.com/phpMan.php/man/pnm/5/markdown)
       file can be then converted to virtually any graphics format using the  tools  of  the  **netpbm**
       package.

## Files
       _/usr/share/groff/1.23.0/tmac/pic.tmac_
              offers simple definitions of the **PS**, **PE**, **PF**, and **PY **macros.

## Bugs
       Characters  that  are  invalid  as  input  to  GNU  _troff_  (see  the  _groff_ Texinfo manual or
       [_groff_char_(7)](https://www.chedong.com/phpMan.php/man/groffchar/7/markdown) for a list) are rejected even in TeX mode.

       The interpretation of **fillval **is incompatible with the _pic_ in Tenth  Edition  Research  Unix,
       which interprets 0 as black and 1 as white.

**See also**
       _/usr/share/doc/groff-base/pic.ps.gz_
              “Making  Pictures  with  GNU  pic”,  by Eric S. Raymond.  This file, together with its
              source, _pic.ms_, is part of the _groff_ distribution.

       “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

       _ps2eps_ is available from CTAN mirrors, e.g., [ftp://ftp.dante.de/tex-archive/support/ps2eps/](ftp://ftp.dante.de/tex-archive/support/ps2eps/)

       W. Richard Stevens, [_Turning_ _PIC_ _into_ _HTML_](<http://www.kohala.com/start/troff/pic2html.html>)

       W. Richard Stevens, [_Examples_ _of_ pic _Macros_](<http://www.kohala.com/start/troff/pic.examples.ps>)

       [_troff_(1)](https://www.chedong.com/phpMan.php/man/troff/1/markdown), [_groff_out_(5)](https://www.chedong.com/phpMan.php/man/groffout/5/markdown), [_tex_(1)](https://www.chedong.com/phpMan.php/man/tex/1/markdown), [_gs_(1)](https://www.chedong.com/phpMan.php/man/gs/1/markdown), [_ps2eps_(1)](https://www.chedong.com/phpMan.php/man/ps2eps/1/markdown), [_pstopnm_(1)](https://www.chedong.com/phpMan.php/man/pstopnm/1/markdown), [_ps2epsi_(1)](https://www.chedong.com/phpMan.php/man/ps2epsi/1/markdown), [_pnm_(5)](https://www.chedong.com/phpMan.php/man/pnm/5/markdown)

groff 1.23.0                                31 March 2024                                     [_pic_(1)](https://www.chedong.com/phpMan.php/man/pic/1/markdown)
