Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

\file_if_exist:nTF searches the TeX/LaTeX input path for the filename given as an argument. Now I am looking for a way to get hands on the complete path to the file, in case it was found. From the LaTeX2e command \IfFileExists I know that it stores the path to the file in the macro \@filef@und. I wonder if there is a LaTeX3 counterpart to \@filef@und. If not, I kindly ask the LaTeX3 developers to provide a such, because it may come in handy in certain programming tasks.

share|improve this question
    
Currently, there is no public version of this information: the method of using \@filef@und is clearly an abuse of \IfFileExist. I wonder if you can give a good example where the path is needed outside of the file loading routine? –  Joseph Wright Apr 12 '11 at 7:40
    
@Joseph: First of all, \IfFileExist and \file_if_exist:nTF are not file loading but file locating routines. Hence, it is up to the user (or package author) to decide what to do with the information gained. One possible use is related to the latex->dvips->ps2pdf workflow. A LaTeX package may contain raw Postscript file reading/writing operators in its code. LaTeX and Ghostscript don't necessarily evaluate the same search paths and the Ghostscript search path cannot be set from within the LaTeX document. (to be continued) –  AlexG Apr 12 '11 at 8:32
    
@Joseph: (continued) For convenience, in order to unburden the potential package user from manipulating Ghostscript search paths, it would be nice if the LaTeX search path provided by the user in his document could be used to find a file. The path to the file could then be inserted into the Postscript code by the LaTeX package. –  AlexG Apr 12 '11 at 8:33
1  
@Alexander: Interesting example, which is outside of my range of experience. I'll see what makes most sense in terms of a structured interface here. Perhaps \file_get_path:nN, returning \q_no_value if the file is not found? –  Joseph Wright Apr 12 '11 at 14:29
    
@Joseph: This would be really great. Thank you for taking this into consideration! –  AlexG Apr 12 '11 at 14:36
show 2 more comments

1 Answer

up vote 7 down vote accepted

I have just added to the development version of expl3 a function \file_add_path:nN:

\file_add_path:nN { <file name> } <tl var>

which will result in the (storage macro) containing either:

  1. The fully-qualified file name, if the file is found on the LaTeX path or
  2. Nothing at all (i.e. an empty macro) if the file is not found

I've also adjusted the other file code to make use of this. The idea is that you can save doing the file test if you know you'll need to use the path, by doing

\file_add_path:nN { filename } \l_my_tl
\tl_if_empty:NTF \l_my_tl
  { No-file-found-code }
  { File-found-code }

but unlike LaTeX2e this is documented and therefore officially-supported.

This will go to CTAN with the next update: let me know if this is urgent (I do the releases 'from time to time').

share|improve this answer
    
Perfect! Thank you a lot! There is no rush on updating, though. I have just another suggestion regarding the LaTeX search path. It would be nice to have two variants of the existing \file_path_include:n macro, one that adds a new path on the left and another one to add it on the right side of the existing search path, in order to have control over the priority. It's only for completeness and not essential at all. Thank you once more. –  AlexG Apr 21 '11 at 7:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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