1

I would like to sort the nomenclature in each group alphabetically (with respect to the symbols' descriptions).

MWE:

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

%% This code creates the groups
% -----------------------------------------
\usepackage{etoolbox}
\renewcommand\nomgroup[1]{%
  \item[\bfseries
  \ifstrequal{#1}{A}{Physics constants}{%
  \ifstrequal{#1}{B}{Number sets}{%
  \ifstrequal{#1}{C}{Other symbols}{}}}%
]}


\newcommand\Nomenclature[3]{\nomenclature[#1,#3]{#2}{#3}}
% -----------------------------------------

\begin{document}
Here is an example:

\Nomenclature[A]{\(c\)}{Speed of light in a vacuum}
\Nomenclature[A]{\(h\)}{Planck constant}
\Nomenclature[A]{\(G\)}{Gravitational constant}
\Nomenclature[B]{\(\mathbb{R}\)}{Real numbers}
\Nomenclature[B]{\(\mathbb{C}\)}{Complex numbers}
\Nomenclature[B]{\(\mathbb{H}\)}{Quaternions}
\Nomenclature[C]{\(V\)}{Constant volume}
\Nomenclature[C]{\(\rho\)}{Friction index}

\printnomenclature
\end{document}

Transcript written in main.ilg:

This is makeindex, version 2.16 [MiKTeX 22.3].
Scanning style file C:/Users/X/AppData/Roaming/MiKTeX/makeindex/nomencl/nomencl.ist........
** Input style error (file = C:/Users/X/AppData/Roaming/MiKTeX/makeindex/nomencl/nomencl.ist, line = 36):
   -- Unknown specifier lethead_prefix.
** Input style error (file = C:/Users/X/AppData/Roaming/MiKTeX/makeindex/nomencl/nomencl.ist, line = 37):
   -- Unknown specifier lethead_suffix.
** Input style error (file = C:/Users/X/AppData/Roaming/MiKTeX/makeindex/nomencl/nomencl.ist, line = 38):
   -- Unknown specifier lethead_flag.
....done (12 attributes redefined, 3 ignored).
Scanning input file main.nlo...done (0 entries accepted, 0 rejected).
Nothing written in main.nls.
Transcript written in main.ilg.

New information:

%%
%% This is file `nomencl.ist',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% nomencl.dtx  (with options: `idxstyle')
%% 
%% Copyright 1996-2019 Boris Veytsman, Bernd Shandl, Lee Netherton, CV
%% Radhakrishnan, Brian Elmegaard
%% 
%% 
%% This file can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License distributed from CTAN
%% archives in the directory macros/latex/base/lppl.txt; either
%% version 1.2 of the license, or (at your option) any later version.
%% 
%% 
%% Nomenclature style file for MAKEINDEX.
%% For nomencl v2.5 (and later)
%% 
%% Formats glossary entries to show, e.g. nomenclature of equations.
%% 
%% ---- for input file ----
keyword    "\\nomenclatureentry"
quote '%'
%% ---- for output file ----
preamble   "\n\\begin{thenomenclature} \n"%
postamble  "\n\n\\end{thenomenclature}\n" group_skip "\n"
delim_0    ""
delim_1    ""
delim_2    ""
%% The next lines will produce some warnings when
%% running Makeindex as they try to cover two different
%% versions of the program:
lethead_prefix "\\nomgroup{"
lethead_suffix "}"
lethead_flag   1
heading_prefix "\\nomgroup{"
heading_suffix "}"
headings_flag  1
line_max 1000
2
  • Do you want sorting by symbol or by description? Sorting by symbol isn't really easy, for instance \mathbf{C} would be sorted after all \mathbb symbols. From your code, I gather that you want sorting by description. Please, advise.
    – egreg
    Commented Nov 12, 2022 at 14:13
  • @egreg I would like sorting by description.
    – el_maxx
    Commented Nov 14, 2022 at 19:54

2 Answers 2

1

Your code is OK, apart from the fact that you have to call

\Nomenclature{A}{\(c\)}{Speed of light in a vacuum}

with braces {} and not brackets [].

However, I suggest a small change to make the case switch easier to manage end more efficient instead of nesting \ifthenelse. Just note that spaces in the texts have to be denoted by ~ in the context of \ExplSyntaxOn. The cases are more easily extendable.

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

%% This code creates the groups
% -----------------------------------------
\ExplSyntaxOn
\RenewDocumentCommand\nomgroup{m}
 {
  \item[\bfseries
    \str_case:nn { #1 }
     {
      {A}{Physics~constants}
      {B}{Number~sets}
      {C}{Other~symbols}
     }
  ]
 }
\ExplSyntaxOff

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

\begin{document}

Here is an example:

\Nomenclature{A}{\(c\)}{Speed of light in a vacuum}
\Nomenclature{A}{\(h\)}{Planck constant}
\Nomenclature{A}{\(G\)}{Gravitational constant}
\Nomenclature{B}{\(\mathbb{R}\)}{Real numbers}
\Nomenclature{B}{\(\mathbb{C}\)}{Complex numbers}
\Nomenclature{B}{\(\mathbb{H}\)}{Quaternions}
\Nomenclature{B}{\(\mathbf{C}\)}{Something}
\Nomenclature{C}{\(V\)}{Constant volume}
\Nomenclature{C}{\(\rho\)}{Friction index}
\Nomenclature{C}{\(r\)}{Radius}
\Nomenclature{C}{\(\mathit{Re}\)}{Reynolds number}

\printnomenclature

\end{document}

enter image description here

I added some fake entries to be sure about the sorting.

To add space before and after the group names you can do

\ExplSyntaxOn
\RenewDocumentCommand\nomgroup{m}
 {
  \par\addvspace{1cm}
  \item[\bfseries
    \vrule width 0pt depth 1cm
    \str_case:nn { #1 }
     {
      {A}{Physics~constants}
      {B}{Number~sets}
      {C}{Other~symbols}
     }
  ]
 }
\ExplSyntaxOff

I used 1cm to exaggerate the effect. Change both to what suits you.

enter image description here

14
  • 1
    @el_maxx Works for me
    – egreg
    Commented Nov 18, 2022 at 12:41
  • 1
    @el_maxx The information is insufficient to make a diagnose. Do you have text? Without it, nothing is written out.
    – egreg
    Commented Nov 18, 2022 at 13:00
  • 1
    @el_maxx I can read nomencl.ist on my system. Please, ask a new question with the details of what's going wrong.
    – egreg
    Commented Nov 18, 2022 at 13:36
  • 1
    @el_maxx Add \par\addvspace{0.3cm} before \item in the definition of \nomgroup.
    – egreg
    Commented Nov 18, 2022 at 15:40
  • 1
    @el_maxx I added the code.
    – egreg
    Commented Nov 18, 2022 at 22:40
0

Two changes were needed.

First, you didn't need to try to concatenate two pieces of info to get the sort key that you wanted. According to the nomencl package's documentation, section 2.2, the main command's syntax is \nomenclature[<prefix>]{<symbol>}{<description>} and

The sortkey will be <prefix><symbol>...

So, just change:

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

to

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

(plus, even if you you had to concatenate the values yourself, it would be #1,#2 that you'd want.)

Second, when you use your new command, you have square braces around the first parameter when you needed curly braces. So just change:

\Nomenclature[A]{\(c\)}{Speed of light in a vacuum}

to

\Nomenclature{A}{\(c\)}{Speed of light in a vacuum}

And you'll get this output. No other changes are needed.

enter image description here

2
  • @el_maxx did this answer your question?
    – James
    Commented Nov 13, 2022 at 2:13
  • Thank you very much, James. I would like sorting by description. Is that possible?
    – el_maxx
    Commented Nov 14, 2022 at 19:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .