TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've overheard mention of LaTeX being used for the production of eBooks. I'm thinking that it's in reference to producing small pages of a fixed size, say 7", fixed type size, say 8pt, for reading pdf files on the ever more popular Tablet Computers, but not particularly the eInk eReaders that have even smaller screens than that and primarily use ePub, Mobi or Kindle formats.

On second thought, I figured I could be wrong about that. It seems like a programmer could more easily create a LaTeX compiler (a hypothetical alternative to pdfLaTeX) that instead generates epub, mobi or something else I don't know about, which flows to the size of the eReader screen, and resizes to the preferred font size its reader likes.

Has that already been done for those who'd love to use LaTeX for reflowable eBooks, but NOT pdf eBooks?

share|improve this question
that is essentially the same as generating html and tex4ht, latexml etc have customizations to generate the metadata needed to package up an html based ebook. – David Carlisle Jan 26 at 21:11
You can do it but I’m not sure if it makes a lot of sense: much of LaTeX’ strength is as a typesetting engine and you lose all that when producing an ebook: engines such as pdfLaTeX are comparable to the ebook reader and produce the display rather than the epub/mobi: they interpret the (ebook) input and render it. And they make fundamentally different trade-offs: an ebook reader engine needs to render text very quickly with limited resources, but produces sub-optimal (let’s not mince words here: terrible) layout. pdfLaTeX produces great layout but uses time-consuming algorithms for this. – Konrad Rudolph Jan 27 at 12:58
What If a new .eBk format using a new standardized set of LaTeX packages, a finalized LaTeX3, and a new eBk TeX distribution were created just for ebook reader devices, so it could compile every .eBk file to it's screen dimension and the reader's choice of font and sizes: maybe 8pt, 9pt, 10pt, 11pt or 12pt, and the reader's choice for Roman, San-Serif and Typewriter fonts. And, the device could adjust (recompile) changes in preferences if necessary. Imagine what that would be like. I wish users would develop such a system. That seems easy, and eReader devices are getting powerful. – user12711 Jan 28 at 15:15
up vote 22 down vote accepted

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:

\HCode{<style type='text/css' >\Hnewline
body{font-family:rmfamily, "EBGaramond", sans-serif;
p img{display:inline;}

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.

\HCode{<style type='text/css' >\Hnewline
body{font-family:rmfamily, "EBGaramond", sans-serif;
p img{display:inline;}

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

share|improve this answer
Excellent example. I didn't realize all that was possible with html (or epub). – user12711 Feb 14 at 3:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.