# [Tex/LaTex] gnuplot in LaTeX, without gnuplottex

gnuplotlatexmk

I'm using the cairolatex terminal in gnuplot to create some surface plots (pgfplots is failing the task because of its hunger for memory). As the number of plots increase, I would like to include the gnuplot compilation into my tex compilation to ensure the plots are up-to-date. I came across the gnuplottex package, which seems to handle the task, though it's slow.

I have a large, nested document. Tex root is thesis.tex where I include, amongst others, theory.tex. In theory.tex I have put

\begin{figure}[htbp]
\centering
\end{figure}


where gnuplot/cascade.texcontains the gnuplot code

\begin{gnuplot}[terminal=cairolatex]
set samp 100;
set iso 40;
set xrange [0:1];
set yrange [0:1];
set zrange [0.8:2];
unset key;
unset colorbox;
set hidden3d front;
a = 1;
set xyplane at a;
f(x,y) = (x+y)/(2*sqrt(x*y));
set xlabel "$\\tau_I$";
set ylabel "$\\tau_D$";
set zlabel "$\\zeta$";
splot f(x,y) with pm3d at b, f(x,y) with lines;
unset output
\end{gnuplot}


The output of this setup is awesome. But whenever I change something in theory.tex, the entire gnuplottex routine recompiles. This takes quite some time, and is very annoying.

How come latexmk doesn't recognise that the gnuplot code hasn't changed and leave it? Could this dependency be specified, and in that case, how?

EDIT: gnuplottex is fairly slow on my system, although gnuplot is really quick. How can I avoid using gnuplottex, it's long compilation time and thus avoid having gnuplottex recompiling every time?

I have avoided using gnuplottex at all by adding the following custom dependency to .latexmkrc:

add_cus_dep('gnu','tex', 0, 'makegnu2tex');
sub makegnu2tex {
system("gnuplot \"\$_[0].gnu\"") ;
}


My gnuplot file uses the cairolatex terminal (or any other terminal who produce a .tex file). My latex document contains \input{gnuplot_output.tex} which, because of the newly defined dependency, causes a system call to gnuplot upon tex compilation. The .gnu file and .tex files are now a normal dependency, and gnuplot will not recompile unless the time stamp is changed.

It's important to notice that the path specified in set output "path/gnuplot_output.tex" in the .gnu file is relative to the tex root file as long as the gnuplot system call is induced by latexmk.