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:


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


1 Answer 1


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
% define macro for newpage insertion
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}}
% define it for \newpage
% modify \Configure{BODY} so our confiurations work on all extracted pages

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.

  • this answer works great with Mac Books but unfortuntately I'm not getting page breaks with ReadEra? Apr 16, 2023 at 0:13
  • 1
    @buttonsrtoys this is the problem with e-book readers - not all of them support all features. The e-ink readers like Pocketbook or Kobo are even worse in this regards, unfortunately.
    – michal.h21
    Apr 17, 2023 at 7:58
  • I experimented with Calibre's "split html file" tool to put each block of text that needed a page break afterward in its own html file. Apparently ReadEra starts a new page at the end of an html file, so it worked perfectly. So my flow is now Latex -> tex4ebook -> Calibre. If there's a command in tex4books to tell it to put a block of text in its own html file, I'm all ears. Otherwise, this flow works really well. Apr 18, 2023 at 20:44
  • @buttonsrtoys it is possible, see kodymirus.cz/tex4ht-doc/Configurations.html#page-breaks - but it doesn't work well with tex4ebook§
    – michal.h21
    Apr 19, 2023 at 8:30
  • I would question the statement that page breaks wouldn't really matter in HTML pages (for the use case of EPUBs). I mean, there surely is a reason why tex4ebook indeed adds page breaks for the TOC.
    – clel
    Oct 13, 2023 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .