1

I'm writing a book with several chapters, and I've split every chapter to separate files. In my preamble, I have this:

\include{chap1}
\include{chap2}
...

File chap1.tex:

\chapter{Chapter text - Number 1}
Text text text

and similar for chap2.tex (and all other chapter files). This works as expected.

However, I recently thought that instead of having \chapter{} in the chapter files, I will move these to the preamble and just keep the substance in the chapter files. Like this:

\chapter{Chapter text - Number 1}
\include{chap1}

\chapter{Number 2}
\include{chap2}

and so on. However, the result of this was not as expected. I get a chapter heading (expected), but the rest of the page is completely blank. I have to turn page to get to the chapter contents.

Expected results was exactly the same as if I had \chapter{} inside the chapter files.

Why does the blank page happen if I split \chapter{} and the chapter contents?

Sigur
  • 37,330
bos
  • 275
  • 1
    Replace \include{} by \input{}. – Sigur Feb 23 '19 at 18:19
  • From texdef -t latex \include we see that it calls \@include, which starts with \clearpage. This explains the result you observed. – Sigur Feb 23 '19 at 18:23
  • @Sigur: worked. Please add an answer so I can accept it. – bos Feb 23 '19 at 18:28
  • 2
    Related: https://tex.stackexchange.com/q/246/121799 –  Feb 23 '19 at 18:34
  • The main difference between \include and \input is being able to implement \includeonly, so forcing a new page at the start and end makes sense. I would put \chapter inside the included file. – John Kormylo Feb 24 '19 at 18:16

1 Answers1

3

From texdef -t latex \include we find:

\include:
macro:#1->\relax \ifnum \@auxout =\@partaux \@latex@error {\string \include \space cannot be nested}\@eha \else \@include #1 \fi

where we also can find \@include. So, from texdef -t latex \@include we find:

\@include:
macro:#1 ->\clearpage \if@filesw \immediate \write \@mainaux {\string \@input {#1.aux}}\fi \@tempswatrue \if@partsw \@tempswafalse
\edef \reserved@b {#1}\@for \reserved@a :=\@partlist \do {\ifx
\reserved@a \reserved@b \@tempswatrue \fi }\fi \if@tempswa \let
\@auxout \@partaux \if@filesw \immediate \openout \@partaux #1.aux
\immediate \write \@partaux {\relax }\fi \@input@ {#1.tex}\clearpage
\@writeckpt {#1}\if@filesw \immediate \closeout \@partaux \fi \else
\deadcycles \z@ \@nameuse {cp@#1}\fi \let \@auxout \@mainaux

and the very beginning shows macro:#1 ->\clearpage, that is, the first command is \clearpage.

This is why the \include{file.tex} clears the page before inserting the contents of file.tex.

For completeness, lets see: texdef -t latex \clearpage

\clearpage:
macro:->\ifvmode \ifnum \@dbltopnum =\m@ne \ifdim \pagetotal <\topskip \hbox {}\fi \fi \fi \newpage \write \m@ne {}\vbox {}\penalty -\@Mi

where we find \newpage.

As exercise to the reader, check texdef -t latex \newpage. Also, compare the above with texdef -t latex \input.

Sigur
  • 37,330