tex4ebook can be used for LaTeX to ebook formats conversion. It supports epub
, epub3
and mobi
formats.
I've had some presentations about it last year, slides in Czech are online, as well as source code of examples. Examples include sample code and results, so they are interesting even when you don't understand Czech.
Default look is rather plain and basic, you need to use custom CSS to add some custom design. Maybe use some CSS framework which supports responsive design, it is important in order to support devices with various screen sizes. The CSS can be added in the .cfg
file, such as this one:
\RequirePackage{include4ht}
\RequirePackage{addfont4ht}
\Preamble{xhtml}
\CoverMetadata{cover.png}
\AddCss{scale.css}
\Configure{textbf}{\NoFonts\HCode{<strong>}}{\HCode{</strong>}\EndNoFonts}
\Configure{textit}{\NoFonts\HCode{<em>}}{\HCode{</em>}\EndNoFonts}
\begin{document}
\NormalFont{EBGaramond}{EBGaramond12-Regular.woff}
\BoldFont{EBGaramond}{EBGaramond12-Italic.woff}
\ItalicFont{EBGaramond}{EBGaramond12-Italic.woff}
\Configure{@HEAD}{
\HCode{<style type='text/css' >\Hnewline
body{font-family:rmfamily, "EBGaramond", sans-serif;
font-size:1.3em;
}\Hnewline
p img{display:inline;}
</style>}}
\EndPreamble
packages include4ht
and addfont4ht
are part of helpers4ht bundle, which isn't on CTAN yet. They provide commands \AddCss
for adding custom CSS (scale.css in this case), and \NormalFont
, \BoldFont
and \ItalicFont
, which add custom fonts in .woff
format. All needed files can be found in previously linked repository with examples for my presentation.
\Configure{@HEAD}{
\HCode{<style type='text/css' >\Hnewline
body{font-family:rmfamily, "EBGaramond", sans-serif;
font-size:1.3em;
}\Hnewline
p img{display:inline;}
</style>}}
this code declares included EBGaramond
font to be used in the document, it needs to be included after all other CSS
code, so we must use this special construct to insert something into HTML header.
Unfortunately all these features (custom fonts, responsive CSS etc.) supports only epub3
format. You can compile your TeX file using command
tex4ebook -c configfile.cfg -f epub3 texfile.tex
You can see example of TeX file converted using this converter and styled with scale.css
here
Best Answer
As far as I know, fixed layout
epub3
is being used mainly for children books, manga comics and educational textbooks with lots of pictures etc. For documents usually produced with LaTeX, ie. text based documents with floating tables, graphs and images, reflowable epub is better, as the reading device may decide itself where to break pages, depending on the size of the device. For some articles about issues with fixed layouts, see this and this articles.For the question about ease of fixed layout epub3 creation from LaTeX, no it would be not easy. Lots of
.tex
to.html
convertors exist, which can be used as base forepub
conversion. In fact, there is tex4ebook, tool which usetex4ht
convertor to translate LaTeX directlyepub
,epub3
andmobi
formats (note: I am the author). for fixed layout, special configurations would have to be provided and some commands would need to be inserted in the LaTeX source.In my opinion, reasons why not so many ebooks produced by LaTeX exist are that:
There is really bad support for math in ebook readers. epub3 readers should support
mathml
, but in reality, they don't. In the best case, they use mathjax internally for math rendering, but it was painfully slow when I tried one of such apps on my android phone. this may got better in the future, I hope. You may test someepubs
from Frédéric Wang or Glenn Barnich to see how well your reader supportepub3
.in
epub
andmobi
, math must be included as images, which looks really horrible especially for inline math - characters aren't on the baseline, a different font than in the document is used and if the images have a different resolution than the device, they may be too big or deformed (see this for some experimental solution).ebooks look much worse than
pdf
. While they have some positive features overpdf
, like the possibility to resize text or change the font, ebook readers use html viewers for rendering and the typography they produce really doesn't satisfy standards for someone who uses LaTeX to produce typographically perfect documents..tex
to.html
convertors are hard to use and they have sparse documentation, so many people stop trying when they encounter some problem (this is probably the main reason).