# Using relative paths for \include commands

I have a top-level latex file: `/thesis.tex`

And subfolders with chapters: `/chap1/ch1.tex`

In `thesis.tex` I use `\include` commands like so:

``````\include{chap1/ch1}
``````

And in `ch1.tex` I have more includes for the sections of the chapter:

``````\include{introduction}
``````

The `ch1.tex` file and all its included sections use relative paths as above (this was a standalone document that is now a chapter of the larger thesis.tex doc). I realize I have to fix all the paths in the include statements for `ch1.tex` and its sections to respect the main document directory as the root:

``````\include{chap1/introduction}
``````

Is there another way? Do I have to go through and change all the include and figure references in this way, or is there a way I can tell all such links to use relative paths within ch1?

-
You have `chap1` in one place, but then mention `ch1` in another. Also, a leading slash denotes an absolete path. Is your `thesis.tex` really in `/`? :-) –  Andrey Vihrov Aug 12 '11 at 17:04
I'm not sure but maybe the `import` package is what you need. –  Martin Scharrer Aug 12 '11 at 19:10

It is best to use relative paths, that way if you move the entire directory tree things will still work. So use

``````\newcommand*{\MyPath}{../thesis}%
\input{\MyPath/chap1/ch1.tex}
``````

So assuming that you have your files as:

``````<some path>/thesis/thesis.tex
<some path>/thesis/chap1/ch1.tex
<some path>/thesis/chap2/ch2.tex
``````

all the files are input relative to where they are with respect to the thesis directory.

Am pretty sure that you'll need to update all you `\input` statements, but this way it is flexible in case you decide to change the top level directory, or move it somewhere.

-

Adding this as a separate answer as I am not recommend using this method as it likely more work than it is worth, and that is to modify the input macro to do a search for a file over a list of directories and include that. This would have the advantage that you would not need to change each of the individual files, and allow you to move files around and still have them work.

If you decide to pursue this approach this question on How to iterate through the name of files in a folder might be helpful.

-