(click anywhere to close)

# [LaTeX] Math Graphics

category: Writing | course: LaTeX Math | difficulty:

In the basic course we saw that the command for including a picture file, which could be a picture of mathematics of course, was \includegraphics, which was slightly odd. LaTeX does have a simple picture environment, but because the language was meant to typeset pieces with heavy use of math, this environment is reserved for mathematical graphics.

Within the picture environment, there’s a small list of commands you can use to place different types of simply figures, which combined together can generate complex mathematical graphics. It isn’t very difficult, it might just be a lot to take in at once. We’ll start off simple.

## Starting the Picture Environment

It’s a regular environment, except for the fact that the arguments are supplied differently: with parentheses, instead of brackets. The syntax is:

\begin{picture}{width, height)(xOffset, yOffset) picture commands … \end{picture}

These arguments are not regular LaTeX numbers with units – they refer to the amount of units within the picture. To length that holds this information is \unitlength, which you can change the way you’re used to.

\setlength{\unitlength}{4pt}
\begin{picture}(20,20)(0,0)
%Picture with width and height of 80pt
%But there's nothing in it yes, let's change that!
\end{picture}


The xOffset and yOffset set the coordinates of the lower left corner of the picture. So, in the example, the point (0,0) is used for the lower left corner, which means any negative coordinates would not be visible inside the picture.

## Putting Graphics on the Page

To put graphics on the page, three very important commands are available.

\put(x, y){object}

Places object at position (x,y). You’ll learn about all the math objects soon.

\multiput(x, y)(deltaX, deltaY){n}{object}

Places n objects, starting at position (x,y), with deltaX and deltaY space between each object and the next.

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

Places a quadratic Bezier curve using the three data points you provide. Mostly used for drawing graphs. These curves are, sadly enough, beyond the scope of this tutorial.

\setlength{\unitlength}{4pt}
\begin{picture}(20,20)(0,0)
\put(0,0){\line(1,0){5}}
\multiput(4,3)(1,1){10}{\line(0,1){5}}
\end{picture}


## Changing Thickness

By default, lines have medium thickness. You can change this at any time, by adding one these commands. Such a command has effect until a next one is encountered.

 Command Description \thicklines Slightly thicker lines \thinlines Slightly thinner lines \linethickness{length} Sets a custom line thickness

## Math Objects

As promised, here’s a list of all the math objects that can be placed within the picture:

 Command Description \line(x, y){length} Creates a line with length length, with direction vector (x,y). A direction vector can only take integers. \vector(x, y){length} Also creates a line, but with an arrow at the end. \circle{diameter} Creates a circle \circle*{diameter} Creates a filled circle (a disk). \oval(width, height)[position] Creates an oval. The optional argument position can be top, right, bottom or left (t, r, b, l), and determines what part to show. \frame{…} Creates a rectangular frame around the object that’s inside, with no padding space. Text or math You can put any of the LaTeX you learned inside a picture – regular text and fancy math. This, however, only works for single lines.
\setlength{\unitlength}{4pt}
\begin{picture}(20,20)(0,0)
\put(0,0){The formula is $x^2 + y^2 = 4$}
\put(8,8){\circle{4}}
\put(16,16){\oval(6,6)[t]}
\put(12,12){\vector(1,0){10}}
\end{picture}


## Save Boxes

If you want to reuse a certain (complex) graphic multiple times in your picture, you can save it in a save box. This way you can put a graphic in the picture, just by referencing the name under which you saved it. This is a very powerful way of creating pictures, which greatly reduces the time it takes to create them.

To declare a new save box, use

\newsavebox{name}

To define it, i.e., tell exactly what’s inside, use

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

Then, you can put it in your picture wherever you want, and as many times as you like, using

\usebox{name}

\setlength{\unitlength}{4pt}
\begin{picture}(20,20)(0,0)
\newsavebox{MYBOX}
\savebox{MYBOX}(5,5)[l]{%
\put(0,0){\circle*{4}}
\put(1,0){\circle*{4}}
}
\put(10,10){\usebox{MYBOX}}
\end{picture}

CONTINUE WITH THIS COURSE
Do you like my tutorials?
To keep this site running, donate some motivational food!
Crisps
(€2.00)
Chocolate Milk
(€3.50)
Pizza
(€5.00)