How to prepare eps files with beautiful LaTeX letters?
Motivation
Scientific figures frequently require LaTeX letters
for mathematical symbols as the axis label, for instance.
Solution
One solution is to use the "epslatex" option of gnuplot (v4).
Necessary softwares
- gnuplot (v4)
- LaTeX
- dvips
- epstopdf
- pdftops (In Mac+Homebrew, type "brew install poppler")
Details
Let test.gp be the test script file of gnuplot(v4)
to create a beautiful eps file.
The file name (test.gp) is arbitrary.
You have
- 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
Step1: Prepare a gnuplot script file (test.gp)
test.gp
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
Step2: Create tex and eps files (test.tex, test.eps)
prompt> gnuplot test.gp
prompt> ls test*
test.eps test.gp test.tex
The created test.eps has the graph part only as:
test.eps
Step3: Include test.tex in a tex file (include.tex : name is arbitrary)
include.tex
\documentclass{article}
\usepackage{graphicx,color}
\pagestyle{empty}
\begin{document}
\begin{figure}[h]
\input{./test.tex}
\end{figure}
\end{document}
Step4: Compile the include.tex
prompt> latex include.tex
The created include.dvi has unnecessary space.
In the next step, we get out the figure part only.
Trouble Shooting
Problem
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:
- 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}'
Step5: Get out the figure part
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:
\usepackage[dvipdfmx]{graphicx}
Without them, it might be possible that your figure is placed at a strange place in your pdf file.
Even if you have no problem in your PC, a problem may appear in different systems (collaborators, arXiv, journals, ...)
Additional comment:
If the above "dvipdfmx" option does not work, try:
\documentclass[..., dvipdfmx]{article}
..
\usepackage{graphicx}
The created eps file is:
test.eps (final form)
Further
It is convenient to use a shell script file
to automatically execute the above commands.
test.sh
#!/bin/csh -f
set includefile="include"
foreach gpfile ( "test" ) (You may add the script files as
( "test" "test2" "test3" ) )
echo ${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,
prompt> chmod u+x test.sh
prompt> ./test.sh
Further2
You can also use a shell script to create file by file.
Last modified: Fri Aug 25 09:54:01 JST 2017