Skip to main content
James Gifford—NitroPress
Legend
April 16, 2022
Answered

Identifying/Mapping TOC text anchors

  • April 16, 2022
  • 2 replies
  • 3209 views

Is there any straightforward way to identify the automatically generated text anchor for any TOC entry? I generate a TOC that works fine for both the print edition and the EPUB/Kindle side TOC. It creates 120-odd text anchors of the name style '_idTOCAnchor-34'.

 

In theory, I can do internal references using these anchors... but in practice, the order and numbering seem to be almost random. ...Anchor-1, for example, goes to the last section heading in the document, and I haven't been able to make any sense out of the numeric order.

 

So if I want to link to a section titled "End Material" on page 195, without going and setting a specific text anchor of known name, how do I identify that heading's TOC anchor number? (It seems with all the various menus and palettes and such, this should be much easier... but I'm stumped.)

 

This topic has been closed for replies.
Correct answer Peter Kahrel

The order is probably not random. The anchors must be added from back to front, and they are numbered ascending, so they appear to be in reverse order.

You can use this script to map anchors:

https://creativepro.com/files/kahrel/indesign/text_anchors.html

P.

2 replies

Peter Kahrel
Community Expert
Community Expert
March 6, 2023

 a way to modify the script so that it can automatically rename the anchors based on the text of the paragraph they are anchored to

 

A separate script would make more sense.

 

that portion of the script doesnt seem to prompt

 

Not sure I understand what you mean here. What kind of prompt were you thinking of?

Inspiring
March 7, 2023

Sorry, i think i misread his post and thought a second dialog would pop up after selecting which TOC style you want.

Peter Kahrel
Community Expert
Peter KahrelCommunity ExpertCorrect answer
Community Expert
April 16, 2022

The order is probably not random. The anchors must be added from back to front, and they are numbered ascending, so they appear to be in reverse order.

You can use this script to map anchors:

https://creativepro.com/files/kahrel/indesign/text_anchors.html

P.

James Gifford—NitroPress
Legend
April 18, 2022

So, other than this comprehensive mapping... is there any way to identify a specific text anchor? If you're working with hidden characters shown, and there's a blue colon indicating an anchor, is there any way to identify that anchor? I've tried a number of things and nothing in the standard UI seems to present that info. Am I missing something, or would it take a similar script to produce the anchor ID?

 

Peter Kahrel
Community Expert
Community Expert
April 19, 2022

nothing in the standard UI seems to present that info

InDesign's interface for text anchors is useless.

To obtain the id of a selected text anchor you can use this script:

anchors = app.documents[0].hyperlinkTextDestinations.everyItem().getElements();
for (i = 0; i < anchors.length; i++) {
  if (anchors[i].destinationText == app.selection[0].insertionPoints[0]) {
    alert (anchors[i].id);
    exit();
  }
}
alert ('Select a text anchor');

P.