0

I am having a really really weird problem trying to include graphics files in my latex document that were created using the gnuplot epslatex terminal.

I have created a gnuplot script which uses the epslatex terminal and writes the output to a file named foo.tex. As expected it outputs two files: foo.eps and foo.tex. In my latex file named paper.tex I then include foo.tex in a figure by using:

\begin{figure}[ht]
\input{foo.tex}
\end{figure}

I then compile the latex file using the command:

  latex paper.tex

I then convert the paper.dvi file to a .ps file using:

  dvips paper.dvi

and I then try to convert this to a .pdf file using:

  ps2pdf paper.ps

but it fails with an error message that means just about nothing to me and I can't view the plot in the .pdf file when using my .pdf viewer. Here is the error message:

    Error: /syntaxerror in /--%ztokenexec_continue--
    Operand stack:
    ExtendTextBox
    Execution stack:
    %interp_exit   .runexec2   --nostringval--   --nostringval-- --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   2045   1   3   %oparray_pop   2044   1   3   %oparray_pop   2025   1   3   %oparray_pop   1884   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
    Dictionary stack:
    --dict:960/1684(ro)(G)--   --dict:1/20(G)--   --dict:90/200(L)--   --dict:198/300(L)--   --dict:67/200(L)--   --dict:181/256(L)--
    Current allocation mode is local
    GPL Ghostscript 9.26: Unrecoverable error, exit code 1

Now here's the really really weird part. After much frustration (many hours) I accidentally found that if I run my gnuplot script but write to the screen (that is I comment out the part that sets the terminal to epslatex and I comment out the part that writes the output to a file) and then I retry the ps2pdf command it then works and I can view the plot in the .pdf file.

This makes absolutely no sense to me! It appears that running the gnuplot script and plotting to the screen fixes something in foo.tex and foo.eps AFTER they have been created. What is going on?

  • Can you post the error message please? – Lars Kotthoff Jun 6 at 2:26
  • Do you really need latex+dvips+ps2pdf? With just pdflatex paper you should be OK. – egreg Jun 6 at 12:13
  • 1
    Maybe you didn't do unset out (which finalizes and closes the output .eps file)? Switching the terminal in gnuplot might do that automatically. – Marijn Jun 6 at 18:59
  • egreg, I was experiencing the same problem with pdflatex. – D_J_S Jun 6 at 20:13
  • Lars Kotthoff, I edited the question to include the error message. – D_J_S Jun 6 at 20:14
1

The problem is that file maintains open by gnuplot waiting for data, if you need to use the file created you must close that file using set output command and then return the previous device using set term pop command

  • Thank you @user191086. A very convincing argument. – D_J_S Jun 17 at 20:18
0

The solution to the problem (Thanks Marijn) is to include the following line at the end of the gnuplot script:

    unset output

However I do not understand how plotting to the screen would also fix the problem after the files foo.tex and foo.eps had already been written. That remains a mystery to me. Is GnuPlot setting a system variable that is used by ps2pdf? Something is buggy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.