Update index

For various reasons, indexes often need post-editing. This can be the case after generating a word index (author, language, etc.) or after combining several indexes. After some editing, you could end up with two or more identical topics with different page numbers:

Leech, G., ii, iv, 1, 2, 3, 7, 10, 21, 22, 23
Leech, G., iii, vi, 14, 6, 8, 9, 10, 15, 11, 22, 23

After manually combining these entries you get this:

Leech, G., ii, iv, 1, 2, 3, 7, 10, 21, 22, 23, iii, vi, 14, 6, 8, 9, 10, 15, 11, 22, 23

To reorganise the page numbers, run the script to get this:

Leech, G., ii–iv, vi, 1–3, 6–11, 14–15, 21–3

The script runs either on just the selected paragraph (no need to select the whole paragraph, just place the cursor somewhere in it) or on the whole index. To process the whole index, select one of the index's text frames and run the script.

Page ranges in the original are 'unranged' by the script and reranged if necessary.

Ranging pages

In the example above, pages are ranged. Whether this should happen and, if yes, in what way, is determined by the setting of the global constant page_span at the beginning of the script. "0" means 'no ranging at all'; "1" is the standard ranging of consecutive numbers; "2" allows for gaps of one page. By increasing the page_span, the spanner becomes more tolerant. Look for this line at the beginning of the script:

page_span = 1

and set the value you want (0 to disable spanning). Some examples:

page_span = 0: '1, 2, 3, 4, 6, 8' (no change)
page_span = 1: '1, 2, 3, 4, 6, 8' > '1-4, 6, 8'
page_span = 2: '1, 2, 3, 4, 6, 8' > '1-6, 8'
page_span = 3: '1, 2, 3, 4, 6, 8' > '1-8'

Dropping digits (abbreviating ranges)

The script is set to drop digits (also known as 'abbreviating page ranges') so that 123-129 is changed to 123-9. Ranges are abbreviated maximally (as is customary in Britain), e.g. 2006-9. To disable digit dropping, look for this line:

drop_digits = true;
and change it to
drop_digits = false;

The script has no interface.

Version history

October 2015: yet another fix needed for paragraph styles.

June 2010: fixed issue with paragraph styles.

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 the main page on indexing

Back to the main script page

Installing and running scripts

Editing a script

Questions, comments? Get in touch