9

I want to create epub document, but I only have a tex file (unfortunately, mathematical formulas, and drawing diagrams). I tried pandoc: tex to html, tex to xhtml, to xml, but nothing works properly. I use tikz.

You can do the epub file with png or svg?

Some ideas?

  • 2
    This question has been asked before several times. Look at the answers here: tex.stackexchange.com/questions/1551/use-latex-to-produce-epub. From my personal experience, every solution needs some tweaking. I've been playing with tex4ht to generate html, do some tweaking, build the epub with a script, some more tweaking and then calibre. As for images, I don't remember if epub supports svg, but it does support png. – Nico Jan 30 '14 at 14:25
  • Thx, I'll try, but I must have an automatic tool. – mkjasinski Jan 30 '14 at 14:29
  • The tweaking I've mentioned I've managed to do it with a script. Actually, 2. One to convert to html and one to create the epub. – Nico Jan 30 '14 at 14:34
  • I've done a lot, but I can't do charts. – mkjasinski Jan 30 '14 at 14:37
  • 2
    You're unlikely to get perfect results with pandoc, unless your tex file is pretty simple. However, this might be of interest: a pandoc filter that will process the tikz diagrams in your document and turn them into embedded images which can appear in the EPUB. For background on pandoc filters, see <johnmacfarlane.net/pandoc/scripting.html>. – John MacFarlane Jan 30 '14 at 18:32
2

OK, I have solution.

  1. create pdf (input.tex)

    pdflatex input.tex
    
  2. create png

    convert -quality 05 input.pdf output.png
    
  3. create html (png files have so much how many pages in PDF file, for example: 4)

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8"/>
        <style>
            img {
                display: block;
            }
        </style>
    </head>
    <body>
        <img src="output-0.png"/>
        <img src="output-1.png"/>
        <img src="output-2.png"/>
        <img src="output-3.png"/>
    </body>
    </html>
    
  4. create metadata for EPUB (metadata.xml)

    <dc:title>[ebook_name]</dc:title>
    <dc:identifier id="pub-id">[ebook_id]</dc:identifier>
    <dc:creator opf:file-as="[secondName,firstName]" opf:role="aut">[firstName secondName]</dc:creator>
    <dc:rights>[company]</dc:rights>
    <dc:language>[lang]</dc:language>
    <dc:publisher>[company]</dc:publisher>
    
  5. create epub file

    pandoc -f html -t epub3 --epub-metadata=metadata.xml -o output.epub output.html
    
-1

Your best bet might be the tex -> pdf -> epub route. Calibre or other software can make a decent attempt, but it will probably not be fully automatic.

  • I tried, but unfortunately there are problems with graphs. I must have an automatic conversion tool, Tex is built automatically, epub also must be built automatically. – mkjasinski Jan 30 '14 at 14:28
  • 4
    Using pdf as an intermediate format is a disaster. Loses all semantic markup, many paragraphs, introduces new paragraphs at every page break. Just. Don't. – WillAdams Jan 30 '14 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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