Index Fixes: Sorting
InDesign doesn't distinguish letter-by-letter and word-by-word sorting, it supports only letter-by-letter sorting.
InDesign’s index supports language-specific sorting quite well in that sorting idiosyncracies in each supported language are honoured and diacritics are sorted according to the rules of each language.
However, a problem is that 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. In an index with many commas, as in an index of names, this leads to very bad results.
The following list was posted by a baffled user in Adobe’s InDesign user-to-user forum many years ago:
Li Bassi, A. Li, C. Liebers, J. Li, G.N. Li, J. Li, J.F. Li, K. Lima, C.J. Li Mora, A. Lim, C.S. Lim, S.C. Linfield, E.H. Lin, Z.-D. Li, P.W. Li, R. Lis, T. Li, S.W.
A list of names, each surname followed by a comma and initials. InDesign’s letter-by-letter sort ignores commas, which leads to this very badly sorted list It should be sorted as follows: first all the Lis together, then the names that start with Li.
Li, C. Li, G.N. Li, J. Li, J.F. Li, K. Li, P.W. Li, R. Li, S.W. Li Bassi, A. Liebers, J. Lim, C.S. Lim, S.C. Lima, C.J. Li Mora, A. Lin, Z.-D. Linfield, E.H. Lis, T.
Whether Li Bassi and Li Mora should be sorted as they are shown here or whether they should be sorted together immediately after the block of Lis is a matter of debate, but both can be handled.
Fortunately it’s fairly simple to influence the way that topics are sorted. The correct sort order can be set as follows: duplicate the topic name in the sort-order field and replace the comma with a 0 (a zero).

Naturally, setting all those sort orders manually is not an option, and fortunately this is very easy to script:
(function () {
var t = app.documents[0].indexes[0].allTopics;
for (var i = 0; i < t.length; i++) {
t[i].sortOrder = t[i].name.replace (',', '0');
}
}());
Save this script in InDesign’s Scripts folder and run it with a document open. For details on installing scripts, see here.
In the name index shown above, with the sort-order fix applied, all names are sorted letter-by-letter. I’ll repeat a fragment here:
Li, S.W. Li Bassi, A. Liebers, J. Lim, C.S. Lim, S.C. Lima, C.J. Li Mora, A.
But it might be clearer for the reader to group Li Bassi and Li Mora together after the Lis. In effect you sort those two names word-by-word, and indeed the Chicago Manual of Style mentions that though letter-by-letter sorting is preferred, indexes often end up with a mix of sorting strategies.
The fragment with the to open compound Lis, so to speak, sorted word-by-word, looks as follows:
Li, S.W. Li Bassi, A. Li Mora, A. Liebers, J. Lim, C.S. Lim, S.C. Lima, C.J.
The only additional change in the sort orders is to replace the spaces after Li with the letter A:

(function () {
var t = app.documents[0].indexes[0].allTopics;
for (var i = 0; i < t.length; i++) {
t[i].sortOrder = t[i].name
.replace (',', '0')
.replace (' ', 'A');
}
}());
Further refinements are usually needed. Some will be systematic, in which case you can script them, while others are not very predictable, in which case you’ll have to apply them manually. The latter will be few in number, most probably.
Note: If you manually edit a generated index and need to resort it, you can use Marc Autret’s SmartSort script.
Return to Index Fixes page.
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
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.
This article was last modified on September 5, 2026
This article was first published on September 5, 2026
Commenting is easier and faster when you're logged in!
Recommended for you
Index Fixes: Cross-References Often the Wrong Type
When you have a topic with just cross-references, they should (almost always) be...
CreativePro Video: InDesign Styles – Beyond the Basics
In this week’s CreativePro video, Anne-Marie “Her Geekness” Concepcion, co-host...
Index Graph: Show the Distribution of Index Markers
To show how the index markers (page references) are distributed across the docum...
