[Tex/LaTex] epslatex: relative path issue

gnuplotinputpathsportability

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….

Best Answer

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.

Related Question