# relative paths don't work without absolute path

I'm trying to automate pdftex to generate docs. I'm in some kind of hell where TeX assumes people want to use absolute paths or the working directory.

I have the file main.tex. It imports several files from subdirectories:

``````\include{one/one}
\include{two/two}
``````

I invoke `pdftex /path/to/main.tex` from another directory and tex consistently tries to import relative to the directory 'pdftex' was invoked from rather than the directory of main.tex.

I can't predict what the absolute paths will be on different machines to use those. The 'import' package would only work if I had yet another TeX file in the current working directory that knew what the absolute path to main.tex would be. Is there any way to have main.tex use relative paths without having to include absolute paths in a TeX file? I just want the file to use paths that are relative to where that file is, not relative to the working directory or the phase of the moon.

(As a minor blessing, at least none of those included TeX files needs to include other files or graphics, because that'd be its own problem.)

-

Note you should not include the `.tex` extension when using `\include` Unlike `\input` using `.tex` is not the same as using the default, it will find the same tex file but generate a different aux file `one.tex.aux` (if the file system allows that) rather than `one.aux`.

It normally works best to just use local file names rather than paths.

Just have

``````\include{one}
\include{two}
``````

then use a command line of

``````TEXINPUTS=/path/to//: pdftex main
``````

(or equivalent in other command lines, the above works in bash)

Setting TEXINPUTS as above sets the TeX input path to be `/path/to` and all its sub-directories (the trailing `//` and then the standard search path (because of the final `:`) then `main` on the command line finds `/path/to/main.tex`, `\include{one}` finds `/path/to/main/one/one.tex` and , `\include{two}` finds `/path/to/main/two/two.tex` irrespective of the current directory in which the command is run.

-
Thanks for catching the .tex mistake, I've edited. TEXINPUTS looks like a pretty painless workaround. – pushcx Aug 1 '12 at 0:21
I got this to work for me as: TEXINPUTS=.:input//:/usr/share/texmf-texlive/tex// pdflatex main.tex And all my includes had to be `\include{one}` without a directory. So as long as no two files have the same name and you don't mind crudding up the working directory with .aux files, this just barely works. Yay, TeX. – pushcx Aug 5 '12 at 19:38

You can try one of the package mentioned in the FAQ http://www.tex.ac.uk/cgi-bin/texfaq2html?label=docotherdir.

But my advice is: Don't start pdflatex from another directory. Write your script or whatever you are doing to "automate" the generation of your docs so that it switches to the directory of the main file first. You obviously know the path from your current directory to the main file, so why don't you use it for a `cd` first?

-
I don't want the script to `cd` because that's added state for it to maintain. I'm checking out the FAQ now, thanks - I certainly didn't find it in my searches. – pushcx Aug 1 '12 at 0:23