Design: Formatting your book for electronic publication

Sat 10 June 2017
By Cosmin Deaconu and Marie Deaconu-Baylon

Cosmin Deaconu is the person who helped produce my book. He formatted the book as a CreateSpace paperback and Kindle e-book. He also produced the book cover. He'll share the resources he developed to publish my book. Please feel free to contact me via my website with questions. We are very open to improving these articles and tools.

Table of Contents:



Amazon's Kindle Development Program (KDP) allows you to easily distribute your book via the most popular e-book platform relatively easily. Amazon allows you to upload your manuscript in several popular formats (including Microsoft Word), which may produce satisfactory results, but you won't have full control over everything. In this article, I will describe what I did to produce an Amazon e-book I was happy with.

First, I'll start with a brief digression about what I'm sure everybody is really excited about—e-book file formats! While print books are often sent to printers in a format like PDF, which fixes the position of every letter on every page, this is not ideal for e-books, which you want to be able to be easily readable at different sizes on different devices and so on. For this reason, e-book formats are typically based on HTML, the same format that web sites are displayed in, but there are several different ways to package them.

Files made for Amazon Kindle typically can't be read by other e-readers (like Apple iBooks or Google Play), although because the internals are similar, they are relatively easily converted between each other using a program like Calibre, a free software package for all things e-book. I did not use Calibre in my process, preferring to handle the low-level details myself, but I do not hesitate to recommend it to others as a general tool. Another free tool, more focused on e-book creation, that I have heard good things about (but haven't used) is [Sigil](http:// Like most tools, Sigil works mainly with the EPUB format, which is is used (in some cases with modifications) by most e-readers other than Kindle. However, this is no big problem, as you can create an EPUB and upload that to KDP and Amazon will convert it just fine.

Compared to EPUB, which is a well-documented open format, Amazon's formats are more secretive (although Calibre seems to have effectively reverse-engineered them). Amazon does provide a tool, kindlegen, that you can use to convert your own EPUB (or other files) to Kindle format, but it does not yet support the newest Kindle format, KFX, which they are keeping tighter control over. This newer format is perhaps better known as "Enhanced Formatting." One of the main things it allows is hyphenation, which makes the text look much more evenly justified. If you are on a platform where Kindle Previewer is supported, that will open an older format and allow you to view in the newer format. I think Calibre (at least on some platforms) has a plugin that uses Kindle Previewer (in a way that wasn't meant to be used) to surreptitiously create a file in KFX format. I haven't tried it, and since it's essentially a hack, it may not be the most reliable thing to do.

Finally, Amazon has some detailed (although not particularly lucid) documentation here. I'm not sure I can recommend reading the whole thing, although there are interesting tidbits.

Manually producing an e-book using my tools


The process I used was essentially to construct something like an EPUB from scratch. I say something like an EPUB because it's not really an EPUB per se—it's missing some files necessary to be a true EPUB—but it's enough of an epub to be understood by Amazon's kindlegen. The code I used, which also produces a print version of the book using LaTeX (see related article) is available on GitHub.

An EPUB is basically a zip file that has an HTML version of your book plus a few special files. Therefore, the first step is to convert your manuscript to HTML.

In my case, I used a set of sed scripts (basically a fancy find-and-replace) to convert from the ad hoc style Marie and I used to HTML (that way we could use the same source document for both the print and e-book version, so they would never go out-of-sync with each other). This can of course also be accomplished by a more standard format like markdown (or you can even convert to HTML, to some extent, from LaTeX format). There are a few things to keep in mind:

  • For North for Sun there are both parts and chapters. So I use the HTML <h1> tag (highest-level heading) for parts and <h2> for chapters. You may not have parts in which case you may want to use <h1> for parts.
  • In addition to making the chapter and part title text bigger, we also wanted to be able to jump there from the table of contents. For this reason, you need an "anchor tag," like <a name="ch1"></a> everywhere you want to jump to. The way we formatted the book, it was easy to automatically do this for chapters, (since they were numbered), but because the parts weren't numbered, I just added it manually (since there are only 4 parts and it was easier than coding something up). If you're making your HTML file in a different way, you may need to add these manually everywhere.
  • We also wanted the first paragraph of a chapter to not be indented, which means that the first paragraph had to be a different style. sed is not so adept at multi-line changes, so I had to run it through twice to achieve this properly.
  • I split the title page, copyright notice, and dedication into another HTML file so that it would appear before the table of contents. More on that in a bit.
  • I used the following terms for syles:
    • prt: An HTML section (div) surrounding the part headings
    • cop: An HTML section (div) surrounding the copyright
    • tit: An HTML section (div) surrounding the title page
    • aut: An HTML section (div) surrounding the author page
    • ack: An HTML section (div) surrounding the acknowledgements page
    • ded: An HTML section (div) surrounding the dedication page
    • ni: Style for first paragraph (p) of each chapter, so that it wouldn't be indented.
  • There are some .htmlstart and .htmlend files, which have the necessary HTML bits that go at the start and end. I generate front.html and NorthforSun.html by concatenating those with the files converted by my sed scripts.

In addition to your content HTML files (however you generate it) you need a few more files. Feel free to rename as needed (but you'll have to rename in multiple places, of course):

  • style.css. This controls how everything looks! I added some comments to hopefully guide you.
  • toc.html The table of contents in HTML format. This will appear at the start of your book.
  • toc.ncx The table of contents in some strange XML format. This is used for the navigation tools in Kindle.
  • cover.jpg This gets used as the book cover. Of course you'll probably want a different cover :)
  • NorthForSun.opf This has all the metadata for the book. It defines the other files that are part of the book and so forth.

You can then just put all those in a zip file and that is enough of an EPUB for kindlegen to recognize. For a real EPUB, I think a few more files are necessary, which would not be so hard to add, but because I only cared about Kindle format here, I didn't bother figuring it out. This may change in the future.

I automated the conversion from our custom format to HTML and the creation of an epub using the same Makefile used for the print version. The command, in the directory (assuming you have make, cat and sed, which you will automatically on Mac OS X or Linux, but will need to either install cygwin or the new Linux Subsystem for Windows on Windows).

make NorthForSun.epub

Should do the trick. Then you can run that through kindlegen to produce a .mobi file. If you put kindlegen in the same directory, the Makefile can do that for you too (make kindlegen will complain if it detects any significant problems with your book. If not, you can preview the produced file in the Amazon Kindle Previewer (or upload it to KDP and use the online previewer) to check for any problems.

While this method is somewhat more technically challenging than using a more intuitive program like Sigil, it allows you to make changes as needed to your book and then remake both the print and e-book versions at the same time (just type make to do that... although you will want to read the article on producing the print book first.

Step-by-step instructions


Here are some step-by-step instructions to get you started.

  1. Download the code from the GitHub.
  2. Modify manuscript.txt, author.txt, acknowledgments.txt, dedication.txt, NorthForSun.opf, toc.html, toc.ncx for your book (using what is there already as a guide. See the print article for some more hints).
  3. If you're on Windows, you need some UNIX tools which you can get either with cygwin or the new Linux Subsystem for Windows.
  4. Download kindlegen and put the executable (either kindlegen or kindlegen.exe, depending on your operating system).
  5. Open a terminal (command prompt) and navigate to the directory with the code (for example, cd Downloads/NorthForSun_selfpub if you put everything in the Downloads directory).
  6. Type make If you don't understand how to change the code to rename the book, you can just rename the file at this point.
  7. Check the file you made with the online KDP previewer or the downloadable Amazon Previewer.

Uploading to KDP


Amazon KDP has detailed and clear Help Topics to assist you in your process. I thought the KDP e-book upload was more straightforward than the CreateSpace upload. If you are looking for more detailed instructions, I highly recommend CreateSpace and Kindle Self-Publishing Master Class by Rick Smith. I read this book many times; it was my main reference as I was filling out the KDP steps. Here are a few notes on my observations of the process:

  • Create an account at You can use your existing Amazon account, but I created a new one.
  • Click Bookshelf. Click "Create a New Title" and select e-book.
  • Details: See my article on writing a synopsis for entering a description. For keywords, I entered keywords related to the target markets for my book (mental health advocates/consumers, fantasy readers, and people interested in Asian American and Filipino identity). For categories, I was straightforward and chose Magical Realism and Asian American. Some people think it's helpful to choose smaller categories because you supposedly have better odds for a higher Amazon sales rank. My categories happen to already be small.
  • Content: Upload your file and cover. I made a change to the file once after already publishing. The new manuscript was approved and replaced overnight. In the meantime, the old version of the Kindle e-book remained available for purchase.
  • Pricing: The calculator shows your royalties for different list prices. I'm experimenting with pricing and will share my outcomes in a separate article.

After publishing, I tested the Kindle e-book by purchasing a copy for myself. I figured it was an okay value because I get 70% royalties anyway, and purchases help toward Amazon sales rank. I picked up on an error in this test e-book, and we made the changes and published again. Amazon approved the changes overnight (about 12 hours). The previous version was available for sale during the change.

Back to index