I have a directory structure like this:


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?

  • 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, 2015 at 4:17
  • @jon Thanks - that actually solved it.
    – Koz Ross
    Sep 23, 2015 at 12:21

2 Answers 2


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
  • 1
    Arg! I spent so much time on finding this! Thank you so much :) Feb 5, 2017 at 13:29
  • 1
    @ingomueller.net -- Haha, always the worst! Glad you found it eventually!
    – jon
    Feb 5, 2017 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 4, 2019 at 5: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, 2021 at 12:18

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!


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .