0

The following code is the content of my main.tex.

The file a.tex is in the subdirectory tmp under the directory where main.tex is, that is to say: ./main.tex and ./tmp/a.tex.

The problem of my code is: \IfFileExists find the file ./tmp/a.tex. As there is no file ./a.tex, I think the typeset should be NO FILE. But the actual typeset is a.tex.

Is it a problem of my version of LaTex, MikTex, xelatex, auctex or any others?

PS: the subdirctory tmp is used to store those tmpt and aux files during compilation.

Code:

\documentclass{article}
\begin{document}
  \makeatletter
  \IfFileExists{a.tex}
  {\filename@parse{a.tex}\filename@area\filename@base.\filename@ext}
  {NO FILE}
  \makeatother
\end{document}
lyl
  • 2,727

1 Answers1

3

\IfFileExists tests "would \input work".

So as you say you have configured things so \input{a.tex} inputs a file, then the test is true.

It is not normally desirable (or possible) to know where in the input path the file is located. For example this test allows LaTeX to detect a missing package with \usepackage{mistake} but a working example such as \usepackage{longtable} works portably even though the absolute file path to longtable.sty is system dependent

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
David Carlisle
  • 757,742
  • Does that parentheses mean "it's not normally possible" or absolute "it's not possible"? ■ Side note, what about with LuaTeX powers? – user202729 Jul 14 '22 at 09:54
  • @user202729 well you could use kpsewhich (which you can use without --shell-escape i most configurations) to get the full path. – David Carlisle Jul 14 '22 at 13:10
  • For reference, OP asked a new question on how to get the absolute path → https://tex.stackexchange.com/q/650955/250119 – user202729 Jul 16 '22 at 10:37