Wednesday, August 17, 2011

My ePub file is finally awesome

But before I get to that: I’ve uploaded the final part of my book excerpt, Chapter Three! I’ve also re-uploaded chapters 1 & 2 because I made some minor changes in them as I was going through my print proof. My second proof was ordered today, so barring anything crazy with that, I hope to be ready to publish by the end of next week. Exciting!

Now, on to the original point of this post. While I wait for that second proof to print and ship to me, I’ve been going through the ebook files to make sure they’re all clean and perfect and ready to go. I want to be able to publish all versions at once, so as soon as the print edition is good, I’m going to hit the button on everything. Which means I need to make sure my Kindle and ePub files are as sparkling and wonderful as possible.

I’ve been going through the ePub first (for Nook, since that seems to be the only platform I can publish to on my own right now), and found a few errors. Easy enough to fix, but as I was looking them over in the Nook for PC and Adobe Digital Editions readers, I noticed some other things that weren’t working quite right. First, in Adobe Digital Editions, the table of contents pane was empty, with a message that the book didn’t have a TOC. Well, that’s not true! I spent quite a lot of time coding a toc.ncx file so my TOC would show up in any reader! Google to the rescue: it turned out I had a tiny bit of that code wrong. In case anyone comes across a similar problem, here’s what fixed it for me:

#1: This may or may not have been the problem, but it’s still a good thing to check. The UID identifier in both the toc.ncx and content.opf files have to match. Mine didn’t for some reason. The identifier is a unique name/number you give your file. You can use an ISBN if you have it, but since I don’t (I don’t think Nook uses them), I used my web address and date: allisonkraft.com080911. That was in one file, but somehow, in the other, the id was allisonkraft.com072711 or something like that. Different date, making for a different ID.

Here are the what the IDs should look like in the coding of your files.

In the TOC.NCX, it will be near the top, between the HEAD tags, as metadata tags.

<meta name="dtb:uid" content="Your-Unique-ID" />

And in the CONTENT.OPF file, also near the top, between the METADATA tags.

<dc:identifier id="BookId">urn:uuid:Your-Unique-ID</dc:identifier>

#2: The other problem I ran into was that I had the pointers to the TOC.NCX coded wrong.  In the CONTENT.OPF file, after the manifest section, you have the spine section. In this part, you list item of the TOC, referring back to their counterparts in the manifest. It’s all very circular to me, but apparently it needs to be this way. Anyway, the coding of the spine section itself should look like this:

<spine toc="ncx">
    <itemref idref="CoverPage" linear="no" />
    <itemref idref="content" />


With each “itemref” line being a file in the manifest that will be an individual item on your table of contents. But what had me messed up was that, when I was creating mine, somehow I ended up with that first line as <spine toc=”toc”> rather than ncx. I also had to change it in the manifest section of the content.opf file:

<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />

But once I had those two IDs changed from toc to ncx, it worked! I now have a TOC in Adobe Digital Editions!

The other problem I found was one that might not affect many people. At the end of my novel, I have a section of research notes that gives some added information on the historical figures I used. I use endnotes in this section, which employed anchor tags to bring the reader quickly to the cited reference at the end of the section. Anchors are like a hyperlink, but a link that points to a location within the same file rather that outside of it. I had coded this with the old standby of

<a href=”#en1”>en1</a>

Where “#en1” pointed to an anchor tag at the end of the file, as such:

<a name=”en1”>1</a> Cited reference blah blah

This worked perfectly in Kindle, but when you make an epub file, they recommend you use XHTML rather than plain HTML. And XHTML is a much pickier language. So when I tried those links in Nook and ADE, they didn’t go anywhere. Nook didn’t move at all when I clicked, and ADE brought me back to the start of that section rather than the reference at the end. But there was an easy fix! Instead of using the “name” tag on the anchor, you have to use “id” instead. Like so:

<a id=”en1”>1</a> Cited reference that actually works blah blah

Voila! Working endnotes! And now, my ePub file is awesome! Everything works like it should, it looks fantastic, and I couldn’t be happier.

Well, I would be happier if I could find a way to get the damn thing into the iBookstore without going through Smashwords, but for now I’m going to have to be okay with Kindle and Nook. I can worry about the other platforms later. (Kobo, it turns out, is a little too complicated for me to deal with right now. The biggest hurdle being that they require an ISBN, which they don’t appear to offer, so I would have to shell out $125 for one! Not in the budget right now.) I’m still considering Google Books, though, as an alternative for those who don’t have Kindles or Nooks. I think most readers can read ePub bought from Google Books.


  1. Thanks for the reminder about using "id" instead of "name" - I'd forgotten and was converting a footnote-heavy text. (And I couldn't find it offhand in my own reference book! D'OH!)

    As an aside, if you're still looking for distribution to the iBookstore and Kobo, I do both - for lower rates than Smashwords.

    Have a great one!

  2. @Steve Saus Glad I could help! When I cam across that issue in my own book, it took quite a bit of searching before I found someone with the "id" tip. I'm glad my sharing it has helped others.

    I'll keep you in mind about Kobo/iBooks. I'm still looking into options there, but if nothing works out, it's good to know there are non-Smashwords options out there.