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...
\clearpagecomes from it has appeared here a few times recently. redefining\clearpagein that way completely breaks latex, the simple answer is do not do that. – David Carlisle Apr 17 '18 at 17:37\clearpage(from\includeor 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