concept LaTeX in category gnuplot

appears as: LaTeX
Gnuplot in Action

This is an excerpt from Manning's book Gnuplot in Action.

eIn Emacs, for instance, typing C-x 8 RET, followed by the code point in hex or the Unicode name, will work—note that tab-completion of the name is available. You may also want to check out the TeX input method: you enable it using C-x RET C-\, followed by TeX. You can now input Greek letters and other symbols as in LaTeX: for instance, typing \lambda will produce the corresponding Greek letter.

Then we discuss gnuplot’s special cairolatex terminal, which allows you to combine gnuplot graphics with LaTeX text in the same illustration so that you can use the full power of LaTeX for mathematical typesetting in gnuplot graphs.

Listing 10.3. Importing a PDF into LaTeX: see figure 10.4 (file: doc1.tex)

The graphicx package provides the \includegraphics command, which takes the name of the graphics file to include as a mandatory parameter. (The filename extension isn’t required, and it’s recommended that you omit it.) The \include-graphics command takes a number of optional parameters as key/value pairs, which let you perform useful operations on the image as it’s included: you can trim, scale, and rotate it. Here, its size is adjusted ever so slightly (from 5 inches to 10 cm).[3] The document’s final appearance after processing with LaTeX is shown in figure 10.4.

3There are many more options—check your favorite LaTeX reference for details. A good place to start is H. Kopka and P. W. Daly, Guide to LaTeX, 4th ed. (Addison-Wesley, 2004).

10.4.3. Letting LaTeX generate the graph

When you use the cairolatex terminal, gnuplot draws the graph, and LaTeX provides the text labels. You can go a step further and let LaTeX draw both the text and the graph. Gnuplot merely creates a set of LaTeX commands that accomplish both tasks. Several terminals take this approach; here I’ll briefly introduce the tikz terminal as an example for the overall concept. The context terminal follows a similar idea.

Notice that the tikz terminal is invoked with the standalone option: in this case, you’re creating just the graph. Gnuplot produces a LaTeX file called tikz.tex that can be processed using pdflatex. Some auxiliary files that are required by LaTeX are part of the gnuplot distribution, but you can also generate local copies of them in the current directory by including the keyword createstyle in the call to set terminal tikz .... The resulting graph is shown in figure 10.6. Be aware that you need to have the pgf (TeX Portable Graphics Format) package installed, which is part of the LaTeX distribution but may not be installed by default.

Figure 10.6. A graph drawn using the tikz terminal. See listing 10.6 for the commands.

How does this entire approach compare to the alternatives? Historically, one advantage of letting LaTeX generate the graph was that LaTeX allowed greater control over the appearance of lines, dash patterns, and the like. This aspect has become less important as gnuplot has acquired some of these capabilities.

Terminals such as pdfcairo produce a separate (standalone) graph, which potentially has to be included into a document. Using the tikz or context terminal, you can embed the commands that generate the graph into the document, so only a single file has to be processed. Whether this is a good idea is another question—personally, I prefer the separation of concerns provided by having standalone graphs and a document that references them. Also be aware that LaTeX may encounter resource (specifically, memory) limitations when processing large graphs.

Gnuplot in Action: Understanding Data with Graphs

This is an excerpt from Manning's book Gnuplot in Action: Understanding Data with Graphs.

Finally, a word of warning: don’t assume that the gnuplot plot or replot commands will automatically flush their output buffers to file! This isn’t a problem with bitmap terminals, but can lead to frustrating problems with file formats that can contain more than one graph in a single file (among them PostScript, PDF, and SVG). I’ve also encountered this sort of problem with terminals that generate output which requires postprocessing (for instance, by LaTeX).

11.4.2. Using PostScript plots with LaTeX

One very common use of PostScript graphs is to include them as illustrations in a LaTeX document. In this section, I give a couple of cookbook-style recipes. First, I describe how to include a regular PostScript file as an image in a LaTeX document. Then we discuss gnuplot’s special epslatex terminal, which allows us to combine PostScript graphics with LaTeX text in the same illustration, so that we can use the full power of LaTeX for mathematical typesetting in gnuplot graphs.

Listing 11.6. Combining gnuplot and LaTeX using the epslatex terminal

The text for labels and tic marks that we’re adding to the graph now contains LaTeX directives. In particular, note the $...$, which indicate math-mode in LaTeX, and which are required for many of the special mathematical formatting commands.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest