2

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.

user41974
  • 841

1 Answers1

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
\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.

michal.h21
  • 50,697
  • this answer works great with Mac Books but unfortuntately I'm not getting page breaks with ReadEra? – buttonsrtoys Apr 16 '23 at 00: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 '23 at 07: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. – buttonsrtoys Apr 18 '23 at 20:44
  • @buttonsrtoys it is possible, see https://www.kodymirus.cz/tex4ht-doc/Configurations.html#page-breaks - but it doesn't work well with tex4ebook§ – michal.h21 Apr 19 '23 at 08: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 '23 at 13:29