Building books with Markdown using pandoc

Create epubs with pandoc using markdown syntax — painlessly.

John Paul Ada
Jun 29, 2017 · 4 min read

TL;DR: If you want to do this quickly, install pandoc and use my markdown book template.

Installing Pandoc

brew install pandoc

Creating a simple Markdown book

# Chapter 1
## Subtitle
This is your first markdown chapter!

Building the book

pandoc -S -o book.epub content.markdown

Create metadata file

---
title:
- type: main
text: My Book
- type: subtitle
text: An investigation of metadata
creator:
- role: author
text: John Smith
- role: editor
text: Sarah Jones
identifier:
- scheme: DOI
text: doi:10.234234.234/33
publisher: My Press
rights: © 2007 John Smith, CC BY-NC
...
---
title:
- type: main
text: My Book
- type: subtitle
text: An investigation of metadata
creator:
- role: author
text: John Smith
- role: editor
text: Sarah Jones
identifier:
- scheme: DOI
text: doi:10.234234.234/33
publisher: My Press
rights: © 2007 John Smith, CC BY-NC
stylesheet: epub.css
cover-image: cover.jpg
...

Creating a stylesheet

body { margin: 5%; text-align: justify; font-size: medium; }
code { font-family: monospace; }
h1 { text-align: left; }
h2 { text-align: left; }
h3 { text-align: left; }
h4 { text-align: left; }
h5 { text-align: left; }
h6 { text-align: left; }
h1.title { }
h2.author { }
h3.date { }
ol.toc { padding: 0; margin-left: 1em; }
ol.toc li { list-style-type: none; margin: 0; padding: 0; }

Adding a cover image

Applying metadata to book

pandoc -S -o book.epub metadata.txt contents.markdown

Embed custom fonts

pandoc -S --epub-embed-font='fonts/*.ttf' -o book.epub metadata.txt contents.markdown

Add a Table of Contents

pandoc -S --toc --epub-embed-font='fonts/*.ttf' -o book.epub metadata.txt contents.markdown

Epub Template

pandoc -S --toc --epub-embed-font='fonts/*.ttf' -o book.epub metadata.txt contents.markdown

Programmers — Developers

The official publication of the Programmers,Developers…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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