TransWikia.com

Sort entries under abbreviations and symbols according to their section

TeX - LaTeX Asked by thisismetrying on August 11, 2021

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
% -------------------------------------------
renewcommandnomgroup[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.

One Answer

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
        parnoindenttextbf{##2}
        seq_map_variable:cNn {__nomen_seq_name:n {##1}} l_nomen_tmpa_tl {
            % section heading
            parnoindent 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_strc_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}

parPrintNomen

end{document}

Correct answer by Alan Xiang on August 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP