Learn How To Create a .TOC.NCX for an ePUB Book with Calibre

in #utopian-io6 years ago (edited)

Contribution to the Open Source Project: Calibre


calibrehome2.jpg

Github Repository:

https://github.com/kovidgoyal/calibre

Learn how to Create a Table of Content (.toc) with Navigation Control File (.ncx) into an ePUB Book

What Will I Learn?

5 Major Concepts:

  • Understand the ePUB books in Calibre are coded with many index_split_.html files in accordance to the size of the ePUB book.
  • Learn how to edit the ePUB book by looking at the divisions that separate the index_split_html files.
  • Learn how to code the Chapter numbers in the HTML files that correspond to the ePUB book so that they can appear on the .toc.ncx file.
  • Learn how to read a little HTML source codes so that you can put in the Chapter Numbers to create the .toc.ncx for the ePUB book.
  • Learn how to synchronize the HTML files to the Chapter divisions of the book so that the chapter sections are hyperlinked to the .toc.ncx of the ePUB book.

Requirements

  1. System Requirements: Install Calibre Software 3.23 (updated on May 4, 2018)
  2. OS Support:
  • Windows (Vista, 7, 8 and 10)
  • Linux (32-bit and 64-bit Intel
  • Mac OS X (10.9 Mavericks and higher)

Read the Calibre page and download their software onto your computer.
After download, click execute and start using this software following today's tutorial.

Resources about Calibre:

Difficulty

Intermediate (It is helpful if you can read a little bit of HTML codes)

Description

I receive a lot of requests from people to format their books for them because their ePUB books do not have "Chapter Numbers" and a Table of Content is missing in their ePUB book. (A shortened form to write Table of Content is TOC). This then creates a big problem because when the TOC is missing, there are no clickable hyperlinks to navigate around in the ePUB book.

In each ePUB book, there is a source code written to put in the 'Navigation Control File" file for XML applications. The shortened form is usually written in NCX. So, when the TOC is not coded into the .TOC.NCX file, there is no hyperlinked TOC into the ePUB book.

All Indie authors should learn how to create a .TOC.NCX file so that chapter links are hyperlinked to the TOC in their eBooks. This will then give their readers an enjoyable experience in reading their eBooks.

I used to create hyperlinked TOC manually using Microsoft word and then change the entire document into a HTML file to create the .TOC.NCX to incorporate it into the ePUB book. This takes at least a day's work.

Well, I have good news for you. The Caliber software has a made it easier for you to create the .TOC.NCX file inside their software.

Caliber has a feature in the 'Edit Book' widget whereby you can 'edit' the HTML files and use the HTML source code for .toc.ncx file to create a Table of Content with clickable links that are directly hyperlinked to the different chapters of the ePUB book.

This is what this tutorial is all about. As soon as you learn this method, you do not need to spend a whole day hyperlinking your books using a Word Editor.

Video Tutorial Demo

  1. First, I will show you an example of an ePUB book with the Chapter Numbers and .toc.ncx missing in the ePUB book so that you can see what the problem is.
  2. From there, I will show you an example of an ePUB book with Chapter Numbers and .toc.ncx inside the ePUB book. You will see how user friendly this serves for the reader.
  3. I will explain the concepts of HTML in relation to the eBook so that you understand why the ePUB book is split into different htmls.
  4. Follow the guidelines and steps in the tutorial so as to know where to key in the chapter numbers in the HTML filies
  5. Finally, create a .toc.ncx file for the ePUB book by changing the source codes in the .toc.ncx XML application.

Step 1: Go to Edit Book

Highlight the book you want to edit and click on 'Edit Book' to start making the changes.

toc6.jpg

The middle section is where all the HTML codes are located for this book. This is the area where we will be making all the changes for the book.

Even if you don't know how to decipher HTML, you can still follow my steps as I explain to you how to read them.

I explain to you the codes and which lines you need to focus on to key in the Chapters.

Step 2: Match the HTML files for each section of your book

You can see that the book is all sectioned off in HTML files and it is important that you know how to match the HTML files to the ePUB book.

toc1.jpg

  • There are only 10 chapters in this book but there are 13 HTML files.
  • This will alert us that the HTML files do not correspond to the Chapter divisions.
  • Many people make this assumption that each HTML file corresponds to a new chapter, that is not so
  • The reason why there are more HTML files is because some chapters are longer, therefore they take up 2 HTML files for those chapters.
  • Note that the first page of the book is called: page.xhtml file as that is a title page.

Step 3: Key in the Chapters numbers to the corresponding HTML files

a. Look for the h2id codes in the HTML file

h2id=id_The Chapter Title

<h2 id="id_The_Black_Boar_of_Lonesome_Water" class="block_8">The Black Boar of Lonesome Water</h2>

b. Key in the Chapter Numbers

Add Chapter Number in front of the Chapter Title.

Chapter 1

For example: The Black Boar of Lonesome Water is Chapter 1, so I key in "Chapter 1" in front of 'The Black Boar of Lonesome Water.

The html code for this line will be changed to the following:

<h2 id="id_The_Black_Boar_of_Lonesome_Water" class="block_8">Chapter 1 The Black Boar of Lonesome Water</h2>

c. Look at the Preview Section to check everything

When the coding is done on the editing HTML (in the red box there), you see the preview on the right panel with "Chapter 1" added in front of the title.

toc2.jpg

Step 4: Complete adding all Chapter Numbers in front of all 10 chapter headings

I will go through each of the HTML files with you in the video so that you can find the corresponding headings to put in the Chapter numbers.

toc3.jpg

The new chapter divisions correspond to the following html files in this book:

index-split-001.html - Chapter 1
index-split-002.html - Chapter 2
index-split-003.html
index-split-004.html - Chapter 3
index-split-005.html - Chapter 4
index-split-006.html - Chapter 5
index-split-007.html
index-split-008.html - Chapter 6
index-split-009.html - Chapter 7
index-split-0010.html - Chapter 8
index-split-0011.html
index-split-0012.html - Chapter 9
index-split-0013.html - Chapter 10

In this video, you will see how this synchronize nicely to the corresponding html files.

You can do the same to any of your ePUB books. The principle works the same way. Know how to identify the HTML files with the heading divisions of the book.

Step 5: Create the toc.ncx file for easy navigation

We need to create the toc.ncx file in your ePUB book so that the chapters content become clickable table of contents for people to navigate around in your ePUB book.

A general source code for toc.ncx is like this:

 <?xml version='1.0' encoding='utf-8'?>
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="eng">
  <head>
    <meta content="006983f7-443c-4ef8-8efa-48322366550d" name="dtb:uid"/>
    <meta content="4" name="dtb:depth"/>
    <meta content="calibre (3.21.0)" name="dtb:generator"/>
    <meta content="0" name="dtb:totalPageCount"/>
    <meta content="0" name="dtb:maxPageNumber"/>
  </head>
  <docTitle>
    <text>The Secret Trails</text>
  </docTitle>
  <navMap>
    <navPoint class="chapter" id="num_1" playOrder="1">
      <navLabel>
        <text>THE SECRET TRAILS</text>
      </navLabel>
      <content src="index_split_000.html"/>
    </navPoint>
    <navPoint class="chapter" id="num_2" playOrder="2">
      <navLabel>
        <text>SECRET TRAILS</text>
      </navLabel>
      <content src="index_split_000.html#id_SECRET_TRAILS"/>
    </navPoint>
    <navPoint class="chapter" id="num_3" playOrder="3">
      <navLabel>
        <text>(Untitled)</text>
      </navLabel>
      <content src="index_split_000.html#toc_id_1"/>
    </navPoint>
    <navPoint class="chapter" id="num_4" playOrder="4">
      <navLabel>
        <text>BY CHARLES G. D. ROBERTS</text>
      </navLabel>
      <content src="index_split_000.html#id_BY"/>
      <navPoint class="chapter" id="num_5" playOrder="5">
        <navLabel>
          <text>The Black Boar of Lonesome Water</text>
        </navLabel>
        <content src="index_split_001.html"/>
        <navPoint class="chapter" id="num_6" playOrder="6">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_001.html#id_I"/>
        </navPoint>
        <navPoint class="chapter" id="num_7" playOrder="7">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_001.html#id_II"/>
        </navPoint>
        <navPoint class="chapter" id="num_8" playOrder="8">
          <navLabel>
            <text>III</text>
          </navLabel>
          <content src="index_split_001.html#id_III"/>
        </navPoint>
        <navPoint class="chapter" id="num_9" playOrder="9">
          <navLabel>
            <text>IV</text>
          </navLabel>
          <content src="index_split_001.html#id_IV"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_10" playOrder="10">
        <navLabel>
          <text>The Dog that saved the Bridge</text>
        </navLabel>
        <content src="index_split_002.html"/>
        <navPoint class="chapter" id="num_11" playOrder="11">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_002.html#id_I_1"/>
        </navPoint>
        <navPoint class="chapter" id="num_12" playOrder="12">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_002.html#id_II_1"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_13" playOrder="13">
        <navLabel>
          <text>The Calling of the Lop-horned Bull</text>
        </navLabel>
        <content src="index_split_004.html"/>
        <navPoint class="chapter" id="num_14" playOrder="14">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_004.html#id_I_2"/>
        </navPoint>
        <navPoint class="chapter" id="num_15" playOrder="15">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_004.html#id_II_2"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_16" playOrder="16">
        <navLabel>
          <text>The Aigrette</text>
        </navLabel>
        <content src="index_split_005.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_17" playOrder="17">
        <navLabel>
          <text>The Cabin in the Flood</text>
        </navLabel>
        <content src="index_split_006.html"/>
        <navPoint class="chapter" id="num_18" playOrder="18">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_006.html#id_II_3"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_19" playOrder="19">
        <navLabel>
          <text>The Brothers of the Yoke</text>
        </navLabel>
        <content src="index_split_008.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_20" playOrder="20">
        <navLabel>
          <text>The Trailers</text>
        </navLabel>
        <content src="index_split_009.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_21" playOrder="21">
        <navLabel>
          <text>Cock-Crow</text>
        </navLabel>
        <content src="index_split_010.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_22" playOrder="22">
        <navLabel>
          <text>The Ledge on Bald Face</text>
        </navLabel>
        <content src="index_split_012.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_23" playOrder="23">
        <navLabel>
          <text>The Morning of the Silver Frost</text>
        </navLabel>
        <content src="index_split_013.html"/>
      </navPoint>
    </navPoint>
  </navMap>
</ncx>

Now, we need to identify the places to put in the Chapter Numbers to correspond with the index_split_html files.

Here is an example of Chapter 2:

<navLabel>
          <text>Chapter 2 The Dog that saved the Bridge</text>
        </navLabel>
        <content src="index_split_002.html"/
  • As you can see Chapter 2 is now directly linked to index_split_002html
  • The corresponding chapter needs to match with the right index_split_html.

toc4.jpg

You can watch the video as I put in all the other chapter numbers. Only when we do this will you find all the Chaptes in the .toc.nxc hyperlinked to the correct html files of the ePub Book.

The new source code file with all the correct corresponding html files:

<?xml version='1.0' encoding='utf-8'?>
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1" xml:lang="eng">
  <head>
    <meta content="e32e9e94-9a7b-4b4c-8231-9068b0e61e2e" name="dtb:uid"/>
    <meta content="4" name="dtb:depth"/>
    <meta content="calibre (3.21.0)" name="dtb:generator"/>
    <meta content="0" name="dtb:totalPageCount"/>
    <meta content="0" name="dtb:maxPageNumber"/>
  </head>
  <docTitle>
    <text>The Secret Trails</text>
  </docTitle>
  <navMap>
    <navPoint class="chapter" id="num_1" playOrder="1">
      <navLabel>
        <text>THE SECRET TRAILS</text>
      </navLabel>
      <content src="index_split_000.html"/>
    </navPoint>
    <navPoint class="chapter" id="num_2" playOrder="2">
      <navLabel>
        <text>SECRET TRAILS</text>
      </navLabel>
      <content src="index_split_000.html#id_SECRET_TRAILS"/>
    </navPoint>
    <navPoint class="chapter" id="num_3" playOrder="3">
      <navLabel>
        <text>(Untitled)</text>
      </navLabel>
      <content src="index_split_000.html#toc_id_1"/>
    </navPoint>
    <navPoint class="chapter" id="num_4" playOrder="4">
      <navLabel>
        <text>BY CHARLES G. D. ROBERTS</text>
      </navLabel>
      <content src="index_split_000.html#id_BY"/>
      <navPoint class="chapter" id="num_5" playOrder="5">
        <navLabel>
          <text>Chapter 1 The Black Boar of Lonesome Water</text>
        </navLabel>
        <content src="index_split_001.html"/>
        <navPoint class="chapter" id="num_6" playOrder="6">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_001.html#id_I"/>
        </navPoint>
        <navPoint class="chapter" id="num_7" playOrder="7">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_001.html#id_II"/>
        </navPoint>
        <navPoint class="chapter" id="num_8" playOrder="8">
          <navLabel>
            <text>III</text>
          </navLabel>
          <content src="index_split_001.html#id_III"/>
        </navPoint>
        <navPoint class="chapter" id="num_9" playOrder="9">
          <navLabel>
            <text>IV</text>
          </navLabel>
          <content src="index_split_001.html#id_IV"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_10" playOrder="10">
        <navLabel>
          <text>Chapter 2 The Dog that saved the Bridge</text>
        </navLabel>
        <content src="index_split_002.html"/>
        <navPoint class="chapter" id="num_11" playOrder="11">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_002.html#id_I_1"/>
        </navPoint>
        <navPoint class="chapter" id="num_12" playOrder="12">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_002.html#id_II_1"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_13" playOrder="13">
        <navLabel>
          <text>Chapter 3 The Calling of the Lop-horned Bull</text>
        </navLabel>
        <content src="index_split_004.html"/>
        <navPoint class="chapter" id="num_14" playOrder="14">
          <navLabel>
            <text>I</text>
          </navLabel>
          <content src="index_split_004.html#id_I_2"/>
        </navPoint>
        <navPoint class="chapter" id="num_15" playOrder="15">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_004.html#id_II_2"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_16" playOrder="16">
        <navLabel>
          <text>Chapter 4 The Aigrette</text>
        </navLabel>
        <content src="index_split_005.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_17" playOrder="17">
        <navLabel>
          <text>Chapter 5 The Cabin in the Flood</text>
        </navLabel>
        <content src="index_split_006.html"/>
        <navPoint class="chapter" id="num_18" playOrder="18">
          <navLabel>
            <text>II</text>
          </navLabel>
          <content src="index_split_006.html#id_II_3"/>
        </navPoint>
      </navPoint>
      <navPoint class="chapter" id="num_19" playOrder="19">
        <navLabel>
          <text>Chapter 6 The Brothers of the Yoke</text>
        </navLabel>
        <content src="index_split_008.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_20" playOrder="20">
        <navLabel>
          <text>Chapter 7 The Trailers</text>
        </navLabel>
        <content src="index_split_009.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_21" playOrder="21">
        <navLabel>
          <text>Chapter 8 Cock-Crow</text>
        </navLabel>
        <content src="index_split_010.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_22" playOrder="22">
        <navLabel>
          <text>Chapter 9 The Ledge on Bald Face</text>
        </navLabel>
        <content src="index_split_012.html"/>
      </navPoint>
      <navPoint class="chapter" id="num_23" playOrder="23">
        <navLabel>
          <text>Chapter 10 The Morning of the Silver Frost</text>
        </navLabel>
        <content src="index_split_013.html"/>
      </navPoint>
    </navPoint>
  </navMap>
</ncx>

Now the .toc.ncx file has clickable Table of Contents to navigate inside the ePUB book.


Step 6 - The Final Product with TOC and .toc.ncx

Here is how the final product looks:

toc5.jpg

Supplementary Resources:

#1. The source code of the .toc.ncx file can be downloaded from my Github site:
https://gist.github.com/rosatravels/ff942619b6ea158498e393634ae91803

#2. The new source code of the .toc.ncx file can be downloaded from my Github site:
https://gist.github.com/rosatravels/ff942619b6ea158498e393634ae91803/revisions

#3. The new ePUB book with the Chapter titles & .toc.ncx file can be downloaded here on my Github Site: Click Here

Video Tutorial

Enjoy the Video!

Sort:  

Thank you for the contribution @rosatravels.

Great work. Any learner wishing to make a table of contents would have no problems after studying your lesson.

Your contribution has been evaluated according to Utopian rules and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post,Click here


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you @buckydurddle for reviewing my contribution , as always :)

Thank you for the guide.

You are welcome.

Hey @rosatravels
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.027
BTC 59171.28
ETH 2598.57
USDT 1.00
SBD 2.42