2

I am new to tex4ebooks (which I totally like after my first experiences) and I have some troubles with correct formatting:

  1. Forcing a page break does not work for me, even when using the configuration as suggested here

  2. Nested enumerations do not work correctly, if I use lower levels already for the first item (the lower level currently only starts on the second line, leading to unexpected break within the first sentence that even changes when changing the window-size).

  3. Identation of items is done in an unexpected and not very beautiful way (both when breaking the line within an item and when the numbering gets higher, zb. 10.) When not using enumitem, the identation looks fine, but then you cannot use the enumitem-options...

  4. Some of the enumitem options (e.g. parsep) are ignored, leading to unwanted spacing between items --> large space between 1.2 and 2. but no space between 2. and 3.

Is there a way to solve these issues?

Here my MWE:

\documentclass{article}

\usepackage{enumitem}

\begin{document}

\textbf{Title}

\mypagebreak

This text should be on a new page.

Issues with enumerations:

\begin{enumerate}[parsep=0.2cm]
\item
\begin{enumerate}[parsep=0.1cm, label=\arabic*]
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\end{enumerate}
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\item Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi nec ante.
\end{enumerate}

\end{document}

And here is my config file:

% save the clearpage before it is redefined by tex4ht
\let\oldclearpage\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\oldclearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclearpage\Configure{newpage}{}}
\begin{document}
\EndPreamble

If I use the the configuration file suggested in the answer below, then the page breaks in Calibre do no longer work accurately, meaning that the page break runs through the text, splitting it on two pages, which obviously does not look nice and makes it rather difficult to read the text, see pictures below:

Page 1:

enter image description here

Page 2:

enter image description here

Moreover, I run into troubles on pages that have a larger table, but I will ask a separate question for that issue, since I have also some problems with tables when using another configuration.

1
  • sorry for the delay, I only now was able to answer.
    – michal.h21
    Commented Feb 4, 2022 at 14:00

1 Answer 1

1

You are right that the default styling of enumitems is not too nice. We can try to use a CSS grid for correct styling, but the problem is that most Epub viewers don't support modern CSS features, or only partially.

Try this configuration:

% save the clearpage before it is redefined by tex4ht
\let\oldclearpage\clearpage
% define macro for newpage insertion
\Preamble{xhtml}
\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}\newpage}
% define it for \newpage
\Css{.newpage{page-break-before:always;}}
% modify \Configure{BODY} so our confiurations work on all extracted pages
\Configure{@BODY}{\def\clearpage{\bgroup\mypagebreak\oldclearpage\egroup}}
\Configure{@/BODY}{\global\let\clearpage\oldclearpage\Configure{newpage}{}}
\Css{dt.enumerate-enumitem{float:none;clear:none;margin:none;}}
\Css{dl.enumerate-enumitem{display:grid; grid-template-columns: 4rem 1fr;}}
\begin{document}
\EndPreamble

There are just two fixes:

\def\mypagebreak{\Configure{newpage}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="newpage"></div>}}\newpage}

We insert the \newpage, this will apply the HTML code for the page break.

\Css{dt.enumerate-enumitem{float:none;clear:none;margin:none;}}
\Css{dl.enumerate-enumitem{display:grid; grid-template-columns: 4rem 1fr;}}

These CSS instructions reset styling for enumitems, and then turn on the CSS grid. The 4rem value affects the indentation of the items. I had to set quite a big value because Calibre would break the item label into two lines otherwise.

This is the result in Calibre:

enter image description here

2
  • Using the new configuration leads to strange page breaks in Calibre - I have added the output in my initial question. Is there a solution for that avoiding page breaks runnig through the text even when using this CSS configuration?
    – Jack
    Commented Feb 6, 2022 at 17:18
  • @Jack unfortunately, Epub readers have lot of issues regarding rendering and CSS support, so stuff that works in browsers doesn't here. I played with solution that uses some older CSS constructs, but the result was even worse in Calibre. And actual E-ink readers are even worse in this regards.
    – michal.h21
    Commented Feb 6, 2022 at 18:55

You must log in to answer this question.

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