## LaTeX forum ⇒ WinShell ⇒ Integrate Gnuplot

Information and discussion about WinShell, a free integrated LaTeX environment for Windows
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

### Integrate Gnuplot

Hi

I'm running WinShell under Windows and I was wondering if anyone could help me call Gnuplot 'plot' command directly from LaTeX source?

e.g.
`plot sin(x)/x`

I can generate .tex files from Gnuplot and use in my LaTeX documents with '\input' with no problem, but it's a bit long winded

Thanks

Tags:

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
Take a look at the gnuplottex package. But there are much smarter ways to produce plots by the pgfplots package (based on pgf/tikZ) or the pst-plot package (based on PSTricks).

Best regards and welcome to the board
Thorsten
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

torbjorn t.
Posts: 162
Joined: Wed Jun 17, 2009 10:18 pm
pgfplots can even use gnuplot to compute the coordinates.

psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm
Thanks both

As a LaTeX newbie, I'd never heard of pgplots - looks good so far

psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm
torbjorn t. wrote:pgfplots can even use gnuplot to compute the coordinates.

OK

But how? I'm using

`\addplot gnuplot[id=sin]{sin(x)};`

and I get the message:

pgfPlots.tex(21): Error: Package pgfplots Error: Sorry, the gnuplot-result file 'pgfPlots.sin.table' could not be found. Maybe you need to enable the shell-escape feature? For pdflatex, this is '>> pdflatex -shell-escape'. You can also invoke '>> gnuplot <file>.gnuplot' manually on the respective gnuplot file

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
You have to compile the concerned document with activated shell escape. Assumed that you are using the MiKTeX distribution it should read like this.
`pdflatex --enable-write18 document.tex`

Your editor should allow in its options to add this switch to the command line arguments for the compiler so that it is always invoked with activated shell escape.

Furthermore you have to make sure that Gnuplot can be found. Therefore you have to supplement the »Path« variable with the path of Gnuplot. This requires that you remember where you unpacked the archive at that time.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm
Thanks localghost

I'm sorry, but I really need to be hand-held through this

I have gnuplot in my PATH; specifically if I type in gnuplot from any directory in Command Prompt the program starts

I have changed the pdfLatex cmdLine in WinShell as suggested. This now reads
`-synctex=-1 "%s.tex" pdflatex --enable-write18 document.tex`

But I still get the message

`pgfPlots.tex(20): Error: Package pgfplots Error: Sorry, the gnuplot-result file 'pgfPlots.sin.table' could not be found. Maybe you need to enable the shell-escape feature? For pdflatex, this is '>> pdflatex -shell-escape'. You can also invoke '>> gnuplot <file>.gnuplot' manually on the respective gnuplot file..`

Can you help?

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
psionman wrote:[…] I have changed the pdfLatex cmdLine in WinShell as suggested. This now reads
`-synctex=-1 "%s.tex" pdflatex --enable-write18 document.tex`

[…]

I can't remember that I told you to insert exactly what I suggested. What I told you was only to supplement the command line arguments for the compiler with the --enable-write18 switch.

Since I don't use WinShell I can only assume the right settings for this editor. I guess that in the corresponding WinShell options there is a box for the executable of the compiler (PDFLaTeX) and a separate box for its command line arguments. Thus the command line arguments should read at least like this.
`-synctex=-1 --enable-write18 "%s.tex"`

That should suffice to invoke external programs like Gnuplot by the compiler. If this works with the pgfplots package, it will also work for any other package that needs shell escape.
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1