Running tex4ebook on the following example


Some dedication text



\chapter{How are you}


produces an .epub where the \book is formatted as a likeSection, but without any prior page breaks nor any corresponding bookmarks.

What configurations are needed for tex4ebook (or tex4ht) to support memoir's \book construct, or would this require more extensive changes upstream?

1 Answer 1


There is no support for the \book command in tex4ht, so what you see is just the formatting based on the fonts used by this command. Try the following configuration code that redefines it as a sectioning command recognized by tex4ht:

\Configure{book}{\ifvmode\IgnorePar\fi\EndP\HCode{<h2 class="bookHead"><span class="booknumber">}\bookname\refstepcounter{book}\space\thebook\HtmlParOff\HCode{</span><span class="booktitle">}}{\HCode{</span></h2>}\HtmlParOn}{}{}

The \NewSection command redefines \book as sectioning command recognized by tex4ht. The second argument should contain the counter command used to print the section number.

It is then necessary to configure the HTML code using \Configure{book}. This configuration is declared by \NewSection. It is a bit complicated, so I will try to describe it in more detail:

 {\ifvmode\IgnorePar\fi\EndP\HCode{<h2 class="bookHead"><span class="booknumber">}\bookname\refstepcounter{book}\space\thebook\HtmlParOff\HCode{</span><span class="booktitle">}}

The \ifvmode\IgnorePar\fi\EndP closes the current paragraph, this code is necessary for all block level elements in tex4ht. The \HCode{<h2 class="bookHead"><span class="booknumber">} starts the HTML code, the span.booknumber element is used to style the book number, as it should stay on a separate line than the book title. \bookname is Memoir's command that contains the Book string. We need to manually increment the book counter using \refstepcounter command. \HtmlParOff disables HTML paragraphs, because some spurious paragraphs were produced in my tests. The \HCode{</span><span class="booktitle">} closes the book number and opens span.booktitle for the book title.


This code just closes all opened HTML elements and enables paragraphs.


This command style the book number, it is just printed on a separate line.


Requires \book to be included in TOC, on a same level as \part. I am not sure if it is possible to put it on a higher level without need to redefine lot of stuff.


This will open a new HTML page for each book.

This is the result in ebook-viewer:

enter image description here

  • Thanks for the solution and the very clear explanation! This certainly works for me, and happy enough to have the \book and \part bookmarks on the same level.
    – imnothere
    May 31, 2019 at 13:02

You must log in to answer this question.

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