A Quick and Dirty Guide to Creating an EPUB with Pandoc

14 March, 2020

As you may or may not know, I publish an email letter called Weekly Musings. To celebrate the letter’s first year, I recently decided to collect the first 52 essays into an ebook.

With the last few ebooks I’ve published (at least ones in EPUB format), I’ve written them in a desktop application called Sigil. This time ’round, things were a bit different.

The 52 essays that I wanted to collect in the book were individual files formatted with Markdown. Converting them to HTML (which is file format in which Sigil stores chapter files) and importing them into Sigil would have been a bit of a chore. Instead, I turned to Pandoc to quickly do the deed.

Pandoc, if you’re not familiar with it, is something of a Swiss Army Knife for converting between markup languages. Pandoc can also create EPUB files.

Let’s look at how I did it.

What You’ll Need

Before you can create the ebook, you’ll need to install Pandoc on your computer.

You’ll also need:

As I mentioned at the beginning of this article, my book was a set of 52 separate files. I also added an introduction, an author bio, and a colophon. I had to combine all those files into one. I’ll explain how to do that in a future article.

Doing the Conversion

So, you have everything you need. How do you create an EPUB? Use this command:

pandoc --toc --toc-depth=1 --epub-metadata=metadata.yaml --epub-cover-image=cover.png --css=book.css -o myebook.epub

Let’s break the command down:

If everything goes well, you’ll have an EPUB file within a few seconds.

To test your book, open it in an ebook reader. You should also run it through an EPUB validator to make sure there are no problems with the file.

This definitely wasn’t the most elegant way to create an ebook. While quick and dirty, the job got done and I had an ebook ready for download by a wider audience.

Scott Nesbitt