Answers.Body: <p>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.</p>
  <p>I don't see documentation for it, but I see a <a href="https://www.mobileread.com/forums/showthread.php?t=235496" rel="nofollow noreferrer">thread on mobileread</a> (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.</p>
  <p>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.</p>
  <p>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).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-11T14:21:41.997Z
Answers.Text: This answer seemingly has nothing to do with the question? I am trying to convert the TARGETS of the existing ToC links into hyperlinks that point back to the originating ToC hyperlink. As stated in the question, the export of ToC as links worked perfectly and is finished.  Now I need the targets converted into hyperlinks?
Answers.UserDisplayName: nijineko
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-19T21:01:17.053Z
Answers.LastActivityDate: 2022-07-19T21:01:17.053Z
Answers.UserDisplayName: idiotprogrammer
Body: <p>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.</p>
  <p>Now I want to make all the link targets from the ToC into links themselves pointing back to the appropriate page of the ToC.</p>
  <p>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.</p>
  <p>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?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-19T20:43:11.280Z
Comments.Text: by ebook, do you mean epub or pdf? Also, is this ODT file a static doc or one you will be updating?
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-19T20:48:30.820Z
Comments.Text: 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.
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-30T01:35:37.113Z
Comments.Text: End product will be PDF
Comments.UserDisplayName: nijineko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-31T04:12:20.053Z
Comments.Text: 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.
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-07-31T04:14:38.480Z
Comments.Text: If you are using ODT styles correctly and applying headings and subheadings correctly to sections, autogenerating the TOC should be easy.
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-03T04:34:50.040Z
Comments.Text: @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.
Comments.UserDisplayName: nijineko
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-04T17:01:54.463Z
Comments.Text: 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.
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-04T17:10:55.110Z
Comments.Text: 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.
Comments.UserDisplayName: idiotprogrammer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-08-04T17:19:58.733Z
Comments.Text: 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.
Comments.UserDisplayName: idiotprogrammer
Tags: <table-of-contents><hyperlinking><libreoffice>
Title: How to use a macro or Find/Replace to make ToC link targets into links themselves pointing back to the ToC in Libreoffice?
UserDisplayName: nijineko
ThreadText: # How to use a macro or Find/Replace to make ToC link targets into links themselves pointing back to the ToC in Libreoffice?
  
  (Asked by: username_0 on 2022-07-16)
  
  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 from 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?
  
  **Tags:** table-of-contents, hyperlinking, libreoffice
  
  > **Comments:**
  > **username_1**: by ebook, do you mean epub or pdf? Also, is this ODT file a static doc or one you will be updating?  
  > **username_1**: 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.  
  > **username_0**: End product will be PDF  
  > **username_1**: 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.  
  > **username_1**: If you are using ODT styles correctly and applying headings and subheadings correctly to sections, autogenerating the TOC should be easy.  
  > **username_0**: @username_1 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.  
  > **username_1**: 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.  
  > **username_1**: 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.  
  > **username_1**: 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.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-19. Score: 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](https://www.mobileread.com/forums/showthread.php?t=235496) (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).
  
  > **Comments:**
  > **username_0**: This answer seemingly has nothing to do with the question? I am trying to convert the TARGETS of the existing ToC links into hyperlinks that point back to the originating ToC hyperlink. As stated in the question, the export of ToC as links worked perfectly and is finished.  Now I need the targets converted into hyperlinks?  
  
  ---
  
  