Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Change working directory

2,094 views
Skip to first unread message

C.G.Senthilkumar.

unread,
Feb 2, 2007, 5:04:05 PM2/2/07
to

Hi,

Is there a way I could ask latex to change current working directory?
The following is my scenario:

I have a project report written in latex and it uses the project results
from a sub-directory as shown below.
$ pwd
HOME/project/report
$
$ grep input article.tex
\input{../src/data/results.tex}
$
$ latex article.tex

Now, I want to include that report, amongst others, in my dissertation.
$ cd ../../dissertation
$ grep article dissertation.tex
\input{../../project/article.tex}
$ latex dissertation.tex

Now latex can't find my ../src/data/results.tex that is \input{} from
article.tex file because the current working directory is
HOME/dissertation and there is no sub directory called src.

Thanks in advance.
Senthil.

--
Today's fortune:
From 0 to "what seems to be the problem officer" in 8.3 seconds.
-- Ad for the new VW Corrado

Heiko Oberdiek

unread,
Feb 2, 2007, 6:39:36 PM2/2/07
to
"C.G.Senthilkumar." <chee...@pc45.cs.ucdavis.edu> wrote:

> Is there a way I could ask latex to change current working directory?

No (not even with \write18, because it would only change the working
directory of the subprocess).

> The following is my scenario:
>
> I have a project report written in latex and it uses the project results
> from a sub-directory as shown below.
> $ pwd
> HOME/project/report
> $
> $ grep input article.tex
> \input{../src/data/results.tex}
> $
> $ latex article.tex
>
> Now, I want to include that report, amongst others, in my dissertation.
> $ cd ../../dissertation
> $ grep article dissertation.tex
> \input{../../project/article.tex}
> $ latex dissertation.tex
>
> Now latex can't find my ../src/data/results.tex that is \input{} from
> article.tex file because the current working directory is
> HOME/dissertation and there is no sub directory called src.

* You can use the environment variable TEXINPUTS, e.g.
export TEXINPUTS=.:~/project/report:

* \input@path could be defined, e.g.
\makeatletter
\providecommand{\input@path}{}
\renewcommand*{\input@path}{\input@path{../../project/}}
\makeatother

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Boris Veytsman

unread,
Feb 2, 2007, 6:41:01 PM2/2/07
to chee...@cs.ucdavis.edu
CGS> From: "C.G.Senthilkumar." <chee...@pc45.cs.ucdavis.edu>
CGS> Date: Fri, 2 Feb 2007 22:04:05 +0000 (UTC)

CGS> I have a project report written in latex and it uses the project results
CGS> from a sub-directory as shown below.
CGS> $ pwd
CGS> HOME/project/report
CGS> $
CGS> $ grep input article.tex
CGS> \input{../src/data/results.tex}
CGS> $
CGS> $ latex article.tex

CGS> Now, I want to include that report, amongst others, in my dissertation.
CGS> $ cd ../../dissertation
CGS> $ grep article dissertation.tex
CGS> \input{../../project/article.tex}
CGS> $ latex dissertation.tex

The simplest way is to say in dissertation.tex something like
\def\datadir{../project/src/data}

and in article.tex
\makeatletter
\ifx\datadir\@undefined\def\datadir{../../src/data}\fi
\makeatother

Then you can use \input{\datadir/results.tex}, and \datadir will
expand to the proper directory.

--
Good luck

-Boris

The turtle lives 'twixt plated decks
Which practically conceal its sex.
I think it clever of the turtle
In such a fix to be so fertile.
-- Ogden Nash

Gernot Hassenpflug

unread,
Feb 3, 2007, 12:48:37 AM2/3/07
to
>>>>> "Heiko" == Heiko Oberdiek <ober...@uni-freiburg.de> writes:

Heiko> "C.G.Senthilkumar." <chee...@pc45.cs.ucdavis.edu> wrote:
>> Is there a way I could ask latex to change current working
>> directory?

Heiko> No (not even with \write18, because it would only change
Heiko> the working directory of the subprocess).

>> The following is my scenario:
>>
>> I have a project report written in latex and it uses the
>> project results from a sub-directory as shown below. $ pwd
>> HOME/project/report $ $ grep input article.tex
>> \input{../src/data/results.tex} $ $ latex article.tex
>>
>> Now, I want to include that report, amongst others, in my
>> dissertation. $ cd ../../dissertation $ grep article
>> dissertation.tex \input{../../project/article.tex} $ latex
>> dissertation.tex
>>
>> Now latex can't find my ../src/data/results.tex that is
>> \input{} from article.tex file because the current working
>> directory is HOME/dissertation and there is no sub directory
>> called src.

Heiko> * You can use the environment variable TEXINPUTS, e.g.
Heiko> export TEXINPUTS=.:~/project/report:

Heiko> * \input@path could be defined, e.g. \makeatletter
Heiko> \providecommand{\input@path}{}
Heiko> \renewcommand*{\input@path}{\input@path{../../project/}}
Heiko> \makeatother

Heiko gave a way for tex to become aware of the path globally, and
Boris gave a useful way for tex to expand a pathname in the latex
document.

I would suggest another way also: you could create symbolic links in a
directory that is already on the tex path (e.e., current directory) to
all the non-local files you want to include. I always do that instead
of copying files since then I only have to modify the original files
(generated .eps figures, for example) and it also allows me to keep a
local name for the distant files (often shorter or names more
compatible with tex demands, such as no active characters in the
names).
--
G Hassenpflug

0 new messages