The epslatex terminal splits a figure in two: gnuplot draws the graphics into an .eps file, and writes every piece of text — title, axis labels, legend — into a companion .tex file for LaTeX to typeset. The payoff is that figure text uses exactly the fonts and math typesetting of your paper, because LaTeX itself renders it.
set terminal epslatex size 12.5cm,9cm color colortext
set output "decay.tex"
set title "Exponential decay"
set xlabel "$t$ (s)"
set ylabel "$N(t)$"
set xrange [0:10]
plot exp(-0.5*x) with lines linewidth 2 title "$e^{-t/2}$"
set output
Run this script and gnuplot writes two files: decay.tex (the file you named in set output) and decay.eps (its name is derived by replacing the .tex extension with .eps). The .eps holds the drawing without text; the .tex positions the text over it. Note the labels: because LaTeX will typeset them, they are written as LaTeX — $t$, $N(t)$, even a full formula as the legend entry $e^{-t/2}$. That is the whole point of this terminal: real math in labels, in the document’s own typeface.
The color colortext options ask for a color figure with colored text typeset by LaTeX (drop them for a monochrome figure). The size is given in physical units — set it to the figure’s final size in the paper, because the .tex fragment is included at 100 percent scale so that the typeset text matches the surrounding font size.
Including the figure in LaTeX
% in the preamble:
\usepackage{graphicx}
\usepackage{color}
% in the document:
\begin{figure}
\centering
\input{decay}
\caption{Exponential decay of $N(t)$.}
\label{fig:decay}
\end{figure}
The figure is pulled in with \input{decay} — not \includegraphics — because the .tex file itself contains the code that includes the .eps graphic and overlays the text. The preamble needs graphicx for that inclusion and color when you use colortext. Two workflow notes worth knowing: the classic latex + dvips route consumes .eps natively, while pdflatex cannot embed EPS directly — modern TeX distributions convert it to PDF on the fly via the epstopdf mechanism when shell escape is enabled in its restricted form, and if your toolchain forbids that, convert decay.eps once with the epstopdf tool and keep the resulting PDF next to it.
The standalone option
By default epslatex writes a fragment meant for \input. Add the standalone option — set terminal epslatex standalone size 12.5cm,9cm color colortext — and gnuplot instead writes a complete LaTeX document with its own preamble, which you can compile on its own to preview the figure; in standalone mode the graphics file is named decay-inc.eps (note the added -inc). Standalone is convenient for building a library of pre-compiled figures, while the default fragment mode keeps one source of truth inside the paper project.
Common mistakes
- Only the .tex file copied into the project: the figure appears without its drawing, or LaTeX errors that it cannot find the graphic. The .tex and .eps files are a pair — always move and commit both.
- Text comes out the wrong size: the fragment was scaled with
\resizeboxor\includegraphics-style width options. That scales the typeset text too and breaks the match with the body font. Fix the size in gnuplot (set terminal epslatex size ...) and include at natural size. - Backslashes vanish from labels: inside a gnuplot script file, a LaTeX command needs its backslash to survive string handling. In double-quoted gnuplot strings, write math exactly as shown above and check the generated .tex file if a label looks wrong — it shows literally what LaTeX received.
Related tutorials: The TikZ Terminal, The Gnuplot + LaTeX Workflow. See also the full Gnuplot Tutorials index.
Try it online: You can prototype the plot itself online, then run the same script locally with the epslatex terminal to generate the .tex/.eps pair. Paste the script into the Gnuplot Online terminal and run it in your browser — no install needed. To run gnuplot locally instead, see the installation guide and the download page.
Go deeper: For a systematic walk through gnuplot from first plots to publication-ready figures, see Gnuplot in Action by Philipp K. Janert — Janert is a gnuplot developer, and the book is the most complete tutorial reference for the program. Affiliate link: see our Affiliate Disclosure.
