0

This question already has an answer here:

I am looking for a way, if possible, of specifying file paths not relative to the main document but to the subdocument in which they are contained. As background:

I am writing my thesis chapter by chapter. I have written each chapter as an independent document, edited it, and now want to combine all chapters into one document. Each chapter document is structured to have a main.tex which contains the preamble, the \begin{document}, etc. The actual text is contained in a file called toc.tex which contains the section structuring of each chapter and in turn imports the documents containing each section. So main.tex looks something like this:

PREAMBLE
\begin{document}
\maketitle
\tableofcontents
\input{toc.tex}
\printbibliography
\end{document}

each toc.tex looks something like the following:

\section{A}
\input{./Content/A.tex}
\section{B}
\input{./Content/B.tex}

This means that I can compile each chapter individually. My plan was now to compile the overall thesis by using a main_thesis.tex which looks something as follows:

PREAMBLE
\begin{document}
\maketitle
\tableofcontents
\input{toc_thesis.tex}
\printbibliography
\end{document}

where the file toc_thesis.tex looks as follows:

\chapter{Introduction}
\input{./chapters/Introduction/toc.tex}
\chapter{Body}
\input{./chapters/Body/toc.tex}

My folder structure would thus looks along the following lines:

thesis
   chapters
      Introduction
         Content
         Figures
      Body
         Content
         Figures

When I now compile main_thesis.tex I get an error message saying File `./Content/intro.tex' not found. \input{./Content/intro.tex}, i.e. the file toc.tex in the Introduction chapter can't find the file intro.tex which is contained in ./chapters/introduction/Content as it is looking in ./Content which doesn't exist.

As far as I understand this is because the paths apparently are always relative to where the main file resides not the inputted subfile (https://en.wikibooks.org/wiki/LaTeX/Modular_Documents#Using_different_paths). My question is, is there anyway of changing this behaviour to get LaTeX to use the paths relative to the input files not the main file? I am using TeXStudio should this be of relevance to the question.

marked as duplicate by Schweinebacke, TeXnician, Stefan Pinnow, Troy, user36296 Jul 11 '17 at 13:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    if the filenames are unique you can just set your TEXINPUTS and use \input{A} and it will work from the main doc or from a chapter, otherwise see the import package which is designed to address exactly your problem. – David Carlisle Jul 11 '17 at 12:01
  • 1
    Welcome to TeX.SX! I would prefer one main.tex with the whole preamble and the chappter in separate .tex files. – Bobyandbob Jul 11 '17 at 12:03
  • 2
    You can use the import package. But imho on the long run it is more difficult as you have to handle more than one reference point for file path. When you move the file the pathes are wrong. Its easier with not to many subfolders. – Ulrike Fischer Jul 11 '17 at 12:28

Browse other questions tagged or ask your own question.