0

All of the chapters in my EPUB contain only the text of the chapter and do not have the chapter number or the chapter title at the beginning of the body.

The Table of Contents file, (nav.xhtml) has the correct chapter numbers and titles along with hyperlinks to each of the different chapter files, (xhtml files).

How can I automate a process in which the chapter number and title for each chapter file is copied from the table of contents and pasted into the beginning of each corresponding chapter file? I have and use Calibre, but I cannot figure out a process.

Thanks.

1 Answer 1

0

You're looking at the problem backwards.

My admittedly complex solution is to code in Docbook XML, and then the XML to XHTML transformation autogenerates the TOC with correct title. (Docbook XSLT autogenerates the epub nav document and all related material).

With most tools the nav.xhtml file is autogenerated by whatever is H1 in the particular chapter.

To give another example: You can create an epub very easily in LibreOffice or MS Word by putting everything in a single document and then styling the chapter headings with the HEADING style (or something like that). You can run calibre on that -- and as long as the chapter heads have a heading style, it will autogenerate the navigation document from the headings.

My Docbook-based production method includes an autonumber feature -- but I generally turn it off because I'd rather hard code the chapter numbers. Perhaps MSOFFICe/LIBOFFICE let you do autonumbering in the heading element.

The navigation document is usually both human readable and machine readable. Unlike epub2/older Kindle ebooks (where you needed to create a logical TOC (html document) and a ncx file, today's navigation documents serve both purposes.

I have not used transformations on Calibre, but I'm guessing it is theoretically possible to autogenerate these things from within it with xpath/xslt.

1
  • It's possible to add sequential chapter numbers with Calibre regex functions. However, it wouldn't be possible to also add the chapter title without a Python script.
    – user4665
    Jan 9, 2019 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.