38

I have a directory structure like this:

project
   pdf
   src

My source file is located in src, and I'm trying to run pdflatex from the project directory using a command like this:

pdflatex -halt-on-error src/foo.tex -output-directory pdf

The compilation works, but foo.pdf ends up in project, rather than in pdf, which is obviously not what I want. I would assume that -output-directory would take care of this, but it doesn't seem to. What am I missing?

Koz Ross
  • 841
  • 2
  • 11
  • 14
  • 9
    I think the order is important here. The command is: latex [options] [file] [commands]. But -output-directory is not a command; it is an option. – jon Sep 23 '15 at 04:17
  • @jon Thanks - that actually solved it. – Koz Ross Sep 23 '15 at 12:21

2 Answers2

45

From the trusty man page for tex and pdftex (the command name):

tex [options] [&format] [file|\commands]

So the order is important: options go before the filename. Therefore, you should use:

pdflatex -halt-on-error -output-directory pdf src/foo.tex
jon
  • 22,325
  • 1
    Arg! I spent so much time on finding this! Thank you so much :) – ingomueller.net Feb 05 '17 at 13:29
  • 1
    @ingomueller.net -- Haha, always the worst! Glad you found it eventually! – jon Feb 05 '17 at 22:37
  • 1
    Is this something specific to pdflatex or is it common for *nix terminal tool options/files to be order sensitive? I feel like I usually interchange these without a problem. – haff Dec 04 '19 at 05:22
  • Note that on your machine, you might need to do -output-directory=pdf (i.e the equals sign instead of a space) – Anupam Mar 31 '21 at 12:18
4

I tried jon's solution, but I got an error regarding where the .log file to write to, so I found this:

pdflatex -aux-directory=<DIRECTORY OF LOG & AUX FILES> -output-directory=<DIRECTORY OF OUTPUT PDF FILE> FILENAME.tex

Worked like a charm!

Faris
  • 41
  • 1
    Note that -aux-directory is specific to MikTeX, and so won't work on MacTeX or TeXLive. https://tex.stackexchange.com/a/126897/211532 – Chris L. Barnes Apr 02 '20 at 09:29