# How not to switch context when working on hierarchical documents in TeXStudio?

Right now I'm using TeXStudio with pdflatex on MikTeX on Windows 10 (64-bit).

What I'm doing is that I have hierarchy of folders:

• "root" / Project's directory (contains project-specific .sty package)
• Sub-Project 1 (contains the master document for this sub-project)
• Sub-Project 1 content (contains a bunch of .tex files with content)
• Sub-Project 2 (contains the master document for this sub-project)
• Sub-Project 2 content (contains a bunch of .tex files with content)
• ...

Now as per the Wikibook I'm using subfiles to include from the sub-project's main document the content documents. The main document also includes the project-specific style package.

Now when I'm using TeXStudio, I have to open the master document and compile when viewing it to look at my compiled sub-document, the reason seems to lie in relative paths. That is if I compile from a content-document I get

File ../project1.sty' not found. \usepackage


as my error message.

As this is (slowly) getting annoying, how can I fix this error?

For your convenience, a content document template roughly looks like:

\documentclass[../master.tex]{subfiles}
\begin{document}
% content goes here
\end{document}


And the relevant parts of the master document looks like:

\documentclass[12pt,a4paper]{article}
\usepackage{../project1}
\usepackage{subfiles}
% other packages and some configuration
\begin{document}
\subfile{./tex/part1.tex}
% other includes go here, includes are auto-generated using a macro
\end{document}


The upper document would live in /project1/subproject1/tex/part1.tex.
And the lower would live in /project1/subproject1/master.tex.
The style package would live in /project1/project1.sty`.

• In TeXStudio there is the option to declare the current document to be the master document. This is done under "Options>Root Document". – Skillmon Jul 4 '17 at 12:12
• @Skillmon you are right, this is exactly what I needed. Would you mind posting this as an answer? – SEJPM Jul 4 '17 at 12:14