Pandoc, Markdown and eBook-production

Why don’t you save the long pandoc command lines as a bash script?

In this project I write in Markdown most of the time. I may need the same text in many formats:

  • .docx for the boss
  • .pdf for nice presentations
  • .tex for serious work
  • .epub for ebooks
  • .mobi for Kindle

I have chosen to write most of my texts in Markdown. Pandoc can transform Markdown to all the formats above. Except perhaps .mobi. Here you need Amazon’s kindlegen.

In order to create an Ebook and a Kindle version, you need to:

pandoc -o myText.epub
kindlegen myText.epub

Kindlegen will create a file with the .mobi extension: That’s it. Your book is ready for Kindle.

Here’s a list of pages, that I tend to use over and over again:

Let’s try a conversion from Markdown to an eBook. The –ebook-cover will ad a frontpage. So you’ll have an eBook with a nice cover. The –toc means Table of Content.

pandoc -s --epub-cover-image=owl.jpg --toc meta.txt -o x.epub

As you progress the pandoc commandline tends to become very long indeed. I save such lines i as a bash script. Here’s a sample:

# Create the eBook and a Kindle version of the same
pandoc -S --epub-cover-image=owl.jpg --toc -o yourBook.epub meta.txt
kindlegen yourBook.epub

Save the file as Then run this command: chmod a+x Now you can run the entire command like this:


in a terminal. As soon as your pandoc command works you can save it for future use. You could even save the script in


Then you can use your script as a Linux command.

I’m sure that you can do something similar in Windows or OSX. In the heyday of MS DOS I might have saved the pandoc command in a .bat file. But in the end I prefer a Linux solution.

By thine own ingenium create your solution …


By Per Thykjaer Jensen

Per is the WordPress expert at Business Academy Aarhus. Senior Lecturer at the Multimedia Design Programme. His background is in the Arts: MA Literature History and BA Art History. Later he added a MA in IT, interaction and Multimedia. And he is a wicked Linux user.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.