The minimal example
If I have a directory containing my main LaTeX source file and it uses \input to incorporate some data in another file, I can use a relative pathname. E.g., with these files:
~/tmp/relative-paths-mwe/mwe.tex
\documentclass{article} \begin{document} \input{./src/ex.tex} \end{document} ~/tmp/relative-paths-mwe/src/ex.tex
some input Now, from the command line, if I'm in ~/tmp/relative-paths-mwe, I can build as expected:
~/tmp/relative-paths-mwe$ pdflatex mwe.tex This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013) ... Output written on mwe.pdf (1 page, 12192 bytes). Transcript written on mwe.log. However, if I'm in the parent directory, ~/tmp/, I can't build because the relative paths (as I understand it, and based on the symptoms) are resolved with respect to the current working directory rather than the file where the \input appears:
~/tmp$ pdflatex relative-paths-mwe/mwe.tex ...! LaTeX Error: File `./src/ex.tex' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: tex) Enter file name: Is there a way to specify the paths in such a way that I can refer to other content using relative paths, but still be able to call pdflatex from arbitrary directories?
The non-minimal example
I think that the above is a complete minimal working example for which if I get an answer, I can solve my actual problem. In case there's a difference that someone can predict in advance, or anyone is wondering why I'm trying to do something unusual, a bit of explanation is in order. I've got a source repository for a project, and it has a subdirectory for a LaTeX document, and a subdirectory for an Apache Maven project. The document had been using the listings environment to include source code from the Maven project using relative paths along the lines of
../mavenproject/src/more-path/code.extension There's a LaTeX Maven Mojo that's supposed to be able to compile LaTeX documents, so I decided to try moving the document directory to mavenproject/src/latex/mydoc. Now, I can build the document manually from mavenproject/src/latex/mydoc if I change the relative paths to
../../more-path/code.extension but I can't build with those paths using the LaTeX Mojo, because it's run from the mavenproject directory, which is several directories up from the document root. I can obviously adjust to handle that, but then I can't build from mydoc anymore. I'm hoping that there's a way to specify the pathnames relative to the including document, or to specify the a document root, and write paths relative to that. I hope that a solution to the minimal example above will transfer over to my actual situation.
TEXINPUTS.pdflatex(latex, etc.) directory, rather than the directory containing the file? That seems to break the concept of a relative pathname. Shouldn't we expect\include{./foo.tex}in a filebar.texto look forfoo.texin the same directory asbar.tex?pdflatexprocess. If you do a complex C compilation, you can move from a directory to another and use relative paths, but only when compiling one of the.cfiles. Then a linking phase takes place, but there's no analogy with linking in TeX: everything is obtained in a unique run. One could modify\input(not\include, I'm afraid) to use a path relative to the file it's called from.$HOME(only have one include file), since that is searched by default by Latex. Otherwise, as others said, use $TEXINPUTS