[Tex/LaTex] Path to External Files in Nested \input



I usually load a helping TeX file that contains my customizations, e.g., usual packages, corporate standard colors, and macros for abbreviations. I want my helping file to also load another external file that is in the same folder. I certainly want to avoid giving the explicit path to the second external file every time.


Let's say the helping file is cosmetix.tex, which loads abbreviations.tex. abbreviations.tex is in the same folder as cosmetix.tex and both are in a folder called common:

% cosmetix.tex
% ... some customization
% load abbreviations

My main file is tester.tex:

% tester.tex

% load cosmetix

Dummy text.

This leads to the following error: LaTeX error: File `abbreviations.tex' not found.


How can I use nested \inputs with files in different folders without (i) converting my code to a package and (ii) using absolute paths?


Although this question is pretty generic, it is also a follow up to my previous question: Reproducing an official letterhead. I have reproduced my institute's letterhead, which in turn needs to load the logo. I load the letterhead using the \input mechanism. I know this is not the most elegant way, but until I get time to convert this to a package (or read scrlttr2 documentation to convert my letterhead to an option file), this is a solution that reasonably works for me.

As I mentioned above, I can't use absolute paths because I'm using multiple computers with different operating systems, and therefore, the root of the directory tree is different for each computer.

Best Answer

Use the package import, which does exactly one thing: to solve this problem. See


Basically the package defines two commands: \import and \subimport. \import needs an absolute path, while subimport needs a relative path. They both look at the current folder and TEXINPUTS first. If you want to avoid checking TEXINPUTS, use the starred version.


For your case, the only line you need to change is to update \input to \subimport (and of course, add \usepackage{import}). That is, you would need to write:


No changes are necessary in cosmetix.tex.

Related Question