[Tex/LaTex] How to sort two glossaries (list of acronyms and list of symbols) differently

glossariessorting

I use the glossaries package to create a list of acronyms as well as a list of symbols.

\usepackage[acronym,style=long]{glossaries}

For the list of symbols the standard-glossary is used.

Now I want to sort the list of acronyms alphabetically (sort=standard), but the list of symbols in order of appearance (sort=def). How do I do that?

I use MikTeX 2.9 with TeXnicCenter 2 (beta) on Windows 7. My project includes the hyperref package.

Best Answer

Update:

As from glossaries version 4.04 (which I've just uploaded to CTAN) there are now three options for generating glossaries:

  1. Using TeX to sort the glossaries (new).
  2. Using makeindex to sort the glossaries.
  3. Using xindy to sort the glossaries.

The options 2 and 3 still can't use independent sort methods for different glossaries, but the new option can:

\documentclass{article}

\usepackage[acronyms]{glossaries}

\makenoidxglossaries

\newacronym{cd}{CD}{covariant derivative}
\newacronym{gr}{GR}{general relativity}
\newacronym{pnd}{PND}{principle null direction}

\newglossaryentry{vfield}{
  name={\ensuremath{A^a}},
  description={Some vector field}
}

\newglossaryentry{manifold}{
  name={\ensuremath{\mathcal{M}}},
  description={Some manifold}
}

\begin{document}

Einstein developed the theory of \gls{gr}. Take the \gls{cd} and
apply it on the \glspl{pnd}. We define \gls[format=textbf]{manifold} to be some
manifold.

\clearpage

\gls[format=textbf]{vfield} is some vector field on \gls{manifold}
that has nothing to do with the \glspl{pnd}.

\printnoidxglossary[type=acronym,sort=letter]

\printnoidxglossary[sort=use]

\end{document}

This only requires two LaTeX runs (no need to use xindy or makeindex). The list of acronyms is sorted by letter (using datatool's \dtlletterindexcompare handler) and the main glossary is sorted according to use. Other sort options are: word (word ordering using datatool's \dtlwordindexcompare handler), def (order of definition), case (case-sensitive using datatool's \dtlcompare handler) and nocase (case-insensitive using datatool's \dtlicompare handler).

Page 1:

Image of page 1

Page 2:

Image of page 2

Main drawbacks:

  • Sorting is slower than when using makeindex / xindy (except for the use method, which doesn't require any sorting).
  • Consecutive locations won't be turned into a range (although it's possible to redefine the macro that displays the location list).
  • Entries must be defined before the start of the document environment.

Solution using datagidx:

Here's my original solution using datagidx (part of the datatool bundle):

\documentclass{article}

\usepackage{datagidx}
\usepackage[colorlinks]{hyperref}

\newgidx{acronym}{Acronyms}
\newgidx{symbol}{Symbols}

\DTLgidxSetDefaultDB{acronym}

\newacro{html}{hypertext markup language}
\newacro{css}{cascading style sheet}
\newacro{xml}{extensible markup language}

\DTLgidxSetDefaultDB{symbol}

\newterm[description={sample 1}]{B}
\newterm[description={sample 2}]{X}
\newterm[description={sample 3}]{A}
\newterm[description={sample 4}]{C}

\begin{document}

\gls{B}, \gls{X}, \gls{C}, \gls{A}.

\acr{xml}, \acr{html}, \acr{css}.

% default sort is alphabetical
\printterms[database=acronym,columns=1,style=align]

% sort by definition (i.e. don't sort)

\printterms[database=symbol,sort={},columns=1,style=align]

\end{document}

Result:

Image of result

Related Question