Index from Topics List

Using the entries in a word list, the script adds index markers (topics and page references) to all open InDesign documents.

This script is part of the Indexes and Concordances collection. See the full collection here.ย 

Using the entries in a word list, the script adds index markers (topics and page references) to all open InDesign documents.

Use

First, rename the word list so that it has topic list in its name and open it. Then open all documents that should be indexed and run the script. It has no interface. The script uses each item in the list to create a topic in each document and adds page references.

A log is created in a new document that lists items that could not be found (see below).

Settings

The script can be set to search case-sensitively, to delete an existing index, to target only paragraphs formatted with certain paragraph styles, and to create page ranges from paragraph styles. These items can be changed in the script file. To do so, open the script in a text editor, make any changes, and save the script file as a plain text file.

Ignore commas

By default the script ignores everything from the first comma in a topic name. Thus, of the entry

Leech, G.

Only Leech is used for the search: after all, a text is more likely to contain just an author’s surname than their surname followed by their initials or first name. To change this, and have the script look for the whole entry, i.e., including the comma and what follows it, change this line in the script:

var comma_split = true;

to read var comma_split = false;

Ignore parentheses

This one is similar to the previous one: ignore everything from the first opening parenthesis. Take this entry:

Country Girl (O'Brien)

By default, the script looks for Country Girl only. To change this, look for this line in the script:

var paren_split = true;

and change it so that reads var paren_split = false;

Case-sensitivity

The script searches case-sensitively by default. To make it search case-insensitively, change this line:

var case_sensitive = true;

to read var case_sensitive = false;.

Whole words only

The script searches only for whole words. Cannot be changed.

Replace existing indexes

By default, the script deletes any existing topics and page references. To keep an existing index, change this line:

var replace_index = true;

to read var replace_index = false;.

Certain paragraph styles only

There are probably a number of parts in each document that you want to exclude from the index. Typically, indexes don’t refer to such items as bibliographies, quotations, and chapter titles. Some publishers want to exclude tables as well. To allow for this, the script can be set to mark topics only in paragraphs formatted with certain paragraph styles.

The script defaults to ignore this feature, that is, everything it finds is marked for the index. To make the script look in certain paragraphs, list those paragraph styles, using only the first three letters of their names only, separated by a |, the vertical bar. Look in the script for this line:

var paragraph_styles = "";

This is the default โ€“ the script finds all paragraphs. To include only paragraphs that are formatted with the paragraph styles bodybody no indentsectionAsectionBsectionC, etc., change the above line to this:

var paragraph_styles = '|body|section';

Thus, use the first few letters of the paragraph style (case sensitive), prefixed by |. Be careful not to add any spaces before or after the | symbol.

Page ranges from paragraph styles

There are several ways to set up page ranges for topics (to next use of style, to next style change, for next n pages, etc.). The script handles only ‘to next use of style’. Thus, when a key word is found in a defined paragraph style (such as a section heading), it sets a page range to the next instance of the same paragraph style.

To set up this feature, look for this line

var to_next_style = '';

To set up the page-range feature for the styles whose name starts with H3H4sectionAsectionBsectionC, etc., change that line as follows:

var to_next_style = 'H3|H4|section';

Cross-reference tags

By default the script handles cross-reference tags see and see only. To change that, look for the line

var xRref_see = 'See';

and change the tag to those used in the word list. In a Spanish word list you would use something like 

var xRref_see = 'Vรฉase';
var xRref_see_also = 'Vรฉase tambiรฉn';

Note that this applies to the word list only: how the tags appear in the generated index is determined by your InDesign’s locale. Thus, when you process a Spanish text and word list in an English installation, the cross-reference tags will be generated as See and See also. Applying language code isn’t going to help, you’ll have to replace the tags in the generated index.

The word list

Topics and subtopics

To create topics and subtopics, separate them with ##. For example, the following item in the word list:

whiskey##Scotland##Islands##Laphroaig

Creates the following topic chain in the document:

Create subtopics

Cross-references

Cross-references can be added by using the usual see and see also tags or the equivalents in another language. If a topic has more than one cross-reference, specify each on a new line, as in the following example (the commas are optional):

book, see also tome
book, see also volume
Cross-references shown in the index panel

Styling

InDesign doesn’t allow styling in topic names in the Index panel. But there’s a fairly same way yo deal with this, namely, with the use of simple HTML-like format tags. The script supports one-letter tags in angle brackets. For instance, to include a topic name in italics, specify it in the word list as follows:

<i>Country Girl</i>

The script creates the topic name as it appears in the list and adds the name without the tags as the sort order to ensure that the topic is sorted correctly:

Sort order set without style tags

If a topic and its subtopic(s) are styled, the tags should be applied to each name individually, not to the whole string:

<i>Country Girl</i>##<i>reviews</i>

Naturally, these style tags appear in the generated index, so any styling should be applied after generating the index separately.

Styling the generated index

Style tags appear in the generated index, and should be replaced with ‘real’ styling. The easiest way is to create a character style for each style (italic, bold, etc.) and use a Find/Change Grep query to apply the styles. The screenshot shows how to apply the character style italic to the style tags <i>. . .</i>:

Apply character styles to style tags

You’ll need a separate query for each style. If you have more than one or two queries you can run them with one click using this script


Version history

9 Aug. 2025: Added support for styling, page ranges, and cross-references. The matching of paragraph styles to be ignored is now a bit more flexible (see under Certain paragraph styles only)

28 Aug. 2024: Some matches needed to be refined. If a search term contains a dash, then the script should target the term with normal and non-breaking hyphens. Similarly, if a search term contains a space, then the script should find the term with a non-breaking space as well. Parentheticals weren’t matched correctly. All this is fixed. Also, the paren_split option somehow got lost, now reinstated. Finally, ScriptUI progress bars stopped working in ID2025, so I removed all progress indication.

6 Aug. 2024: When run against more than one document the scripts log contained many false negatives. Fixed.

16 Sept. 2023: Some improvements make the sript more efficient. Various clarifications in the text.

28 July 2019: The script now creates a log file that shows which items weren’t found and a list of amiguous entries.

16 Nov. 2011: Fixed bug that ignored some words in the word list.

Around 2007: 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


Repository Home Page


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.

Bookmark
Please login to bookmark Close

This article was last modified on August 22, 2026

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading comments...