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:
root.tex
\documentclass[a4paper,10pt]{scrartcl}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\begin{document}
\graphicspath{{sub/}}
\input{sub/chapter.tex}
\end{document}
sub/chapter.tex
\includegraphics{image.png}
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.
\includegraphics. I'm not sure whether that is the problem, but it might at least be a problem. – Timm Mar 08 '17 at 12:42texwill added additionally. (I never use --output-directory, imho you get more problems than gains.) – Ulrike Fischer Mar 08 '17 at 12:58-output-directoryis error prone, what would you use instead to build a latex project from another directory? – a_guest Mar 08 '17 at 15:14