I am trying to set up a book template for tex4ebook using memoir and Texlive.
The MWE that has everything I want is:
\documentclass[ebook,12pt,oneside,openany]{memoir}
\begin{filecontents}{test.bib}
@book{Hiemenz,
author={Hiemenz},
title={Polymer Chemistry}
}
\end{filecontents}
\usepackage{lipsum}
\usepackage[backend=biber,hyperref=auto,backref=true]{biblatex}
\bibliography{test}
\usepackage{imakeidx}
\makeindex[intoc=true,columns=1]
\usepackage[hyperindex=true]{hyperref}
\title{Book}
\author{Author}
\date{}
\begin{document}
\maketitle
\frontmatter
\tableofcontents \newpage
\mainmatter
\chapter{C1}
aword\index{aword}
\lipsum \newpage
Here comes a quotation \cite{Hiemenz}.
\chapter{C2}
bword\index{bword}
\lipsum \newpage
\backmatter
\phantomsection
\addcontentsline{toc}{chapter}{Bibliography}
\printbibliography \newpage
\phantomsection
\printindex
\end{document}
Using pdflatex produces a correct result.
Using tex4book causes some problems.
The build.mk4 file is:
Make:add("biber","biber ${input}")
Make:htlatex {}
Make:biber {}
Make:htlatex {}
Make:htlatex {}
Make:htlatex {}
The cfg file is:
% 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}
\CutAt{section}
%
% enforce newpage
%
% 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 doesn't produce a correct ebook. The Index entry is missing in the table of contents and the index pages are not hyperlinks.
Is there any way to get the tex4ebook version to work correctly?
Thank you.
Edit 1
I forgot to put in \mainmatter before the first chapter. It's now included. I've left the rest of the input file the same to allow a comparison with @michal.h21 excellent solution.
Edit 2 - Extra questions
Question 1:
I want to include a cover (call it cover.jpg) and have it show up correctly on the Kindle version with a link in the table of contents so that the toc in the ebook picture looks like:
Cover
Beginning [Comment: Where should this link to in sample.tex?]
Rest of table of contents as in original question
I've looked at here and here but I'm not sure what's the best way to do this and avoid the double cover issue discussed on these pages.
Question 2:
The two web pages above also discuss various ways to tidy the html code generated in the build process. What is the recommended way to do this?
In summary, what additional changes are necessary to the revised sample.tex and build.mk4 from @michal.h21 and my sample.cfg to make all this work? [imakeidx.4ht from @michal.h21 remains as is.]
I hope that these additional changes will provide a complete template for Kindle ebooks that other users can easily adapt for their books.
Thank you.