1

Nomencl package latex: create two lists and order them by order of appearance (list with more than 100 elements)

I found this solution for ordering by appearance (nomencl package : sort by order of appearance) but it does not work for more than 100 entries

\usepackage{etoolbox}
\usepackage[]{nomencl}   
    \makenomenclature

\providetoggle{nomsort} \settoggle{nomsort}{true} % true = sort by use, false = sort as usual

\makeatletter \iftoggle{nomsort}{% \let\old@@@nomenclature=@@@nomenclature
\newcounter{@nomcount} \setcounter{@nomcount}{0}% \renewcommand\the@nomcount{\two@digits{\value{@nomcount}}}% Ensure 10>01 \def@@@nomenclature[#1]#2#3{% Taken from package documentation \addtocounter{@nomcount}{1}% \def@tempa{#2}\def@tempb{#3}% \protected@write@nomenclaturefile{}% {\string\nomenclatureentry{\the@nomcount\nom@verb@tempa @[{\nom@verb@tempa}]% \begingroup\nom@verb@tempb\protect\nomeqref{\theequation}% |nompageref}{\thepage}}% \endgroup @esphack}% }{} \makeatother

And I can't conjugate this solution with the creation of separate lists with nomencl. To create different lists I am using this:

\newif\iffirstglossary\firstglossarytrue
%% This removes the main title:
\renewcommand{\nomname}{}
%% this modifies item separation:
\setlength{\nomitemsep}{8pt}
%% this part defines the groups:
%----------------------------------------------
\usepackage{etoolbox}
\renewcommand\nomgroup[1]{%
\iffirstglossary
\firstglossaryfalse
\else
\clearpage
\fi
  \item[\Large\bfseries
    \ifstrequal{#1}{N}{List of Symbols}{%
    \ifstrequal{#1}{O}{List of Operators}{%
    \ifstrequal{#1}{A}{List of Abbreviations}{}}}%
]\vspace{10pt}} % this is to add vertical space between the groups.
rufia
  • 13

1 Answers1

0

Troy's answer needs a couple of patches for this. The first is already given in a comment, \two@digits adds a zero to the start of any single-digit numbers, going over 100 we now need a three-digit version of each number so define and use

\def\three@digits#1{\ifnum#1<100 0\ifnum#1<10 0\fi\fi\number#1}

The second part is probably a mistake in the linked answer, the optional argument is omitted in favour of the counter, with \string\nomenclatureentry{#1\nom@verb in the package becoming \string\nomenclatureentry{\the@nomcount\nom@verb in the answer. However, I don't see any reason not to first sort by the prefix and then by order of appearance (if you just want order of appearance and a single list, just don't use the prefix). This would call for \string\nomenclatureentry{#1\the@nomcount\nom@verb.

So relative to Troy's answer we need a couple of small changes in the \makeatletter/\makeatother block

\makeatletter
\def\three@digits#1{\ifnum#1<100 0\ifnum#1<10 0\fi\fi\number#1}

\iftoggle{nomsort}{% \let\old@@@nomenclature=@@@nomenclature
\newcounter{@nomcount} \setcounter{@nomcount}{0}% \renewcommand\the@nomcount{\three@digits{\value{@nomcount}}}% Ensure 100>001,010 etc \def@@@nomenclature[#1]#2#3{% Taken from package documentation \addtocounter{@nomcount}{1}% \def@tempa{#2}\def@tempb{#3}% \protected@write@nomenclaturefile{}% {\string\nomenclatureentry{#1\the@nomcount\nom@verb@tempa @[{\nom@verb@tempa}]% Write prefix and then order \begingroup\nom@verb@tempb\protect\nomeqref{\theequation}% |nompageref}{\thepage}}% \endgroup @esphack}% }{} \makeatother

which we can see works with your multiple lists and over 100 nomenclature instances.

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

\providetoggle{nomsort} \settoggle{nomsort}{true} % true = sort by use, false = sort as usual

\makeatletter \def\three@digits#1{\ifnum#1<100 0\ifnum#1<10 0\fi\fi\number#1}

\iftoggle{nomsort}{% \let\old@@@nomenclature=@@@nomenclature
\newcounter{@nomcount} \setcounter{@nomcount}{0}% \renewcommand\the@nomcount{\three@digits{\value{@nomcount}}}% Ensure 10>01 \def@@@nomenclature[#1]#2#3{% Taken from package documentation \addtocounter{@nomcount}{1}% \def@tempa{#2}\def@tempb{#3}% \protected@write@nomenclaturefile{}% {\string\nomenclatureentry{#1\the@nomcount\nom@verb@tempa @[{\nom@verb@tempa}]% \begingroup\nom@verb@tempb\protect\nomeqref{\theequation}% |nompageref}{\thepage}}% \endgroup @esphack}% }{} \makeatother

\newif\iffirstglossary\firstglossarytrue %% This removes the main title: \renewcommand{\nomname}{} %% this modifies item separation: \setlength{\nomitemsep}{8pt} %% this part defines the groups: %---------------------------------------------- \renewcommand\nomgroup[1]{% \iffirstglossary \firstglossaryfalse \else \clearpage \fi \item[\Large\bfseries \ifstrequal{#1}{N}{List of Symbols}{% \ifstrequal{#1}{O}{List of Operators}{% \ifstrequal{#1}{A}{List of Abbreviations}{}}}% ]\vspace{10pt}} % this is to add vertical space between the groups.

\begin{document} \ExplSyntaxOn \str_map_inline:nn {kjihgfedcba}{ \str_map_inline:nn {kjihgfedcba}{ \nomenclature[N]{$#1##1$}{#1##1} \nomenclature[O]{$#1##1$}{#1##1} }} \ExplSyntaxOff \nomenclature{$j$}{Appears first} \nomenclature{$i$}{Appears second} \nomenclature{$h$}{Appears third} \nomenclature{$g$}{Appears fourth} \nomenclature{$f$}{Appears fifth} \nomenclature{$e$}{Appears sixth} \nomenclature{$d$}{Appears seventh} \nomenclature{$c$}{Appears eighth} \nomenclature{$b$}{Appears ninth} \nomenclature{$a$}{Appears tenth~(last)} \printnomenclature

Abbreviations appear as in \verb|https://tex.stackexchange.com/a/383460|. Symbols and Operators appear separately through use of the optional prefix, both defined in order $kk$, $kj$, \ldots, $ka$, $jk$, \ldots, $aa$. \end{document}

Dai Bowen
  • 6,117
  • Thank you very much. Works perfectly. I would like to increase the size between the titles and the entries of the list. There is also a difference between the distances to the top of the page for the list of abbreviations and for the other lists. Can you also help me with that? – rufia Apr 18 '23 at 19:12
  • @rufia Probably best to ask a new question if there's nothing useful on the site already. It shouldn't depend on any of the sorting stuff so just needs the nomgroup definition and anything else you're doing that might affect the spacing. You're probably pushing the limits of nomencl though and might be better off adopting glossaries. – Dai Bowen Apr 19 '23 at 18:20