[Tex/LaTex] Does \InputIfFileExists not work anymore

conditionals

For several years I've used the following in most LaTeX documents to input a macros file that lives in different folders on my Mac and my Linux machine:

\InputIfFileExists{/Mac/path/macros.tex}%
{\input{/Mac/path/macros.tex}}
{\input{/linux/path/macros.tex}}

It worked splendidly until I recently updated my TeX distribution. After updating, I got an error even with this MWE:

\documentclass{amsart}
\InputIfFileExists{/Mac/path/macros.tex}%
{\input{/Mac/path/macros.tex}}
{\input{/linux/path/macros.tex}}
\begin{document}
text
\end{document}

The error reads:

Command \first already defined. Or name \end... illegal, see p. 192 of the manual.

(Here \first is the first command defined in my file macros.tex.)

I see now that changing to \IfFileExists fixes everything, and I'm happy to do that. I'm curious, though, why does \InputIfFileExists throw this error?

A quick Something search for \InputIfFileExists didn't turn up much useful, just this old TeX.SE question.

Best Answer

TL;DR: You're actually looking for

\IfFileExists{/Mac/path/macros.tex}%
  {\input{/Mac/path/macros.tex}}
  {\input{/linux/path/macros.tex}}

The macro \InputIfFileExists{<file>}{<true>}{<false>} takes three arguments: the file to check the existence of, the <true> code to execute before inputting the file in case it is found and the <false> code to execute if the file doesn't exist. The way you're using it makes me think you're actually looking for \IfFileExists, which is why it works when you switch to that notation.

In your usage

\InputIfFileExists{/Mac/path/macros.tex}%
  {\input{/Mac/path/macros.tex}}
  {\input{/linux/path/macros.tex}}

\InputIfFileExists{<one>}{<two>}{<three>} checks for the existence of <one>. If it exists, it will necessarily execute \input{<one>}. So, if /Mac/path/macros.tex exists, you'll actually end up trying to \input{/Mac/path/macros.tex} twice.

The code \input{/linux/path/macros.tex} will be executed when the file <one> doesn't exist.


If the only reason for conditioning on the path stems from a choice of your operating system, you might be interested in looking at the ifplatform package. See Is there a macro telling which OS we're using?.