Manage text anchors

Text anchors are useful things. InDesign uses them as targets for cross-references, hyperlinks, and bookmarks (when you create a bookmark, a text anchor is created behind the scenes), and you can add text anchors for your own use. When you delete a bookmark, its associated text anchor is deleted along with it. But when you delete hyperlinks and cross-references, their destination text anchors remain in the document.

This can lead to many orphaned text anchors. Though they do no harm other than cluttering some of the hyperlink dialogs, I like to get rid of orphaned anchors every now and then. Unfortunately, it's not possible in InDesign to get an overview of what a document's anchors are used for.

Another shortcoming in the way that InDesign manages its anchors is that it's not possible to show where anchors are. It's sometimes useful to see an overview of the text anchors in a document, on a page, or in some selected text.

The only thing that InDesign has to offer to manage text anchors (using the term 'manage' very loosely here) is the Hyperlink Destination Options window:

InDesign's Hyperlink destinations window

You can rename a text anchor and you can move an anchor to the current text insertion point – or so you're led to believe but it doesn't work: the anchor is moved to the beginning of the story.

The script described here addresses all this and adds functionality. It lists all text anchors in a document and shows if they are in use and if yes, what they are targeted by:

Text anchor manager

The first column shows the name of all text anchors in the document; in the second column you see what the anchor is targeted by ('Xref' for 'cross-reference'), and the third column displays the name of the source linked to the anchors. If columns 2 and 3 are empty, the text anchor is not targeted by anything.

The text field and the buttons function as follows. Most functions are pretty straightforward

Text field

The text field can be used to filter the list. When I type drop there and press the tab key (or click outside text field), the list is filtered to contain only the anchors whose name contains drop:

Text anchor manager

To show only the anchors whose name begins with drop, enter ^drop – you can use standard regular expressions in the field.

Go to selected

The text anchor is selected and the script sets the zoom to 400% so that the selected anchor becomes visible.

Rename

Rename the text anchor.

Move to ip

This fixes the InDesign move function. To move a text anchor, select the insertion point that you want to move the anchor to and click Move to ip.

Delete selected

Delete the selected text anchors.

Select unused

Select all text anchors in the document that aren't targeted by anything.

Show anchors

To display the location of anchors, click Show anchors. The script adds small anchored frames at the page edge and adds the anchor's name to the frame. To make visible the line that connects the anchored frame and its anchor – as in the screenshot – make sure that text thread display is enabled (View > Extras > Show Text Threads), and select the text frame that contains the anchored frame:

text anchors

Here, stack difference Mac/PC is the name of the text anchor that's at the beginning of the word differently.

With nothing selected, all text anchors in the document are displayed; with a selection, only the anchors in the selection are shown. (Note: when you select a text frame, the script shows the anchors much quicker than when you select some text.)

Note that InDesign shows text anchors in the story editor:

text anchor in story editor

But that won't tell you the name of that anchor, and the story editor can be very sluggish in long documents.

Delete displayed anchors

To remove all displayed anchor frames, click Delete displayed anchors – this removes just the text frames with anchor names, not the anchors. The styles that were created (a paragraph and an object style) and the swatch are deleted too.


Version history

1 Jan. 2017: If an anchor was in a table or in a footnote, the 'Go to selected' function didn't work properly. Fixed.

8 May 2016: Added code to get around the problem that listboxes don't display in CS6 on Windows 10.

10 Apr. 2016: Largely rewrote the script and added some functions (filtering the display, move anchors).

19 Oct. 2014: Added a button Show anchors to show where a document's text anchors are. Names are aded in anchored frames. And a button to delete those frames.

3 Dec. 2012: Added a note to say that I discovered that in 2010 Gerald Singelmann wrote a script that has some of the functionality of my script (http://www.indesign-faq.de/de/textanker-pflegen).

26 August 2012: First posted.


Useful script? Saved you lots of time?

Consider making a donation. To make a donation, please press the button below. This is Paypal's payment system; you don't need a Paypal account to use it: you can use several types/brands of credit and debit card.

Peter Kahrel's paypal account

Show script (right click, Save Link/Target As to download)

Back to script index

Installing and running scripts

Questions, comments? Get in touch