Tools for Writing an Ebook

It never really occurred to me to research which tools I would need to create an ebook because I knew I was going to use Markdown, which could then be translated into pretty much any format using Pandoc. Bu since a few people have asked for more details on exactly which tools I used, here’s a quick rundown:

  1. I write books as single text files lightly marked up with Pandoc-flavored Markdown.
  2. Then I run Pandoc, passing in custom templates, CSS files, fonts I bought and so on. Pretty much as detailed here in the Pandoc documentation. I run these commands often enough that I write a shell script for each project so I don’t have to type in all the flags and file paths each time.
  3. Pandoc outputs an ePub file and an HTML file. The latter is then used with Weasyprint to generate the PDF version of the ebook. Then I used the ePub file and the Kindle command line tool to create a .mobi file.
  4. All of the formatting and design is just CSS, which I am already comfortable working with (though ePub is only a subset of CSS and reader support is somewhat akin to building website in 1998 — who knows if it’s gonna work? The PDF is what I consider the reference copy.)

In the end I get the book in TXT, HTML, PDF, ePub and .mobi formats, which covers pretty much every digital reader I’m aware of. Out of those I actually include the PDF, ePub and Mobi files when you buy the book.

FAQs and Notes.

Why not use InDesign or iBook Author or _______?

I wanted to use open source software, which offers me more control over the process than I could get with monolithic tools like visual layout editors.

The above tools are, for me anyway, the simplest possible workflow which outputs the highest quality product.

What about Prince?

What does The Purple One have to do with writing books? Oh, that Prince. Actually I really like Prince and it can do a few things that WeasyPrint cannot (like execute JavaScript which is handy for code highlighting or allow for @font-face font embedding), but it’s not free and in the end, I decided, not worth the money.

Can you share your shell script?

Here’s the basic idea, adjust file paths to suit your working habits.

#!/bin/sh
#Update PDF:
pandoc --toc --toc-depth=2 --smart --template=lib/template.html5 --include-before-body=lib/header.html -t html5 -o rwd.html draft.txt && weasyprint rwd.html rwd.pdf


#Update epub:
pandoc -S -s --smart -t epub3 --include-before-body=lib/header.html --template=lib/template_epub.html --epub-metadata=lib/epub-metadata.xml --epub-stylesheet=lib/print-epub.css --epub-cover-image=lib/covers/cover-portrait.png --toc --toc-depth=2 -o rwd.epub draft.txt

#update Mobi:
pandoc -S -s --smart -t epub3 --include-before-body=lib/header.html --template=lib/template_epub.html --epub-metadata=lib/epub-metadata.xml --epub-stylesheet=lib/print-kindle.css --epub-cover-image=lib/covers/cover-portrait.png --toc --toc-depth=2 -o kindle.epub Draft.txt && kindlegen kindle.epub -o rwd.mobi

I just run this script and bang, all my files are updated.

What advice do you have for people trying to write an ebook?

At the risk of sounding trite, just do it.

Writing a book is not easy, or rather the writing is never easy, but I don’t think it’s ever been this easy to produce a book. It took me two afternoons to come up with a workflow that involves all free, open source software and allows me to publish literally any text file on my hard drive as a book that can then be read by millions. I type two key strokes and I have a book. Even if millions don’t ever read your book (and, for the record, millions have most definitely not read my books), that is still f’ing amazing.

Now go make something cool (and be sure to tell me about it).