[Tex/LaTex] custom sorting of nomencl groups

nomenclnomenclature

I am using the nomencl groups as described in the manual:

\documentclass{article}
\usepackage{nomencl}
\makenomenclature

\RequirePackage{ifthen}
\renewcommand{\nomgroup}[1]{%
\ifthenelse{\equal{#1}{R}}{\item[\textbf{Variables}]}{%
\ifthenelse{\equal{#1}{G}}{\item[\textbf{Constants}]}{}}}

\begin{document}
\nomenclature[ga ]{$\alpha$}{Constant}
\nomenclature[rx ]{$x$}{Variable}
\printnomenclature
\end{document}

enter image description here

Now, after I finished my document, I see that if I could print the Variables groups first and the Constants group afterwards it would perfectly align with the pagebreak I have in my nomenclature.

How can I customize the sort order of groups? Note that it is not an option to change the prefix of the groups, as I have more than 100 nomenclature entries in my text, and I would like to avoid going through all of them.

Best Answer

You should fix how you input the nomenclature entries.

Here's an example for getting constants before variables:

\documentclass{article}
\usepackage{nomencl}
\makenomenclature

\usepackage{ifthen}

% The order will be 1. constants, 2. variables
% because C comes before V
\renewcommand{\nomgroup}[1]{%
  \ifthenelse{\equal{#1}{V}}{\item[\textbf{Variables}]}{%
  \ifthenelse{\equal{#1}{C}}{\item[\textbf{Constants}]}{}}%
}

\newcommand{\nomconst}[1][]{\nomenclature[C#1]}
\newcommand{\nomvar}[1][]{\nomenclature[V#1]}

\begin{document}
Some text
\nomconst[a]{$\alpha$}{Constant}
\nomvar[x]{$x$}{Variable}
\printnomenclature
\end{document}

enter image description here

With just a few changes in the preamble and none in the document, we can get the reverse order:

\documentclass{article}
\usepackage{nomencl}
\makenomenclature

\usepackage{ifthen}

% The order will be 1. variables, 2. constants
% because A comes before B
\renewcommand{\nomgroup}[1]{%
  \ifthenelse{\equal{#1}{A}}{\item[\textbf{Variables}]}{%
  \ifthenelse{\equal{#1}{B}}{\item[\textbf{Constants}]}{}}%
}

\newcommand{\nomconst}[1][]{\nomenclature[B#1]}
\newcommand{\nomvar}[1][]{\nomenclature[A#1]}

\begin{document}
Some text
\nomconst[a]{$\alpha$}{Constant}
\nomvar[x]{$x$}{Variable}
\printnomenclature
\end{document}

enter image description here

The optional argument to \nomconst and \nomvar are the sorting hints for MakeIndex which you're already using.

Related Question