# Book template for tex4ebook

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
\printbibliography \newpage

\phantomsection
\printindex

\end{document}


Using pdflatex produces a correct result.

Using tex4book causes some problems.

The build.mk4 file is:

-- par.encoding  = par.encoding or "utf8"
-- par.language = par.language or "english"
par.idxfile = par.idxfile or par.input .. ".idx"
local modules = par.modules or {}
local t = {}
for k,v in ipairs(modules) do
t[#t+1] = "-M ".. v
end
par.moduleopt = table.concat(t, " ")
local xindy_call = "xindy -L ${language} -C${encoding} ${moduleopt}${idxfile}" % par
print(xindy_call)
return os.execute("xindy -L ${language} -C${encoding} ${moduleopt}${idxfile}" % par)
end, {modules = {"texindy"}, language = "english", encoding = "utf8"})

if mode=="draft" then
Make:htlatex {}
else
Make:htlatex {}
Make:biber {}
-- xindymodule = Make.params["input"]
Make:xindy {modules = {"sample"}}
Make:htlatex {}
Make:htlatex {}
Make:htlatex {}
end


The Make:xindy command can accept some additional arguments, namely language, encoding, idxfile and modules table. We can use the default values, we only need to pass the module generated by imakeidx.4ht, using

 Make:xindy {modules = {"sample"}}


The module is named as \jobname.xdy, we should post it without the extension. My file is named sample.tex, thus the module name is sample.

This is the result:

Edit:

You can add the cover image to the document using \coverimage command. It assumes that it is in png format, so you need to add

 \Configure{CoverMimeType}{image/jpeg}


to the .cfg file if you want to use jpg. You can use the trick with \phantomsection and \addcontentsline to put it to the TOC. The \coverimage is defined by tex4ebook, so you must use it only when you compile the document with tex4ebook, for example:

\ifdefined\HCode
\phantomsection

• @user41974 I've added the solution for the cover image, it is included in the document and in the toc, but only in the HTML mode, hence \ifdefined\HCode. Regarding your last question, you can execute tidy command on all your pages with -t command line option, this should suffice. You can also use make4ht filters, but they usual deal with unusual cases. – michal.h21 Jan 16 '17 at 14:18