Problem
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.
Example
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
\input{abbreviations.tex}
My main file is tester.tex
:
% tester.tex
\documentclass{article}
% load cosmetix
\input{common/cosmetix.tex}
\begin{document}
Dummy text.
\end{document}
This leads to the following error: LaTeX error: File `abbreviations.tex' not found.
Question
How can I use nested \input
s with files in different folders without (i) converting my code to a package and (ii) using absolute paths?
Context
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. SeeBasically the package defines two commands:
\import
and\subimport
.\import
needs an absolute path, whilesubimport
needs a relative path. They both look at the current folder andTEXINPUTS
first. If you want to avoid checkingTEXINPUTS
, use the starred version.Example
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
.