3

How do I sort the entries corresponding to each section of my document under abbreviations and symbols? In other words, I want a structure like this:

Abbreviations

Section 1

Section 2

...

Last section

Symbols

Section 1

Section 2

...

Last section

My code so far:

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

This code only produces continuous lists of the abbreviations and symbols regardless of which section these entries belong to.

  • 1
    For a LaTeX based alphanumeric bubble sorter, see https://tex.stackexchange.com/questions/372639/trying-to-eliminate-stack-overflow-during-recursion. How you implement it in your context is more challenging. – Steven B. Segletes Apr 23 '21 at 12:01

1 Answers1

1

This is a custom LaTeX3 solution. It only demonstrates the concept. One needs to put a lot of work in it to make it look nice. Also, the nomenclature items within each section are not sorted, they just appear in the order the \Nomen command is called.

enter image description here

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

Alan Xiang
  • 5,227