Index to Text: Convert Page References to Text Tags
Problems with indexes can be solved by converting all page references to text.
These scripts are part of the Indexes and Concordances collection. See the full collection here.
The Index to Text script (index-to-text.jsx) converts all page references in a document to text tags of the form <ix>dog</ix> and inserts these where the page reference occurs in the text. This is usually right before the first character of the indexed word, so that you end up with e.g.
<ix>dog</ix>
where the tag shown in red is inserted before the text occurrence dog, shown in black.
Subtopics
Any subtopics are separated from the main topic and other subtopics by #. Example: all page references to the topic dog with subtopic collie which itself has a subtopic border collie are replaced with the text string <ix>dog#collie#border collie</ix>. If a page reference to this topic chain occurred at the phrase border collie in the text, you would see this:
<ix>dog#collie#border collie</ix>
After converting all page references, all topics are deleted and the index is cleared.
Sort order
If a topic has a sort order defined, the sort order is suffixed to the topic’s name separated by @. For example, the topic \target with sort order targetis inserted as follows:
<ix>\target@target</ix>
Other properties
The remaining properties (page-reference type, style override, and limit) are added to the string, separated by %%. Example:
dog%%FOR_NEXT_N_PAGES~~Principal~~4%%
where FOR_NEXT_N_PAGES is the page-reference type, Principal is the name of the number style override, and 4 is the page count.
Use
The script has no interface; just run it. You could change the codes that the script expects with other codes.
Build or rebuild index from tags
The index can be rebuilt later using the Index Rebuild script (index-rebuild.jsx).
Problem entries
Problem entries are skipped so that their markers stay in the text. After running the script, if there were any errors an alert is shown. Check the index panel and try to fix the problematic entries.
Use
The scripts have no interface; just run it.
Version history
10 Aug. 2023: Added support for page reference type, style override, and limit.
11 July 2018: Improved error handling.
26 February 2016: Sort orders are now added to the text tag.
May 2009: First posted.
Peter Kahrel Script Repository
Hosted as a community service, and with deep appreciation, by CreativePro.com
Scripts by Topic | Script Index
Basic Script Installation and Use
How to Modify or Configure These Scripts
Resources for Scripting and Publishing Automation
About This Repository
Contact Peter Kahrel
Note to users: You run scripts at your own risk: CreativePro and the author accept no liability for anything that may be caused by any of these scripts. Always take the necessary precautions. We encourage you to save backups and test scripts on copies of your documents.
This article was last modified on August 22, 2026
This article was first published on December 3, 2025
Commenting is easier and faster when you're logged in!
Recommended for you
InDesign Magazine Issue 68: Workflow
We’re happy to announce that InDesign Magazine Issue 68 (December, 2014) is...
Spread Rotation Menu Commands
Spreads can be rotated using some deeply embedded menu commands. A script can ma...
