Thursday, July 14, 2011

ePub done! And Kindle TOC tips

Yesterday, I managed to get my book properly into ePub format. Woo! I still need to put it on a Nook and read through it (and possibly get it on my iPad and see if I can read it in iBooks), just to be sure the formatting is good, but a quick skim in Adobe Digital Editions looked promising. It was a real pain to do, partly because I’m such a control freak and had to do it all by hand, but also because, when I got frustrated with that method and actually tried a conversion program, it made a royal mess out of the whole thing. This is why I am such a control freak: if you want it done right, do it yourself.

I’ll do a post later about what I had to do to wrangle my nicely-polished Kindle HTML file into an equally-polished ePub, but rather than going off on a new subject right now, I want to finish what I promised last week and write up some tips on doing a Table of Contents for a Kindle ebook.

When I was first converting my novel into HTML, I put the TOC right into the document, right after the cover. It worked well, and I thought I was all good to go, until I realized that, when reading it on my Kindle, the table of contents in the navigation menu (the “Go To…” part) wasn’t working. All I could do was go to the beginning or type in a specific location. I wanted the TOC to work there as well, so I did a little research and found out a Kindle file needs more than just what I had. It needs a separate TOC.HTML file and a TOC.NCX file, as well as some extra coding in the .OPF file. We’ll get to all those shortly.

First, I think it’s good to have your TOC right in your book’s HTML. That way, when someone starts reading, they see it.  For mine, I have my book set to open on the cover, and then the next page is the TOC. Not everyone may want this, so it’s up to you if you want it there or not. If not, keep reading anyway, because there are parts of this you will still need to do.

Anchors

Your book is most likely one long file for Kindle, which means to make a TOC work, you need anchor points. This means, at the start of each chapter or section, or any other area you plan to specify in a table of contents, you need something that will tell the TOC where to go. This is an anchor. It looks like this:

<a name=”chapter1”><h1>ONE</h1></a>

So at each point within your document you want listed in the TOC, you will have to add the above anchor.  Give each one a unique name (“chapter1”, “thanks”, “author”, etc.), so the links don’t get confused. Also, you don’t have to have it wrapped around something the way I did.  You could also do it this way:

<a name=”chapter1”></a>

<h1>ONE</h1>

You may not even need the closing </a> tag, but I’m a stickler for proper code, and hate to leave tags open. Mainly what you’re doing is setting a point within the document for the link to go when someone clicks on “Chapter 1” in the TOC, like a bookmark. So in order for that to happen, you need a corresponding entry in said TOC. Like such:

<a href=”#chapter1”>Chapter One</a>

The # is what tells it to look for an anchor within the document rather than looking for a file name elsewhere. You can call the links whatever you want, but it’s best to keep them concise and don’t use spaces.

Once you’re done setting up all your anchors, you would create something like this near the start of your HTML (in mine, it’s right after the cover, which I chose to specify within the HTML to make sure people see it upon opening the book.)

<div id="toc"><h1>Contents</h1></p>

<p class="noindent"><a href="#copy">Copyright</a><br/>
<a href="#thanks">Acknowledgments</a><br/>
<a href="#chapter1">Chapter One</a><br/>
<a href="#chapter2">Chapter Two</a><br/></p></div>

The <div id=”toc”> (don’t forget the closing </div> at the end) helps tell the Kindle where the TOC is. The <p class=”noindent”> is a class style I use to tell the Kindle not to indent the first line of the paragraph. You can find more about that in a previous blog post.

The TOC.HTML and TOC.NCX

Now, in addition to this, you will also need a separate HTML file called toc.html. Even if you don’t do the internal one, you still need the external. For the most part, you can copy/paste your internet TOC into a new Notepad doc (or whatever program you use to edit HTML). Add in the headers and footers necessary, and edit the links to tell it which file to look in for the anchors. I’ve marked those in red below so you can see what I mean. In this example, the name of the novel’s HTML file is mybook.html, so your link is telling the Kindle to look for the “chapter1” bookmark (anchor) within the mybook.html file.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
    <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
    <TITLE>Table of Contents</TITLE>

<style>
p.noindent { text-indent:0; margin-top:50;}
</style>

<p><h1>Contents</h1></p>

<p class="noindent"><a href="mybook.html#copy">Copyright</a><br/>
<a href="mybook.html#thanks">Acknowledgments</a><br/>
<a href="mybook.html#chapter1">Chapter One</a><br/>
<a href="mybook.html#chapter2">Chapter Two</a><br/></p>

</body>
</html>

Save this file as “toc.html” and move on to the fun part (there would be sarcasm there if you could hear me), the NCX file. This next part I learned by reading CJ’s Easy as Pie Kindle Tutorialas, so rather than repeat her advice, I’m linking you to the post about TOCs. She explains it better than I ever could, anyway. It’s probably going to take a little trial and error to get it working properly: I know it did for me. The thing I came up against most was that, once I had the toc.ncx file implemented and working, the Kindle ignored my start tag and wouldn’t start the book on the cover anymore. I eventually got It fixed, but I can’t for the life of me remember now why it stopped working in the first place, or what the fix was.  I think the key was having the following code in the .opf file:

<reference type="start" title="Start" href="book1.html%23start"></reference>

Hopefully between my tips and CJ’s guide, the TOC thing makes a little more sense. I’ll do another post later in the week about my adventures in ePub.

Before I sign off, Happy Bastille Day (or Féte Nationale) to any French or Francophiles (like me) out there! I was in Paris for the holiday back in 1994, and I will never forget it. Vive la France!

0 comments:

Post a Comment