[Tex/LaTex] using subfiles package and input at the same time

inputsubfiles

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:

enter image description here

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

Best Answer

I am just turning my comment into an answer, since it solved OP's issue.

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.

If this is not possible, one may want to try the solution given in this answer by Heiko Oberdiek: https://tex.stackexchange.com/a/79060/74960 .

Related Question