How I wrote and published my novel using only open source tools
From Markdown to paperback and Kindle without proprietary software.
I've recently published my first novel The Golden Legacy on Kindle and paperback through Amazon, achieving very professional results. Along the way, I created a process and a couple of tools based exclusively on open source software. Here’s my process.
The most important piece of content for publication is the manuscript (i.e. the text of the novel). I originally started writing this in a Google Doc, but it soon became apparent that Offline Mode wasn't as robust as I expected (this was critical for me, since I wrote the whole novel during my daily commute), and Docs had latency problems handling a really big document. So I wrote a quick script to export the text to Markdown and abandoned the Google Doc.
There are many editors for Markdown. For a brief period of time, I used Texts on Mac, but in the end I went the old-school way with vim (gvim on Linux and mvim on Mac).
I didn't use much formatting. I used # for chapter headers, ## for chapter subtitles (e.g. dates and locations), and indented text for preformatted monospaced sections (the novel includes some encrypted text the protagonists attempt to decode).
Kindle and epub
I created a separate Markdown file for the front matter of the book, that is, all the text that comes before the text of the novel itself (I consider the Prologue and the Epilogue integral parts of the story). The front matter includes the title page, colophon, and acknowledgements. I also had the book cover as a separate file.
The magical tool that converts this into an epub file is the fantastic pandoc. Besides the text (both front matter and manuscript), it can also take the filename of a cover image, a metadata file, and a stylesheet file.
The metadata file is an XML file with Dublin Core tags such as title, author, and copyright line. Although this information is already included in the front matter, this is metadata for the epub file itself, and not part of the text visible to the reader.
The stylesheet file is a CSS file that lets you customise the appearance of the book. In my case, I just modified the Header tags to be centered, but used the defaults otherwise.
Pandoc produces a very good epub file with these inputs, but I wanted further customisation. Since an epub file is a zip file with some HTML and metadata, I wrote a quick Python script that unzips the file, moves a few things around in the content.opf file, and reassembles the epub.
This epub file is directly readable by Apple iBooks and Google Play Books. For Kindle, you create the same epub file but without the cover, and then upload the epub file and the cover image separately during the setup process in the Kindle Direct Publishing site.
Creating the ebook files is straightforward. Paperback is substantially more complex, since you have full control over the formatting of the book.
I went with CreateSpace, which does print on demand, and is fully integrated with Amazon. For CreateSpace you need a cover file and an interior file.
The cover file is a high-resolution PDF file with the back cover, the spine, and the front cover, with a blank space where CreateSpace inserts the ISBN. There are templates and very exact guidelines on their website; just ask the cover designer to follow them.
The interesting part is the interior file. This is another PDF file which will be printed exactly as it looks, so it’s extremely important to get it right.
To create this file, I used Pandoc again, this time to convert the Markdown files to ODT (OpenDocument Text), which can be read by LibreOffice.
The key step is to provide a reference ODT file to Pandoc. Pandoc takes the styles, headers, and footers from this document and applies them to the output. So here is where you define the page headers and footers, the way chapter headings and subheadings look, and so on.
LibreOffice has many page formatting options that are non-obvious but incredibly important. For example, I wanted the first page of each chapter to be a right page, and to exclude the page header. I defined my chapter heading style to have a “page break before” and set a page style of “first page” (which is a right page without a header), which is followed by “right page,” which is followed by “left page,” which goes back to “right page.”
Getting the spacing right for the title page was tricky as well. I wanted it vertically centered, which doesn’t exist as a concept in Markdown, so I just inserted empty lines.
Once you’re satisfied with the result, you can print the document to PDF and upload it to CreateSpace.
I couldn't be happier with the finished book — it looks fantastic! Give CreateSpace correctly formatted PDF files, and they will give you an absolutely professional-looking book. And holding your actual, tangible, physical book in your hands is hard to describe.
The Golden Legacy is available on Kindle and in paperback on Amazon. If you want to read it but not buy it, contact me and I’ll be happy to get you a copy. This is my first novel, so feedback is extremely welcome!