LaTeX/PSTricks

PSTricks is a set of extensions. The base package is pstricks, other packages may be loaded when required.

The xcolor extension gets loaded along PSTricks, so there is no need to load it manually.

PSTricks has one technical specification: it uses PostScript internally, hence the name. Thus you cannot use the pdftex or pdflatex compilers, you will need to use dvips to get your proper document. It is still possible to get PDF from PS files thanks to ps2pdf. There is also the possibility to use the PDFTricks extension, which makes it feasible to use pdflatex together with PSTricks commands.

However, if you have installed the package xetex-pstricks, you can use <tt>pstricks</tt> with <tt>xetex</tt> or <tt>xelatex</tt> without modification of source file.

The <tt>pspicture</tt> environment
PSTricks commands are usually placed in a  environment.

The first argument between parentheses specifies the coordinates of the upper-right corner of the picture. The bottom-left corner is at (0,0) and is placed at the reference point of the next character in the LaTeX document.

It is also possible to specify the coordinates (x0,y0) of the bottom-left corner: Thus the size of the picture is (x1–x0) × (y1–y0). The default unit for coordinates is centimeters (cm); this can be changed with, as in  .  Any TeX dimension is allowed.

Lines and polylines
A simple line gets printed with

To get a vector, add an arrow as parameter:

You can add as many points as you want to get a polyline:

To get rounded corners, add the following option: or

Rectangles
The starred version prints a filled rectangle. Use the following parameter to get rounded corners:

Polygons
Polygons are always closed. The syntax is the same as for :

As for rectangles, the starred version prints a filled polygon. And the  option will print rounded corners.

Circles, arc and ellipses
Starred version fills the shape.

For circles, you need to provide center coordinates and radius:

To restrict the drawing to an arc, append the starting and ending angles in trigonometric notation:

Finally, ellipses:

Curves
will print a symmetric parabola with vertical asymptote, vertex (x1,y1) and ending at (x0,y0).

Use  to print a Bézier curve with an arbitrary number of control points. Arcs have at most 4 control points. Use the  option to print the control points and the tangents.

Use  to print the interpolation of the given points. The  command omits the first and the last arcs.

Text
Use to print text. Provide an angle to rotate the text.

You can provide the anchor of the text which will be at the specified coordinate.

Available anchors:
 * B, Bl, Br: baseline center, left and right.
 * t, tl, tr: top center, left and right.
 * b, bl, br: bottom center, left and right.

There is also the  command with further options: The  parameter is the distance from the coordinate.

PSTricks features several frame style for text.
 * \psframebox{text}: rectangle.
 * \psdblframebox{text}: double rectangle.
 * \psshadowbox{text}: shaded rectangle.
 * \pscirclebox{text}: circle.
 * \psovalbox{text}: oval.
 * \psdiabox{text}: diamond.
 * \pstribox{text}: triangle.

Example:

Using the  extension, it is possible to draw a text path.

To print a text following a path without printing the path, you need to use.

Example:

Grids
Without any parameter, the  command will print a grid all over the pspicture, with a spacing of 0.2 (i.e. 2mm). You can specify parameters:


 * : prints a grid from (0,0) to (xmax,ymax).
 * : prints a grid from (xmin,ymin) to (xmax,ymax).
 * : prints a grid from (xmin,ymin) to (xmax,ymax), one of the node is at (x0,y0).
 * : the full line of the main graduations is replaced by a dotted line. The value is the number of dots per graduation.
 * : same as  but for sub-graduations.
 * : color of graduations and sub-graduations.
 * : width of the lines.
 * : number of subgraduations between two main graduations.
 * : size of the label numbers.
 * : self-explanatory.
 * : same as above, but valueneg specifies the size for negative coordinates, valuepos for positive coordinates.
 * : self-explanatory. value may be one of . This is useful for huge graduations (i.e.   is high).


 * Example

If you want to add axes, use the <tt>pstricks-add</tt> extension with the following commands: (xmin,ymin) and (xmax,ymax) being the extreme, (x0,y0) being the intersection.
 * Axis


 * Options
 * and  defines the spacing between graduations.
 * lets you use the comma as decimal separator.
 * As for lines,  adds arrows on axes.


 * Example

All shapes
These are to be added between square brackets.


 * : if value is without unit, then the default unit is used.
 * : color is as defined by the <tt>xcolor</tt>package.
 * : value is one of.
 * : highlights points.
 * specifies the size of the points.
 * where value is among:
 * *: disc
 * o: circle
 * +,x: cross
 * square, squarre*: starred version is filled.
 * diamond, diamond*
 * triangle, triangle*
 * etc.
 * etc.

For example

To apply parameters globally:

This command also lets you change the default unit for lengths.
 * and
 * and

value is a number with or without unit. This changes the scale of the drawings, but will not change the width of lines.

Open shapes
You can define the extreme of an open shape (line, polyline, arc, etc.) with an optional parameter. There is a decent list of available symbols.
 * : arrow.
 * < >: double arrow.
 * |: bar.
 * |*: centered bar.
 * oo: circle.
 * o: centered circle.
 * **: disk.
 * *: centered disk.
 * | |: arrow plus bar.
 * cc: rounded extreme.
 * c: centered rounded extreme.

Example:

Closed shapes
For closed shape you may define the fillstyle.


 * : pattern. Possible values:.

Example:

Object location
The  and   commands can be used to move any object.

or You can repeat the operation with : You can use the same options as for :
 * Example

With no text but with graphics only, you can use the  command:

The <tt>PDFTricks</tt> extension
The original <tt>PSTricks</tt> package does not work with <tt>pdflatex</tt>, but thankfully <tt>PDFTricks</tt> allows us to bypass this limitation.


 * Usage
 * Declare the <tt>PDFTricks</tt> packages in the preamble.
 * Place all <tt>PSTricks</tt> extensions in a  environment; place all <tt>PSTricks</tt> commands in a   environment.
 * Compile with <tt>pdflatex -shell-escape </tt>.

The <tt>-shell-escape</tt> parameter enables shell command calls. It is required for <tt>PDFTricks</tt> to run.


 * Example

Another way to use <tt>PSTricks</tt> with <tt>pdflatex</tt> is the <tt>pst-pdf</tt> package.

LaTeX/PSTricks