by

Make Your Own E-Books with Pandoc

Book bindingAs devices for reading e-books proliferate, it increasingly makes sense to make publications available in an e-book. There are a number of cases in which you might do this:

  • If you have a blog and want to make the best posts into an e-book. For example, sociologist Kieran Healy created an e-book of posts from his blog.
  • If you have content in one format that you want to read as an e-book instead. For example, our own Mark Sample took the open-access book Hacking the Academy and turned it into several versions of an e-book for Nooks, iPads, and Kindles.
  • If you want to give your readers the option to read your content as an e-book. For example, I’m the web editor for The Journal of Southern Religion. As a supplement to the articles on the website, I intend to make an e-book of each issue with the articles “bound” together.

Making an e-book can be easy—almost trivially easy—using Pandoc, a tool I’ve written about earlier on ProfHacker. Of course, Pandoc isn’t the only way to do this. Mark has used Sigil and written about it, and another good option is Anthologize, which Julie wrote about.

Since a good way to learn is by doing, let’s create an e-book of My Favorite ProfHacker Posts. You can follow along with the commands below and these files hosted on GitHub, and you can also look at the Pandoc documentation. We’ll use just three posts to keep it simple:

Here’s how to make an e-book with a few commands.

1. Get a clean copy of each of the “chapters.”

You’ll need a clean, plain-text copy of each of the documents that will go into your e-book. You might have them in your blog, in an HTML file, or perhaps in a LaTeX file. Either Markdown or HTML is fine. In this case, since I don’t have the originals of these posts, I’m going to use Pandoc to grab them from the web and convert them to Markdown. (I explained how to do this in the previous post about Pandoc.) Let’s grab Billie’s post and turn it into Markdown; you’d do the same thing for the other two posts.

pandoc -s -r html http://chronicle.com/blogs/profhacker/writers-bootcamp-the-draw-method/23097 -o ch01.hara.markdown

You’ll have to delete the junk from the files, such as the Chronicle’s navigation bar, but this is easy. We’re left with three files, one each for the post by Billie, George, and Mark.

2. Create the front matter

Our e-book will need a little metadata. First we’ll make a simple text file which will be our title page. We’ll call it title.txt. It will have these two lines for the title and author. (See the file on GitHub.)

% My Favorite ProfHacker Posts
% Team ProfHacker

We’ll also need to provide the equivalent of a copyright page, which gives some information about the book. This is also a simple two-line text file, which we’ll call metadata.xml. (See the file on GitHub.)

<dc:rights>The copyright status of this e-book is ambiguous.</dc:rights>
<dc:language>en-US</dc:language>

3. Stitch the e-book together with Pandoc

Now that we have all the parts of the e-book, we can stitch it together with one Pandoc command. You would type this into the command line. (The \s tell the shell that you are breaking one long command into several lines.) The first line calls pandoc, tells it where to find metadata.xml. The second line tells pandoc to output (-o) an EPUB file named my-favorite-profhacker-posts.epub. The remaining lines list the parts of the book in order.

pandoc -S --epub-metadata=metadata.xml \
    -o my-favorite-profhacker-posts.epub \
    title.txt \
    ch01.hara.markdown \
    ch02.williams.markdown \
    ch03.sample.markdown

And that’s all there is to it: you’re a twenty-first-century Gutenberg. You can download our new e-book from GitHub. Now you have an e-book in the EPUB format, which works on Nooks, iPads, iPhones, and iPods, and which you can easily convert to the MOBI format for Kindle using Calibre.

What uses do you have for e-books? Have you made your own e-book? Let us know in the comments.

Photo courtesy of Flickr user Simon Zirkunow / Creative Commons licensed

Return to Top