• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Identifying/Mapping TOC text anchors

Community Expert ,
Apr 16, 2022 Apr 16, 2022

Copy link to clipboard

Copied

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.)

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢
TOPICS
EPUB , How to

Views

892

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 16, 2022 Apr 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.

Votes

Translate

Translate
Community Expert ,
Apr 16, 2022 Apr 16, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 16, 2022 Apr 16, 2022

Copy link to clipboard

Copied

Excellent — thank you!

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 18, 2022 Apr 18, 2022

Copy link to clipboard

Copied

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?

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2022 Apr 19, 2022

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

Hi Peter, thanks for the great script you linked to! i was wondering if there was 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? my scripting is rusty and am trying to remember how to pull that information

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

In addition i found a post by the late Jongware that is intended to create anchors based on paragraph styles, but that portion of the script doesnt seem to prompt, any help is appreciated.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 16, 2023 Sep 16, 2023

Copy link to clipboard

Copied

@Peter Kahrel 

Thank you for sharing the script. I downloaded and installed it. It worked beautifully the first time!

However, each successive time after that, something appears to "shift" in the window the script opens. First time, all the buttons on the right were missing.

Second time, the space above the labels increased (marked in green in the attached png).

Any idea what's going on? How to fix it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 16, 2023 Sep 16, 2023

Copy link to clipboard

Copied

I sometimes get reports about problems with the interface, though I never see those myself. I notice that I updated the script (slightly), and I have now uploaded that update. (I can't remember what changed, must have been something minor.)

 

If the problem persists, first try to resize the script's window to something very small. Click and drag from the bottom-right up and left. That way you force the window to redraw, which may fix the problem.

 

If taht doesn't work, delete the text_anchors.txt file. It sits next to the jsx file in the Scripts panel.

 

I hope that either of these suggestions helps.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 21, 2023 Sep 21, 2023

Copy link to clipboard

Copied

LATEST

@Peter Kahrel:

Downloaded the script ... thank you.

The issue of window shifting occurs repeatedly after the first time. The solution that has worked so far is clicking & dragging from the bottom-right to the left. In the process, the window does get resized and appears as-expected.

Thank you for the script & the suggestion.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 06, 2023 Mar 06, 2023

Copy link to clipboard

Copied

 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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Mar 07, 2023 Mar 07, 2023

Copy link to clipboard

Copied

I've tried the script you linked to at the top of this page, and it works, but only the first time i use it. Once the TXT file is created the dialog bugs out and the right hand side with the buttons becomes obscured. reducing the window width will bring them back into view but reducing beyond a point will cause the dialog to minimize or move off screen causing some other issues. I've commented out the function savedata and function getprevious and it works much better for me now.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines