[Tex/LaTex] adding gnuplot capability to latex

gnuplottexmakertikz-pgf

I have been working with LaTeX, under TeXMaker (latest version 3.2.2) for several months, and recently added PGF/TikZ capability. On that occasion I feared there would be problems as I really have very little understanding of how the various applications hang together, or even where to find them. But no, once I found where TeXMaker resided I simply added the PGF files as a subdirectory and to my complete surprise, it all worked. Similar success was had with adding tikz-3dplot capability.

Recently, working my way through the TikZ manual I wanted to experiment with gnuplot, and all hell broke loose. I am even unable to find what type or version of LaTeX I am working with, i.e. cannot find executables. I know I have MiKTeX 2.9 loaded as I recall pulling it off the net, but if this is the variant of LaTeX my TeXMaker is working with I cannot tell. The one thing I do find is texmaker.exe, everything else is turning into a complete mystery. Without a doubt I am coming across as a complete air head, but my main interest lies in mathematics, but realize I need to invest effort to make the most of LaTeX and its graphic capabilities as a tool.

Could someone kindly point me to a brief and succinct overview of how the following hang together: LaTeX, TeXMaker, PGF-TikZ, gnuplot. I am working under Windows 7.

Best Answer

Here's a set of steps I took to get gnuplottex working in Windows. I'm running TeX Live rather than MiKTeX, so let me know if this doesn't work.

First, you need to install gnuplot. The binary I used was taken from this page. When installing it, the only change from the default I made when following the installer was to select "Add application directory to your PATH environment variable." This may not be necessary, but seemed like a good idea.

enter image description here

Next you need to tell Texmaker that it's ok for pdflatex to call external programs. Assuming that you use pdflatex as your typesetter, then you only need to add the --enable-write18 option to the command. To do this, in Texmaker go to Options->configure Texmaker, and add --enable-write18 to the options for the PdfLaTeX command. See the highlighted text in the image below:

enter image description here

Following these steps, try the following example code:

\documentclass[a4paper]{article}
\usepackage{gnuplottex}          % <- Use if running MiKTeX.
%\usepackage[miktex]{gnuplottex} % <- Use instead if running TeX Live.

\begin{document}

\begin{gnuplot}[terminal=pdf,terminaloptions={font ",10" linewidth 3}]
    plot sin(x), cos(x)
\end{gnuplot}

\begin{gnuplot}[scale=0.8]
    set grid
    set title 'gnuplottex test $e^x$'
    set ylabel '$y$'
    set xlabel '$x$'
    plot exp(x) with linespoints
\end{gnuplot}

\end{document}