Kindle Forum banner

Gah! ToC submission...

646 Views 5 Replies 3 Participants Last post by  Speaker-To-Animals
Hi all,

My noodle is currently being baked by Calibre and XPath expressions.

I'm trying to get it to auto-generate a ToC, but my Chapters are demarcated by 'Heading 1' and 'Heading 2' classes. I thought that would be enough? But h1 and h2 either aren't recognised, or the second bit of the operator is being recognised, because they're not named 'Chapter 1' - they're all dates.

I'm getting closer. My XPath expression currently is:
//*[((name()='h1' or name()='h2' or name()='h3') and re:test(., '\s*((August)\s+)|((One|Two|Three|Four)(\s+|$))', 'i')) or @class = 'chapter']

The book is in four sections - 'One', 'Two', 'Three', 'Four' (each of which should be in the ToC and is, and each of which is 'Heading 1' style

However, each chapter, for example '9th August' (all of which should be in ToC, and all of which are 'Heading 2' style) currently aren't being recognised.

Can anyone suggest what I should do?

Thanks
1 - 6 of 6 Posts
:)

Got it - it's a bit of a blunt solution, but:

//*[((name()='h1' or name()='h2') and re:test(., '.*', 'i')) or @class = 'chapter']

Just returns everything in a h1 or h2. Worked fine for me.
David J Perry said:
Can anyone suggest what I should do?
Yes. I suggest that you learn how to use Calibre.
:)

I say that as a bit of a joke, but only a bit, and with no malice intended. Calibre is an easy app to use once you learn how, but it is not an easy app to learn how to use in the first place. But you really have to learn how to use it so you don't get frustrated or go off on a tangent, as you have here, while thinking that your problem is solved. Calibre is a very large and complex program that does all sorts of stuff but has only a few commands for book formatters. However, those commands work extremely well and are quite simple… if you know how to use them.

The "solution" that you mention:

David J Perry said:
//*[((name()='h1' or name()='h2') and re:test(., '.*', 'i')) or @class = 'chapter']
…is actually not part of the "Table of Contents" section of Calibre. It's part of the "Structure Detection" section. What you have asked Calibre to do with that command (that "XPath expression") is to detect where the chapters are.

If you go to the "Table of Contents" window of Calibre, you will see the TOC Filter, which is the place to easily set the look of your Table of Contents. Your h1 paragraphs can be set to be at the First Indent Level of the Table of Contents (that is, not indented at all), and your h2 paragraphs can be at the Second Indent Level.

The two Calibre sections can, and most often do, work together, but they do not have to. It's perfectly possible to have a normal-looking Table of Contents but have the text of the book appear to have no separation at all between chapters. I have read some novels that have no separations just because the book designer wanted it that way.

p.s. Have you figured out how to set the start point of the book yet? You previously referred to yourself as:

David J Perry said:
completely HTML savvy
…and yet you had to ask:

David J Perry said:
How can I achieve this in the HTML?
There is an extremely simple HTML solution to that problem. Can you figure it out?

(Hint: Calibre can do it, too.)
See less See more
Word Fan said:
The "solution" that you mention:

...is actually not part of the "Table of Contents" section of Calibre. It's part of the "Structure Detection" section. What you have asked Calibre to do with that command (that "XPath expression") is to detect where the chapters are.
Err, I know. I was there...

I didn't say that the solution did turn out to be part of the ToC section. Just that I wanted to create the ToC.

Word Fan said:
You previously referred to yourself as: HTML Savvy

...and yet you had to ask: How can I achieve this in HTML?
But that's the point, isn't it?

It turned out it didn't necessarily need an HTML solution. I solved it through both careful and thorough coding in my style sheet, and fudging the XPath expression (which I had previously had no experience of) to solve it.

I'm not sure what your post is for? I solved my problem, and included the solution in case it helped others. Yours seems to be about chiding me for something - not quite sure what. Thanks for the input though...
David J Perry said:
I'm not sure what your post is for? I solved my problem, and included the solution in case it helped others.
My point was---and I tried to be gentle about it---was that you didn't provide a solution for others. You "fudged" through something that worked for you in that particular instance, but it could easily mess up a book that some neophyte somewhere was trying to format in the future.

The way to create a Table of Contents in Calibre is to use its Table of Contents window.

The way to create chapter structure in Calibre---by adding page breaks or other chapter indicators---is to use its Structure Detection window. Calibre comes with the "Structure Detection" field already filled out with a general command that works much of the time. It works so well that many people---most people---never find out how to modify it. In fact, they never even know that it's there. They also then, unfortunately, never learn how to fix it when something does not turn out the way that they expect.

If you don't want to accept my help, fine, but I'm not going to sit here and let you say that you have found "the solution." You haven't, and I don't want that misinformation to get passed on to others unchallenged.

There are far too many self-publishers out there who have a hard enough time formatting their books as it is. They don't need bad information screwing them up even more.
See less See more
Download Vellum and save yourself the headache.
I don't think Vellum will do a multilevel TOC, which I believe is what the person is attempting to do.

Code:
Section 1
   Chapter 1
   Chapter 2
Section 2
   Chapter 1
   Chapter 2
etc.

To be honest, I just did a test. I put together a document with the body in "normal," the top head in "header 1," and the subheads in "header 2" and I imported the docx into Calibre and converted it without monkeying with the settings at all.

I got a full nested HTML TOC and a NCX with all the chapters and subchapters in it.

One thing with Calibre is ditch the HTML. There's no need to go there. Just do it in Word and save it as a docx. The docx converter is fantastic and seems to handle everything without any tinkering.
See less See more
1 - 6 of 6 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top