I am wondering how to make the best combination using latex and gnuplot. I am currently using the epslatex terminal in gnuplot and the link input to latex. Is there another more efficient way?
I have tried many different ways to achieve this integration. Here I share what I learn:
If you will keep your LaTeX source files and the data files together, you can try to use pgfplots package (I think that today is integrated in TikZ package), which give you a good way to control the plots directly from the LaTeX source file. It is a very nice package and have a lot of style options. Also pgfplots have a way to plot raw data by calling to GNUplot during the LaTeX compilation, or even to put directly in the text file your GNUplot script lines. See the manual for examples and details.
However, there is some drawbacks that I found with this approach:
- If you have many plots, the compilation could become very slow and
- your LaTeX project tends to become less portable.
The first problem can be partially solved by using the external library from TikZ package. It avoid to recompile the plots all the times, by saving an individual pdf of each plot (or tikzpicture). However, if you have a large data plot, and you want to change, for instance, the axis name, you'll have to recompile again. I made some LaTeX wraps commands to easily and cleanly place the pgfplots and control the external libraries (force to recompile, avoid to recompile, etc). If you are interested, I can post the codes.
The second problem (the project portability) is more important to me and was the reason that I abandon the pgfplot approach. At the end of the day, with pgfplot/GNUplot you will need to access to the raw data files to compile... and that could not be always easy to do. For instance, if you send the LaTeX source to a coworker, you have to send also the data, and the project could achieve a huge memory size. If can share without raw data using the TikZ external library... but any mistake... and you will have a broken project.
On the other hand.. Why to integrate with LaTeX and GNUplot the data files?
(EDIT: My apologies for the next, I didn't see that you already use this approach)
The last versions of GNUplot (I think after version 4.2) have a very nice epslatex terminal. I choose this way to work. With term option "standalone" you will get a .tex file that can be compile when you want to obtain the plot. Therefore, you can just make a GNUplot script with this terminal and use a regular includegraphics to place the plot in LaTeX. You can put any latex symbol in the gnuplot script file or even select the same font that you use in your latex document. Furthermore, you can share the .tex file (with the associated .eps file) of the plot in the same folder of your LaTeX project without memory size penalties. If any minor change is needed in the future (for example change the language of the axis, or the font size) you can change directly the tex file associated with the plot and then safety recompile. Here a mini-example:
#!/bin/gnuplot
set terminal epslatex size 15cm,10cm color standalone
set output 'portableplot.tex'
set xlabel 'latex \small codes \large here'
set ylabel 'Nice font'
plot [-10:10][] -x w l lt 1 lw 5 lc rgb 'red' t 'and maths $\frac{2}{3}$',\
sin(x) w l lt 1 lw 5 lc rgb 'black' t ' $\alpha\beta^2$'
Dear Sergio, it would be really nice if you can upload your libraries (that you have created for pgfplots).
Although I stick to the second approach you have described: I am using cairolatex terminal (I have some issues with eplatex, namely with the transparency when using gnuplot 5).
What I understood you want to run both latex commands and gnuplot at a time. I recommend you to write a shell script and write both commands in it. Then you will execute commands for both via a single shell script command.
I am finding my footing as well. In the past, I created .eps file in gnuplot and \includegraphics{} in latex. This is fast and works reasonably well, but you do not have access to latex type-setting for labels, etc.
Another option you have is use "epslatex" terminal in gnuplot. You get two files .tex and .eps. You can use \import{fname} //no extension// to compile your graphs in latex. This way you get access to latex type-setting using conventional latex code (e.g. set xlabel 'Wavelength $\lambda$ [nm]' //note single quotes; apparently one needs to use two \ if " " are used//.
If you are looking to import your graphs to powerpoint, I would recommend using:
\documentclass{standalone}
It will automatically crop the .pdf output.
The best solution seems to be using "gnuplottex" package:
\usepackage{gnuplottex}
It allows you enter your gnuplot code directly into latex source code. Alternatively, you can "import" existing .gnuplot file (make sure there are no "set output" and "set terminal").
Sample code:
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage[cleanup,subfolder]{gnuplottex}
# "cleanup" and "subfolder" options are ... optional :-)