TeX - LaTeX Asked by Stuart on May 25, 2021
I have a latex document like the below
documentclass{article}
usepackage{graphicx}
newcommand{plott}[1]{
begin{figure}
includegraphics{#1}
end{figure}
}
begin{document}
plott{"c:documentschart1.pdf"}
plott{"c:downloadschart2.pdf"}
end{document}
Now as well as chart1.pdf and chart2.pdf I have files chart1.csv and chart2.csv (which live in the same folders as these charts) which contains the data that went into make the chart.
I want to add logic to plott to copy these csvs to a third folder so that when I compile the document I get not only a document but also a folder containing all of the input data. Is it possible for latex to copy external files like this?
Using immediatewrite18
you can run an external program from a .tex file, so
newcommand{plott}[2][]{
immediatewrite18{cp #2 plott}
begin{figure}
includegraphics[#1]{#2}
end{figure}
}
(1) will include #2 in the output and
(2) will copy it into the plott
folder.
(1) You are using a Unix-like OS.
(2) A TeX Live distribution is installed on your system.
(3) A folder named plott
exists in the same directory of the main .tex
file. You can create it automatically with immediatewrite18{mkdir plott}
if you prefer.
I used two images from TeX Live, but you can change the path, of course, and use other files:
documentclass{article}
usepackage{graphicx}
newcommand{plott}[2][]{
immediatewrite18{cp #2 plott}
begin{figure}
includegraphics[#1]{#2}
end{figure}
}
begin{document}
plott{/usr/local/texlive/2020/texmf-dist/tex/latex/mwe/example-image-a.jpg}
plott{/usr/local/texlive/2020/texmf-dist/tex/latex/mwe/example-image-b.jpg}
end{document}
Correct answer by Ivan on May 25, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP