Formatting an ebook

17 03 2011

So after I  published four stories as ebooks, it came to my attention that the Kindle versions had some formatting issues.  The big problem was that every now and then the indentation of paragraphs got screwed up.  Instead of just indenting the first line of a new paragraph, it indented every line.  It didn’t do this very often  (if it had I would have noticed it earlier) and would return to the proper formatting after just a couple bad paragraphs .

This was unacceptable to me.  It visually disrupts the reading experience and can yank the reader out of the story.  Very bad, so I needed to fix it.  It took me several hours of tinkering to figure out how to do it.  Maybe I’m just inept, but the process didn’t seem very straightforward to me so I’m going to spell it out here for the benefit of others.

(And to those who already purchased my ebooks, I’m sorry for the mistakes.  I uploaded new versions which should go live in the next 24 hours or so, but I believe only for new customers)

Warning to those who don’t give a damn about ebook formatting and the creation of epub / mobi files: this post will be extremely boring / useless to you.  I recommend you watch this video of a guy failing at an automatic door instead and come back when I post something else.

Ok, now that we’ve gotten rid of them let’s get down to business.  I originally uploaded the stories to Kindle Direct Publishing as Word documents formatted in accordance to the Smashwords Style Guide.  I did this since I was uploading to Smashwords as well and they seemed to have the more stringent (or at least more thoroughly defined) formatting rules.  I went back and looked at my source document to see if there was any funky Word formatting in there that would cause the weird indentations.  There was not, or at least not that I could find even with the “Show all nonprinting characters” thing turned on.  Since I was unable to solve the conversion problem, I decided I needed to cut out the conversion process and produce my own ebook files directly.

Easier said than done.  I needed to find some software that would allow me to create, edit, and save epub / mobi files.  For some reason this appears to be a relatively rare thing.  I found a few helpful tools for this (and a few not so helpful tools), and will outline them below.

Scribus –  http://www.scribus.net/canvas/Scribus

This software package, as it turns out, does not help in creating ebooks.  At least not directly.  As such I considered just omitting it from this post, but figured it was worth mentioning because several people interested in ebook formatting would also be interested in POD formatting, and that’s where Scribus would come in handy.

It is a free desktop publishing application.  For those who loved analogies on the SATs, Scribus is to inDesign as OpenOffice is to Microsoft Office (or GIMP is to Photoshop).  Not as feature rich as inDesign (hey, it’s free), and I’m not going to go into its use (I barely touched it after I discovered it didn’t output epub files), but if you are looking for a free alternative to inDesign it would be worth looking into.  I checked it out because I know that inDesign can save epub files, so I figured I’d see if Scribus can.  Alas, it (currently at least) cannot.

Calibre – http://calibre-ebook.com/

My Google searches led me first to Calibre, which is basically a free conversion tool.  But it seems primarily aimed at content consumers instead of content producers.  If you buy a DRM-free epub book but wanted to read it on your Kindle, you could use Calibre to do the epub to mobi conversion.  It can import and export a variety of formats, and many authors seem to use it for that purpose when producing content.  For example, it accepts RTF as a source so you could use it to go straight from Word to epub/mobi.

But I didn’t like it very much.  Using it instead of the automatic Kindle Direct Publishing converter was really just exchanging one automatic converter for another.  True, it gives you some more options, but it’s still just a converter and you can beat your head against a wall trying to coax it into converting things the way you want them.

And as far as I can tell, using Calibre to produce a mobi file for upload to Kindle Direct Publishing is a TERRIBLE idea.  It always seems to create a table of contents and appends it to the end of the mobi file.  Not only does the formatting of the auto giant-font table look hideous, it’s completely unnecessary for a short story and in the wrong place for a novel (who puts the TOC at the end?).  For the life of me I couldn’t get it to stop doing that, and about 15 minutes worth of Googling suggested  that a) others have the same problem, and b) if the solution to this problem exists, its obscure enough that 15 minutes of Googling didn’t reveal it.

Sigil – http://code.google.com/p/sigil/

First, the good news.  We finally arrive at the tool that you will actually want to use, and it’s free.  As far as I can tell, Sigil is the only program that allows you to actually edit (instead of  just convert to) epub files.  It is also a WYSIWYG (what you see is what you get) editor, so you can be (reasonably) confident that when you get the formatting the way you want it within the program, it’s not going to get screwed up downstream (a little more on this later).

Now, the bad news.  Sigil is not very helpful in actually creating the formatting.  The formatting is controlled through CSS style sheets, which means HTML type coding.  You probably don’t want to do this from scratch.  Instead, you want to first convert your story with formatting into HTML (Word can save your document as an HTML file) and then import it into Sigil for tweaking.  Or, as I found, the Smashwords-generated epub file is remarkably clean.  Their converter seems much better than Amazon’s (although, to be fair, Amazon did the conversion in a few seconds where as my story waited in the Smashwords “meatgrinder” queue for over 24 hours).  If you have already uploaded to Smashwords you can download an epub copy and open that up in Sigil for tweaking (for example, you probably want to remove the “Smashwords Edition License Notes” thing before uploading to Kindle).

Speaking of using the Smashwords epub file, one thing I noticed is that it had some meta data in it that I did not expect.  Apparently it pulled the Word registration data and included the software registered user name as the “author.”  So, if you are writing under a pen name and do not want your real name attached to your story for whatever reason (e.g. the internet is for porn), you may want to check this and make sure your name is not secretly attached in the meta data.

After verifying my chapter indentation in Sigil and editing some meta deta I wanted to upload the ebook to Kindle.  Unfortunately, Sigil only saves in epub and not mobi.  Using Calibre to convert to mobi is once again a TERRIBLE idea (stupid appended TOC.  Every.  Single.  Time), so I tried uploading the epub directly (Amazon’s automatic conversion can take epub as an input, much like it can take Word documents).

Once again, formatting issues.  Different ones this time, though.  My indentation was finally consistent, but my scene breaks of three centered asterisks:

* * *

all became left justified.  And my “About the author” section at the end had the heading and  first line of the paragraph indented when I didn’t want it to.  These formatting issues were not there in the epub version.

I spent about another hour fruitlessly searching for a Sigil-like program for mobi files.  Then I realized that my initial title page had centered text that converted just fine, so I decided to interrogate the code to see why those translated fine while my section breaks did not.

It comes back to those CSS style sheets.  It appears that when Amazon does the file conversion, it pays attention to formatting instructions in some areas and ignores them in others.  The trick, then, is to place the instructions in the right spot so that it won’t be ignored.  If you go to the “code view” so that you can see the actual html codes, this was what my properly centered byline looked like:

<p class=”western”>A. G. Baines</p>

And this was what my improperly not-centered scene dividers looked like:

<p class=”western5 sgc-1″>* * *</p>

The <p> and </p> tags merely mark the beginning and end of a paragraph.  The class=western stuck in the opening <p> tag refers to a named paragraph formatting style defined in the css file.  The definition for “western” was as follows:

.western {
display: block;
font-size: 1.125em;
font-weight: bold;
line-height: 150%;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin-top: 1em;
text-align: center

}

Notice the last attribute, which tells it to be centered (I made it bold for emphasis).   Any paragraph referencing the style “western” will be formatted accordingly.

Now look at my scene divider code again.  The style is “western5 sgc-1″.  The problem turned out to be that the “western5″ style defined in the css file did not have the text-align: center attribute in it.   To make the text centered,  ”sgc-1″ was appended to the style name, which referred to a little snippet of code within the header of the html file:

<style type=”text/css”>
@page { margin-bottom: 5.000000pt; margin-top: 5.000000pt; }
p.sgc-1 {text-align: center;}

</style>

(bold again added for emphasis)

This “sgc-1″ callout was what made the text alignment centered in the epub file.  It overrode the standard alignment of “western5″ defined in the css sheet.  However, it appears that Amazon only pays attention to alignment tags within the style definitions in the css file.  It ignores the overrides.  Since “western5″ was not center aligned by default, my asterisks were not centered after the override got ignored.

You should thus always control your formatting through these style definitions in the css file.  If you need subtle changes to one style, define a new style and use it instead.

I was also able to fix my “About the Author” section by editing the style definitions used there.  By default, the Kindle will automatically indent the first line of every paragraph by some default amount.  To override this, you must manually tell it to use a different value (included zero) with the following argument within the style definition:

text-indent: 0.0in;

For the about the author section, I made the value 0.0 for no first-line indent.  For the body of the text I made it 0.25.  Smashwords had it originally at 0.5 since I had a half inch indent on the Word document I used as a source file, but I thought it was too big and looked funny on a smaller screen.

Well, that’s about it.  Once I put all the formatting instructions in the right place the conversion from epub was perfect.

If you are unsure if your epub will convert nicely over Amazon’s conversion process, Amazon has produced a couple of tools to help you.  You can find them here.

First, Kindlegen.  This is a command line tool for converting various formats to mobi.  Let me emphasize the COMMAND LINE aspect of this.  That means in Windows you are bringing up a DOS prompt and on a Mac you are opening up the terminal utility.  There is no graphical user interface.  I did get it to convert, but it was hardly user friendly.

Kindle Preview.  Now THIS is useful.  You can open up your epub file (by clicking on it!) and it will show you what it will look like on the Kindle.  They even put a fake little battery meter in the corner to emulate the total experience.  So use this to make sure the Kindle doesn’t ignore some key piece of formatting.  It even looks as though the previewer produces a mobi file in the process, so you get your file converted as a side benefit (not sure then why anyone would ever use kinglegen, though I guess you could automate that for large batch processes).  Once you get things looking right on the preview, upload either this generated mobi file or your source epub file.  Either one will come out looking the same.

Hope this helps.








Follow

Get every new post delivered to your Inbox.