1

I am exporting a very large document (1400+ pages) to ebook, and have already worked out the Table of Contents (ToC) as hyperlinks to all the chapters and sections, and the hyperlinks work fine after being exported to the target ebook format so that part is done.

Now I want to make all the link targets in the ToC into links themselves pointing back to the appropriate page of the ToC.

I do not wish to attempt this manually one by one, as there are hundreds of entries in the ToC, so I am looking for help to figure out how to take the link target information from the ToC, find said target in the text body, and then convert that target into a link pointing back to the correct ToC page automatically.

Thus my question is how to use a macro or Find/Replace to make ToC link targets into links themselves pointing back to the ToC in Libreoffice?

nijineko
  • 111
  • 2
  • by ebook, do you mean epub or pdf? Also, is this ODT file a static doc or one you will be updating? – idiotprogrammer Jul 19 '22 at 20:43
  • I assume this ODT has lots of chapters -- in the epub output it will probably be separate HTML files so you are linking to separate HTML files and the anchors/ids. Therein lies the challenge. – idiotprogrammer Jul 19 '22 at 20:48
  • End product will be PDF – nijineko Jul 30 '22 at 01:35
  • Maybe you're thinking about it wrong. You can simply delete the TOC and autogenerate it again. Autogenerating the TOC will check the headings and subheadings and put them into the TOC with everything linked properly. I don't think a programmatic or macro-based solution is necessary here. – idiotprogrammer Jul 31 '22 at 04:12
  • If you are using ODT styles correctly and applying headings and subheadings correctly to sections, autogenerating the TOC should be easy. – idiotprogrammer Jul 31 '22 at 04:14
  • @idiotprogrammer You seem to have it backwards. I want all the Headings to become links pointing to the TOC line item for said heading. The TOC is already working perfectly, links and all so no need to change the TOC. – nijineko Aug 03 '22 at 04:34
  • Got it. Just FYI some epub readers (and Kindle) have buttons for GO TO PREVIOUS PAGE and ALL have a separate TOC function which let you return to TOC from any page. EPUB standard was created precisely to handle these navigation issues. Maybe this is out for scope for you, but generally you should be thinking of DOC --> EPUB instead of DOC --> PDF. – idiotprogrammer Aug 04 '22 at 17:01
  • Even if it were possible to make the headings go back to the pdf's TOC, I would not recommend it. Instead, you should let the reading system software (not the document) do the navigating. All EPUB reading systems give a button which allow you to view the TOC and all its elements. That obviates the need for bidirectional links. I have made bidirectional links in my epub files for certain special cases, but I don't see the need here. Of course, you could always add them manually. – idiotprogrammer Aug 04 '22 at 17:10
  • Reading systems like Adobe Digital Editions (and probably Google Play Books) will display TOCs even when viewing PDFs if formatted correctly. How are people going to view your PDF? IIRC, Microsoft Edge can read epubs and display navigation, but it can also do so with well-formatted PDFs. – idiotprogrammer Aug 04 '22 at 17:19

1 Answers1

0

I have never tried it before, but one option might be to convert it from ODT to epub using Calibre. It's a very user friendly tool, but also has lots of configurable options.

I don't see documentation for it, but I see a thread on mobileread (8 years old) where the lead developer (who made Calibre) comments that if the link is correctly made in ODT or .docx the links will be converted automatically in the epub output.

You should definitely try that. But first I would create a simple test document using three or four chapters (defined by the HEADING style) and then try the conversion and see what if anything needs to be tweaked.

Sometimes when I am doing a complicated conversation, it takes a few tries to work out (sometimes MS Word works better than LibreOffice for these advanced tasks, be forewarned).

idiotprogrammer
  • 4,594
  • 13
  • 26