1

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?

  • i think that the string for the "sort" key needs to be in braces, like the other argument values. – barbara beeton Apr 13 '16 at 15:24
  • @barbara: you are probably right that it is better to put them in braces, but I have tested it and it does not change the order of the sorting unfortunately – Ingrid Apr 13 '16 at 15:40
  • did you make sure that makeindex ran again before you ran the last iteration of latex? (that's the same order of steps that would be involved if you made a change to the sort of an index; the glossaries package takes advantage of the makeindex mechanism, which is a multi-step process.) – barbara beeton Apr 13 '16 at 15:44
  • Remove the spaces: sort={temperaturecoefficientfora} – Ulrike Fischer Apr 13 '16 at 15:44
  • @barbarabeeton Ingrid is using the noidx option, which means that the sorting is done by tex and not an external tool. – Ulrike Fischer Apr 13 '16 at 15:44
1

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
}
  • thanks, this last solution is indeed much more elegant and achieves what I want to do much easier. It works in the MWE, but in my large document, it gives errors as sometimes I am using \si{} in the description which apparently is no longer allowed – Ingrid Apr 14 '16 at 8:48
  • @Ingrid updated my answer to allow for \si. – Nicola Talbot Apr 14 '16 at 9:20
  • thanks works like a charm. I am encountering another problem though. I am also having a list of acronyms and now they are also sorted based on the description whereas I would like this list to be sorted alphabetically based on their acronym. Is it possible with this method to have two different methods for each list? – Ingrid Apr 14 '16 at 14:06
  • @Ingrid Yes, I've updated my answer to test for the glossary type. – Nicola Talbot Apr 14 '16 at 17:37
  • thanks for your very quick reply's. They are really appreciated since I am running against a deadline! I clearly still have a lot to learn as I can currently only apply the standard stuff but am clueless about the stuff behind the scenes which is of course necessary when you want to do the cool stuff – Ingrid Apr 15 '16 at 8:07
2

Remove the spaces in the sort key values:

\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=temperaturecoefficientforb,
}

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

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

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

\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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.