Sign up ×
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.

I'm asking here a question which was asked on the italian TeX group forum.

Is there a way to produce Epub output automatically from a LaTeX source?

I should remark that Epub is just HTML+a subset of CSS+some XML for metadata, packed in a ZIP file. So one can settle with the existing tools for HTML conversion. Still something better could be done for Epub output.

In the first place, Epub accepts only a subset of CSS. Then it would be nice to produce the file with the metadata from the LaTeX source too. Finally, I'm not sure how it works, but Epub files allow for automatic hyphenation of words. By this I mean that hyphenation can be specified in the Epub file itself, so that a reader will not need to know hyphenation rules. Note that since Epub files are resizable, all possible points of hyphenation must be specified.

share|improve this question
How would epub handle math ? I'm thinking that an epub format would be a nice touch for my papers when viewed on a mobile browser, but I don't know if the math would get rendered right. –  Suresh Aug 15 '10 at 5:33
Of course this would not be suitable for a math book. But it may be suitable for a novel. –  Andrea Aug 17 '10 at 10:29
@Suresh: EPUB 2.0.1 doesn't have any special support for representing mathematics: you are supposed to represent it using SVG images. The EPUB 2.1 working group is considering including Mathml to support maths. I'm not sure how well ebook readers handle Mathml. –  Charles Stewart Sep 6 '10 at 14:26
Also, epub3 supports MathML now (at least a subset): –  Christoph Jan 19 '12 at 11:03
more recent discussion: –  Ben Crowell Jan 31 '13 at 18:00

9 Answers 9

Pandoc supports converting Latex to Epub. I don't think there's any "black box" solution producing high-quality output, but the HTML that Pandoc generates is easy to work with.


  1. John MacFarlane's Creating an ebook with pandoc (Pandoc site not accessible right now, try Google's cache)
  2. My answer recommending Pandoc to SO question, User manual for Java software: In-application help + PDF, which also discusses some other useful technologies for dealing with Epub conversion.
share|improve this answer
Pandoc doesn't really convert Latex to epub - it leaves a lot of things like figure labels and references out. Might be more trouble "debugging" what pandoc generates, than it's worth, especially if you are converting a 200 page book. I'm tackling this problem right now... –  drozzy Jan 26 '12 at 0:32
@drozzy: In the absence of a good "black-box" solution and you care about quality output, you are going to have to go through the resulting document line-by-line anyway. I'd usually value cleanliness of output over completeness of mapping, based on experience. Using Pandoc's -R option should keep all the needed labels in the output. –  Charles Stewart Feb 9 '12 at 12:12
+1 for answer + for idiom you call "black box" solution. never heard this name/term for it but describes really well, alternatively to "automated", "programmatic" (+ yet to write a solution), or similar. –  naxa Jun 13 '13 at 10:55

I’ve never tried to automate this, but I would think that a script that generates HTML from the TeX source, and then passes that HTML to Calibre’s ebook-convert command line program would be sufficient. You could use TeX4t or similar for the first step.

Do any ePub viewers support hyphenation, even when specified? Most ePub software is based on Adobe Digital Editions, and last I heard, it chokes on this. I doubt iBooks is any better.

share|improve this answer
I'm using Calibre or the Firefox add-on Epub viewer, and both support hyphenation. I don't own an ebook reader, so I can't tell about the support for them. –  Andrea Aug 11 '10 at 17:20
Also, I think that doing LaTeX->HTML->Epub would lose both the metadata and the hyphenation information, which were the reason of my question. –  Andrea Aug 11 '10 at 17:21
I don't know of any way to do hyphenation—I really think it’s a bad idea to try given the current state of ebook readers (as noted in the thread I linked to, ADE, which is what is used on the Nook and Sony Reader, will break the line but not insert a visible hyphen, which is very ugly. As for the other point, calibre will preserve the metadata, so long as either it makes it into the HTML, or you write your script to include it. (See the manual page for ebook-convert I linked above; it has flags for the metadata.) –  frabjous Aug 11 '10 at 20:29

I use the following very simple script:

latexml --dest=$1.xml $1.tex
latexmlpost -dest=$1.html $1.xml
ebook-convert $1.html $1.epub --language en --no-default-epub-cover

It makes use of latexml and ebook-converter (the command line tool that comes with calibre). This works very well with lots of formulas. Once mathML is encoded in newer epub versions things will even get prettier by using latexmlpost -dest=$1.xhtml $1.xml instead of the second line of my script.

share|improve this answer
This is not perfect but it's the best I've seen so far. –  gozzilli Jan 22 '13 at 9:04
+1 never checked that calibre comes with an ebook-converter as stand-alone tool before! –  naxa Jun 13 '13 at 11:05
These binaries are not necessarily on the path. To add them run: sudo ln -s /opt/local/libexec/perl5.12/sitebin/latexml /usr/bin/latexml, sudo ln -s /opt/local/libexec/perl5.12/sitebin/latexmlpost /usr/bin/latexmlpost, and sudo ln -s /Applications/ /usr/bin/ebook-convert –  Filipe Correia May 6 '14 at 13:56

Here's link that mentions using LaTeXML to convert LaTeX to ePub: (see third-last paragraph or so)

share|improve this answer
Indeed, Andrew Ford gave a talk on exactly this topic yesterday. He seemed to have had good success with LaTeXML, although he is still very much learning the necessary points. –  Joseph Wright Oct 17 '10 at 6:16

Is it possible that might be somehow related to the solution requested by the original poster?

(I have only just found Plastex today, and so have had no time to research it very deeply, but I will return and update my post if I find it to be the solution to this question.)

I have found Calibre and Sigil to be excellent tools for working with epub format ebooks, but being able to create epub directly from a LaTeX source document would surely be ideal in my opinion. :)

share|improve this answer
I found PlasTex very easy to use - you need to simplify your LaTeX script slightly but I had my stuff re-compiling perfectly. The only problem is that it looks like a man-page. What I really want to do is turn it into something that looks like a Novel. Any suggestions? –  Salim Fadhley Apr 4 '11 at 23:11

ConTeXt allows for export to xml (and xhtml). With a small wrapper script, it should be possible to convert the output to epub. For example, consider a simple TeX file that inputs another file and has some math in it:


\section {The first section}

\input tufte

  f(x) = \frac 1n \log \Pr(y^n > x)


Processing it through ConTeXt creates a file \jobname.export as follows

<?xml version='1.0' standalone='yes' ?>

<!-- input filename   : test              -->
<!-- processing date  : Fri May  6 23:20:25 2011 -->
<!-- context version  : 2011.05.06 16:52  -->
<!-- exporter version : 0.20              -->

<document language="en" file="test" date="Fri May  6 23:20:25 2011" context="2011.05.06 16:52" version="0.20" xmlns:m="">
  <section detail='section' location='aut:1'>
    <sectiontitle>The first section</sectiontitle>  
We thrive in information--thick worlds because of our marvelous and everyday capacity to select, edit, single out, structure, highlight, group, pair, merge, harmonize, synthesize, focus, organize, condense, reduce, boil down, choose, categorize, catalog, classify, list, abstract, scan, look into, idealize, isolate, discriminate, distinguish, screen, pigeonhole, pick over, sort, integrate, blend, inspect, filter, lump, skip, smooth, chunk, average, approximate, cluster, aggregate, outline, summarize, itemize, review, dip into, flip through, browse, glance into, leaf through, skim, refine, enumerate, glean, synopsize, winnow the wheat from the chaff and separate the sheep from the goats.


              <m:mi>%Gð%@ </m:mi>


(Note: The unicode math characters get garbled during copy paste). This is a translation of the output of the TeX file: the contents of the \inputed file are exported and the TeX math is converted into MathML. This feature is still experimental.

share|improve this answer
In a Usenet thread about this feature,, Hans talks of there being an article on this feature: do you have access to that? –  Charles Stewart May 9 '11 at 12:38
@Charles: That thread is from the ConTeXt mailing list (not usenet). I could not get the Eurotex article. Later in that thread, Hans has said that the latest version allows for an epub export as well but I have not tested that yet. –  Aditya May 10 '11 at 18:30
Context MkIV can generate epub. –  Martin Schröder Oct 4 '11 at 22:18

For kindles you can upload a pdf of your latex file. I added the following to my latex file, and when I uploaded it I found I had a single page per screen at a readable size. There was no need to scroll down the page. However, I used it for a document that had exclusively text. How math would turn out, I can't say.

\usepackage[papersize={4.5in, 6.2in}, width=4.13in, height=5.83in, vcenter, centering]{geometry}
share|improve this answer
Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). Also you don't have to sign with your name since it automatically appears in the lower right corner of your post. –  Adam Liter Apr 2 '14 at 1:26
share|improve this answer
This doesn't work very well: 1. It only supports document classes book and article. 2. It has serious problems with self-defined environment 3. At least for me formulas were not displayed at all. –  moose Nov 8 '13 at 23:25

I use Plastex with theme:minimal, then Sigil to assemble the ePub.

Plastex is open source (Python) so in theory once we understand the code, we could customize it to refine the conversion from LaTeX to HTML. But he raw conversion you get from theme:minimal is not bad at all, including math (which the earlier answer "just upload pdf to Amazon" will definitely not do), plus Bibliography, footnotes, tables (a bit ugly but fixable), \includegraphics very nice, etc.

share|improve this answer

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.