Assembling a document using epslatex

If you have the tikz terminal available, you will most likely want to use it in situations such as those in the previous recipe, where you want to incorporate the results of the TeX typographical engine into your plots.

If tikz support happens not to be compiled into your version of gnuplot, you can achieve the same results using the older epslatex terminal. This is almost always available; you can check by typing set term and perusing the resulting long list of output devices that gnuplot knows about.

Using the tikz terminal for these purposes may lead to a simpler workflow, as it produces a TeX file that can be processed with pdflatex to produce a PDF file directly. This is what most people want to do most of the time, now that PDF has become the de facto standard for technical and scientific documents.

The epslatex terminal was designed for an earlier age when the only graphics format that could be included in LaTeX documents was encapsulated PostScript, and the final result of running TeX or LaTeX over your document was a DVI (device independent) file. Support for viewing these files is not widespread.

Fortunately, with one additional processing step, we can use the epslatex terminal to get exactly the same results, and in a PDF file too. In this recipe, we show how to generate the previous figure using a different method (there may be slight differences in spacing, as the generated figure may have a very slightly different size or margins).

How to do it…

The following steps are required to use the epslatex terminal:

Making the plot

Following is the gnuplot script for creating the graph:


set terminal epslatex
set out 'r4.tex'
unset key
set label 'Large$displaystyle lim_{xLongrightarrow0}frac{sin(x)}{x}=1$' at graph .55, .75
set title 'Large Illustrating Ls Rule: $frac{sin(x)}{x}$'
plot [0:15] sin(x)/x lw 2

The only change from the previous recipe is in the first line, where we have selected the epslatex terminal.

When this script is fed to gnuplot, it will create two files: a LaTeX document called r4.tex and an encapsulated PostScript file, containing the graph, called r4.eps.

The LaTeX document

Include the generated LaTeX file in your LaTeX document, as shown in the following listing:

documentclass{article}
usepackage{graphicx}
usepackage[rflt]{floatflt}
usepackage[T1]{fontenc}
usepackage{textcomp}
usepackage[utf8x]{inputenc}
usepackage{gnuplot-lua-tikz}
pagestyle{empty}
egin{document}
openup.5em
egin{floatingfigure}{2.9in}

esizebox{2.5in}{!}{input{r4}}
end{floatingfigure}

oindent The figure to the right provides an illustration of L'H^o-pi-tal's Rule. Recall that this rule can be applied when taking the limit as $xlongrightarrow x_a$ of a ratio of two functions where the ratio approaches the indeterminate form $frac{0}{0}$; in the case where both functions are differentiable at $x_a$, the ratio approaches the ratio of their derivatives. In the case illustrated both $sin(x)$ and $x longrightarrow0$ as we approach the origin, but the ratio of their derivatives, $frac{cos(x)}{1} longrightarrow 1$. L'H^o-pi-tal's Rule also applies in the case of the indeterminate form $frac{infty}{infty}$.
end{document}

The only difference from the previous recipe is the name of the included file.

Producing the PDF

Assuming our final desired result is a PDF document, we must first transform the encapsulated PostScript file r4.eps into a PDF file. It doesn't matter how we do this, but one convenient method available on Linux is to use the command-line tool epstopdf, which does just what it says. On the Macintosh, if epstopdf is not installed, we need to merely open the EPS figure in Preview and then save it. Preview converts the file to PDF for display.

Once this is done, we need to simply run pdflatex on the file to get our final document.

Another workflow is to process our main document with the latex command, producing a DVI file. This can be converted, if desired, to a PDF file with the command-line tool dvipdfm or friends.

How it works…

When using the epslatex terminal, gnuplot will create two output files rather than the single file that we usually get. We will have our graph in the form of an encapsulated PostScript file with an eps extension. We will also have a LaTeX file with the name that we specify in the set out command. We should pick a filename with the extension .tex to make subsequent processing more convenient. The EPS file will have the same base name (name aside from the extension) as the one given in the set out command.

The LaTeX file generated by gnuplot need not normally be edited or looked at. Its job is to overlay all the text, including the tic and axis labels, title, and so on, onto the plot in the EPS file. If you look at the graph file itself (r4.eps in the example, or r4.pdf after conversion), you will see a bare plot with no labels or text.

Finally, our main document includes the LaTeX file created by gnuplot, which will in turn include the graph. We can include this file any way we wish, but usually we will put it in some sort of figure environment.

For most of the other details of how this recipe works, refer to the previous recipe.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.108.86