I want to access and plot the same data from different LaTeX documents (a paper and a beamer presentation) using gnuplottex
. The data and the gnuplot script is stored at some individual position relative to the two documents. To re-use as much code as possible, I would like to define the relative path to the data in each document in a macro, here \datapath
.
My question is: How can I pass the value of this command to the gnuplot script? I would basically like to use the following in my MWE:
plot \datapath'/data.csv' using 1:2 with lines
I did find this thread. However I was unable to modify it to my needs. Can someone help me, please?
MWE
\documentclass{article}
\usepackage[latin1]{inputenx}
\usepackage{filecontents}
\usepackage[
miktex, %
subfolder, % generated graphs in a ”gnuplottex” subfolder
cleanup, % Delete the .gnuplot files after conversion
]{gnuplottex}
\newcommand{\datapath}{./ZZZ}
\begin{document}
% This is the data file to be plotted from
\begin{filecontents*}{\datapath/data.csv}
Col1,Col2
0,0
1,1
\end{filecontents*}
% This is the gnuplot script I would like to use the value of \datapath in
\begin{filecontents*}{\datapath/script.gnuplot}
set key autotitle columnhead
set datafile separator "," # for csv-file
plot './ZZZ/data.csv' using 1:2 with lines
\end{filecontents*}
\begin{figure}[htbp]
\centering
\gnuplotloadfile[terminal=cairolatex]{\datapath/script.gnuplot}
\end{figure}
\end{document}
plot \datapath'/data.csv' using 1:2 with lines
instead ofplot './ZZZ/data.csv' using 1:2 with lines
. But how can I pass and expand the value of\datapath
inside the gnuplot document or store the content of\datapath
in a variable inside the gnuplot script as done in the post I linked to in my question? – raedma Feb 15 '18 at 17:30\renewcommand{\gnuplotexe}{gnuplot -e "dirname=./ZZZ"}
and usedirname
in the script file. I don't know about quoting, though, perhaps you don't need them. – egreg Feb 15 '18 at 18:25