Index fixes

The usefulness of InDesign’s index function is constrained by bugs and absent features. The purpose of this page is to highlight those that I'm aware of and provide workarounds, often in the form of one or more scripts.


No styling in topic names

Topic names cannot be styled in the Index panel. It's not possible to italicise any part of a topic's name, for example. However, a simple solution is to add text tags such as <i>. . .</i> and use two GREP queries in the generated index to apply charactyer styles and remove the tags, or set up a GREP style in the topic paragraph styles to hide those tags and apply some styling.

Details


Topic structure is not editable

You can change the names of existing topics, but it's not possible to make changes in topic hierarchies. It's not possible, for example, to drag the subtopic InDesign to a different topic, or drag it up one level to make it a level-1 topic. (In Affinity Publisher this is possible.)

InDesign's Index panel

I'm aware of two workarounds. The first is Kerntiff's index utilities. They include scripts to relocate topics together with their references. Another possibility is a set of scripts I wrote several years ago (they still work fine). The latter can also be used to try and fix a corrupt index.


Multiple indexes

InDesign documents can contain only one index. But when you need more than one index, for example, a subject index, a language index, and an author index, there are ways to work around that limitation.

Details


Cross-references often the wrong type

When you have a topic with just cross-references, they should (almost always) be see ones. Conversely, if a topic has any page references, if the topic also has cross-references they should be see also. When you do a lot of editing in a document and its index markers, the cross-reference types can get mixed up. InDesign doesn’t check this, but a script can fix the cross-reference types. (Note: This script is for single-document texts only: it doesn't work well in books.)

Download script


Cross-references are not sorted

Cross-references are printed in the order in which they were added to the document. If you add to a topic a cross-reference to the topic Python, and later, at the same topic, create a cross-reference to the topic JavaScript, you end up with See also Python; See also JavaScript. This can be fixed with a script:

Download script

This script is useful only in single-document texts, and it just sorts a topic's cross-references. For books and additional cross-reference handling, see the next section.


See also cross-references are not grouped and immediately follow the topic

See also subtopics aren't sorted, are not grouped, and always appear before any page references, immediately after the parent topic. So you'll always end up with something like this:

Sort and combine index cross-references; after

Clearly, the subtopics should be sorted and grouped so that you'll have one See also stub. In addition, many publishers want subtopics to be placed after any page references, so sub-topic placement should be an option. This can be handled by a script.

Details and script


Keeps don't work as expected

Keep with next n lines is a confusing option. Its effect is to keep together with the current paragraph the first n lines of the next paragraph. This means that if you want to keep together an index section heading and the first two topics that follow it, or a topic with the first two subtopics, you're dealing with the next n paragraphs, which of course is not the same as the next n lines.

But even if Keeps worked more as expected, for an index what you really need is conditional keeps, for example, keep a topic with the next paragraph only if the next paragraph is a subtopic. Or keep a topic together with the previous topic only if it's the same level and if it's the last in a block (to avoid widowed topics). And since InDesign doesn't do conditional keeps we need a script.

Details and script


Page ranges are problematic

InDesign offers various ways to manage page ranges. Some of these work fine, others are almost impossible to handle. Indicating the scope of a page reference as a number of paragraphs or pages is fine in a static document, but in a document that changes from time to time these are a nightmare. In addition, the 'For Next No. of Paragraphs method is so poorly designed that it's basically useless.

The only really manageable way to deal with page ranges is the use of markers in the text that indicate the end of the range. Most word processors have such a system. I've been using a script-based marker system for index page ranges for years, and it works quite well.

Details and script


Indexes often don’t sort very well

There is good support for language-specific sorting with respect to accents, but sorting in general often leads to bad results. There are two main problems: InDesign doesn't distinguish letter-by-letter and word-by-word sorting, it supports only letter-by-letter sorting. And the problem with that is that InDesign ignores all commas and spaces, applying an extreme (and ill-conceived) version of letter-by-letter sorting. Fortunately it's not too difficult to change InDesign's index sorting behaviour.

Details


Topics from a word list

When you create a page reference from a selected word or phrase there's an option to mark up all occurrences of that word or phrase:

Index: Add all occurrences

But there's no way to add a list of words other than using a script.

Details and script

Note that there are scripts that can create a stand-alone index from a word list (see e.g. Marc Autret's script and mine, but since we're concerned here only with InDesign's index feature we won't go into stand-alone indexes any further).


CJK topic names don't appear

Usually, when you add a topic whose name starts with a non-Latin letter (a digit, puctuation mark, or non-Latin script), InDesign creates a topic section Symbols and places it there. But with Chinese, Japanese, and Korean characters that doesn't happen: they just don't appear at all, not anywhere. The fix is simple.

Details

Locator limitations

InDesign's index supports just one type of locator, namely, the page number. On top of that, only bare page numbers are supported: additions for context (footnote, table) are not supported. An index with anything other than bare page numbers is possible only with a script.

Such a script is not exactly a trivial matter. It reads InDesign's index markers and builds a model of the index in memory, then outputs the index using all the data from the Generate Index window (styles, separator characters, etc.).

In this approach the index (the markers in the document) is maintained as usual; the only difference is that instead of using InDesign to generate the index, you use a script. No concrete scripts are offered here because these scripts almost always have to be customised to a considerable extent.

Page numbers only

To create an index in which the locators are section or paragraph numbers (anything other than page numbers, in fact) a script is needed.

InDesign doesn’t distinguish text locations

InDesign’s locators don’t distinguish context, such as footnote text versus main body text. It’s therefore not possible to indicate in an index whether a reference is in the main text or in a footnote. The same goes for other locations, such as tables and figure captions.

However, a script that creates an index can deal with these different locators.

InDesign doesn’t support page-number modifiers

InDesign’s only enhancement to page references in the index is the application of a character style (a ‘Number style override’ in the Page Reference window). This is useful, for instance, to mark principal page references bold or italic in the generated index.

You'd think that you could use a number-style override to mark page-reference markers in tables or footnotes, then after generating the index, look for the override character styles, insert some letter, and remove the character style. But that works only if the modified page reference is the only page reference on that page. It's therefore useless. Besides, as mentioned earlier, page-numner overrides don't work in books.


Special characters can break the index

Topic names mustn’t contain special characters (typographer’s quotes, en- and em-rules, etc.) InDesign can’t generate an index that contains such a character. The problem is that when such an error occurs InDesign just says something vague about an illegal character without indicating which topic or topics contain those illegal characters or what those characters are.

problems such as these can be caused by copying and pasting topic names. It's easy, for instance, to include a paragraph break or a space character (other than the normal space). You can't see those characters in after pasting a string that contains them in the New Page References window: the problem shows only when you generate the index.

Fixing this can be a nightmare. One possibility is the index-to-text script, which converts all index markers to text strings. These strings are inserted in the text at the location of the converted markers. You can now inspect the markers and make any corrections. Then you can convert the text strings back to InDesign index markers using the index_rebuild script.

Another way to try and find problems is to write out the index as a separate document, see Topic structure is not editable


Books

A bug and a piece of bad design blight InDesign books with regard to indexes: number-style overrides don't work (bug) and if a book contains more than about 120 files you can't generate an index (bad design). The number of 120 isn't an absolute for some strange reason, it fluctuates between 120 and 140. The limit as by design, for the operating system (both Mac and Windows) have nothing against hundreds of files open at the same time. Even after this problem was pointed out to them, Adobe decided to leave things as they are.

Number style overrides don't work in books

Number Style Override can be used to apply a character style to a page number in the generated index to mark, for example, principal page references. But this doesn't work in book files and unfortunately there's not much that can be done about it.

InDesign can open only about 120 documents

When InDesign generates a table of contents of a book file, it polls the book file’s documents: it opens each document in turn, collects data, and closes each document. Then it generates the table of contents. With this approach it does not matter how many documents the book file contains.

Unfortunately, to generate an index InDesign needs to have all documents open. And because InDesign can’t have more than about 120 documents open, this means that if your book file contains more than about 120 files you can’t generate the index.

This is a serious problem. The only way around it is a script that creates a model of the index in memory: it opens each document in turn, collects each document’s index data, closes each document, and generates the index. This was described above.


We close this page with a bug in the scripting system.

Scripting problem: Index markers are misplaced after tables

When a script inserts an index marker and the text contains one or more tables between the insertion point and the beginning of the story, the marker is inserted too far ahead in the text. The more tables there are and the bigger those tables, the bigger the offset. (This doesn’t happen when you add a page reference by hand.) Any script that places page references must be aware if this. This fix is fairly simple, see the function in the linked script:

Download script

Index and PDF

To do.

Index and Epub

To do.


Change log

18 Dec. 2023: Changed the text and fixed some links in the sections dealing with sorting, grouping, and placing cross-references.

12 Dec. 2023: The link to the script mentioned on this page was wrong; fixed.

13 Aug. 2023: Added a section on creating topics from a wordlist.

12 Aug. 2023: Did Multiple indexes as a separate page and added a second method.

10 July 2023: Posted.


Back to script index

Installing and running scripts

Questions, comments? Get in touch