# Path to External Files in Nested \input

## 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
\input{abbreviations.tex}


My main file is tester.tex:

% tester.tex
\documentclass{article}

\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 \inputs 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.

-
 I always use relative paths, so something like ../common/ (with as many ../ needed to get to a common point) assuming that you keep all the files at the same hierarchy depth. Otherwise you could define a \Path which has the full path and use \input{\Path/common/}. – Peter Grill Jun 17 '12 at 1:57 @PeterGrill, that's how I do it too---a macro containing relative path and pass it to the helper file. But if the files are in the same folder, shouldn't this make my life easier? – Ali Mehrizi Jun 17 '12 at 3:08 You can add the helper files to your local TeX common folder, e.g., ~/texmf/tex/latex/commons. See tex.stackexchange.com/a/1167/9626 by @JosephWright – Ali Mehrizi Jun 17 '12 at 5:22 @AliMehrizi, yes, I could, but if I didn't use Dropbox to sync my files across different computers or if Dropbox let me use a second folder to share. – Ali Mehrizi Jun 17 '12 at 5:23 @AliMehrizi, hmm, you only marginally mentioned that in your question, but now I see it. How about updating TEXINPUTS on your computers? See, e.g., tex.stackexchange.com/questions/6528/… – Ali Mehrizi Jun 17 '12 at 5:29

I personally try to avoid having to remember to change settings just because I switched computers. And since you are using Dropbox, I would recommend you set up your directory structure so that it is portable and does not require special settings:

 /Projects
common/
paper1/
paper2/


Don't keep files in the \Projetcs directory, but only in the sub-directories, and always use relative paths:

\newcommand*{\CommonPath}{../commom}%
\input{CommonPath/abbreviations.tex}%


Alternatively, you could adapt one of the solutions from How to detect and condition based on hostname to define a different root path depending on which machine you are on.

-
 in fact my directory structure is already similar to what you mentioned, but with the addition that my root also has a (for example) Proposals folder in which subfolder proposal1 also needs to call something from common. Your solution of giving path as a macro would work if I use \CommonPath in both the main file and the helper file. – Ali Mehrizi Jun 17 '12 at 23:57

As discussed in comments on the question, it seems a reasonable solution is to update the TEXINPUTS variable. You will have to update this variable on all of your computers. If you are using Dropbox or any sync software to keep your computers in sync, you should put the common folder in their path.

For WindEdt/Win7, Choose Variables tab from Options | Execution Modes. Under TEXINPUTS variable (or add it if it's not there) enter the absolute path to the folder. The screen shot below shows how when the common folder is called _Common.

-

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

http://www.ctan.org/pkg/import

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.

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:

\subimport{common}{cosmetix.tex}


No changes are necessary in cosmetix.tex`.

-