Sunday, April 7, 2013

magic with TOC: edit or create a TOC for your documents or ebooks

Hope you enjoyed polishing and shining your e-books. Now let's look at more heavy duty stuff. The last post already detailed how you can get the "Edit TOC" button on the main toolbar. It is the rightmost button on the main toolbar in the figure below.

Create TOC:

If you have an e-book without a  Table of Contents (TOC),  but it is well structured with headings calibre allows you to create a TOC in a few simple steps.Consider the following "Example Ebook":

As you can see the e-book has no TOC, although it has headings and sub headings. Select the e-book in the main calibre window and click the "Edit TOC" button. A new window opens with the following options in the right side menu.

Click on "Generate TOC from all headings. The following TOC shows up in the editor window:

It has a well constructed TOC. Sometimes the headings in the ebook file are not well marked and some may be missing. In that case you can edit the generated TOC as explained in the next section.

Here is what the above generated TOC looks like in the calibre viewer:

Edit TOC:
So here I will start with a book that has an unsatisfactory TOC and play around with some of the available tools to make it better. This is just an example to show you some of the things you can do.

The above figure is a snapshot of the calibre viewer with the TOC of the e-book displayed. This TOC is messy as some chapters are subsets of others and although the chapters have names in the book, the TOC only lists chapter numbers. So lets see what we can do to spruce it up.

Select the e-book in the main calibre window and click the "Edit TOC" button. Then the above window opens up. Now as you can see Chapter II to Chapter XI are a part of Chapter I. Now say you want to make them independent chapters not belonging to Chapter I then select Chapter I and click the "Flatten this entry" button on the right hand side menu. Once you do this you will see:

If you now click "OK" and view the ebook the TOC looks like

As you can see in the two above figures Chapter II to Chapter XI are in the same level as Chapter I and not a part of it. But now say you want to make Chapter I to Chapter XI all members of Part I of the book. That too can be done.

In the "Edit TOC" window shown two figures above select "Preface". Then on the menu on the right, click "New entry below this entry". This takes you to the following window:

Move the mouse and position it just above Chapter one and left click. On the right hand side replace "(Untitled)" with "Part I" and click "OK". Now this is what you see.

To make Chapter I to Chapter XI  members of Part one just drag and drop them in to part one in the correct order. Then this is what you see.

Now if you click "OK" and open the book in the viewer you will see:

You can also edit the text for any of the entries in the TOC by double clicking the entry in the TOC editor window. As you can see below I have edited "Chapter I" to the name of the chapter in the book.

The following figure shows the TOC in the viewer with all the chapters in Part I with their proper names.

This articles outlines some of the things you can do with "Edit TOC". There are a few other options too. This should help you get started. Then enjoy tweaking and playing around with all the options. Feel free to leave comments about other interesting things you tried.

Thursday, April 4, 2013

this is the way to polish your e-books

It has been a while but again calibre has some great new features. So let us take a look at them. Here I will discuss "Polish Ebooks" introduced in 0.9.23 and next time "Edit TOC" introduced in 0.9.25. Note that polishing is only supported for books in AZW3 and EPUB formats. Hopefully any bugs that were present to start with have been ironed out. Your feedback is always welcome and since this is a fairly new feature, click here to report any bugs.

Adding the buttons:
To start with lets get the "Polish" and "Edit TOC" buttons, so we can click on them.. Go to "Preferences", click on "Toolbar", click on the button that says "Click to choose toolbar or menu to customize". In this case I have chosen "Main Toolbar" because I want the icons for "Polish" and "Edit TOC" to appear in the main toolbar so I can access them easily. If you think you wont use them too often you can have them on a secondary optional toolbar or wherever is convenient for you.
So after I click main toolbar the following window opens up:

On the left menu of available actions you will see the "Polish" and "Edit TOC" buttons highlighted by red rectangles in the above figure. They are towards the bottom of the menu so you may have to scroll down. Select them both. then click the right pointing blue arrow (circled in red in the above figure). This will move these icons from the available actions list to the current actions list. Click "Apply" on the top left corner and close your Preferences window. Now the added buttons will be included in the toolbar you chose. In this case in the main toolbar as shown below:

Polishing Options:

Select all the e-books to be polished in the same way and then click the polish icon in the main toolbar. The following window opens up:

The available options are outlined here.
You can:
  • Subset all embedded fonts
  • Smarten punctuation
  • Update metadata
  • Update cover
  • Add a metadata page at the start of the book
  • Remove a previously inserted metadata page
Many of these options were available earlier too, but to implement them you would have to convert the book again which for some e-books can be slow and CPU intensive. Now you can just spruce them up quickly because  polishing, unlike conversion, does not change the internal structure/markup of your book, it performs only the minimal set of actions needed to achieve its goals.
The "About" button next to each action gives details about exactly what the particular polishing tool achieves.

Subset all embedded fonts and Smarten punctuation:
This is just copied from the about section of "Subset all embedded fonts". The information is quite clear and I had nothing to add to it:

Similarly smarten punctuation simply converts plain text dashes, ellipsis, quotes, multiple hyphens, etc. into their typographically correct equivalents.
Caveat: The algorithm for "Smarten punctuation" can occasionally generate incorrect output.

Update metadata and Update cover in book files:
When you click "Edit Metadata" in calibre and change the metadata or the cover of a book the information is saved in a file called metadata.db in your calibre library. This information is only transferred to the particular book file when you convert the book or export it. However now this information can be updated in the book files by simply choosing the appropriate options in "Polish". Note there are separate buttons for updating the cover and for updating the rest of the metadata. The metadata that is updated will depend on what metadata the e-book format supports. Unfortunately many e-book formats do not support all the metadata that calibre allows you to store.

The following is a screen shot of calibre before "Update cover in book files" was done:

The e-book had been downloaded from Project Gutenberg.  then the metadata was edited to add the cover you can see on the right information panel of the main calibre window. But the polishing was not done so the the cover displayed when viewed was the generic cover page Project Gutenberg uses for all books.

Next we ran the "Update cover in book files" under "Polish" and voila,

the chosen cover is now the first page in the viewer.

Add metadata as book jacket page:

This allows you to add a book jacket containing all the metadata you added under "Edit Metadata" in calibre, including title, author, publisher, tags, comments, rating, series information etc. The book jacket page is always the very first page and precedes the cover page if there is one.

The following shows the book jacket for the book we have been using as an example so far:

The last option in "polish" is to remove the previously added book jacket in case you did not like it.

Coming soon:
In a week or two I will discuss the "Edit TOC" feature added in 0.9.25. It may still have a few bugs so let's give it some time to be straightened out. Also I have to go learn about it.

Hope you enjoyed this post. Have fun polishing away.