[Tex/LaTex] glossaries use of sort key

glossariessorting

after reading the manual of the glossaries packages I was under the impression that when you use the sort key that it would be sorted alphabetically according to the text given in this sort key. However, this MWE does not achieve this (in reality of course I have much more symbols so I really need the automatic sorting and it would take to long to define them in the correct order when I define them)

\documentclass{report}
\usepackage{lipsum}
\usepackage[]{hyperref}
\usepackage[acronym,nogroupskip,nonumberlist,nopostdot,toc]{glossaries}

\makenoidxglossaries

\newglossaryentry{thetab}
{%
name={$\Theta_{b}$},
description={temperature coefficient for b},
sort=temperature coefficient for b ,
}

\newglossaryentry{thetaa}
{%
 name={$\Theta_{a}$},
 description={temperature coefficient for a},
 sort=temperature coefficient for a,
}

\newglossaryentry{thetade}
{%
name={$\Theta_{de}$},
description={temperature coefficient for de},
sort=temperature coefficient for de,
}

\newglossaryentry{thetaOP}
{%
name={$\Theta_{OP}$},
description={temperature coefficient for OP},
sort=temperature coefficient for op,
}

\begin{document}

\printnoidxglossary[sort=standard,title={List of Symbols}]

\chapter{first chapter}
\lipsum

testing \gls{thetab} and \gls{thetaa} 

some more references \gls{thetade} and \gls{thetaOP}

\end{document}

which gives this result:

enter image description here

where I would have expected this order if sorted alphabetically:

temperature coeffcient for a

temperature coeffcient for b

temperature coeffcient for de

temperature coeffcient for OP

what am I doing wrong?

Best Answer

I'm not sure why the standard sort order isn't working, but it works fine if you switch to letter:

\documentclass{report}
\usepackage{lipsum}
\usepackage[]{hyperref}
\usepackage[acronym,nogroupskip,nonumberlist,nopostdot,toc]{glossaries}

\makenoidxglossaries

\newglossaryentry{thetab}
{%
name={$\Theta_{b}$},
description={temperature coefficient for b},
sort=temperature coefficient for b,
}

\newglossaryentry{thetaa}
{%
 name={$\Theta_{a}$},
 description={temperature coefficient for a},
 sort=temperature coefficient for a,
}

\newglossaryentry{thetade}
{%
name={$\Theta_{de}$},
description={temperature coefficient for de},
sort=temperature coefficient for de,
}

\newglossaryentry{thetaOP}
{%
name={$\Theta_{OP}$},
description={temperature coefficient for OP},
sort=temperature coefficient for op,
}

\begin{document}

\printnoidxglossary[sort=letter,title={List of Symbols}]

\chapter{first chapter}
\lipsum

testing \gls{thetab} and \gls{thetaa} 

some more references \gls{thetade} and \gls{thetaOP}

\end{document}

This produces:

image of glossary

Incidentally, if you want to sort by a different field (the description in this case), you can redefine the hook that sets the value of the sort key. For example:

\documentclass{report}
\usepackage{lipsum}
\usepackage[]{hyperref}
\usepackage[acronym,nogroupskip,nonumberlist,nopostdot,toc]{glossaries}

\makenoidxglossaries

\makeatletter
\renewcommand{\glsprestandardsort}[3]{%
 \protected@edef#1{\glsentrydesc{#3}}%
}
\makeatother

\newglossaryentry{thetab}
{%
name={$\Theta_{b}$},
description={temperature coefficient for b}
}

\newglossaryentry{thetaa}
{%
 name={$\Theta_{a}$},
 description={temperature coefficient for a}
}

\newglossaryentry{thetade}
{%
name={$\Theta_{de}$},
description={temperature coefficient for de}
}

\newglossaryentry{thetaOP}
{%
name={$\Theta_{OP}$},
description={temperature coefficient for OP}
}

\begin{document}

\printnoidxglossary[sort=letter,title={List of Symbols}]

\chapter{first chapter}
\lipsum

testing \gls{thetab} and \gls{thetaa} 

some more references \gls{thetade} and \gls{thetaOP}

\end{document}

Edit:

A better redefinition of \glsprestandardsort is:

\glssanitizesorttrue

\renewcommand{\glsprestandardsort}[3]{%
  \glsfieldfetch{#3}{desc}{#1}%
  \glsdosanitizesort
}

(This no longer needs the \makeatletter...\makeatother part.)

The \glssanitizesorttrue bit will make \glsdosanitizesort apply \@onelevel@sanitize to the sort field, which will allow commands like \si to appear in the description (but it will apply the same logic as makeindex and treat \si as the sequence of characters \, s and i).

The second argument of \glsprestandardsort is the glossary type, so you can test it to vary the way the sort field is set according to the glossary. For example:

\renewcommand{\glsprestandardsort}[3]{%
  \ifthenelse{\equal{#2}{main}}%
  {%
    \glsfieldfetch{#3}{desc}{#1}%
  }{}%
  \glsdosanitizesort
}
Related Question