Q: how do I alphabetize strings with diacritics?
Problem
I have a long list of author names, some of whom have letters with diacritics in their names (e.g., "á" or "é"). I want to sort this list alphabetically.
The problem: sort
ing the list with string-lessp
does not sort them alphabetically.
According to the accepted answer in this post from a sister site, English ignores the diacritics in sorting except to break ties. (Other languages do it differently.)
Toy Example
Here's a toy example. The list of letters that I start with is
already ordered alphabetically. When I sort
this list with
string-lessp
, however, it sorts them in what I presume is
unicode point order rather than alphabetical order:
(let ((letters '("a" "à" "á" "â" "b" "c" "e" "é" "ê")))
(sort letters #'string-lessp))
;; => ("a" "b" "c" "e" "à" "á" "â" "é" "ê")
What Do I Do?
How can I alphabetize strings with diacritics in them?
At a minimum, I'd like to respect the "ignore diacritics except to break ties" rule described above. Ideally, I'd like to be able to alphabetize according to an arbitrarily defined language, but I'll happily settle for English.