1

I want to use the sort=def option for glossaries together with style=alttreehypergroup. However, as soon as I specify sort=def, the groups are not recognized any more.

MWE:

% arara: pdflatex: { action: nonstopmode, options: "-halt-on-error -file-line-error" }
% arara: makeglossaries
% arara: pdflatex: { action: nonstopmode, options: "-halt-on-error -file-line-error" }
\documentclass{report}

\usepackage[colorlinks]{hyperref}

% WORKING:
% \usepackage[style=alttreehypergroup, symbols, nolong, nosuper, nonumberlist]{glossaries}

% NOT WORKING:
\usepackage[sort=def, style=alttreehypergroup, symbols, nolong, nosuper, nonumberlist]{glossaries}

\glssetwidest[1]{xxxx}
\makeglossaries

\newglossaryentry{firstgroup}{name={firstgroup}, description={\nopostdesc}}
\newglossaryentry{aaa}{name={aaa}, description=abcd, parent=firstgroup}

\newglossaryentry{secondgroup}{name={secondgroup}, description={\nopostdesc}}
\newglossaryentry{bbb}{name={bbb}, description=abcd, parent=secondgroup}

\begin{document}
\glsaddall
\printglossaries
\end{document}

The output I want (and get without sort=def):

good

What I get with sort=def:

bad

Is it my mistake or is it a bug?

1 Answer 1

2

This is a feature rather than a bug ;-). The sort=def option works by setting the sort key to a number rather than the value of the name key. If you look at the .glo file you will see this:

\glossaryentry{000001?\glossentry{firstgroup}|setentrycounter[]{page}\glsnumberformat}{1}
\glossaryentry{000001?\glossentry{firstgroup}!000002?\subglossentry{1}{aaa}|setentrycounter[]{page}\glsnumberformat}{1}
\glossaryentry{000003?\glossentry{secondgroup}|setentrycounter[]{page}\glsnumberformat}{1}
\glossaryentry{000003?\glossentry{secondgroup}!000004?\subglossentry{1}{bbb}|setentrycounter[]{page}\glsnumberformat}{1}

So now there's only one indexing group and that's the "Numbers" group. This method is the only way of getting makeindex to sort by definition. In fact, makeindex is simply being tricked into sorting by definition. From makeindex's point of view it's simply using its usual sort algorithm.

Groups don't actually make much sense when you use sort=def or sort=use as there's no guarantee that the order will be restricted to groups. What if you defined terms in the order, say, duck, parrot, dog? You would end up with a D group, a P group and another D group.

However, if you're happy to take on the responsibility of ensuring that you don't have segmented groups like that, you can use what the manual refers to as "Option 1":

\documentclass{report}

\usepackage[colorlinks]{hyperref}

\usepackage[style=alttreehypergroup, nolong,nosuper,nonumberlist]{glossaries}

\glssetwidest[1]{xxxx}
\makenoidxglossaries

\newglossaryentry{firstgroup}{name={firstgroup},
description={\nopostdesc}}
\newglossaryentry{aaa}{name={aaa}, description=abcd,
parent=firstgroup}

\newglossaryentry{secondgroup}{name={secondgroup},
description={\nopostdesc}}
\newglossaryentry{bbb}{name={bbb}, description=abcd,
parent=secondgroup}

\begin{document}
\glsaddall

\printnoidxglossary[sort=def]
\end{document}

Note that for this to work as you want it the sort=def must go in the optional argument of \printnoidxglossary not in the package option list.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .