LaTeX to Epub

So, let's pretend for a second. Let's pretend that you write literature and - for reasons beyond mortal understanding - you write in LaTeX. I know: Crazy, right? In this purely hypothetical situation, you might one day want to convert your beautiful TEX-file into an even more stunning EPUB. Oh, and for the sake of argument: Let's say you're an Ubuntu user.

First, you might want to clean up your TEX. Do use normal quotation marks? Meet the csquotes package! It will make your live a whole lot easier and your novel a whole lot more awesome. You might end up with a line in your header that looks somewhat like this (language parameters may vary):

\usepackage[babel,german=guillemets]{csquotes}

Instead of plain old "Yo, man, that's kinda cool" you'll end up with »God, this is fucking awesome!«. Also: For linebreaks, use \par instead of the regular \\. Don't want to do a search & replace for all your 67 chapters? Don't worry, I've got you covered:

\renewcommand{\\}{\par}

Put this line into your master document's header and you'll be fine. By the way, I'm using this document class, but I think you'll do alright with whatever you are comfortable:

\documentclass[12pt,twoside,titlepage,openany]{scrbook}

So, let's get a-converting! You'll need to install tex4ht which combines several tools to convert tex to html. And yes, this step is necessary. And because I know that you probably are a lazy bastard like myself, here's the command line for you to copy:

sudo apt-get install tex4ht

Next, punch in

htlatex filepathandname.tex

and watch the magic happen. If the tool runs through fine, you'll end up with a HTML and a CSS-file of your TEX-document. Neat, right? There are other tools to convert TEX to HTML, but I got the best results with tex4ht and htlatex. But alas, now it's time to teach your ebook-to-be how to be beautiful. Because, let's be serious, you wouldn't want just any ebook. No, your ebook has to wait for you at home completely oiled up and dressed in nothing but fishnet stockings and high heels.

Open the HTML-file in your text editor of choice. (Nobody said this would be easy. What? I did? Well, I LIED!) You'll have to search and replace four HTML-characters. Why, you might ask? Because tex4ht was obviously not intended for literary use and the programmer didn't know the first thing about text layout.

You need to replace

  • ≫ with »

  • ≪ with «

  • > with ›

  • < with ‹

Next, open the CSS-file. (Bear with me, it will totally be worth it!) There are two styles defined in the first few lines, .cmmi-6 and .csmy-6. Delete or comment both or just get rid of the font-style and set font-size to 100%. That's it for the nasty text editor bit!

Now get Calibre if you don't have it already. (You should have it.) Import your HTML-file as new book, then hit the "convert books" button. Type in your metadata, go to "Look & Feel" and check the following boxes:

  • Remove spacing between paragraph (English or American writers might not want to check that box as I've seen a lot of English books with spaced paragraphs)

  • Smarten punctuation

  • Keep ligatures

I don't have any ligatures, but I still check the box because I like the thought of having ligatures. It makes me feel sophisticated. Go to the "Page Setup"-menu and set the margins you would like your ebook to have. Without margins, your text will look completely unprofessional. I use 30 pt margins for left and right and 20 pt margins for top and bottom. There are a lot of other settings to fiddle around with, but the EPUB will now be sufficiently sexy to please your eyes with its sweet yet alluring demeanor.

Convert that hussy and have fun! But for goodness' sake: Close the door to your room before you do.

 

Add new comment

To prevent automated spam submissions leave this field empty.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
6
K
d
E
9
c
Enter the code without spaces.