How to make "\input" in a "\include"-d file use the correct current path?

The FAQ suggests the packages import or chapterfolder:

https://texfaq.org/FAQ-docotherdir


It's not so easy to make \input work from a relative directory as the TeX macro layer doesn't know where your sub.tex` is, it could be anywhere in the TEXINPUTS path. But you may use the same feature if your TEXINPUTS setting (environment variable or texmf.cnf setting) includes .// then Tex will recursively search all subdirectories for each file, so as long as your filenames are distinct it doesn't matter which subdirectory they are in.

so

$ latex test
This is pdfTeX, Version 3.1415926-1.40.11 (Web2C 2010)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, ancientgreek, ibycus, arabic, armenian
, basque....

! LaTeX Error: File `hmm.tex' not found.

but setting the path:

$ TEXINPUTS=";.//" latex test
This is pdfTeX, Version 3.1415926-1.40.11 (Web2C 2010)
 restricted \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2009/09/24>
Babel <v3.8l> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2009-06-19, ngerman-x-2009-06-19, ancientgreek, ibycus, arabic, armenian
, basque,...
(./sub1/hmm.tex

here the file hmm.tex has been found in the subdirectory.

test.tex here is just

 \input{hmm}

Here TEXINPUTS has been changed on the command line just for this command (bash syntax) that may or may not be available depending on your system but you will be able to set TEXINPUTS somewhere.


If you only have files with different name in all your subfolders, I would suggest getting rid of the subfolder calls in your main document and only calling \input{file} while adding the relevant folders to the environment variable TEXINPUTS like:

TEXINPUTS=".:./sub1:./sub2:./sub3:$TEXINPUTS" latex main.tex

you can include path for graphics included with \includegraphics{} as well as it also plays the role of the \graphicspath{} command.

If you have two files with the same name in two different subfolders, then it might be a bit more tricky.