[Tex/LaTex] Sort nomenclature according to description, rather than symbol, whilst using subgroups

nomenclaturesorting

I would like to know how to sort a nomenclature according to the description, and not the symbol, whilst still making use of subgroups (e.g. separate groups for subscripts, superscripts etc)? The following, suggested defining a new command \Nomenclature for sorting according to the description rather than symbol:

\documentclass[a4paper]{report}

\usepackage{nomencl}
\makenomenclature

\newcommand\Nomenclature[2]{\nomenclature[#2]{#1}{#2}}

\begin{document}
Text% to produce a non-empty page

\Nomenclature{$\omega$}{Absolute Frequency}
\Nomenclature{HOA}{Acetic acid}
\Nomenclature{Al}{Aluminium}
\Nomenclature{ASTM}{American Standard Testing Machine}

\printnomenclature

\end{document}

However, I am not sure how to get this to work with subgroups, which I have created using the \nomgroup command in the following way:

\renewcommand\nomgroup[1]{%
  \item[\large\bfseries
  \ifstrequal{#1}{A}{Acronyms}{%
  \ifstrequal{#1}{R}{Roman Symbols}{%
  \ifstrequal{#1}{G}{Greek Symbols}{%
  \ifstrequal{#1}{S}{Superscripts}{% 
  \ifstrequal{#1}{U}{Subscripts}{%   
  \ifstrequal{#1}{X}{Other Symbols}{}}}}}}]
  \insertnomheaders
  }

Any suggestions? Thanks

Best Answer

It is possible, but you have to declare your \Nomenclature command to have three argument:

\newcommand\Nomenclature[3][X]{\nomenclature[#1#3]{#2}{#3}}

Also the command \insertnomheaders is undefined. I've redefined \nomgroup without it (and changed a little):

\renewcommand\nomgroup[1]{%
  \item[\large\bfseries
  \ifstrequal{#1}{A}{Acronyms}{%
  \ifstrequal{#1}{R}{Roman Symbols}{%
  \ifstrequal{#1}{G}{Greek Symbols}{%
  \ifstrequal{#1}{M}{Molecules}{%
  \ifstrequal{#1}{X}{Other Symbols}{}}}}}]%
  }

When you use \Nomenclature you have to specify the first optional argument to be one of the ones listed in \nomgroup so to be inserted in the right subgroup. If you omit the optional argument the default is X.

A MWE:

\documentclass[a4paper]{report}
\usepackage{etoolbox}
\usepackage{nomencl}

\newcommand\Nomenclature[3][X]{\nomenclature[#1#3]{#2}{#3}}

\renewcommand\nomgroup[1]{%
  \item[\large\bfseries
  \ifstrequal{#1}{A}{Acronyms}{%
  \ifstrequal{#1}{R}{Roman Symbols}{%
  \ifstrequal{#1}{G}{Greek Symbols}{%
  \ifstrequal{#1}{M}{Molecules}{%
  \ifstrequal{#1}{X}{Other Symbols}{}}}}}]%
  }

\makenomenclature

\begin{document}
Text% to produce a non-empty page

\Nomenclature[G]{$\omega$}{Absolute Frequency}
\Nomenclature[G]{$f$}{Frequency}
\Nomenclature[M]{HOA}{Acetic acid}
\Nomenclature[M]{Al}{Aluminium}
\Nomenclature[A]{ASTM}{American Standard Testing Machine}
\Nomenclature[X]{foo2}{foo2}
\Nomenclature{foo1}{foo1}

\printnomenclature

\end{document}  

Output:

enter image description here

As you can see, the elements are placed in the right subgroup and ordered according to their description.

Related Question