[Tex/LaTex] Strange sorting of Greek letters using glossaries with xindy

glossariesxindy

When TeXing the attached MWE using xindy for sorting, the Greek entries
are sorted between the Latin letters "R" and "S" while they are sorted after
the Latin Letters when not using xindy. How can this be fixed by

  • either sorting them after the Latin Letters (like with makeindex)
  • or by sorting them before the Latin Letters?

% ----- minimal example -----
\documentclass{scrartcl}
\usepackage{luatex85}     % <-- only needed for LuaLaTeX
\usepackage{longtable}
\usepackage[
        automake,
        nomain,
        nonumberlist,
        symbols,
        % comment next `key-value` and Greek Letters are sorted 
        % after the Latin Letters
        xindy={
            codepage=utf8,
        },
            ]{glossaries-extra}
    \makeglossaries
\renewcommand*{\glspostdescription}{}
\newglossarystyle{symbver}{
    % change length of `\glsdescwidth'
    \setlength{\glsdescwidth}{8cm}

    % put the glossary in a longtable environment:
    \renewenvironment{theglossary}
        {\begin{longtable}[l]{lp{\glsdescwidth}r}}
        {\end{longtable}}

    % No heading between groups:
    \renewcommand*{\glsgroupheading}[1]{}

    % Set the table’s header:
    \renewcommand*{\glossaryheader}{}

    \renewcommand*{\glsresetentrylist}{}

    % Main (level 0) entries displayed in a row optionally numbered:
    \renewcommand*{\glossentry}[2]{%
        \tabularnewline %                           start with empty row
        \rlap{%
            \glsentryitem{##1}%                     Entry number if required
            \glstarget{##1}{\glossentryname{##1}}%  Name
        }
        \tabularnewline %                           end of row
    }

    % Similarly for sub-entries (no sub-entry numbers):
    \renewcommand*{\subglossentry}[3]{%
        % ignoring first argument (sub-level)
        \glstarget{##2}{\glossentryname{##2}}%      Name
        & \glossentrydesc{##2}%                     Description
        & \glossentrysymbol{##2}%                   Unit
        \tabularnewline %                           end of row
    }

    % Nothing between groups:
    \renewcommand*{\glsgroupskip}{}
}
\newglossaryentry{subscripts}{
    type=symbols,
    name={\textbf{Subscripts}},
    description={\nopostdesc},
    sort=d,
}
\newglossaryentry{symb:sub:alpha}{
    type=symbols,
    name=$\alpha$,
    description={entry},
    symbol={},
    sort=α:entry,
    parent=subscripts,
}
\newglossaryentry{symb:sub:omega}{
    type=symbols,
    name=$\omega$,
    description={exit},
    symbol={},
    sort=ω:exit,
    parent=subscripts,
}
\newglossaryentry{symb:sub:relative}{
    type=symbols,
    name=rel,
    description={relative},
    symbol={},
    sort=r:relative,
    parent=subscripts,
}
\newglossaryentry{symb:sub:saturation}{
    type=symbols,
    name=sat,
    description={saturation},
    symbol={},
    sort=s:saturation,
    parent=subscripts,
}
\begin{document}
        \glsaddall[types={symbols}]
    \printsymbols[
        style=symbver,
    ]
\end{document}
% ---------------------------

image showing the result of above code

Best Answer

This seems to be a problem with the way xindy sorts sub-entries. It isn't specific to the glossaries package.

Analysis

The following is a simpler illustration:

\documentclass{article}

\usepackage{fontspec}
\usepackage{makeidx}
\setmainfont{Liberation Serif}

\makeindex

\newcommand*{\lettergroupDefault}[1]{\lettergroup{#1}}

\begin{document}
α\index{α}
ω\index{ω}
r\index{r}
s\index{s}

\printindex
\end{document}

Assuming this document is called test.tex then:

lualatex test
texindy -L english -C utf8 -o test.ind test.idx
lualatex test

produces:

image of index, greek letters appear in default group

This is because xindy has been instructed to sort according to the English alphabet, which is a Latin alphabet, so the non-Latin characters are put in the "default" group because the english module has no rule for them.

If instead you were to do:

lualatex test
texindy -L greek -C utf8 -o test.ind test.idx
lualatex test

then the index looks like:

image of index, the Latin characters are now in the "default" letter group

Now xindy has been instructed to sort according to Greek alphabet, which has no rules for Latin characters, so they're put in the "default" group.

Suppose now you try:

lualatex test
texindy -L russian -C utf8 -o test.ind test.idx
lualatex test

then all the Latin and Greek characters end up in the "default" group:

image of index with all entries in the default group

This is because xindy has now been instructed according to the Cyrillic alphabet and has no rules for the Latin or Greek characters.

Returning to glossaries, here's the index example rewritten:

\documentclass{article}

\usepackage{fontspec}
\usepackage[xindy]{glossaries}
\setmainfont{Liberation Serif}

\makeglossaries

\newglossaryentry{α}{name={α},description={alpha}}
\newglossaryentry{ω}{name={ω},description={omega}}
\newglossaryentry{r}{name={r},description={r}}
\newglossaryentry{s}{name={s},description={s}}

\begin{document}
\gls{α}
\gls{ω}
\gls{r}
\gls{s}

\printglossary[style=indexgroup]
\end{document}

Now:

lualatex test
makeglossaries test
lualatex test

produces:

image of sample document with Greek entries in default group

because it's using the English sorting rules.

This is fine so far, but sub-entries seem to be behaving differently. A slight adjustment to the above example illustrates this:

\documentclass{article}

\usepackage{fontspec}
\usepackage[xindy]{glossaries}
\setmainfont{Liberation Serif}

\makeglossaries

\newglossaryentry{d}{name={d},description={parent}}
\newglossaryentry{α}{name={α},description={alpha},parent=d}
\newglossaryentry{ω}{name={ω},description={omega},parent=d}
\newglossaryentry{r}{name={r},description={r},parent=d}
\newglossaryentry{s}{name={s},description={s},parent=d}

\begin{document}
\gls{α}
\gls{ω}
\gls{r}
\gls{s}

\printglossary[style=indexgroup]
\end{document}

image of document

This results in the strange ordering you noticed. I don't know why it puts the r entry before the Greek letters within the sub-entries, but it behaves as expected if I switch the language back to Greek:

\documentclass{article}

\usepackage{fontspec}
\usepackage[xindy={language=greek,glsnumbers=false}]{glossaries}
\setmainfont{Liberation Serif}

\makeglossaries

\newglossaryentry{d}{name={d},description={parent}}
\newglossaryentry{α}{name={α},description={alpha},parent=d}
\newglossaryentry{ω}{name={ω},description={omega},parent=d}
\newglossaryentry{r}{name={r},description={r},parent=d}
\newglossaryentry{s}{name={s},description={s},parent=d}

\begin{document}
\gls{α}
\gls{ω}
\gls{r}
\gls{s}

\printglossary[style=indexgroup]
\end{document}

This produces:

image of document with Latin entries before Greek

So for some reason, the english xindy module seems to have a slightly different way of sorting the sub-entries. Again, this isn't specific to glossaries as it can be demonstrated with \index:

\documentclass{article}

\usepackage{fontspec}
\usepackage{makeidx}
\setmainfont{Liberation Serif}

\makeindex

\newcommand*{\lettergroupDefault}[1]{\lettergroup{#1}}

\begin{document}
α\index{d!α}
ω\index{d!ω}
r\index{d!r}
s\index{d!s}

\printindex
\end{document}

which produces:

image of index

The problem persists even if I define a letter group for the Greek characters:

% arara: lualatex
% arara: xindy: {language: english, codepage: utf8, modules: [basename, texindy]}
% arara: lualatex
\documentclass{article}

\usepackage{filecontents}
\usepackage{fontspec}
\usepackage{makeidx}
\setmainfont{Liberation Serif}

\makeindex

\newcommand*{\lettergroupDefault}[1]{\lettergroup{#1}}

\begin{filecontents*}{\jobname.xdy}
(define-letter-group "Greek"
   :prefixes ("α" "ω")
   :after "Z")
\end{filecontents*}

\begin{document}
1\index{d!1}
+\index{d!+}
α\index{d!α}
a\index{d!a}
z\index{d!z}
ω\index{d!ω}
r\index{d!r}
s\index{d!s}
1\index{1}
+\index{+}
a\index{a}
r\index{r}
s\index{s}
z\index{z}
α\index{α}
ω\index{ω}

\printindex
\end{document}

This produces:

image of index

The main (top) level entries have been correctly sorted, but not the sub-entries.

Recommendation

I think the simplest solution is to either use a number instead of the Greek letters in the sort key (1 for α etc) or use a prefix that is sorted correctly (such as +). For example:

% arara: lualatex
% arara: xindy: {language: english, codepage: utf8, modules: [texindy]}
% arara: lualatex
\documentclass{article}

\usepackage{fontspec}
\usepackage{makeidx}
\setmainfont{Liberation Serif}

\makeindex

\newcommand*{\lettergroupDefault}[1]{\lettergroup{#1}}

\begin{document}

α\index{d!+α@α}
a\index{d!a}
z\index{d!z}
ω\index{d!+ω@ω}
r\index{d!r}
s\index{d!s}

\printindex
\end{document}

image of index with Greek letters first

Translating this back to glossaries:

% arara: lualatex
% arara: makeglossaries
% arara: lualatex
\documentclass{article}

\usepackage{fontspec}
\usepackage[xindy]{glossaries}
\setmainfont{Liberation Serif}

\makeglossaries

\newglossaryentry{d}{name={d},description={parent}}
\newglossaryentry{α}{name={α},sort={+α},description={alpha},parent=d}
\newglossaryentry{ω}{name={ω},sort={+ω},description={omega},parent=d}
\newglossaryentry{r}{name={r},description={r},parent=d}
\newglossaryentry{s}{name={s},description={s},parent=d}

\begin{document}
\gls{α}
\gls{ω}
\gls{r}
\gls{s}

\printglossary[style=indexgroup]
\end{document}

This produces:

image of glossary with Greek letters first

Related Question