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}
14
  • 1
    add \input{a.tex} and then look which file it actually find. Jul 14, 2022 at 7:33
  • 3
    oh your edit explains it: such a build folder is added to the search path. Jul 14, 2022 at 7:37
  • 1
    you can't. latex has to find the auxiliary there. If you would remove it from the path neither the tableofcontents nor the reference would work anymore. (I never use such a build folder, imho it only make things more complicated.) Jul 14, 2022 at 7:43
  • 1
  • 1
    Latex3 has file_get_full_name
    – user202729
    Jul 14, 2022 at 7:56

1 Answer 1

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

3
  • 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, 2022 at 9:54
  • @user202729 well you could use kpsewhich (which you can use without --shell-escape i most configurations) to get the full path. Jul 14, 2022 at 13:10
  • For reference, OP asked a new question on how to get the absolute path → tex.stackexchange.com/q/650955/250119
    – user202729
    Jul 16, 2022 at 10:37

You must log in to answer this question.

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