1

I build out-of-source with

pdflatex -output-dir=/foo

One of my macros generates temporary files in the working directory.

\immediate\write18{bash -c "some-command >outputfile"}

I want it to save them to the output directory instead.

How can I make my macro aware of the value given to the -output-dir command-line option?

spraff
  • 1,501
  • There is no internal reference to the output directory, so you have to pass it via a macro: pdflatex -output-directory=./foo "\def\outputdir{./foo}\input{myfile}" and, in the document, you will have \outputdir available. – egreg Feb 02 '17 at 11:32
  • There really are no benefits to -output-dir it is much easier just to use the default output then move the generated files afterwards. – David Carlisle Feb 02 '17 at 11:34
  • @DavidCarlisle the benefit is that it doesn't add noise to my git repository – spraff Feb 02 '17 at 11:57
  • @spraff no the script or makefile or whatever you use to call pdflatex can move all generated files to whever you want to move them, at the end that is much easier to configure than having pdftex write some files in a non standard place and then having to configure other related programs to find them. – David Carlisle Feb 02 '17 at 11:59
  • @spraff Why don't you switch to a temporary directory before running pdflatex and setup TEXINPUTS to find the files in your git repository directory? – Schweinebacke Feb 02 '17 at 12:00
  • I've tried both of those approaches and had problems. I'm baffled that a) latex was not originally designed to work well with relative paths, and b) the latex community thinks this is normal or even sensible. I think you guys have just gotten used to latex's way of doing things -- that doesn't mean it's the right way. – spraff Feb 02 '17 at 12:08
  • It's profoundly self-evident to me that the behaviour of a compiler should not depend on where the output goes. If you can't see the sanity of that I don't see any point arguing about it. – spraff Feb 02 '17 at 12:09
  • 1
    @spraff I guess for the more experienced users its as much about trying to help people avoid 'pitfalls' as saying 'this is how it should be'. As already noted in an answer, TeX files written as output are also input: this at least in part is reflective of the history of TeX (a program designed in the 1970s and with a workflow informed largely by working at the console). At least as it's currently implemented, --output-dir doesn't make the output directory an input directory (as far a TeX is concerned, all accessible files are 'here'). That's before you get to other tools ... – Joseph Wright Feb 02 '17 at 13:52

1 Answers1

1

The problem is that in LaTeX the output directory is also an input directory (e.g. aux-file, toc etc) not only for pdflatex but also for other tools. In my experience it is in the long run much better not to use --output-dir. There is always one tool which doesn't find its input files. In git I simply use a sensible .gitignore file to avoid that the auxiliary files are committed.

Beside this: With luatex you can access the command line args as described in this answer: https://tex.stackexchange.com/a/18813/2388.

With pdflatex you can retrieve the --output-dir path in texlive with the help of the currfile package. It needs the --recorder-option.

\documentclass{article}
\usepackage[abspath]{currfile}
\begin{document}
\getabspath{test-utf8.log}
\theabsdir

\end{document}

enter image description here

Ulrike Fischer
  • 327,261