2

I am currently making a list of symbols using the glossaries package. I have adjusted several parameters to fit the lay-out to my liking but in the process the sorting of glossaries has been altered. It now sorts:

capital letters -> Greek letters -> non-capital letters

instead of the desired:

capital letters -> non-capital letters -> Greek letters

MWE:

\documentclass{report}
\usepackage[english]{babel}
\usepackage{tabularx}
\usepackage[acronyms,nonumberlist,nopostdot]{glossaries}
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}

\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{1.5\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
{\end{longtable}}%
 %
\renewcommand*{\glossaryheader}{%  Change the table header
\bfseries Sign & \bfseries Description & \bfseries Unit \\
\hline
\endhead}
\renewcommand*{\glossentry}[2]{%  Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \glsunit{##1}  \tabularnewline}}

%abbreviations
\newacronym{tes}{TES}{thermal energy storage}

%symbols
\newglossaryentry{tau}
{name={\ensuremath{\tau_{s}}},
description={Shear modulus}, unit={\ensuremath{MPa}}}

\newglossaryentry{hf}
{name={\ensuremath{H_{f}}},
description={Heat of fusion}, unit={\ensuremath{kJ/kg}}}

\newglossaryentry{r}
{name={\ensuremath{r}},
description={Radius}, unit={\ensuremath{m}}}

\makeglossaries
\begin{document}

\setglossarysection{section}
\setglossarystyle{super}
\printglossary[style=symbunitlong,title=List of Symbols]
\printglossary[type=\acronymtype,title={List of Abbreviations}]

I use \gls{tes} to have \gls{tau},\gls{hf} and \gls{r}.

\end{document}

Current output:

Output of MWE with incorrect sorting

How can I fix the sorting of glossaries?

2

Since you haven't used the sort key, the sort value is taken from the name field which contains commands, but makeindex doesn't recognise LaTeX commands. It just sees a sequence of characters:

  • \ e n s u r e m a t h (space) { H _ { f } }
  • \ e n s u r e m a t h (space) { \ t a u (space) _ { s } }
  • \ e n s u r e m a t h (space) { r }

These all start with a non-letter (\) so makeindex uses a simple character code comparison when sorting. Each sort value here starts with the same substring \ensuremath { so it's the character following this substring that determines the relative order:

  • H (character code 0x48 = 72)
  • \ (character code 0x5C = 92)
  • r (character code 0x72 = 114)

So the resulting order is \ensuremath {H_{f}} < \ensuremath {\tau _{s}} < \ensuremath {r}.

You need to use the sort key to change this order. If you want case-sensitive letter ordering (so that all the capitals come before lower case) then the sort key will still need to start with a non-letter. The best thing to do is to select non-letter prefixes that will ensure your desired order.

For example, < has character code 0x3C = 60 and > has character code 0x3E = 62, so any sort value that starts with < will come before any that start with >:

\newglossaryentry{tau}
{name={\ensuremath{\tau_{s}}},
sort={>tau},
description={Shear modulus}, unit={\ensuremath{MPa}}}

\newglossaryentry{hf}
{name={\ensuremath{H_{f}}},
sort={<Hf},
description={Heat of fusion}, unit={\ensuremath{kJ/kg}}}

\newglossaryentry{r}
{name={\ensuremath{r}},
sort={<r},
description={Radius}, unit={\ensuremath{m}}}

This will now produce the ordering <Hf < <r < >tau. You may prefer to define custom commands that automatically forms the sort from the label, but since all the labels are lower case, this would need another prefix (say, = character code 0x3D) for the lower case version. For example:

\documentclass{report}
\usepackage[english]{babel}
\usepackage{tabularx}
\usepackage[acronyms,nonumberlist,nopostdot]{glossaries}
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}

\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{1.5\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
{\end{longtable}}%
 %
\renewcommand*{\glossaryheader}{%  Change the table header
\bfseries Sign & \bfseries Description & \bfseries Unit \\
\hline
\endhead}
\renewcommand*{\glossentry}[2]{%  Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \glsunit{##1}  \tabularnewline}}

\makeglossaries

%abbreviations
\newacronym{tes}{TES}{thermal energy storage}

% syntax: \newgreeksymbol[options]{label}{name}{description}{unit}
\newcommand{\newgreeksymbol}[5][]{%
  \newglossaryentry{#2}{name={#3},sort={>#2},description={#4},unit={#5},#1}%
}

\newcommand{\newsymbol}[5][]{%
  \newglossaryentry{#2}{name={#3},sort={=#2},description={#4},unit={#5},#1}%
}

\newcommand{\newSymbol}[5][]{%
  \newglossaryentry{#2}{name={#3},sort={<#2},description={#4},unit={#5},#1}%
}

%symbols

\newgreeksymbol{tau}{\ensuremath{\tau_{s}}}{Shear modulus}{\ensuremath{MPa}}

\newSymbol{hf}{\ensuremath{H_{f}}}{Heat of fusion}{\ensuremath{kJ/kg}}

\newsymbol{r}{\ensuremath{r}}{Radius}{\ensuremath{m}}

\begin{document}

\setglossarysection{section}
\setglossarystyle{super}
\printglossary[style=symbunitlong,title=List of Symbols]
\printglossary[type=\acronymtype,title={List of Abbreviations}]

I use \gls{tes} to have \gls{tau},\gls{hf} and \gls{r}.

\end{document}

image of document

If you're interested, here's a completely different approach. Create a file called, say, abbrvs.bib that contains the abbreviations:

% Encoding: UTF-8
@abbreviation{tes,
  short = {TES},
  long = {thermal energy storage}
}

Create a file called, say, syms.bib that contains the symbols:

% Encoding: UTF-8

@symbol{tau,
  name={\ensuremath{\tau_{s}}},
  description={Shear modulus},
  unit={\ensuremath{MPa}}
}

@symbol{hf,
  name={\ensuremath{H_{f}}},
  description={Heat of fusion},
  unit={\ensuremath{kJ/kg}}
}

@symbol{r,
  name={\ensuremath{r}},
  description={Radius},
  unit={\ensuremath{m}}
}

The document is now:

\documentclass{report}
\usepackage[english]{babel}
\usepackage{tabularx}

\usepackage[record,abbreviations]{glossaries-extra}

\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}

\newglossarystyle{symbunitlong}{%
\setglossarystyle{long3col}% base this style on the list style
\renewenvironment{theglossary}{% Change the table type --> 3 columns
\begin{longtable}{lp{1.5\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}%
{\end{longtable}}%
 %
\renewcommand*{\glossaryheader}{%  Change the table header
\bfseries Sign & \bfseries Description & \bfseries Unit \\
\hline
\endhead}
\renewcommand*{\glossentry}[2]{%  Change the displayed items
\glstarget{##1}{\glossentryname{##1}} %
& \glossentrydesc{##1}% Description
& \glsunit{##1}  \tabularnewline}}

%abbreviations
\GlsXtrLoadResources[
   src={abbrvs},% definitions in abbrvs.bib
   save-locations=false % no number list required
]

%symbols
\GlsXtrLoadResources[
  src={syms},% definitions in syms.bib
  save-locations=false, % no number list required
  sort-field={name},
  sort=letter-case
]

\begin{document}

\setglossarysection{section}
\setglossarystyle{super}
\printunsrtglossary[style=symbunitlong,title=List of Symbols]
\printunsrtglossary[type=abbreviations,title={List of Abbreviations}]

I use \gls{tes} to have \gls{tau},\gls{hf} and \gls{r}.

\end{document}

If the document is called myDoc.tex then the build process is:

pdflatex myDoc
bib2gls myDoc
pdflatex myDoc

This produces:

image of document

If you check the bib2gls transcript file (myDoc.glg) you should find:

texparserlib: {}\ensuremath{\tau_{s}} -> 𝜏s
texparserlib: {}\ensuremath{H_{f}} -> Hf
texparserlib: {}\ensuremath{r} -> r

This shows the sort values that bib2gls uses. The sort method was set to letter-case which again just uses a character code comparison but now \tau is interpreted as the character 𝜏 (U+1D70F) which puts it after the lower case Latin characters.

| improve this answer | |
  • Thanks, I implemented the first option and it works great. Just a small heads up: using \newsymbol might result in errors, as it did for me, so I suggest to use a different name to define that input. – Frits Nov 2 '17 at 9:17

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.