Last time, we made some basic Compile settings to get the HTML output looking right. Now, it’s time to make one last tweak—and build an eBook in record time.

You’re ready to go! All you need to do1 is output an eBook, and you’ll be ready to send that book to Amazon and all the other stores, right? … Right?

Well, maybe not. While Scrivener 3 (coming soon) promises some big improvements in eBook production, we still have to deal with things as they are at the end of September 2017. (Interestingly enough, the improvements involve creating the HTML through MultiMarkdown.) After several years of poking at different ways to do things, this is the workflow I’ve found works best for me:

  1. Compile to MultiMarkdown.
  2. Outside of Scrivener, use the MultiMarkdown tool to create the HTML file.
  3. After a few minor tweaks, import the HTML into Sigil, a tool specifically designed for creating eBooks in the standard EPUB format.2

Compile and Convert

While Scrivener comes with MultiMarkdown, there are two reasons you should run it yourself:

  1. MultiMarkdown is under active development. Thus, Scrivener’s version usually lags the newest version.
  2. You want to specify a couple of options that Scrivener does not. They make the HTML output work better with various tools.

This does involve using the command line. It’s really not that scary, though. So grab the latest version of MultiMarkdown from the download page. Double-click the install file, and let it do its thing.

Now, you’re ready to Compile. Go ahead and click it, but there are two more changes you need to make before you actually run it.

  1. In Separators, go to the “Text and Folder Separator” (the last one), choose Custom in the drop-down menu, and enter the following code:

     <hr class="sigil_split_marker"/>
    
  2. In Meta-Data, click the + button to add a new entry. Call it “CSS” and enter this in the text box below:

     ../Styles/styles.css
    

Hit the Compile button and save your MultiMarkdown file.

Now, open Terminal (MacOS X) or Command Prompt (the Microsoft thing), and move to the directory where you saved your MultiMarkdown file. If you saved it in your Documents folder, you can just type (on a Mac) cd ~/Documents to get there.

Next, convert the MultiMarkdown file to HTML:

multimarkdown --smart --labels --escaped-line-breaks mybook.mmd >mybook.html

The --escaped-line-breaks part is the one that Scrivener doesn’t include. If you don’t use line breaks in your book (two spaces at the end of a line), you don’t need to include it.

Home free, right? Not quite. There’s one line near the top of the HTML file that needs to go away:

<meta charset="utf-8" />

While this is perfectly valid HTML, and even the preferred way to specify the file encoding these days, EPUB validators choke on it. Smashwords, at least, won’t accept your EPUB if it doesn’t pass the gold-standard EPUBCHECK validator. Fortunately, it’s easy to fix: open your HTML file in a text editor and remove it (don’t mess with anything else, though).

Let’s Build an eBook!

I assume you’ve already downloaded Sigil from the link above and installed it. Now, start Sigil and open a new, blank, file. Click the + icon in the toolbar to add new files and find your HTML file. If you have graphics, a CSS style sheet file, or fonts, add those the same way. Sigil pigeonholes incoming files in the right folders: Text for your book, Images for graphics, Styles for stylesheets.

Speaking of stylesheets, you need a CSS stylesheet. If you don’t have one, this will get you started. Name it styles.css, and the link in the HTML finds it for you.

h1, h2 {
    font-weight:bold; text-align:center;
    margin-bottom:1em; page-break-before:always; }
h1 { font-size:150% }
h2 { font-size:125% }

p {
    line-height:120%; text-indent:2em;
    text-align:justify; orphans:2; widows:2;
    margin-top:0; margin-bottom:0 }
p.sectionbrk {
    text-indent:0; text-align:center;
    margin-top:0.2em; margin-bottom:0.2em }

Here’s where it gets cool. Open your HTML file, then either go to the Edit menu and choose Split at Markers, or just press F6. This is where that last separator you set up comes into play—Sigil automatically splits your file into individual chapters.

There’s just a few things left to do:

  1. Right-click on the chapter where you want the eBook to open, and choose Add Semantics from the context menu. Select Text in the box, and click OK.
  2. In the Tools menu, choose Table of ContentsGenerate Table of Contents. This builds the internal TOC, the one the eBook reader uses.
  3. In the Tools menu, choose Table of ContentsCreate HTML Table of Contents. This builds the TOC that people see.

That’s it! Save, and your EPUB is ready to test.

Now What?

Now that you can create a nice eBook from Scrivener’s MultiMarkdown export, next time we’ll look at ways to set up printed books. Warning: some parts will get really deep into the weeds.


1Of course, “all you need to do” is one of the biggest lies told in any language. Just sayin’. (back)
2Amazon accepts books in EPUB format. No need to convert to MOBI, they’ll handle it for you. (back)