miércoles, 28 de marzo de 2012

The epslatex terminal


There are cases when a couple of special symbols are needed in a graph, e.g., when a formula is to be written on top of the curves. While some terminals have an enhanced version, where some symbols can be written, (you can find the availble symbols in Dick Crawford's postscript guide.) it is not always enough. In cases like this, we can make use of the epslatex terminal. As always, first we have to set our terminal as
set terminal epslatex
At this point, we can set labels with any LaTeX symbols, the generated output will contain it properly. For the sake of example, we will plot error function, and write its definition on the figure as follows:
set terminal epslatex
set xrange [-3:3]
set yrange [-1:1]
set label 1 at -2, 0.5 "$erf(x) = \\frac{2}{\\sqrt{\\pi}}\\int_0^x\\, dt e^{-t^2}$" centre
plot erf(x)
Note that we have crammed a lot of LaTeX commands in the label, enclosed by the two $ signs, to indicate that we are dealing with mathematical expressions. You might have to escape the instructions twice, so you will have \\frac{}{} etc.
Now, if you set your output
set output 'errorf.tex'
and replot your graph, you will get two files. (At this point, I would also recommend re-setting the terminal, otherwise, there is no guarantee that gnuplot has closed both your output files, and this could create some trouble later on.) errorf.eps will contain the "visual" part of the graph, i.e., the axes, tics, points, lines, arrows and the like, while errorf.tex holds all the typographic elements. We then have got to combine these two by invoking LaTeX or pdflatex, depending on the exact route you would like to follow. The destination is the same in both cases.
So, let us suppose for the moment that you want to work with postscript, and not with pdf. You should create a LaTeX file, which includes nothing but the file that we have just produced, errorf.tex.
\documentclass{article}
\usepackage{graphics}
\usepackage{nopageno}
\usepackage{txfonts}
\usepackage[usenames]{color}
\setlength{\pagewidth}{4.7in}
\setlength{\pageheight}{3.4in}
\hoffset -2.1in
\voffset -3.8in
\begin{document}
\begin{center}
\input{errorf.tex}
\end{center}
\end{document}
If you want to compile with pdflatex, first you have to convert the postscript file to pdf. In principle, one could use the pdf terminal of gnuplot, but the eps terminal is much more mature, and the end result with pdf is far from the expected. Using the eps terminal is much better, and we can easily convert the file by
ps2pdf -dEPSCrop error.eps error.pdf
Of course, this assumes that you have ghostview installed on your computer. By passing the -dEPSCrop argument to ps2pdf, we can retain the bounding box in the eps file, so the pdf graph won't be bigger. In order to crop the final pdf output to the proper size, the length definitions in the latex file should be replaced by
\setlength{\pdfpagewidth}{4.7in}
\setlength{\pdfpageheight}{3.4in}
\hoffset -2.1in
\voffset -3.8in 

No hay comentarios:

Publicar un comentario