# includeonly and page numbering

I am writing a fairly large documents that contains different chapters included in the main .tex file using the \include command. I find this to be practical as I can then compile a single chapter keeping page numbers and links to other chapters using the \includeonly command.

Recently, I found that \inlcudeonly may be responsible for the addition of a blank page at the end of a document though. I found a fix which is based on a redefinition of the \include command:

\let\oldInclude=\include
\def\include#1{\bgroup\def\clearpage{\relax}\oldInclude{#1}\egroup}


However, this fix seems to create some other issues. In my case, it impacts page numbering due to a conflict with the hyperref package. Everything is fine when compiling the whole document but the compilation of a single chapter (or more) using \includeonly yields some wrong numbering of the last two pages...

I was able to reduce the problem to a mwe where the application of this fix generates a compilation issue. Here are the commands to execute to see the problem: pdflatex main.tex. The compiled pdf has then proper page numbering. Then uncomment the line of \includeonly and run: pdflatex main.tex again.

The resulting pdf has unproper page numbering...

with main.tex:

\documentclass[11pt,letterpaper,fleq,twoside]{article}
\usepackage[]{hyperref}

% fix
\let\oldInclude=\include
\def\include#1{\bgroup\def\clearpage{\relax}\oldInclude{#1}\egroup}

%\includeonly{chapitre_1}

\begin{document}
\include{description}
\include{chapitre_1}
\include{chapitre_1_exercices}
\end{document}


and where description.tex is:

\newpage
\section*{Plan de cours pour la session d'}
Le cours \dots


chapitre_1.tex is:

\newpage
\section{Chapitre 1}

\label{chap_1}
% table des matières
\newpage
\subsection{Introduction}
Contenu du chapitre\dots
\newpage
page supplémentaire pour afficher les numéros de page


and chapitre_1_exercices.tex is:

\newpage
\subsection{Exercices d'application}
Liste d'exercices\dots


I do not see how to update the fix...

• I don't know where this idea to redefine \clearpage comes from it has appeared here a few times recently. redefining \clearpage in that way completely breaks latex, the simple answer is do not do that. – David Carlisle Apr 17 '18 at 17:37
• @DavidCarlisle I see... But do you see any alternative to the issue for which this "fix" was initially proposed ? Without this redefinition, there can be extra blank pages at the end of the compiled pdf. – Alain Apr 17 '18 at 19:44
• an extra \clearpage (from \include or anything else) just before \end{document} shouldn't make a blank page, if you have an example of that post an example in a question and will try to debug. – David Carlisle Apr 17 '18 at 20:08
• @DavidCarlisle thank you, I created a post on this other issue here: tex.stackexchange.com/questions/427197/… – Alain Apr 18 '18 at 11:21