[OS X TeX] Can latex read the name of the folder that contains my latex file?

Alain Schremmer schremmer.alain at gmail.com
Sat Sep 1 01:18:06 CEST 2012

On Aug 31, 2012, at 5:00 PM, Ross Moore wrote:

> Sent from my iPad
> On 01/09/2012, at 0:24, Themis Matsoukas <tmatsoukas at me.com> wrote:
>>      \input{../problem-dbase/problemXYZ/problem.tex}
>> All of this miraculously works, but what I would like to do now is  
>> access from inside problem.tex the name of its enclosing folder and  
>> then pass it to \graphicspath, so that instead of hard-coding the  
>> name "problemXYZ" in the \graphicspath this would be set  
>> automatically in each latex run. I am probably asking for too much  
>> of a miracle...
> No, not too much, if you do a bit of work.
> Use TeX's  \write18  to run a shell command, such as
>      cat `pwd`> pwd.txt
> giving you the name of the directory written inside a simple text  
> file.
> Then use TeX's  \openin  to create a file stream to input the  
> contents of that file.
> Now with TeX's  \read  primitive, you can get the contents of this 1- 
> line file stored as the expansion of a macro. (Then use  \closein   
> to free-up the file stream cleanly.)
> Finally, if you only want the name, not the full path, then you can  
> define a TeX macro that extracts what occurs after the directory  
> delimiter / .  You'll have to run this repeatedly, to extract just  
> the final bit, as TeX's pattern matching occurs on the first instance.
> (or use  dirname   instead of  pwd )
> Consult the TeXbook to learn how to do these non-LaTeX actions.
> Also, you may need to invoke LaTeX with the  -shell-escape  option,  
> if that is not automatically enabled. Herb can comment on this.
> Maybe there is a package that helps make such tasks easier.
> Dunno, as I always write my own coding from scratch, using the  
> primitives.

I have not studied the details of the issue but this reminds me of a  
problem I had which was solved with an earlier version of <http://mirror.hmc.edu/ctan/macros/latex/contrib/fink/fink.pdf 

Hope I am not too offbase

More information about the macostex-archives mailing list