In short:
Say the following is built using pdflatex -output-directory=tmp:
\documentclass{article}
\newwrite\fileHandle
\immediate\openout\fileHandle=outfile.csv
\immediate\write\fileHandle{hello world}
\closeout\fileHandle
\begin{document}
...
\end{document}
Now the file outfile.csv is in the tmp directory.
How can I, using LaTeX only, access the path (considering the -output-directory) of outfile.csv?
Motivation and end goal:
We're making something along the lines of knitr, just for python.
A file, let's call it outfile.csv, is made by LaTeX using \newwrite. Now, I want LaTeX to run a command via \write18 to process this file.
The problem is that if it's run with e.g. the -output-directory flag from pdflatex (or latexmk) the path to this file is not the same as the .tex file.
Consider the following:
\documentclass{article}
% Open a write filehandle
\newwrite\fileHandle
\immediate\openout\fileHandle=outfile.csv
%^ I need the absolute path (or a path relative to this .tex file) to outfile.csv
\newcommand\writeLine[1]{
\immediate\write\fileHandle{#1}
}
\newcommand\processCSV[1]{
% This now creates a file called pathtooutfile
% (Just a dummy operation. In production would be a call to a software
% that actually processed the file).
\immediate\write18{echo #1 > pathtooutfile}
}
\AtEndDocument{%
% Close CSV file
\closeout\fileHandle
% Now, process CSV file, but I need the path!
\def\pathToOutfile{}
% \pathToOutfile should contain the actual path to outfile.csv.
\processCSV{\pathToOutfile}
}
\begin{document}
% Write some arbitrary lines
\writeLine{comma,separated,value}
\writeLine{more,separated,value}
Hello!
\end{document}
Now, assume this file is run using pdflatex -output-directory=tmp/, then I want the file pathtooutfile (that is the \pathToOutfile command) to contain tmp/outfile.csv or /absolute/path/to/outfile.csv. Can this be achieved?
-output-directory-option? I use it by default withlatexmkand haven't had any problems. – Andreas Storvik Strauman Sep 25 '18 at 18:08pdftexcould make a macro like\jobnamebut\outdiror something. – Andreas Storvik Strauman Sep 25 '18 at 18:12pdflatexdo something? I can't imagine it's that much work to implement some form of communication of command line args? – Andreas Storvik Strauman Sep 25 '18 at 18:19pdflatex -output-directory=output '\def\OUTDIR{output/}\input{texfile}'. This would give you a TeX variable \OUTDIR with the information you need. A command line like this can be configured in latexmk. – John Collins Sep 27 '18 at 21:28-output-directorya lot too, and in the atom package for LaTeX, it's a setting that's easily settable! – Andreas Storvik Strauman Sep 28 '18 at 12:40