# How to work with command \input{filename.tex}?

I'm writing a book with lots of chapters using a command \input{filename.tex} for each chapter in the book book.tex. How to make it not to have book.tex and all filename.tex in the same directory? Is it possible to have directory book.tex with subdirectories filename.tex?

-
\input{subdirectory/filename}? – Paul Gessler Aug 9 '14 at 19:41
It might help you: tex.stackexchange.com/a/147503/19356 – kiss my armpit Aug 9 '14 at 20:14

\newcommand\subdir{mysubdir}

...
\input{\subdir/file}


Then you have to change only one name if the subdir changes. However, using \include instead of \input makes more sense if you are using chapters.

-
more on when to use \input and when to use \include can be found here. – greyshade Aug 9 '14 at 19:46
I don't know how to do it according to your advice. Let say I have a directory named Work. There is book.tex, file1.tex, file2.tex and file3.tex files in the Work. I would like to have book.tex which will include file1.tex, file2.tex and file3.tex I put in preambule \newcommand\subdir{book} and then \include{\subdir/file1} \include{\subdir/file2} \include{\subdir/file3} It's not working in this way. – Laura Aug 9 '14 at 20:24
@Jane -- If all .tex files are in the same directory, then you only need to use \include{file1}, \include{file2} and so on. Herbert's \subdir command suggestion was for a sub-directory under (in this case) the Work directory. – jon Aug 9 '14 at 20:41
Jon, I don't want to have it like this, because I have so many outputs in one directory and it's so confusing. I want directory Work which will include Book.tex and the Book.tex will include file1.tex, file2.tex and file3.tex, but I cannot find the way how to make it like this. – Laura Aug 9 '14 at 20:45
@Jane -- Then you need to create sub-directories in the Work directory; e.g., in Work, you have the following directories: chap01, which includes ch01.tex, and chap02, which includes ch02.tex. Then Book.tex would have \include{chap01/ch01} and \include{chap02/ch02}. Obviously under normal circumstances a single command like \subdir cannot point to multiple directories.... – jon Aug 9 '14 at 21:19

You need a folder Work/Book with the chapter .tex files in there in order for this to work.

Alternatively, you can give a path for each \include, relative to the path of yout main .tex file, directly in the curly braces so you don't need the \subdir definition. Just remember to use / instead of \ to concatenate folders in the path.

-

Assuming a directory struture like the following (where directory Work contains the following sub-directories: Chap01 and Chap02, which each have a .tex file of their own):

Work/
|-Book.tex
|-mystyle.sty
|-Chap01/
|-chapter01.tex
|-Chap02/
|-chapter02.tex


Then the main file would have this basic structure:

% Contents of Book.tex
\documentclass{book}
\usepackage{mystyle}
\begin{document}
\include{Chap01/chapter01}% NOTE: these 'sub-files' must not include things like
\include{Chap02/chapter02}%       \usepackage, \begin{document}, or \end{document}
% You could also use \input; for the relative advantages, see http://tex.stackexchange.com/q/246/8528
% \input{Chap01/chapter01}
% \input{Chap02/chapter02}
\end{document}


And the included files would look something like this:

% Contents of chapter01.tex
\chapter{The First Chapter}
This is the first chapter.

-
There's no need to use \include; also \input will accept a subdirectory prefix. – egreg Aug 9 '14 at 21:41
@egreg -- Yes indeed (will edit). For chapters, I recommend \include mainly because of the possibility to use \includeonly. – jon Aug 9 '14 at 22:18
Well, it seems very complicated for me. I tried to do it like this but it writes mystyle.sty is not defined. – Laura Aug 9 '14 at 22:44
@Jane -- Just omit that line: \usepackage{mystyle} was invented simply to point out that you would load "personal" packages normally in comparison with .tex files located in sub-directories. – jon Aug 9 '14 at 22:50
It works now fine.Thans a lot.I am just wondering if it could be proved.I'm using some pictures in almost each chapter.I thought it would be enough just keep the pictures in each chapter directory together with chapter.tex, but I was supposed to put all pictures in work directory together with book.tex. So I still have with book. tex lots of pictures there. – Laura Aug 9 '14 at 23:13