# File paths not relative to main.tex but relative to subfile [duplicate]

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, user36296Jul 11 '17 at 13:46

• 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