# LaTeX/Introducing Procedural Graphics

(Redirected from LaTeX/Creating Graphics)
Jump to: navigation, search

LaTeX

Getting Started

Common Elements

Mechanics

Technical Texts

Special Pages

Special Documents

Creating Graphics

1. Introducing Procedural Graphics
2. MetaPost
3. Picture
4. PGF/TikZ
5. PSTricks
6. Xy-pic
7. Creating 3D graphics

Programming

Miscellaneous

Help and Recommendations

Appendices

edit this boxedit the TOC

In the Importing Graphics chapter, you learned that you can import or link graphics into LaTeX, such as graphics that you have created in another program or obtained elsewhere. In this chapter, you will learn how to create or embed graphics directly in a LaTeX document. The graphics is marked up using commands similar to those for typesetting bold text or creating mathematical formulas, as the following example of embedded graphics shows:

 \begin{displaymath} \xymatrix{ \bullet \ar[r] \ar@{.>}[r] & \bullet }\end{displaymath}

There are several packages supporting the creation of graphics directly in LaTeX, including picture, xy-Pic and PGF/TikZ, described in the following sections.

Compared to WYSIWIG tools like Xfig or Inkscape, this approach is more time consuming, but leads to much better results. Furthermore, the ouput is flawlessly integrated to your document (no contrast in size nor fonts).

See the Importing Graphics for more details on graphics importation and some attempts to circumvent to integration issue.

## Overview

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 epic, eepic or pstricks enhance the original picture environment, and greatly strengthen the graphical power of LaTeX.

While the former two packages just enhance the picture environment, the pstricks package has its own drawing environment, pspicture. The power of pstricks stems from the fact that this package makes extensive use of PostScript possibilities. Unfortunately it has one big shortcoming: it doesn't work together with pdfLaTeX, as such to generate a PDF document form TeX source you have to go TeX→DVI→PDF; losing hyperlinks, metadata and microtypographic features of pdflatex.

In addition, numerous packages have been written for specific purposes. One of them is XY-pic, described at the end of this chapter. A wide variety of these packages are described in detail in The LaTeX Graphics Companion (not to be confused with The LaTeX Companion).

Perhaps the most powerful graphical tool related with LaTeX is MetaPost, the twin of Donald E. Knuth’s METAFONT. MetaPost has the very powerful and mathematically sophisticated programming language of METAFONT. Contrary to METAFONT, which generates bitmaps, MetaPost generates encapsulated PostScript files, which can be imported in LaTeX. For an introduction, see A User’s Manual for MetaPost. A very thorough discussion of LaTeX and TEX strategies for graphics (and fonts) can be found in TEX Unbound.

The last but certainly not least is the PGF/TikZ system. While the previous systems (picture, epic, pstricks or metapost) focus on the how to draw, TikZ focuses more on the what to draw. One could say that TikZ is to drawing in LaTeX as LaTeX is to digital typesetting. It's recommended to use it if your LaTeX distribution includes it.

In many cases, especially for more advanced diagrams, it may be easier to draw the graphics using external vector graphics software, and then import the file into the document (see LaTeX/Importing Graphics). However most software does not support LaTeX fonts or mathematical notation, which can result in not suitable and inconsistent graphics. There are several solutions to this problem.