I’m thinking about self-publishing my novel, Of Fish and Swimming Swords, on Kindle and other ebook readers. Today, I want to talk a little about the process I’m using to build the book as I do final edits and formatting.
The easiest way to build a book for Kindle and have a good chance that it will look like what you want is to create a MobiPocket file. Amazon makes available all of the tools you need to create one of these files. I use a Mac, so if you use either a Mac or a Linux/UNIX system, you should be okay. I’m not sure how things work on Windows.
Ingredients you need to get:
- kindlegen, a program you can get from Amazon
Ingredients already on your Mac or Linux/UNIX system:
I’ll also assume that you unpacked the kindlegen download into your home directory and that the kindlegen program is found at /Users/your-username/kindlegen/kindlegen.
Creating the Workspace
When I’m working on a novel, I have everything I need in a single directory. It helps me keep organized and makes it easy for me to make a backup of the novel without having to tease the files out from everything else on my computer. We’ll call this directory the ‘workspace directory.’
In the workspace directory, I have my chapters, usually with one chapter per file by this point. For right now, let’s have them be HTML files named ch1.html, ch2.html, etc. I use sequential numbers for a reason we’ll see later. If you are only going to be working in HTML, then the numbers aren’t as important. You’ll also want to put here the HTML version of the front of your novel as well as the various special files that are needed to build an e-book, such as the OPF and NCX files.
I also have a ‘graphics’ sub-directory with my any graphics in the e-book. It helps keep the final versions separate from any works in progress I might have lying around in the work directory. For this example, we’ll have ‘graphics/cover.jpg’ be the cover of the book.
Building the Kindle e-Book
Finally, we need to create what’s called a ‘Makefile‘. This is the file that tells `make` how to build everything. It’ll start out fairly simple, but we’ll add some optional parts once we finish building the Kindle e-book.
In your favorite editor, create the following file in the workspace directory and name it ‘Makefile’.
COVER=graphics/cover.jpg HTML_CHAPTERS=ch1.html ch2.html ch3.html ch4.html FRONT=front.html KINDLEGEN_PATH=~/kindlegen #KINDLEGEN_FLAGS=-c2 KINDLEGEN_FLAGS= OPF=novel.opf NCX=novel.ncx MOBI=novel.mobi novel.mobi: $(COVER) $(HTML_CHAPTERS) $(FRONT) $(OPF) $(NCX) $(KINDLEGEN_PATH)/kindlegen $(KINDLEGEN_FLAGS) $(OPF) mobi: $(MOBI)
N.B.: The line after novel.mobi should begin with a tab, not eight spaces.
Make sure that KINDLEGEN_PATH points to the directory holding the kindlegen program. HTML_CHAPTERS should be a list of all of your chapters. OPF is the name of your opf file describing the contents of your e-book, and NCX is the name of your ncx file describing the navigation in your e-book. The kindlegen package from Amazon contains examples of each of these special files. Finally, the file pointed to by FRONT is the material in your e-book that comes before your first chapter, such as the table of contents or copyright notice.
The KINDLEGEN_FLAGS are not set to anything right now. Once you’re ready for the final version of your e-book, go ahead and remove the hash (#) from the first KINDLEGEN_FLAGS line and add it to the second. This uncomments the first and comments out the second. The ‘-c2′ flag tells kindlegen to compress the e-book as much as possible.
Once you have everything set in the Makefile, you can run the following command to build your e-book:
This will look at all of the files in the book: the chapters, the front, the OPF and NCX files, and the cover art. If any of these files are newer than the existing novel.mobi file, or the novel.mobi file doesn’t exist, then the novel.mobi file will be built using the kindlegen command. If you want your e-book to be a different file name, change ‘novel.mobi’ to the name you want everywhere you see ‘novel.mobi’ (should be two places).
Creating Other Formats
So we’re producing an e-book that works on the Kindle. How do we make the other formats, such as an e-pub for Nook? The easiest way is to use Calibre, an open source program that lets you change e-books from one format to another.
I’ll assume that you install Calibre in the default /Applications folder on the Mac. If you’re using Linux or UNIX, you’ll probably know which bits you need to change.
In the Makefile, you’ll want to add a few lines so it looks something like the following. I’ve included the earlier Makefile as I presented it here so you’ll have some context for the additions.
COVER=graphics/cover.jpg HTML_CHAPTERS=ch1.html ch2.html ch3.html ch4.html FRONT=front.html KINDLEGEN_PATH=~/kindlegen #KINDLEGEN_FLAGS=-c2 KINDLEGEN_FLAGS= OPF=novel.opf NCX=novel.ncx MOBI=novel.mobi CALIBRE_PATH=/Applications/calibre.app/Contents/MacOS CALIBRE_FLAGS=--output-profile=nook --input-profile=kindle EPUB=novel.epub novel.mobi: $(COVER) $(HTML_CHAPTERS) $(FRONT) $(OPF) $(NCX) $(KINDLEGEN_PATH)/kindlegen $(KINDLEGEN_FLAGS) $(OPF) mobi: $(MOBI) novel.epub: $(MOBI) $(CALIBRE_PATH)/ebook-convert $(MOBI) $(EPUB) $(CALIBRE_FLAGS) epub: $(EPUB)
Of course, you can change novel.epub to anything you like as long as it’s changed the same way everywhere.
You can now create an e-book for the Nook by running the following command:
It works just like the ‘make mobi’ command. If anything has changed in the HTML files, then it will first build the Kindle version and then convert the Kindle version to the ePub for the Nook.
That’s it. You can now go back to tweaking your chapters, front material, or even cover art and not have to worry about some complex process for creating a new copy of your e-book. In an upcoming post, I’ll talk about what I needed to do to get a PDF for POD publishing.