2

I am writing a document with multiple chapters on Overleaf. When I try to compile a chapter, it does not compile the main document but the included file, which results in errors. Is there a way to have Overleaf compile the main document when I compile a chapter? I have seen similar questions, but usually they involve answers that might not apply to Overleaf.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
User0
  • 163
  • Isnt't there a "main document" setting in Overleafs project settings? – daleif Nov 04 '21 at 13:53
  • You could also try % !TEX root = ... from https://tex.stackexchange.com/q/78101/107497 (and let us know if Overleaf understands it). – Teepeemm Nov 04 '21 at 13:54
  • 1
    @Teepeemm The %! directives don't work in Overleaf (I know it, I work there :-) ) We do however try to detect for the presence of \documentclass so if the chapter file is open in the editor and it contains \documentclass (which doesn't really make sense), the Overleaf compiler will treat it as a main file (as long as it's open in the editor). – yo' Nov 04 '21 at 14:19
  • Is your chapter contain \documentclass{} command? – mmr Nov 04 '21 at 14:49
  • No no \documentclass in the chapter file – User0 Nov 04 '21 at 15:13
  • 1
    @user0 can you confirm that the main document is identified as the main document in Overleaf's settings?...sorry to ask. – commonhare Apr 04 '22 at 13:54

1 Answers1

1

You can check out this command:

\include{xyz}
%\include{chapters/xyz} %using path, chapters folder

This command allows you to include a particular xyz.tex file into another file. From the main document you can include a/more chapter(s) to it and compile. On the other hand, you can include the main.tex into a particular chaper xyz.tex file and compile it.

Teepeemm added:

they're using \include (or \input) already, but that they click "compile" while they're editing the included file. Overleaf tries to compile the included file instead of the including file, and this results in numerous errors because everything up to and including \begin{document} is missing.

Ingmar
  • 6,690
  • 5
  • 26
  • 47
mmr
  • 2,249
  • 5
  • 22
  • 3
    I'm not sure, but I think OP's problem is that they're using \include (or \input) already, but that they click "compile" while they're editing the included file. Overleaf tries to compile the included file instead of the including file, and this results in numerous errors because everything up to and including \begin{document} is missing. – Teepeemm Nov 04 '21 at 16:05
  • yes @Teepeemm that is correct thank you – User0 Nov 05 '21 at 00:01