Here’s how to produce a good looking epub file of your work.
1 – Download and install Pandoc
First off, go download and install pandoc. Pandoc is a command-line tool used to convert ebooks files from one format to another. It is the heart of my little self publishing program, SPAB!. For fiction, the easiest thing to do is start in a markdown-formatted txt file.
2 – Gather your book files
You need:
- Your book as a .txt file, formatted using markdown. See the markdown notes below.
- a custom .css file (or not, but it’ll look way better with one. I have an example below)
- Your book cover image
I would put all of these files in one directory if I were you.
3 – Run pandoc to generate your epub
Open a command window by using the file explorer to find your book directory, hold the shift button and right click on it to get the expanded menu, then click on “Open command window here.”
You’ll get a old school command window that’s already in the directory you need.
Here’s a template for the pandoc command you need to type in.
pandoc -f markdown -t epub --epub-cover-image=cover.jpg -o final.epub --smart --toc --epub-stylesheet=epub.css inputfile.txt
Here’s what this does:
- pandoc the pandoc executable.
- -f markdown tells pandoc that your input file is in markdown formatted text. Pandoc would probably figure this out on its own, but better safe than sorry.
- -t epub tells pandoc to create an epub file. Pandoc can also generate all sorts of other stuff, like pdfs and openoffice odt files.
- –epub-cover-image=cover.jpg use the indicated image as the cover.
- -o final.epub name the output file.
- –smart convert all the striaght quotation marks to smartquotes. Also fixes apostrophes and some other stuff.
- –toc generate a table of contents. It uses all of your markdown headers (see markdown notes below)
- –epub-stylesheet=epub.css style the text in a way that looks professional. I’m including in this post the custom .css file that I use.
- inputfile.txt um, the name of the your text file.
Then hit enter.
Bam! Your epub is created.
Custom .css file
Here’s my custom .css file, which I think makes the prettiest, most professional ebooks ever. At least, it’s what I’m using now. This version is a little better than the one I include in the distribution of SPAB!.
Markdown Notes
Using Markdown to format your text files is simple. The following example explains you the formatting tricks most common to fiction authors.
Other stuff
Here’s a couple of files you can use if you just want to experiment with pandoc using the examplebook.txt and epub.css
Questions? Comments? Concerns? Exclamations?
Yeah. You know what to do.
Okay, now THAT’S nifty. I like this. It’s a close second place to my beloved Scrivener.
I might like that pandoc to convert to something other than .mobi or .epub though. I can most formats, but I heard this will “meat grind” the .doc into an epub too. Is that true?
Looks GREAT B.
Pandoc takes as input markdown, reStructuredText, textile, HTML, DocBook (not microsoft’s .doc), or LaTeX. It’s html input is great to strip out junk html crap. I’ve cleaned several files by using to go from html -> markdown .txt -> html again.
I’m a pretty recent convert to Markdown but it has become my preferred format for much of the writing I do. I appreciate the detailed info on the workflow from Markdown to ePUB. Thanks!