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
:
\Preamble{xhtml}
\NewSection\book{\thebook}
\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}{}{}
\Css{.booknumber{display:block;}}
\Configure{toToc}{book}{part}
\CutAt{book}
\begin{document}
\EndPreamble
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.
{\HCode{</span></h2>}\HtmlParOn}
This code just closes all opened HTML elements and enables paragraphs.
\Css{.booknumber{display:block;}}
This command style the book number, it is just printed on a separate line.
\Configure{toToc}{book}{part}
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.
\CutAt{book}
This will open a new HTML page for each book.
This is the result in ebook-viewer
:
