I have the root of my project in a directory called tex. This directory contains several subdirectories for different chapters:

$ tree
└── tex
    ├── root.tex
    └── sub
        ├── chapter.tex
        └── image.png

The files contain:








When I cd tex and then build the project via pdflatex root.tex everything works fine. However when I want to build the project from somewhere else via the option -output-directory it doesn't work. When I'm in the parent directory of tex and run pdflatex -output-directory tex root.tex it doesn't seem to find the image:

! Package pdftex.def Error: File `sub/image.png' not found.

However from man pdflatex I read:

-output-directory directory Write output files in directory instead of the current directory. Look up input files in directory first, the along the normal search path.

The second part suggests that directory is also used to search input files relative to it. sub/image.png exists in tex so I don't see why it can't find the image.

  • You should not add the ending of the image in \includegraphics. I'm not sure whether that is the problem, but it might at least be a problem.
    – Timm
    Mar 8, 2017 at 12:42
  • No it won't work. "the normal search path" is relative to the directory were you run pdflatex, only tex will added additionally. (I never use --output-directory, imho you get more problems than gains.) Mar 8, 2017 at 12:58
  • 1
    @UlrikeFischer The man page reads "Look up input files in directory first [...]", so I expect every path in my tex files to be relative to the specified directory. However it can't locate the image. If you say -output-directory is error prone, what would you use instead to build a latex project from another directory?
    – a_guest
    Mar 8, 2017 at 15:14
  • I would never build from another directory. Mar 8, 2017 at 15:36

1 Answer 1


Try including files with \input{../tex/sub/chapter.tex}, so go up one directory and then down the same one. This should assure that files are being sought relative to the main tex file instead of in the directory from where the pdflatex command is being run, who knows where that is...

Be sure to include the .tex extension! In my case that was a break point, it didn't work without extension (the way you normally include files).

More info on this topic at Input file folder.

PS If you work on a continuous integration server like Travis you can first change the working directory and then file includes work fine.

You must log in to answer this question.

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