Kindle Formatting Guide

Amazon’s Kindle Direct Publishing service offers great opportunities for independent writers.

It’s also easy to use. Just make an account, fill in some details, upload your source material and… that’s it. Your work is in (digital) print, available to one and all.

So easy.

Except it’s not very easy, because Amazon wants your source material in HTML + CSS format. So you spend hours lovingly hand-crafting a document, and the Kindle just laughs in your face. It doesn’t understand your choice of CSS. It messes up certain HTML constructs (I’m looking at you, <p> tags inside <blockquote>s). Paragraph indents that seem fine on a real Kindle end up broken on the iPad app. This is not conducive to good mental health.

Consequently, I thought I’d share my method for generating Kindle eBooks (or at least the raw HTML) with a minimum of pain and suffering. It’s not for the technophobe (familiarity with Linux and the command line is expected), but maybe it’ll help someone…


* If you need help installing Cygwin, this guide I found looks pretty nice: how-to-use-linux-commands-in-windows-with-cygwin – but I suggest you don’t add the Cygwin path to your Windows environment variables (since it won’t help us here). A base install includes everything you need except Perl, so make sure you search for and add this at the ‘Select Packages’ screen.

Step 1: Write Book

Please don’t write your book using a word processor. Or more specifically, don’t use the inbuilt formatting options of your word processor. This path leads to pain and suffering.

Instead, write your book in plain text (i.e. as one or more ‘.txt’ files). Formatting information (chapter headings and suchlike) should be specified using MultiMarkdown. Don’t worry – the syntax is so simple. Everything the average writer of fiction needs to know is contained within the following example:

# This a Part heading #

## This is a Chapter heading ##

This is a paragraph. Paragraphs are
separated by one or more blank lines.

This another paragraph, followed by
a scene break.

### Scene ###

The following words will be rendered
in an italic typeface: *emphasised text.*

The following words will be rendered
in a bold typeface: **novels should
not contain bold text.**

> This is a quotation.
> Some authors like to start sections
> with a quote or something similar...

Isn’t that nice? You don’t have to waste time with page margins, paragraph indents, header styles or any of that nonsense. It’s just text, with a handful of markup tags – very clean, very easy to convert into whatever format you want.

Auxiliary notes:

Step 2: Prepare eBook Build Environment

Download this file: my_ebook.tar.gz

Extract it by opening a terminal window (of either the Linux or Cygwin variety) and entering:

cd path/to/download/directory
tar -xvzf my_ebook.tar.gz

This should produce a ‘my_ebook’ folder with the following internal structure:

|-- [aux]
|   |-- book_info.txt
|   |-- css.html
|   |-- front_matter.html
|   \-- Metadata__ebook.txt
|-- clean.bash
|-- make.bash
|-- [out]
|-- [src]
|   \-- test.txt
\-- [tmp]

All you have to do is:

  1. Put your book’s source file(s) in the ‘src’ directory, replacing ‘test.txt’. If you have multiple files, make sure they are named such that normal alphanumeric sorting lists them in the order they appear in the book (i.e. call them my_book_part1.txt, my_book_part2.txt, etc.).
  2. Open ‘aux/book_info.txt’. Replace ‘My Book Title’ with the title of your book. Replace ‘My Name’ with your name (or pen name).
  3. Open ‘aux/front_matter.html’. Replace ‘__DEDICATION__’ with whatever text you want to appear on your book’s ‘dedication’ page. If you don’t want a dedication, just delete lines 16–20 (inclusive).

More auxiliary notes:

Step 3: Build Your eBook

In your open terminal window, just enter:

cd path/to/my_ebook

You will find in the ‘out’ directory a formatted HTML version of your book, complete with table of contents, all ready for upload to Kindle Direct Publishing.

That’s it.

Perfect results every time.


Final auxiliary notes:

…and if you’re using Cygwin, and weird/bad things happen, you might be able to fix the problem by running ‘dos2unix’ on your source files – i.e. type this in your terminal window:

dos2unix path/to/my_ebook/src/*

Any problems? Spot any mistakes? Please let me know.