How can I get the current path inside an included standalone file?
1. Theoretical Example:
let's assume the following directory structure:
main.tex
img/
|-standalonefile.tex
|-data
standalonefile.tex:
\documentclass{standalone}
\begin{document}
\somecommand{data}
\end{document}
main.tex:
\documentclass{article}
\usepackage{standalone}
\begin{document}
\includestandalone{img/standalonefile}
\end{document}
Now standalonefile.tex
compiles, but main.tex
can't find data
.
I couldn't find a way to use path from \includestandalone
somehow inside standalonefile.tex
.
2. Practical example with pgfplots
(MWE) (I'm looking for a general solution)
directory structure:
main.tex
plots/
|- plot1/
|- plot1.tex
|- data.csv
main.tex
\documentclass{article}
\usepackage[subpreambles]{standalone}
\begin{document}
\includestandalone{plots/plot1/plot1}
\end{document}
plot1.tex
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table [x=x, y=y, col sep=semicolon]{data.csv};
\end{axis}
\end{tikzpicture}
\end{document}
data.csv
x;y
0;0
1;1
Now plot1.tex
compiles fine, but with main.tex
the data.csv
can't be found.
Ideas for a solution
- a command like
\mystandalonedir
that would return- the relative path to the main file, if included with
\includestandalone
- nothing, if not included
- the relative path to the main file, if included with
- change the base dir somehow with the
\includestandalone
- (or something else ;) )
\input
an\include
commands. But I'll take another look at it.\includestandalone
. If your question gets closed, I'll vote to reopen it. Martin Scharrer is the author of thestandalone
package and a moderator on the site. If he sees your question, I'm sure he'll come up with some solution.docmute
+import
packages in the main file you can use\subimport{img/}{standalonefile}
. Note that in this case the preamble of the nested file is lost (among another problems like references) but you can\input
a common preamble in both files.