2

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.

4
  • There is no clear answer to this as this a matter of taste, however. My personal advise is to place the chapters *.tex files in the same directory where main.tex is stored. By the way, I am not very fond of outsourcing chapters at all, but this is my personal opinion
    – user31729
    Dec 7, 2014 at 11:29
  • Thanks Christian. I'll probably end up doing something similar to what you suggested. After all, it's not such a major issue really. Still think I'll keep outsourcing chapters though, it's bound to become a rather large piece of document, and I prefer working on a single section at a time, rather than compiling a large piece every single time.
    – Jon
    Dec 7, 2014 at 11:44
  • You have not shown any code so it is hard to comment but I don't understand the issue at all, specifically "This obviously won't translate" If you process individual chapters using \includeonly then the paths should not need to change. If you are not doing that you should say what you are doing? Dec 7, 2014 at 19:07
  • I have used the solution where each file is at the same level of hierarchy (as you propose with main/main.tex structure) with the standalone package and works great. Please update the question with why this did not work for you or what error message you encountered. Dec 8, 2014 at 7:32

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .