# epslatex: relative path issue

Please, how one could directly include epslatex graphics into main latex file, say main.tex? main.tex has its own template provided by a third party. I used this command within main.tex file to include the fig:

\def \Fig{figures/results1/figure}
...

\begin{figure*}[thpb]
\centerline{
\subfigure[]{\bimOther{\input{\Fig}} }
...
}
\end{figure*}


where figure is first generated under gnuplot as follows

set terminal epslatex 8 color colortext
set output '/tmp/figure.tex'
...
set macros
filename = "'/tmp/data/signal.dat'"
plot @filename u 1:2 w l ls 1  linecolor rgb "red" notitle


The issue is that when using \input command, the main latex file (main.tex) will look to the path specified by gnuplot, and not that specified in its core, i.e. figures/results1/ in our example. This does not allow for portability. Assume that we have different successive trial results, i.e, figure_1, ...., figure_n. How one could include them, after noticing that the /tmp file would be reverted after each trial?

One solution would be to create for each trial a separate gnuplot code, which is clearly aberrant!

Any help please? I spend more than one day trying to fix this issue....

• Welcome to TeX.sx! – Peter Jansson Apr 17 '13 at 19:47
• Are you saying that the gnuplot script creates a file in /tmp and leaves it there? That's unexpected. Why not create the file in the same directory as the script? – Matthew Leingang Apr 17 '13 at 20:03
• gnuplot script creates both figure.tex and figure.eps files in /tmp folder. It does not leave them there. I copy the generated files into subdirectory figures/results1/ relative to directoty containing main.tex. – Courier Apr 18 '13 at 9:47

# Directory structure

Assume the following directory structure

main.tex
figures/
-- results1/
-- -- figure.gnuplot


# File contents

The two document files yield the following content

figure.gnuplot:

#!/usr/bin/env gnuplot

set term epslatex color
set output '/tmp/temp.tex'

# BEGIN plotting commands
plot sin(x)
# END plotting commands

set output # Closes the temporary output files.
!sed 's|includegraphics{/tmp/temp}|includegraphics{figures/results1/figure}|' < /tmp/temp.tex > figure.tex
!epstopdf /tmp/temp.eps --outfile='figure.pdf'


main.tex:

\documentclass{scrartcl}
\usepackage{graphicx}
\begin{document}

\input{figures/results1/figure.tex}

\end{document}


# Instructions to reproduce

Go to the directory figures/results1/ and execute

gnuplot figure.gnuplot


Two files will appear: figure.tex and figure.pdf.

Now go back to the root folder of your document (where main.tex is) and compile main.tex using any engine, that can handle PDF files (not latex, but pdflatex, xelatex or lualatex).

DONE!

# Remarks

Using this method you get a PDF file of your figure instead of an EPS, which needs to be converted to PDF.

On the other hand, you need to change all the filenames (maybe directories as well) for every new plot.

An alternative replacing the file using bash script:

#/bin/bash

MY_PATH=$(pwd) subpath() { echo "$1" | rev | cut -d"/" -f1-$2 | rev } BASE=$(subpath $MY_PATH 2) for f in *.tex do echo "fixing gnuplot tex file -$f"
NAME=$(basename$f .tex)
mv $f$f.back
sed "s|${NAME}|${BASE}/${NAME}|"$f.back > $f rm$f.back
done