I'm trying to input a separate file, chapter1.tex, into the mainbody.tex file. So in the mainbody.tex file I'm typing,
\documentclass[...]{book}
\blah
\blah
\begin{document}
\input{\...\chapter1.tex}
\end{document}
Both files, chapter1.tex and mainbody.tex, are scripted with the same preamble. When I compile chapter1.tex the process ends without an error and the .pdf document is properly generated. But when I compile the mainbody.tex it gives me
! LaTeX Error: Can be used only in preamble.
and it is referring to the chapter1.tex file.
It seems that, as the main body.tex is being compiled, when the compiler reaches the \input command, it reads the preamble of the chapter1.tex file and it recognizes its commands, as commands of the main body of the mainbody.tex file, thus gives the error.
However, a mainbody.pdf file do generate even if the compiling process ends with an error.
Any idea of what causes the error and how can I get rid of it?
\chapteris interpreted as chapter command. This problem can be avoided by using the slash for path names:\input{/.../chapter1.tex}. The slash also works in the case of Windows. – Heiko Oberdiek Apr 17 '17 at 00:25