How To Generate your Own eBook (epub from markdown)

This is the fastest way I have found to create an eBook. I use a one-line script to generate an epub file (currently the most popular format and will work on any device that has an e-reader). It's very fast and is a big time saver if you want to make simple ebooks quickly.

I discovered during the production of my first eBook that the "putting it all together" part takes a long time. Gathering written words and ensuring that the formatting is consistent, and they fit into a proper eBook that really opens sucks away time.

The first time I used Apple's Pages. It was a nice experience, but eventually became unwieldy as the book grew in size. Beyond 100 pages, it needs a lot of memory just to be open, and I want to be able to quickly jump around through chapters.

Here's my approach - I save each chapter as markdown and used a little script and a tool called pandoc to generate the whole book in a one liner. I would use this approach if I ever needed to compile a quick eBook.

Generate eBook Script - 2 Seconds With Pandoc

I create a file called build-epub.sh with the following You can also override the css if you are adventurous, but this will get you an epub book from markdown files in one line:

pandoc -o machete-mindset-volume-2.epub epub-settings.txt \
chapter-1.md \
chapter-2.md \
chapter-3.md \
...

☝️ This little script creates the whole ebook in a few seconds and saved me a massive amount of time. I put it in a file called build-epub.sh and just execute it directly. Configure the book metadata via epub-settings.txt which looks something like this and accepts any parameters from here. You can even include identifiers like ISBN and rights if you have those.

---
title: Machete Mindset Volume II
language: en-US
creator:
- role: author
  text: Volume II
cover-image: cover.png
...

The files are small because they are minimal (essentially just html and css), and they let the device have more control over how to render the books. With this script, you'll end up with a standard eBook with cover image that is nice and small for distributing as you see fit!

Markdown formatting for Chapters

The chapters are marked as level 1 headers # and otherwise are just standard markdown. Put them in files named chapter-N.md or adjust the script above.

# Chapter 1: Unearthing the Secrets
The sun had barely risen when I found myself trailing behind my Abuela, a sturdy woman with deep-set eyes and a penchant for wisdom beyond her years...

You can even include images with the following syntax:

![la lune](lalune.jpg "Voyage to the moon")