Search code examples
gnuplottikz

Strange tex files management in Gnuplot with tikz term


I fount a strange phenomenon. If we run the following gnuplot script (in a folder with gnuplot-lua-tikz-common.tex, gnuplot-lua-tikz.sty, gnuplot-lua-tikz.tex, t-gnuplot-lua-tikz.tex)

tikzfile="test.tex"
plot x**2
set term tikz standalone monochrome
set output tikzfile #
replot              #
cmd="pdflatex -interaction=nonstopmode ". tikzfile
system(cmd)

we found the following fatal error

! Emergency stop.
<*> test.tex

!  ==> Fatal error occurred, no output PDF file produced!

Anyway we have the test.tex file. Hence if we re-run the same script with the #-marked lines commented we obtain no error and the perfect test.pdf file.

During the first exec, with set term we have an empty file, with replot we fill it, but until the end of the exec we can't use it as an input of pdflatex. Why?

During the second exec we already have the test.tex file, so if we comment set term and replot we can use it as an input of pdflatex. Why?

Thank you.


Solution

  • Gnuplot doesn't automatically flush and finish an output file after a plot.

    So, if you want to further process an output file from within the gnuplot script you must explicitly close the file with set output beforehand:

    tikzfile="test.tex"
    set term tikz standalone
    set output tikzfile
    plot x**2
    
    set output
    cmd="pdflatex -interaction=nonstopmode ". tikzfile
    system(cmd)