0

I have a document written in Markdown, and converted to PDF using pandoc - where suddenly a very stubborn and unwanted clear page has been inserted.

I managed to obtain the final .tex output from pandoc --verbose, and clean it up a bit (the preamble is a mess between what Pandoc inserts automatically, and some of my custom edits through the years), and still show the problem - here it is:

First, let's say, I've generated single.pdf image using the below single.tex via xelatex single.tex:

\documentclass[a4paper]{article}
\usepackage{xcolor}
\begin{document}
\pagecolor{yellow}
...
\end{document}

Then, the actual document demonstrating the problem is this, blankpage.tex:

  % Options for packages loaded elsewhere
  \PassOptionsToPackage{unicode}{hyperref}
  \PassOptionsToPackage{hyphens}{url}
  \PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor}
  %
  \documentclass[
    12pt,
    a4paper,
    table]{extarticle}
  \usepackage{amsmath,amssymb}
  \usepackage{iftex}
  \ifPDFTeX
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}
    \usepackage{textcomp} % provide euro and other symbols
  \else % if luatex or xetex
    \usepackage{unicode-math} % this also loads fontspec
    \defaultfontfeatures{Scale=MatchLowercase}
    \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
  \fi
  \usepackage{lmodern}
  \ifPDFTeX\else
    % xetex/luatex font selection
  \fi
  % Use upquote if available, for straight quotes in verbatim environments
  \IfFileExists{upquote.sty}{\usepackage{upquote}}{}
  \IfFileExists{microtype.sty}{% use microtype if available
    \usepackage[]{microtype}
    \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
  }{}
  \makeatletter
  \@ifundefined{KOMAClassName}{% if non-KOMA class
    \IfFileExists{parskip.sty}{%
      \usepackage{parskip}
    }{% else
      \setlength{\parindent}{0pt}
      \setlength{\parskip}{6pt plus 2pt minus 1pt}}
  }{% if KOMA class
    \KOMAoptions{parskip=half}}
  \makeatother
  \usepackage{xcolor}
  \usepackage[margin=2cm]{geometry}
  \usepackage{listings}
  \newcommand{\passthrough}[1]{#1}
  \usepackage{graphicx}
  \makeatletter
  \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
  \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
  \makeatother
  \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
  \makeatletter
  \def\fps@figure{htbp}
  \makeatother
  \setlength{\emergencystretch}{3em} % prevent overfull lines
  \usepackage{pifont}
  \usepackage{fontspec}
  \setmainfont[Ligatures=TeX]{CMU Serif}
  \unimathsetup{bold-style=ISO}
  \usepackage[skip=4pt,font=small]{caption}
  \usepackage{lastpage}
  \setcounter{tocdepth}{4}%
  \setcounter{secnumdepth}{4}%
  \usepackage{fancyhdr}
  \fancypagestyle{plain}{%
    \renewcommand{\headrulewidth}{0pt}%
    \fancyhf{}%
    \fancyfoot[LE,RO]{\footnotesize Page \thepage\ of \pageref*{LastPage}}%
  }
  \pagestyle{fancy}
  \fancyfoot{}
  \fancyfoot[LE,RO]{\footnotesize Page \thepage\ of \pageref*{LastPage}}
  \usepackage[fit]{truncate}
  \fancyhead[LE,RO]{\nouppercase{\truncate{0.5\headwidth}{\rightmark}}}
  \fancyhead[LO,RE]{\nouppercase{\truncate{0.5\headwidth}{\leftmark}}}
  \lstset{% for listings
    basicstyle=\ttfamily,
    breaklines=true,
    postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},
  }
  \colorlet{dollarcol}{red}
  \usepackage{pmboxdraw}
  \usepackage{newunicodechar}
  \newunicodechar{■}{$\blacksquare$}
  \usepackage[breakable, skins]{tcolorbox}
  \usepackage[toctitles]{titlesec}
  \titlelabel{\thetitle.\quad}
  \usepackage[dotinlabels]{titletoc}
  \usepackage[toc,page,title,titletoc,header]{appendix}
  \makeatletter
  \renewcommand*\l@section{\@dottedtocline{1}{0em}{1.5em}}
  \makeatother
  \setlength\itemsep{0.5\baselineskip}
  \usepackage{enumitem}
  \usepackage{comment}

\title{Example doc} \author{Me} \date{Wednesday, March 13, 2024}

\begin{document} \maketitle

{ \setcounter{tocdepth}{3} \tableofcontents } \clearpage

\section{First section}

Testing ....

\clearpage

\subsection{Second section}

Testing ....

\clearpage

\subsection{Third section}

Testing ....

\clearpage

\section{Fourth section}

\begin{center}

\includegraphics{single.pdf}

\end{center}

\begin{center}

\includegraphics{single.pdf}

\end{center}

\clearpage

\section{Fifth section}

Testing ....

\clearpage \end{document}

So, I compile this with xelatex blankpage.tex, and I see:

pdf screenshot

... a blank page, page number 5, being inserted between page 4 with \subsection{Third section}, and page 6 with \section{Fourth section}.

It's almost as if the blank was inserted to ensure next \section falls on an even page - but this is extarticle class, which as far as I know has the same settings as article class - and that one is not twoside? So as per removing an unwanted page between two chapters class options oneside and openany (LaTeX Warning: Unused global option(s): [openany].) do not help - the extra blank page is still there.

So what is the cause of this extra blank page - and how to I remove it?

(Also irritating, that no matter how many times I run xelatex blankpage.tex, I always get:

LaTeX Warning: Reference `*' on page 7 undefined on input line 142.
...
LaTeX Warning: Reference `*' on page 8 undefined on input line 148.

[8] AED: lastpage setting LastPage (./blankpage.aux)

LaTeX Warning: There were undefined references.

) (see the transcript file for additional information) Output written on blankpage.pdf (8 pages). Transcript written on blankpage.log.

... and LastPage clearly does not work in this example - but never mind that, just need to vent)

sdbbs
  • 245
  • 1
    Maybe you could also look at the markdown package to convert markdown to latex. – jlab Mar 13 '24 at 18:00
  • 2
    your graphic is too large and so LaTeX will move it together with the section heading to the next page and then it will give up and complain in the log about an overfull vbox. – Ulrike Fischer Mar 13 '24 at 18:20
  • Thanks @UlrikeFischer - that clarifies also why \enlargethispage{5\baselineskip} worked to get rid of the extra page (as I posted below) – sdbbs Mar 13 '24 at 18:24
  • 1
    Well I would make the graphic smaller or use pdfpages and its pagecommand option. Also I don't get warnings about undefined references or references * in a current texlive. – Ulrike Fischer Mar 13 '24 at 18:25

2 Answers2

0

Ok, found a workaround - though it would still be better to get a proper answer to the reason for this happening from someone more knowledgeable ...

Anyways - it seems the problem is the image in \section{Fourth section} - if I comment it out, and add a clearpage instead:

%...
  \section{Fourth section}

\begin{center}

% \includegraphics{single.pdf}

\end{center}

\clearpage % added

\begin{center}

\includegraphics{single.pdf}

\end{center}

\clearpage

\section{Fifth section} %...

... then I do not get the extra blank page before \section{Fourth section} (and I have 7 pages in total).

Then, I tried the adding the \enlargethispage{5\baselineskip} ( from How to remove an empty Page between sections with large pictures? ) right after the \clearpage before the \section{Fourth section} - and then the extra blank page before \section{Fourth section} is removed, while keeping the image (again resulting with 7 pages in total):

% ...
  \subsection{Third section}

Testing ....

\clearpage \enlargethispage{5\baselineskip} % added

\section{Fourth section}

\begin{center}

\includegraphics{single.pdf}

\end{center}

\begin{center}

\includegraphics{single.pdf}

\end{center}

\clearpage

\section{Fifth section} % ...

Good enough for me, as long as it works in my actual doc - though it is irritating I really have no idea why would this \enlargethispage work at all ...

sdbbs
  • 245
  • There is no legal page break point between the section title and the image. If the height of the image is too large to fit, LaTeX will necessarily issue a blank page before giving up and ship out an overfull page. – egreg Mar 13 '24 at 18:42
  • If you want a book-like format, use extbook to have true chapters and do not deal yourself with \clearpage commands at the markdown level. If the true problem is to have chapters with the format of sections, (i.e., without the "Chapter X" above), the simplest solution is to switch to scrbook or memoir that have a document class option for that. – Fran Mar 13 '24 at 18:45
0

It's easy to reproduce the issue.

\documentclass{article}

\begin{document}

\section{Test}

\fbox{\rule{0pt}{\textheight}\rule{\dimeval{\textwidth-2\fboxsep-2\fboxrule}}{0pt}}

\end{document}

You get

[1{/usr/local/texlive/2024/texmf-var/fonts/map/pdftex/updmap/pdf
tex.map}]
Overfull \vbox (24.30275pt too high) has occurred while \output is active
[2] (./toobig.aux) )

because there is no legal page break point between the section title and the following text. Now the box (the image, in your case) is too big to fit and so we get a blank page; then TeX tries to typeset again that part, but realizes it's impossible and ships out an overfull page.

This won't show the problem:

\documentclass{article}

\begin{document}

\section{Test}\enlargethispage{25pt}

\fbox{\rule{0pt}{\textheight}\rule{\dimeval{\textwidth-2\fboxsep-2\fboxrule}}{0pt}}

\end{document}

because the page will be enlarged to fit the big object. Of course it will overlap the page number and some other measure has to be taken for this case.

egreg
  • 1,121,712