Create index topics from character styles and/or conditions

The script creates topics for and page references to all text formatted with certain character styles and/or conditional text. The latter is useful for text that that has already some character style applied, because in InDesign you can't apply two or more character styles to the same text range.

Use

Open the documents that you want to process and run the script. It shows this dialog:

[image: index from character styles 1]

Style groups are shown in parentheses after a style name (nested style groups are separated by a colon). Select any character styles from the list in the usual way.

In the Target dropdown, select Character styles or Conditions.

In the Mode dropdown, select either of the three modes:

Content only The script includes in the index just the found text. This could produce a flat, unstructured, index like this (that is, without any subtopics):

[image: index panel]

Style names nest topics A topic is created from the character style's name, the found content is made into a subtopic. If the character style is in a style group, the style group's name is made into the main topic, the style's name into a subtopic, and the content appears as a subsubtopic:

[image: index panel]

Style names are prefixes This option is useful if you want to create two or more indexes. Suppose that, in addition to a subject index, you want two separate indexes, e.g. a name index and an index of titles. The names have the condition Names applied, the titles, the condition Titles. Now when you select those two conditions and Style names are prefixes, you could get this index:

[image: index panel from conditional text]

Names and titles are now each grouped together. After the index is generated you can move these sections to the back of the index, then delete the placeholder names. You could make things even easier by prefixing the condition or style names with ZZ so that they are grouped together at the end of the index, which makes splitting the index more straightforward.

Check Replace existing index to delete all existing topics and page references.

Groups in conditions

Unlike character styles, conditions don't have groups. If you want subtopics using conditions, use %% as a separator. For example, the condition name Titles%%Books, when applied to Bursting Bubbles, would create the topic hierarchy shown in the Index panel:

[image: index panel from conditional group]

Changing the order of first and last names

To change the order of first and last names, so that the text occurrence James McCawley appears in the index as McCawley, James, add @@ at the end of the character style's or condition's name, as in Authors@@.

By default, the script assumes that the first word of the found content is the first name, the second, the last name. If a name consists of two or more words and the first two words form the first name, insert a non-joiner after the last part of the first name. For instance, to have the text occurrence J. S. Bach appear as Bach, J. S., add a non-joiner immediately after S.:

[image: non-joiner]

To insert a non-joiner, go to Type > Insert special character > Other > Non-joiner). When you enable the display of hidden characters (Type > Show hidden characters), the non-joiner is shown as a hacek accent (a.k.a. caron).

Troubleshooting

Errors are usually caused when a character style was applied to a special character such as an en-rule or a paragraph return. The script displays an error message and shows which style was involved. Look for instances of the style in the document and fix the problem, then run the script again.


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

Version history

31 Mar. 2018: Added conditions as a target (in addition to character styles), and provided a third output format.

28 Aug. 2017: Added functionality to change the order of first and last names, e.g. 'John Smith' > 'Smith, John'. See the text for details.

25 Oct. 2016: Fixed a display problem in CS6/Windows 10.

11 Sept. 2016: Improved the support for style groups, and added the addition of subtopics.

3 Sept. 2015: The script now deals with the InDesign bug that causes page reference markers to be placed incorrectly in documents that contain tables.

21 March 2014: Some minor changes to make the script more efficient.

20 Dec. 2012: The script sometimes missed some styles. Fixed.


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

Installing and running scripts

Back to the main page on indexing

Editing a script

Questions, comments? Get in touch