The documentation of TikZ and the underlying pgf system


Explore the comprehensive documentation of TikZ and its underlying pgf system, offering insights from the basics to advanced techniques. Delve into a wealth of options for creating intricate graphics in LaTeX, with tutorials to guide beginners and seasoned users alike. From understanding TikZ as a graphics language to navigating its system and basic layers, discover how to harness its power for precise, customizable visualizations. Uncover the layers beneath TikZ, including its system and basic layers, and learn to leverage them effectively for creating complex graphics with ease. Whether you're a novice or an expert, this book equips you with the knowledge and tools to master TikZ and elevate your document design


pages: 1322, views: 3335

Introduction
Welcome to the documentation of TikZ and the underlying pgf system. What began as a small LaTeX style for creating the graphics in my (Till Tantau’s) PhD thesis directly with pdfLaTeX has now grown to become a full-blown graphics language with a manual of over a thousand pages. The wealth of options offered by TikZ is often daunting to beginners; but fortunately this documentation comes with a number of slowly-paced tutorials that will teach you almost all you should know about TikZ without your having to read the rest.

I wish to start with the question “What is TikZ?” Basically, it just defines a number of TeX commands that draw graphics. For example, the code \tikz \draw (0pt,0pt) -- (20pt,6pt); yields the line and the code \tikz \fill[orange] (1ex,1ex) circle (1ex); yields . In a sense, when you use TikZ you “program” your graphics, just as you “program” your document when you use TeX. This also explains the name: TikZ is a recursive acronym in the tradition of “GNU's Not Unix” and means “TikZ ist kein Zeichenprogramm”, which translates to “TikZ is not a drawing program”, cautioning the reader as to what to expect. With TikZ you get all the advantages of the “TeX-approach to typesetting” for your graphics: quick creation of simple graphics, precise positioning, the use of macros, often superior typography. You also inherit all the disadvantages: steep learning curve, no WYSIWYG, small changes require a long recompilation time, and the code does not really “show” how things will look like.

Now that we know what TikZ is, what about “pgf”? As mentioned earlier, TikZ started out as a project to implement TeX graphics macros that can be used both with pdfLaTeX and also with the classical (PostScript-based) LaTeX. In other words, I wanted to implement a “portable graphics format” for TeX – hence the name pgf. These early macros are still around and they form the “basic layer” of the system described in this manual, but most of the interaction an author has these days is with TikZ – which has become a whole language of its own.

1.1 The Layers Below TikZ
It turns out that there are actually two layers below TikZ:
System layer: This layer provides a complete abstraction of what is going on “in the driver”. The driver is a program like dvips or dvipdfm that takes a .dvi file as input and generates a .ps or a .pdf file. (The pdftex program also counts as a driver, even though it does not take a .dvi file as input. Never mind.) Each driver has its own syntax for the generation of graphics, causing headaches to everyone who wants to create graphics in a portable way. pgf’s system layer “abstracts away” these differences. For example, the system command \pgfsys@lineto{10pt}{10pt} extends the current path to the coordinate (10pt, 10pt) of the current {pgfpicture}. Depending on whether dvips, dvipdfm, or pdftex is used to process the document, the system command will be converted to different \special commands. The system layer is as “minimalistic” as possible since each additional command makes it more work to port pgf to a new driver. As a user, you will not use the system layer directly.

Basic layer: The basic layer provides a set of basic commands that allow you to produce complex graphics in a much easier manner than by using the system layer directly. For example, the system layer provides no commands for creating circles since circles can be composed from the more basic Bézier curves (well, almost). However, as a user you will want to have a simple command to create circles (at least I do) instead of having to write down half a page of Bézier curve support coordinates. Thus, the basic layer provides a command \pgfpathcircle that generates the necessary curve coordinates for you. The basic layer consists of a core, which consists of several interdependent packages that can only be loaded en bloc, and additional modules that extend the core by more special-purpose commands like node management or a plotting interface. For instance, the beamer package uses only the core and not, say, the shapes modules. In theory, TikZ itself is just one of several possible “frontends”. which are sets of commands or a special syntax that makes using the basic layer easier. A problem with directly using the basic layer is that code written for this layer is often too “verbose”. For example, to draw a simple triangle, you may need as many as five commands when using the basic layer: One for beginning a path at the first corner of the triangle, one for extending the path to the second corner, one for going to the third, one for closing the path, and one for actually painting the triangle (as opposed to filling it). With the TikZ frontend all this boils down to a single simple metafont-like command: \draw (0,0) -- (1,0) -- (1,1) -- cycle;