How I wrote and published my novel using only open source tools

From Markdown to paperback and Kindle without proprietary software.

Gabriel Gambetta
Aug 10, 2016 · 5 min read

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 manuscript

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).

Yes, that’s gvim running on Fedora 20.

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

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.

The Golden Legacy on a Kindle.

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.

Paperback

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.

Customising page styles in 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.

The subtle details in formatting make a huge difference in how “professional” the book feels.

Once you’re satisfied with the result, you can print the document to PDF and upload it to CreateSpace.

The results

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!

Published in Techspiration + Ideas + Making It Happen.

Techspiration + Ideas + Making It Happen

Drinking from the firehose, and thriving.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store