[texhax] finding files

Susan Dittmar Susan.Dittmar at gmx.de
Thu Dec 17 16:17:28 CET 2009


> > > Another question: In c/c++ and html, if you have a path in an include
> > > statement the path is relative to the current file. In LaTeX the path is
> > > relative to the master file.  Are these correct observations?
> >
> > This is correct.
> 
> Thanks, though I wish TeX did it the other way.

Well, there are ways...

You already were told one version. I use a rather easy approach for a
project with several main files (choosing different parts of the overall
project), sometimes creating quite a deep nesting of \input'ed files and
subdirectories. Here it is.  Use it like \INPUT{filename} to input a file
in the current directory, and \INPUT[directory]{filename} to input a file
in a different directory, giving relative path from the current directory.

One possible problem is the macro \g at addto@macro. I do not remember out of
the top of my head where it comes from -- maybe it is rather low level TeX,
but maybe it is from one of the many packages I usually load. If you can't
find it, I'll search for you if you want. It appends something to an
existing macro (in a global definition).

I never worked with \graphicspath (something from the graphics/graphicx
package), so I just added a hint for it here. I really should get to
testing this part ;-)

% needs package ifthen; load it if not yet loaded:
\RequirePackage{ifthen}
% this is the current path:
\newcommand{\DIR}{.}
% save current path in this internal macro:
\newcommand{\@SAVEDIR}{}\let\@SAVEDIR\DIR
% Call to \input, with an optional argument giving the (relative)
% directory:
\newcommand{\INPUT}[2][]{%
    \begingroup%
	    \let\@SAVEDIR\DIR% must not be \global\let !
	    \ifthenelse{\equal{#1}{}}{}{\g at addto@macro{\DIR}{/#1}}%
		%   \graphicspath{{\DIR}}%
	    \expandafter\input{\DIR/#2}%
	    \global\let\DIR\@SAVEDIR%
    \endgroup%
}

Perhaps this helps...

	Susan

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://tug.org/pipermail/texhax/attachments/20091217/78dbd5e0/attachment.bin>


More information about the texhax mailing list