I write a scrbook (twoside) in which I \include files for every section. As I normally only want to print the pages for a single included file, I need to \cleardoublepage before (and potentially after) every \include to get the page numbering right.

My idea was to use \apptocmd (from the package etoolbox):


But while the .log file seems to tell that the patching worked, it has now effect.

[debug] tracing \apptocmd on input line 39
[debug] analyzing '\include'
[debug] ++ control sequence is defined
[debug] ++ control sequence is a macro
[debug] ++ control sequence is a macro with parameters
[debug] ++ macro can be retokenized cleanly
[debug] == retokenizing macro now

Can this be done?

  • 1
    I would add the \cleardoublepage at the end of the included file. Then the empty page at the end belongs to the included file and not the master file and \includeonly works better. – Heiko Oberdiek Aug 16 '17 at 18:15
  • Thanks @HeikoOberdiek! I modified my answer with an automated solution of your suggestion. – FlorianL Aug 17 '17 at 6:54

\include should not be modified, in my opinion, because its purpose is to check for nested \include (which is not allowed) and call, if the test is negative, to call \@include.

The \@include macro calls \clearpage twice, at the start and at the end. So what you seem to want is




does the job.

But following Heiko Oberdiek's advice (and IMO better still), one can also patch \@include:

\patchcmd{\@include}{\@input@ {#1.tex}\clearpage}{\@input@ {#1.tex}\cleardoublepage}{}{}
  • To avoid having an empty page at the end of the document because of the last included file: \let\includeclearpage=\cleardoublepage \patchcmd{\@include}{\@input@ {#1.tex}{\clearpage}{\@input {#1.tex}\includecleardoublepage}{}{\errmessage{}}. Then before the last \include: \let\includeclearpage=\clearpage \include{lastfile}. – Heiko Oberdiek Aug 17 '17 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.