Here's the path where my tex file stands :


I also have one import file here :


However for security purpose I also include it here locally :


When I input it in my tex file, e.g. :


I noticed the local file is used over the remote one (latex personal directory)

My question is : how can I manage the following statement ?

  • If the distant file exists then include it over the local one.
  • If the distant file is none then include the local one.

The file search strategy of TeX can be configured, see texmf.cnf for TeX Live. Example for pdflatex:

TEXINPUTS.pdflatex      = .;$TEXMF/tex/{latex,generic,}//

And TEXMF is set by default as:


Or shorter, first the current directory is used, then the home texmf tree, the local texmf tree and at last the distribution tree.

Of course the search order can be changed by changing or overwriting the entries, e.g.


Then first the directory /my/documents/ is searched, then the normal search of the configured TEXINPUT applies because of the trailing colon.

However, the search is directory based, The search order cannot be changed for single files. In your case you have both the main TeX file foo.tex and the other file bar.tex in the same directory /home/me/documents/. The first file should be found there, but the latter should be first found somewhere else:


Thus changing the search order will not help, because foo.tex should not be found first somewhere else, too.

However, in this case, there is a difference in the parent directory of the file that can be used here to differentiate between the two versions:

  % File personal/bar.tex exists and is read
  % File personal/bar.tex is not found, try bar.tex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.