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?



  miktex,    % 
  subfolder, % generated graphs in a ”gnuplottex” subfolder
  cleanup,   % Delete the .gnuplot files after conversion



% This is the data file to be plotted from

% This is the gnuplot script I would like to use the value of \datapath in
set key autotitle columnhead
set datafile separator "," # for csv-file
plot './ZZZ/data.csv' using 1:2 with lines


  • Your MWE works fine for me on Linux with pdflatex. – Lars Kotthoff Feb 15 '18 at 17:22
  • Sure, it works great, no question. But I want to be able to use plot \datapath'/data.csv' using 1:2 with lines instead of plot './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
  • See stackoverflow.com/q/12328603/923955 I guess you need to do \renewcommand{\gnuplotexe}{gnuplot -e "dirname=./ZZZ"} and use dirname in the script file. I don't know about quoting, though, perhaps you don't need them. – egreg Feb 15 '18 at 18:25

You can do it with \immediate\write instead of filecontents*:


\immediate\write\tempfile{set key autotitle columnhead; 
set datafile separator ","; 
plot '\datapath/data.csv' using 1:2 with lines}
  • Thanks, but the data files and the gnuplot script exist as files at a defined location. filecontents* was only used here to provide a complete MWE. – raedma Feb 15 '18 at 17:56
  • I guess then I don't understand your question. How are you going to pass the location of the data if you don't write it to the script file? – Lars Kotthoff Feb 15 '18 at 17:58
  • That exactly is my question. In this post the value of the line color is stored in a macro and expanded into a variable s inside the gnuplot script without writing it. So I guess it is possible. I just wasn't able to modify the approach to my problem. I always get the error that the files cannot be found. – raedma Feb 15 '18 at 18:02
  • This would require modifying the gnuplottex source code to read and replace a macro in the file. – Lars Kotthoff Feb 15 '18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.