- gnuplot (v4)
- LaTeX
- dvips
- epstopdf
- pdftops

- Prepare a gnuplot script file (named test.gp)
- Create tex and eps files (test.tex, test.eps)
- Include test.tex in a tex file (named include.tex)
- Compile the include.tex
- Get out the figure part

set term epslatex color

set output "test.eps"

set xlabel '{\Large $x$}'

set ylabel '{\Large $e^{\alpha x}$}'

set label 1 '{\Large $\alpha=0.1$}' at 1,1

plot exp(0.1*x)

unset label

quit

set output "test.eps"

set xlabel '{\Large $x$}'

set ylabel '{\Large $e^{\alpha x}$}'

set label 1 '{\Large $\alpha=0.1$}' at 1,1

plot exp(0.1*x)

unset label

quit

prompt> gnuplot test.gp

prompt> ls test*

test.eps test.gp test.tex

The created test.eps has the graph part only as:prompt> ls test*

test.eps test.gp test.tex

test.eps

\documentclass{article}

\usepackage{graphicx,color}

\pagestyle{empty}

\begin{document}

\begin{figure}[h]

\input{./test.tex}

\end{figure}

\end{document}

\usepackage{graphicx,color}

\pagestyle{empty}

\begin{document}

\begin{figure}[h]

\input{./test.tex}

\end{figure}

\end{document}

prompt> latex include.tex

The created include.dvi has unnecessary space.
In the next step, we get out the figure part only.

- Not use "_" in your file name(s).
- Put "unset key" in your gnuplot script to eliminate the problematic key.
- Use a safety title in your gnuplot script, like

plot "filename" title '{$x_a$ or letters}'

You have an error like "Missing $ inserted."

**Why?**

If you use a file name including a letter "_",
then it tends to appear in a key of the eps file.
However, LaTeX understands that the letter "_" is a symbol
to make a subscript, like "a" of $x_a$,
and hence LaTeX gives the error to make a mathematical symbol.

**Solutions**

You can solve this problem in several ways:

prompt> dvips -E include.dvi

prompt> epstopdf --outfile=include.pdf include.ps

prompt> pdftops -eps include.pdf test.eps

prompt> rm include.{aux,dvi,log,ps,pdf}

The 2nd and 3rd lines are for nice preview by xdvi with the package:prompt> epstopdf --outfile=include.pdf include.ps

prompt> pdftops -eps include.pdf test.eps

prompt> rm include.{aux,dvi,log,ps,pdf}

\usepackage[dvipdfmx]{graphicx}

The created eps file is:

test.eps (final form)

test.sh

#!/bin/csh -f

set includefile="include"

foreach gpfile ( "test" ) (You may add the script files as ( "test" "test2" "test3" ) )

ech ${gpfile}.gp

gnuplot ${gpfile}.gp

latex ${includefile}

dvips -E ${includefile}.dvi

epstopdf --outfile=${includefile}.pdf ${includefile}.ps

pdftops -eps ${includefile}.pdf ${gpfile}.eps

rm ${includefile}.{aux,dvi,log,ps,pdf} ${gpfile}.{tex,log} (cleaning up unnecessary files)

Then,
#!/bin/csh -f

set includefile="include"

foreach gpfile ( "test" ) (You may add the script files as ( "test" "test2" "test3" ) )

ech ${gpfile}.gp

gnuplot ${gpfile}.gp

latex ${includefile}

dvips -E ${includefile}.dvi

epstopdf --outfile=${includefile}.pdf ${includefile}.ps

pdftops -eps ${includefile}.pdf ${gpfile}.eps

rm ${includefile}.{aux,dvi,log,ps,pdf} ${gpfile}.{tex,log} (cleaning up unnecessary files)

prompt> chmod u+x test.sh

prompt> ./test.sh

prompt> ./test.sh

Last modified: Fri Aug 25 09:54:01 JST 2017