1.7. Sorting and merging

Entries are sorted and merged according to a sort key generated from the headings.

Once generated sort keys contain only a-z, A-Z, 0-9 and space. Sort keys are compared in the standard manner, word-by-word. Case only affects the sort order when it is the only difference between two keys, in which case upper-case is sorted before lower-case (ie. China before china).

Entries with identical keys have their page and cross references combined and the later entry is discarded. If multiple cross references of a entry have identical keys only the first is retained. An entries page references are sorted appropriately: page numbers/ranges in numerical order with overlapping ranges being merged into one.

The sorted index is then output using the same format as the input. This enables the output to be checked, edited if required, and put through the two stages again.

The keys are generated as follows:

  1. The {} and {|} constructs are handled appropriately.

  2. Adjacent word separators (-,;: and space) are replaced by a single space (for word-by-word) or removed (for letter-by-letter).

  3. All non alpha-numerical (except space) characters are removed.

  4. Leading and trailing spaces are removed

Example 1-7. Sorting and merging

heading  12-15
heading *see also* entry  4
heading *see also* subheading  14-17,5-6

is output as:

heading *see also* entry; subheading  4, 5-6, 12-17