# using subfiles package and input at the same time

I want to call some files in folders. So I have 3 files : 1. main.tex (in the root) 2. commands.tex (in ./chapters) 3. control1.tex (in ./chapters) These files contains below codes: main:

\documentclass{report}
\usepackage{subfiles}
\input{chapters/commands}

\begin{document}

\subfile{./chapters/control1.tex}

\end{document}


commands:

\usepackage{graphicx}


control1:

\documentclass[../main.tex]{subfiles}
\begin{document}
\chapter{Control }
\section{intro}
some text
\end{document}


When I run main.tex everything looks good and without error. But if I run control1.tex I got this error:

It should be mentioned that without commands it runs perfect. What should I do? My goal is to put commands line in separate file.

• Why not \include{filename}? That's what I placed in my university's thesis template to insert parts into the document. – TheIncredibleZ1 Aug 4 '16 at 18:19
• Include can not solve my problem. With subfile you should run all file included in main, alone. – hossein behboodi Aug 4 '16 at 18:39
• (should*- -> can) – hossein behboodi Aug 5 '16 at 1:47
• I had the same problem, and I resolved keeping the main.tex file and all the chapters.tex files in the same folder - in this way the relative path is the same for every file, and \input should work properly. Otherwise, you may want to try the solution given in this answer: tex.stackexchange.com/a/79060/74960 – MarcoG Aug 5 '16 at 5:46
• @MarcoG Thanks for the suggestion 👍 – programmer yesterday

The problem is that when the file in ./chapters folder is compiled, it cannot find a file in folder ./chapters/commands.tex, since this is the path relative to main.tex file. I had the same problem while organising the files for my thesis: the easiest solution is to keep all the subfiles and the main file in the same directory - in this way the relative path is the same for every file, and \input should work properly.