[Tex/LaTex] LaTeX document to epub or mobi ebook formats (with mathematical formulas)


Recently I purchased an ebook reader (Kindle), and I want to export some of my document in LaTeX to an ebook format.

I tried exporting from LaTeX to PDF, but isn't perfect because I have to zoom in-out and move around the page many times (isn't confortable like when you read a normal ebook purshased in book stores).
I tried too exporting to RTF, but none of my mathematical formulas were in the output document.

So, do you know a better way to export from LaTeX documents to ebook formats that includes mathematical formulas? And, that works with Kindle (mobipocket)!

Best Answer

tex4ht does an excellent job at converting LaTeX to (X)HTML, and it can convert math to either bitmap or MathML in the process. From there, you can use Calibre to convert the HTML to EPUB or MOBI.

For example, if you want to produce XHTML with MathML, using UTF-8 encoding, you can do:

mk4ht htlatex youfile.tex 'xhtml,charset=utf-8,pmathml' ' -cunihtf -utf8 -cvalidate'

See the documentation for more examples.

On Wikipedia's LaTeX example, this produces a MOBI file which looks like this in Kindle PC Reader:

LaTeX to mobi, with formulas

There's probably a bit to fine-tune, but the idea is there, you get the formulas. Fine-tuning might include disabling ligatures for example.

Note that the tuning might be done in the XHTML to MOBI conversion process, possibly with Calibre's options, since the HTML document looks fine:

latex to XHTML