Ebook Design

A Linux User’s Guide to Formatting Ebooks (Part V)

We’re getting there. One last step and we’re done!

First thing we’re going to do is slap some XHTML headers at the top of our file. Then we’re going to add our CSS. And finally, we’re going to apply that CSS to the relevant bits that need it.

I was going to post a whole bunch of HTML and CSS code in this blog post, but it turns out that is incredibly, hair-pulling-out, I-want-to-fire-a-bazooka-at-a-cow-in-Cambodia PAIN IN THE ASS to try to do such an (admittedly) trivial thing in WordPress.

So I won’t.

Instead, since I post all of my ebook source code on GitHub, I’m going to direct you there, and comment on it from a distance. Here’s the sample we’ll reference: The United States of Air.

(Feel free to borrow the HTML and CSS source code, by the way. The novel is licensed Creative Commons BY-NC-SA, but the code is so basic that the idea of applying copyright to it is downright ridiculous.)

So. Have a look at the first five lines of that HTML. Don’t fuss too much. Just copy and paste them at the head of your own righteous manuscript. (Being sure to change to change the title, of course!)

Lines 7-133 are the CSS declarations that tell the Kindle or epub viewer how to display your text. You can fully customize these to your heart’s content. My own design philosophy is: Keep It Simple. Readers want to read ebooks the way THEY want to read ebooks, so I don’t try to force any particular font or fixed layout down their throats. I would rather make my content as easily accessible as possible than win points for frills.

(If, on the other hand, you are a frilly type of person, perhaps you would be so kind as to post some of your own code snippets? No doubt there are readers of this blog who would like to know how to do all that.)

You’ll want to learn a bit about HTML and CSS if you haven’t already. A good, ebook-specific starting point is Guido Henkel’s now-famous series on ebook formatting from 2010. The code I’m sharing with you I borrowed from Guido, and have been modifying and tweaking over the years to suit my own style. You should do the same.

Now comes the fun part: You need to add the CSS “class=foo” declarations inline where relevant. In practice this means front matter, back matter, and chapter titles. Plus anything unusual in your book, like photos or footnotes or other non-standard layout stuff. Have a look through my own ebook source to get the idea. This will take you maybe half an hour, once you get the hang of it.

Finally, don’t forget to whack the last two lines of my ebook at the end of your own.

Now comes the moment of truth: Is this valid XHTML? And once converted, with it pass muster with Kindle and epubcheck?

Grab yourself a copy of the `tidy` package (sometimes called `html-tidy`). Run it like so:

$ tidy -e my_ebook_source.html

It will tell you where you screwed up. And trust me. You will screw up. Always. Don’t forget to do this step.

Now we’re going to convert the book in calibre, which (if for some reason you don’t already have a copy !?) you can download here.

You can open calibre as an application, but I find this really slow. And since I never use calibre for anything other than ebook conversion, I find it easier (and faster) to use the command line, which is fully documented here.

You can see examples of how I run this on the command line here. (I could bash my forehead against the screen trying to get WordPress to let me copy and paste code…but picking glass shards from my eyebrows somehow doesn’t appeal).

So there you go. Run calibre three times to get your epub, mobi and pdf files, and you’re good to go.

Almost forgot–one final step I recommend is to run epubcheck on your epub output file. Not only to make sure your epub is good, but because this can highlight problems with the kindle file as well.

Download epubcheck from GitHub, follow the instructions in the README (not complicated) and NOW you’re set.

…except for that ugly duckling no one can live without. The ebook distributor whose name we dasht not speak.

Smashwords.

Oops!

See my forthcoming post Wrangling LibreOffice for Smashwords. (Yes, it can be done!)

Written by: J.M. Porup

Novelist J.M. Porup is An American Dissident in Exile. Read More

Recommended

Leave a Comment