[Tex/LaTex] Managing multiple tex files using \include and ../

foldersincludemultiple files

I'm working on a larger thesis assignment, and I've been fiddling around with my various tex files in different folders, trying to make it look nice and orderly.

Atm. my structure is similar to this:

main.tex
img/image.png
tex/chapter01.tex

Where all other .tex files are including in the main file using \include{tex.chapter01.tex}. It works pretty well, I usually work on a single chapter file at the time which I compile by itself, and later on I compile the whole main file to see everything together.

However, I have one little issue. When working on a single chapter file I include images using \includegraphics{../img/image.png}. This obviously won't translate when compiling the whole main file since the correct command there would be \includegraphics{img/image.png}.

So I'm looking at the option of having a separate main folder as well making the structure like this:

main/main.tex
img/image.png
tex/chapter01.tex

Thus I can use the ../ command everywhere. Similar to what is described in the second answer here: Using subfiles package with .sty files (PS. I do not use the subfiles package)

However, this doesn't seem to work with the \include command. Ex: \include{../tex/chapter01} seems to give an error. Is this a common issue?

Hope you understand my problem. Thank you for any input.

EDIT:
I seem to have found an answer here: Restructure classic thesis project with subfolders using Kile
Apparently, \include doesn't really work when navigating upwards in folders.
So I ended up by just putting the main.tex file together with my other .tex files as Christina suggested.

Best Answer

The package import is what you are searching for. If I understand correctly, you want also compile chapter without the main file, so this can combined with the package docmute or standalone:

main.tex (in a root directory as /home/jon/thesis)

\documentclass{book}
\usepackage{graphicx}
\usepackage{docmute}
\usepackage{import}
\title{A book}
\begin{document}
\maketitle  
\chapter{This is the main file}
  This is the main file
  The figure \ref{im} % 2.1 
  is in chapter \ref{subdoc} % 2
\subimport{tex/}{chapter01}
\end{document}

chapter01.tex in subdirectory tex (/home/jon/thesis/tex)

\documentclass{book}
\usepackage{graphicx}
\begin{document}
\chapter{A chapter}
\label{subdoc}
  This is a subdocument. 
  The figure \ref{im} % 1.1 
  is in chapter \ref{subdoc} % 1
\begin{figure}[htp]
\centering
\includegraphics{../img/image}
\caption{My image}
\label{im}
\end{figure}    
\end{document}

For chapters you can use \subincludefrom instead of \subimport. Run texdoc import for more information.

Related Question