![分组时按字母顺序对命名法进行排序](https://linux22.com/image/457265/%E5%88%86%E7%BB%84%E6%97%B6%E6%8C%89%E5%AD%97%E6%AF%8D%E9%A1%BA%E5%BA%8F%E5%AF%B9%E5%91%BD%E5%90%8D%E6%B3%95%E8%BF%9B%E8%A1%8C%E6%8E%92%E5%BA%8F.png)
我想按字母顺序对每个组中的名称进行排序(根据符号的描述)。
梅威瑟:
\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}
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.
新的信息:
%%
%% 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
答案1
你的代码很好,除了你必须调用
\Nomenclature{A}{\(c\)}{Speed of light in a vacuum}
用大括号{}
而不是方括号[]
。
不过,我建议进行一点小改动,使 case switch 更易于管理,而不是嵌套,从而提高效率。请注意,在 的上下文中,\ifthenelse
文本中的空格必须用 表示。case 更容易扩展。~
\ExplSyntaxOn
\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}
我添加了一些虚假条目以确保排序正确。
要在组名前后添加空格,您可以这样做
\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
我使用了 1cm 来夸大效果。请将两者更改为适合您的值。
答案2
需要进行两项变革。
首先,您不需要尝试连接两条信息来获取所需的排序键。根据 nomencl 包的文档第 2.2 节,主命令的语法\nomenclature[<prefix>]{<symbol>}{<description>}
是
排序键将是 <前缀><符号>...
因此,只需更改:
\newcommand\Nomenclature[3]{\nomenclature[#1,#3]{#2}{#3}}
到
\newcommand\Nomenclature[3]{\nomenclature[#1]{#2}{#3}}
(另外,即使您必须自己连接这些值,您想要的也是 #1、#2。)
其次,当您使用新命令时,第一个参数周围有方括号,而您需要使用花括号。因此只需更改:
\Nomenclature[A]{\(c\)}{Speed of light in a vacuum}
到
\Nomenclature{A}{\(c\)}{Speed of light in a vacuum}
您将获得此输出。无需进行其他更改。