Tx · LaTeX & TikZ

How to Use gnuplottex on Windows 8.1

Published By the 9to5Science editorial team

At a glance

  1. 1. Install the tools

    Install a TeX distribution, the gnuplottex package, and the separate gnuplot program.

  2. 2. Check the command

    Open Command Prompt and confirm that gnuplot --version and pdflatex --version both work.

  3. 3. Enable shell escape

    Compile with shell escape enabled so gnuplottex can launch gnuplot during the LaTeX run.

  4. 4. Test a small plot

    Use a minimal document first, then check the PDF and compilation log for errors.

Advertisement

gnuplottex lets a LaTeX document run gnuplot code during compilation and include the resulting plot. Windows 8.1 does not require a different LaTeX environment: the usual requirements are a working TeX installation, the gnuplottex package, and a gnuplot executable that can be launched by name.

The most common cause of failure is that the editor or TeX compiler cannot find gnuplot.exe, or that shell escape is disabled. Check those two things before changing the plot code.

Install and check the prerequisites

Install a TeX distribution such as MiKTeX or TeX Live, and install the gnuplottex package through that distribution’s package manager if it is not already present. Install gnuplot separately; installing the LaTeX package does not install the gnuplot program.

Open Command Prompt and run:

gnuplot --version
pdflatex --version

Both commands should print version information. If Windows reports that gnuplot is not recognized, add the folder containing gnuplot.exe to the Windows PATH environment variable, then open a new Command Prompt and try again. Add the folder path without wrapping it in quotation marks. For example, if the executable is in C:\Program Files\gnuplot\bin, add that folder as a PATH entry. The actual folder can vary by installer and version.

If you compile from an editor, the editor must inherit the updated PATH. Close and reopen it after changing the environment variable. You can also configure the editor to use the full path to the gnuplot executable if it provides that option.

Minimal working example

Save this as demo.tex:

\documentclass{article}
\usepackage{gnuplottex}

\begin{document}

Here is a plot generated by gnuplot:

\begin{gnuplot}
set grid
plot sin(x) title "sin(x)"
\end{gnuplot}

\end{document}

Compile it from the folder containing demo.tex. With TeX Live, run:

pdflatex --shell-escape demo.tex

With MiKTeX, use:

pdflatex --enable-write18 demo.tex

The gnuplot environment contains gnuplot commands, not ordinary LaTeX drawing commands. In this example, gnuplot plots the sine function and adds a grid. The package arranges for gnuplot to run and for its output to be included in the LaTeX document.

Shell-escape option names depend on the TeX distribution and version; check the compiler’s help if the command is not accepted. In a graphical editor, look for a setting that enables shell escape or write18 for the PDFLaTeX command. The precise menu and command field depend on the editor. Do not enable shell escape for documents you do not trust: it permits LaTeX to run external commands.

Diagnose common errors

“gnuplot is not recognized” or a similar command error: Windows cannot locate gnuplot.exe. Check the PATH setting and verify gnuplot --version in a newly opened Command Prompt.

The output says shell escape is disabled: Enable shell escape in the compiler command or editor settings. This is separate from installing the package and gnuplot.

LaTeX says it cannot find gnuplottex.sty: Install gnuplottex using the package manager for the same TeX distribution that runs pdflatex. Having another TeX installation on the computer can make it easy to install the package in one distribution and compile with another. Check which executable is being used with where pdflatex in Command Prompt.

The document compiles but the plot is missing or stale: Read the full log for the first gnuplot or file-inclusion error. Run the compilation from the document’s folder so generated files are written where expected. gnuplottex normally generates and includes plots during the same compilation, so inspect the log rather than assuming another run will fix a missing plot. Avoid deleting generated plot files while the compilation is still running.

A path with spaces causes trouble: First test the commands from a simple working folder, such as C:\texwork. Keep the gnuplot installation on PATH as a separate PATH entry rather than trying to embed its path in the plot commands. If invoking a program by its full path, quote that path in the Windows command line.

What to check next

If the minimal example still fails, separate the problem into two tests: run gnuplot --version from the same environment used by your editor, then compile the minimal document from Command Prompt with shell escape. The first failing test identifies whether the issue is gnuplot installation/PATH or LaTeX configuration. Consult the gnuplottex package documentation if you need a different terminal or output format, since those settings can depend on the LaTeX engine and package version.

References

  1. The gnuplottex package on CTAN
  2. gnuplot documentation

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.