# Tex4ebook and page breaks

This is a follow-up of this question of mine and uses the same setup.

How do I force tex4ebook to respect requests to go to a new page. Example:

\documentclass{article}
\usepackage{xskak}
\newcommand\mychessboard[1][]{\chessboard[#1]}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\clearpage
\lipsum[1]
\clearpage
\lipsum[1]
\clearpage
\end{document}


The page breaks are ok using latex but are ignored by tex4ebook. Is there a way to fix this?

Thanks.

There are two things. First, page breaks doesn't really matter in HTML pages, so tex4ht doesn't try to preserve them. Second, \clearpage is used in quite a lot of LaTeX macros internally, so if you configure it to insert some code for page breaks, it may end at unexpected places.

Anyway, you can configure it using following configuration:

% save the clearpage before it is redefined by tex4ht
\let\oldclrearpage\clearpage
% define macro for newpage insertion
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
\Preamble{xhtml}
% define it for \newpage
\mypagebreak
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclrearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclrearpage\Configure{newpage}{}}
\begin{document}
\EndPreamble


This configurations redefines \clearpage to include <div class="newpage"></div> in the document, it does the same thing also for newpage, which has standard tex4ht configuration, as opposed with \clearpage, which must be redefined as macro. CSS is used for request page breaking. Finally, \clearpage must be cleared at end of each extracted page, it would otherwise output <div class="newpage"> after </html>, resulting in invalid HTML document.