根据缩写和符号的章节对条目进行排序

根据缩写和符号的章节对条目进行排序

如何根据缩写和符号对文档各部分对应的条目进行排序?换句话说,我想要这样的结构:

缩写

第 1 部分

第 2 部分

...

最后部分

符号

第 1 部分

第 2 部分

...

最后部分

我迄今为止的代码:

\vspace{-4em}
\makenomenclature
\renewcommand{\nomname}{}
% This code creates the groups
% -------------------------------------------
\renewcommand\nomgroup[1]{%
  \item[\bfseries
  \ifstrequal{#1}{A}{Abbreviations}{%
  \ifstrequal{#1}{B}{Symbols}{%
  \ifstrequal{#1}{O}{Other Symbols}{}}}%
]}
% -------------------------------------------

\begin{document}
% Add abbreviations and symbols below
% [A] = abbreviation, [B] = symbol

\nomenclature[A]{TA}{Test abbreviation}
\nomenclature[B]{$\alpha$}{Test symbol}

\printnomenclature[5 em] 
\end{document}

此代码仅生成缩写和符号的连续列表,无论这些条目属于哪个部分。

答案1

这是一个自定义的 LaTeX3 解决方案。它仅演示了概念。需要投入大量精力才能使其看起来不错。此外,每个部分中的命名项目未排序,它们只是按\Nomen调用命令的顺序出现。

在此处输入图片描述

\documentclass{article}
\usepackage{expl3}
\usepackage{amsmath, amssymb}
\usepackage{datetime2}
\usepackage{longtable}

\ExplSyntaxOn

\prop_new:N \g_nomen_group_name_prop

\cs_set:Npn \__nomen_seq_name:n #1 {
    __g_nomen_internal_#1_seq
}

\cs_set:Npn \__nomen_section_seq_name:nn #1#2 {
    __g_nomen_section_internal_#1_\int_to_alph:n{#2}_seq
}

\newcommand{\DeclareNomenGroup}[2]{
    \prop_gput:Nnn \g_nomen_group_name_prop {#1} {#2}
    \seq_new:c {\__nomen_seq_name:n {#1}}
}

\newcommand{\Nomen}[3]{
    \seq_if_exist:cF {\__nomen_section_seq_name:nn {#1} {\thesection}} {
        \seq_new:c {\__nomen_section_seq_name:nn {#1} {\thesection}}
    }
    % add section id to the sequence
    \seq_if_in:cxF {\__nomen_seq_name:n {#1}} {\thesection} {
        \seq_gput_right:cx {\__nomen_seq_name:n {#1}} {\thesection}
    }
    \seq_gput_right:cn {\__nomen_section_seq_name:nn {#1} {\thesection}} {
        {#2}{#3}
    }
}

\tl_new:N \l_nomen_tmpa_tl
\tl_new:N \l_nomen_tmpb_tl

\newcommand{\PrintNomen}{
    \prop_map_inline:Nn \g_nomen_group_name_prop {
        % output title
        \par\noindent\textbf{##2}
        \seq_map_variable:cNn {\__nomen_seq_name:n {##1}} \l_nomen_tmpa_tl {
            % section heading
            \par\noindent Section~\l_nomen_tmpa_tl
            % nomen content
            % write it out to an external file
            \iow_open:Nn \g_tmpa_iow {\jobname-nomen.vrb}
            \iow_now:Nx \g_tmpa_iow {\c_backslash_str begin{longtable}[l]{ll}}
            \seq_map_variable:cNn {\__nomen_section_seq_name:nn {##1}{\l_nomen_tmpa_tl}} 
                \l_nomen_tmpb_tl {
                \iow_now:Nx \g_tmpa_iow {\tl_item:Nn \l_nomen_tmpb_tl {1} & \tl_item:Nn \l_nomen_tmpb_tl {2} \c_backslash_str\c_backslash_str}
            }
            \iow_now:Nx \g_tmpa_iow {\c_backslash_str end{longtable}}
            \iow_close:N \g_tmpa_iow
            % read back
            \input{\jobname-nomen.vrb}
        }
    }
}

\ExplSyntaxOff


\begin{document}

% declare nomen groups
\DeclareNomenGroup{A}{Abbreviation}
\DeclareNomenGroup{B}{Symbol}

\section{The first section}

\Nomen{A}{TA}{Test abbreviation}
\Nomen{B}{$\alpha$}{Test symbol}
\Nomen{B}{$c$}{Speed of light in a vacuum inertial system}
\Nomen{A}{TFS}{The first section}

\section{The second section}

\Nomen{B}{$h$}{Plank Constant}
\Nomen{B}{$g$}{Gravitational Constant}
\Nomen{B}{$\mathbb{R}$}{Real Numbers}
\Nomen{A}{TSS}{The second section}
\Nomen{A}{SRA}{Some random abbreviation}

\par\PrintNomen

\end{document}

相关内容