[Tex/LaTex] pdflatex seems to ignore -output-directory

pdftex

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?

Best Answer

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