7

If I want to check first if a file is in the current dir and then look for it in the texmf tree I can do it like this:

\documentclass{article}
\begin{document}
\IfFileExists{./biblatex.def}
 {yes, current dir}
 {\IfFileExists{biblatex.def}
  {yes, texmf dir}{no}}      
\end{document}

Is there a way to do it the other way round? To first search the texmf tree and to use a local file only if this failed? (I'm asking more out of curiosity then need, I just thought about the search order in some code and realized that I have no idea how to exclude the current dir).

3
  • 2
    The search order is the one fixed in the (pseudo)environment variable TEXINPUTS that by default has first the current directory, then the personal tree (in ~/texmf or similar place, see TEXMFHOME), then the local tree (see TEXMFLOCAL) and then the main tree (see TEXMFMAIN), with variations according to the engine used.
    – egreg
    May 21, 2014 at 16:37
  • 2
    as egreg says you could put . at the other end of the search path, or if (as here) you know where it would be in texmf (if it is installed) you can use biblatex/biblatex.def which will find the standard place but not a def file in the current directory May 21, 2014 at 16:57
  • @DavidCarlisle: that could fail too (the current directory could have a subfolder biblatex) but nevertheless I think this is for the my case a perfect solution. Changing the search path is out of question as I only want to control the search path of some configuration files. May 22, 2014 at 16:29

2 Answers 2

4

as egreg says you could put . at the other end of the search path, or if (as here) you know where it would be in texmf (if it is installed) you can use biblatex/biblatex.def which will find the standard place but not a .def file in the current directory. Assuming that you don't have a biblatex directory locally, if you do use latex/biblatex/biblatex.def or whatever path fragment you need to distinguish the copies.

8

The program kpsewhich could be used. In TeX Live it belongs to the commands that can be used in restricted shell escape.

\documentclass{article}
\begin{document}
\newread\mypipe
\openin\mypipe="|kpsewhich -progname pdflatex -all biblatex.def"
\loop
  \ifeof\mypipe
  \else
    \begingroup
      \endlinechar=-1 % suppress space at line end
      \read\mypipe to \x
      \texttt{\x}\par
    \endgroup
\repeat
\end{document}

Option -all lists all matches for the given file name.

1
  • 1
    Interesting idea, but sadly a bit problematic in miktex: First pipes are not enabled by default, one has to use --enable-pipes. And second miktex doesn't output matches in the current dir as ./XXX like texlive but with the full path. This makes it difficult to test if the match is from the texmf or not. (miktex also outputs matches in the texmf-tree twice. No idea why looks like a bug to me.) May 22, 2014 at 16:33

You must log in to answer this question.

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