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

Ross Moore ross.moore at mq.edu.au
Fri Aug 31 23:00:43 CEST 2012

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.

> Themis

Hope this helps,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/macostex-archives/attachments/20120901/c01fdba2/attachment.html>

More information about the macostex-archives mailing list