# LaTeX/Picture

The picture environment allows programming pictures directly in LaTeX. On the one hand, there are rather severe constraints, as the slopes of line segments as well as the radii of circles are restricted to a narrow choice of values. On the other hand, the picture environment of LaTeX2e brings with it the \qbezier command, "q" meaning *quadratic*. Many frequently-used curves such as circles, ellipses, and catenaries can be satisfactorily approximated by quadratic Bézier curves, although this may require some mathematical toil. If a programming language like Java is used to generate \qbezier blocks of LaTeX input files, the picture environment becomes quite powerful.

Although programming pictures directly in LaTeX is severely restricted, and often rather tiresome, there are still reasons for doing so. The documents thus produced are "small" with respect to bytes, and there are no additional graphics files to be dragged along.

Packages like pict2e, epic, eepic or pstricks enhance the original picture environment, and greatly strengthen the graphical power of LaTeX.

## Contents

## Basic commands[edit]

A picture environment is available in any LaTeX distribution, without the need of loading any external package. This environment is created with one of the two commands

\begin{picture}(x, y) |

or

\begin{picture}(x, y)(x0, y0) |

The first pair, , affects the reservation, within the document, of rectangular space for the picture.

The optional second pair, , assigns arbitrary coordinates to the bottom left corner of the reserved rectangle.

The numbers *x*, *y*, *x*0, *y*0 are numbers (lengths) in the units of \unitlength, which can be reset any time (but not within a picture environment) with a command such as

\setlength{\unitlength}{1.2cm} |

The default value of \unitlength is 1pt.

Most drawing commands have one of the two forms

\put(x, y){object} |

or

\multiput(x, y)(dx, dy){n}{object} |

Bézier curves are an exception. They are drawn with the command

\qbezier(x1, y1)(x2, y2)(x3, y3) |

With the package picture absolute dimension (like 15pt) and expression are allowed, in addition to numbers relative to \unitlength.

## Line segments[edit]

Line segments are drawn with the command:

\put(x, y){ \line(x1, y1){length} } |

The \line command has two arguments:

- a direction vector,
- a "length" (sort of: this argument is the vertical length in the case of a vertical line segment and in all other cases the horizontal distance of the line, rather than the length of the segment itself).

The components of the direction vector are restricted to the integers (*−6, −5, ... , 5, 6*) and they have to be coprime (no common divisor except 1). The figure below illustrates all 25 possible slope values in the first quadrant. The length is relative to \unitlength.

\setlength{\unitlength}{5cm} |

## Arrows[edit]

Arrows are drawn with the command

\put(x, y){\vector(x1, y1){length}} |

For arrows, the components of the direction vector are even more narrowly restricted than for line segments, namely to the integers (*−4, −3, ... , 3, 4*). Components also have to be coprime (no common divisor except 1). Notice the effect of the \thicklines command on the two arrows pointing to the upper left.

\setlength{\unitlength}{0.75mm} |

## Circles[edit]

The command

\put(x, y){\circle{diameter}} |

draws a circle with center (x, y) and diameter (not radius) specified by *diameter*. The picture environment only admits diameters up to approximately 14mm, and even below this limit, not all diameters are possible. The \circle* command produces disks (filled circles). As in the case of line segments, one may have to resort to additional packages, such as eepic, pstricks, or tikz.

\setlength{\unitlength}{1mm} |

There is another possibility within the picture environment. If one is not afraid of doing the necessary calculations (or leaving them to a program), arbitrary circles and ellipses can be patched together from quadratic Bézier curves. See *Graphics in LaTeX2e* for examples and Java source files.

## Text and formulae[edit]

As this example shows, text and formulae can be written in the environment with the \put command in the usual way:

\setlength{\unitlength}{0.8cm} |

*\multiput* and *\linethickness*[edit]

The command

\multiput(x, y)(dx, dy ){n}{object} |

has 4 arguments: the starting point, the translation vector from one object to the next, the number of objects, and the object to be drawn. The `\linethickness` command applies to horizontal and vertical line segments, but neither to oblique line segments, nor to circles. It does, however, apply to quadratic Bézier curves!

\setlength{\unitlength}{2mm} |

## Ovals[edit]

The command

\put(x, y){\oval(w, h)} |

or

\put(x, y){\oval(w, h)[position]} |

produces an oval centered at *(x, y)* and having width *w* and height *h*. The optional position arguments *b, t, l, r* refer to "top", "bottom", "left", "right", and can be combined, as the example illustrates. Line thickness can be controlled by two kinds of commands: \linethickness{''length''} on the one hand, \thinlines and \thicklines on the other. While \linethickness{''length''} applies only to horizontal and vertical lines (and quadratic Bézier curves), \thinlines and \thicklines apply to oblique line segments as well as to circles and ovals.

\setlength{\unitlength}{0.75cm} |

## Multiple use of predefined picture boxes[edit]

A picture box can be *declared* by the command

\newsavebox{name} |

then *defined* by

\savebox{name}(width,height)[position]{content} |

and finally arbitrarily often be *drawn* by

\put(x, y){\usebox{name}} |

The optional position parameter has the effect of defining the "anchor point" of the savebox. In the example it is set to "bl" which puts the anchor point into the bottom left corner of the savebox. The other position specifiers are top and right.

The *name* argument refers to a LaTeX storage bin and therefore is of a command nature (which accounts for the backslashes in the current example). Boxed pictures can be nested: In this example, \foldera is used within the definition of \folderb. The \oval command had to be used as the \line command does not work if the segment length is less than about 3 mm.

\setlength{\unitlength}{0.5mm} |

## Quadratic Bézier curves[edit]

The command

\qbezier(x1, y1)(x, y)(x2, y2) |

draws a quadratic bezier curve where , denote the end points, and denotes the intermediate control point. The respective tangent slopes, and , can be obtained from the equations

See *Graphics in LaTeX2e* for a Java program which generates the necessary \qbezier command line.

\setlength{\unitlength}{0.8cm} |

As this example illustrates, splitting up a circle into 4 quadratic Bézier curves is not satisfactory. At least 8 are needed. The figure again shows the effect of the \linethickness command on horizontal or vertical lines, and of the \thinlines and the \thicklines commands on oblique line segments. It also shows that both kinds of commands affect quadratic Bézier curves, each command overriding all previous ones.

## Catenary[edit]

\setlength{\unitlength}{1cm} |

In this figure, each symmetric half of the catenary is approximated by a quadratic Bézier curve. The right half of the curve ends in the point (2, 2.7622), the slope there having the value m = 3.6269. Using again equation (*), we can calculate the intermediate control points. They turn out to be (1.2384, 0) and (−1.2384, 0). The crosses indicate points of the real catenary. The error is barely noticeable, being less than one percent. This example points out the use of the optional argument of the \begin{picture} command. The picture is defined in convenient "mathematical" coordinates, whereas by the command

\begin{picture}(4.3,3.6)(-2.5,-0.25) |

its lower left corner (marked by the black disk) is assigned the coordinates (−2.5,−0.25).

## Plotting graphs[edit]

\setlength{\unitlength}{1cm} |

The control points of the two Bézier curves were calculated with formulas (*). The positive branch is determined by , and , . Again, the picture is defined in mathematically convenient coordinates, and the lower left corner is assigned the mathematical coordinates (−3,−2) (black disk).

## The *picture* environment and gnuplot[edit]

The powerful scientific plotting package gnuplot has the capability to output directly to a LaTeX picture environment. It is often far more convenient to plot directly to LaTeX, since this saves having to deal with potentially troublesome postscript files. Plotting scientific data (or, indeed, mathematical figures) this way gives much greater control, and of course typesetting ability, than is available from other means (such as postscript). Such pictures can then be added to a document by an \include{} command.

N.B. gnuplot is a powerful piece of software with a vast array of commands. A full discussion of gnuplot lies beyond the scope of this note. See [[1]] for a tutorial.