As mentioned in my last question i have problems with \input command and relative paths which getting wrong. I also tried the import-package but don't get this to work.

Till now I just have two shared preambles at different locations so each file can find it, but it is not so great when having to edit two files.

Is there may a function in tex that I give it a root folder and just let tex search inside this folder for a specific file (tikz_packages.tex for example) and so don't have to argue with the problem with the relative paths.

Or another option may be give him two paths. When he can't find the first path he should just use the second path, then the third path till he find it.

If I get it correct there is some command like this which first look in the first path, then the seconde and so on but only for graphics:


Is something like this possible in latex? Since my folder is not so big the searching should not take much time.

Many thanks.

  • With windows, right click the file, select Properties, then copy the Location (full path name). Then it won't matter where you start. Commented Aug 18, 2018 at 14:01
  • You could use \IfFileExists{<relative path 1>}{\input{<relative path 1>}}{\input{<relative path 2>}}, if there are two relative paths where your file could be. If there are more possibilities, you can probably nest these if ... then statements.
    – Max
    Commented Aug 18, 2018 at 14:49
  • Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Commented Sep 13, 2018 at 9:40
  • 1
    I finally used the soultion provided by @Max
    – SRel
    Commented Sep 13, 2018 at 9:42
  • @SRel Do you want me to write an answer?
    – Max
    Commented Sep 13, 2018 at 10:11

2 Answers 2


When I have files that should be found from various locations and from various other files I normally put them in the standard search path of my tex system(s).

Sometimes I put them in texmf-local, but for many projects this is often a project specific texmf tree. The files are then e.g. in


The tree is activated with (in a current texlive, miktex has an equivalent command) with

    tlmgr conf auxtrees add path/to/project-texmf

This avoids a lot hassle with relative input pathes, but it requires that the files have across all my texmf trees unique names. So generic names like "bibliography.bib" or "mypackages.tex" should better be avoided.


Okay I don't know excatly why but i made a MWE and try using the import-package again and it seems to work now oO.


folder structure:



\input{preamble/packages.tex}  %% works
\input{"C:/Users/xxx/Google Drive/WS_1819/path_test/preamble/packages.tex"} %% works
\input{images/image.tex}  %% don't work
\subimport{images/}{image.tex}  %% work




I am in tikz_packages

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .