LaTeX/Introducing Procedural Graphics

From Wikibooks, open books for an open world
(Redirected from LaTeX/Creating Graphics)
Jump to navigation Jump to search

LaTeX

Getting Started
  1. Introduction
  2. Installation
  3. Installing Extra Packages
  4. Basics
  5. How to get help

Common Elements

  1. Document Structure
  2. Text Formatting
  3. Paragraph Formatting
  4. Colors
  5. Fonts
  6. List Structures
  7. Special Characters
  8. Internationalization
  9. Rotations
  10. Tables
  11. Title creation
  12. Page Layout
  13. Customizing Page Headers and Footers‎
  14. Importing Graphics
  15. Floats, Figures and Captions
  16. Footnotes and Margin Notes
  17. Hyperlinks
  18. Labels and Cross-referencing
  19. Initials

Mechanics

  1. Errors and Warnings
  2. Lengths
  3. Counters
  4. Boxes
  5. Rules and Struts

Technical Text

  1. Mathematics
  2. Advanced Mathematics
  3. Theorems
  4. Chemical Graphics
  5. Algorithms
  6. Source Code Listings
  7. Linguistics

Special Pages

  1. Indexing
  2. Glossary
  3. Bibliography Management
  4. More Bibliographies

Special Documents

  1. Scientific Reports (Bachelor Report, Master Thesis, Dissertation)
  2. Letters
  3. Presentations
  4. Teacher's Corner
  5. Curriculum Vitae
  6. Academic Journals (MLA, APA, etc.)

Creating Graphics

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

Programming

  1. Macros
  2. Plain TeX
  3. Creating Packages
  4. Creating Package Documentation
  5. Themes

Miscellaneous

  1. Modular Documents
  2. Collaborative Writing of LaTeX Documents
  3. Export To Other Formats

Help and Recommendations

  1. FAQ
  2. Tips and Tricks

Appendices

  1. Authors
  2. Links
  3. Package Reference
  4. Sample LaTeX documents
  5. Index
  6. Command Glossary

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 output is flawlessly integrated into 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[edit | edit source]

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 from TeX source, you have to go from TeX to DVI to PDF, losing hyperlinks, metadata, and microtypographic features of pdflatex in the process.

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[1]. A very thorough discussion of LaTeX and TEX strategies for graphics (and fonts) can be found in TEX Unbound[2]

The last but certainly not least are the PGF/TikZ and Asymptote systems. While the previous systems (picture, epic, pstricks or metapost) focus on the how to draw, TikZ and Asymptote focus more on the what to draw. One could say that TikZ and Asymptote are to drawing in LaTeX as LaTeX is to digital typesetting. It's recommended to use one of these if your LaTeX distribution includes it. TikZ is a pure (La)TeX system, not reliant on external software, while Asymptote is an external system which integrates seamlessly with (La)TeX. If using Asymptote, it is very helpful to use latexmk to manage the compilation steps.

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.


Previous: Curriculum Vitae Index Next: MetaPost
  1. https://www.ntg.nl/doc/hobby/mpman.pdf
  2. https://books.google.com/books/about/TeX_Unbound.html?id=VrHEswEACAAJ