TeX - LaTeX Asked by raedma on January 22, 2021
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?
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}
You can do it with immediatewrite
instead of filecontents*
:
newwritetempfile
immediateopenouttempfile=datapath/script.gnuplot
immediatewritetempfile{set key autotitle columnhead;
set datafile separator ",";
plot 'datapath/data.csv' using 1:2 with lines}
immediatecloseouttempfile
Answered by Lars Kotthoff on January 22, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP