nomencl 包中有两个列表并按外观排序

nomencl 包中有两个列表并按外观排序

Nomencl 包 latex:创建两个列表并按出现顺序排序(包含 100 多个元素的列表)

我找到了按外观排序的解决方案(nomencl 包:按出现顺序排序)但对于超过 100 个条目则不起作用

\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

而且我无法将此解决方案与使用 nomencl 创建单独的列表结合起来。要创建不同的列表,我使用以下命令:

\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.

答案1

特洛伊的回答需要几个补丁。第一个已经在评论\two@digits在任何一位数的开头添加一个零,超过 100 我们现在需要每个数字的三位数版本,因此定义并使用

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

第二部分可能是链接答案中的一个错误,省略了可选参数以支持计数器,而答案中的\string\nomenclatureentry{#1\nom@verb\string\nomenclatureentry{\the@nomcount\nom@verb中则变成了。但是,我认为没有理由不先按前缀排序,然后按出现顺序排序(如果您只想要出现顺序和单个列表,请不要使用前缀)。这将要求\string\nomenclatureentry{#1\the@nomcount\nom@verb

因此相对于特洛伊的回答\makeatletter我们需要在/\makeatother块中做一些小改动

\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

我们可以看到它适用于您的多个列表和超过 100 个命名法实例。

\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}

相关内容