1

I have currently the Latex code written in the .cls file to display a list of abbreviations as follows:

\newcommand\listnomenclature{Abbreviations}
\usepackage{longtable}

\newcommand\listofnomenclature[2]{
\btypeout{\listnomenclature}
\addtotoc{\listnomenclature}
    \chapter*{\listnomenclature
      \@mkboth{
          \MakeUppercase\listnomenclature}{\MakeUppercase\listnomenclature}}
\begin{longtable}[c]{#1}#2\end{longtable}\par
    \cleardoublepage
}

It is used in the following way:

\listofnomenclature{ll}{
GHG     &   GreenHouse Gasses \\
CoMP    &   Cooperative Multi-Point \\
ITU     &   International Telecommunication Union \\
}

Is it possible to modify the codes in the .cls file so that the output is sorted alphanumerically without drastically changing the way it is used?

David Carlisle
  • 757,742
Ivan
  • 83
  • Implementing general sorting in TeX is quite a difficult task. Wait till your list is complete and sort it with one of the many available utilities. – egreg Dec 10 '12 at 00:08
  • Is it possible to create a database of acronyms just like the .bib file and then use it by calling \cite equivalent ? And later generate out the sorted list of acronyms that are actually used in the document? If so, can you point me to the right package please? Thanks – Ivan Dec 10 '12 at 10:15
  • I'd go with MakeIndex rather than BibTeX. Did you have a look at the glossaries package? It has many bells and whistles, among which treatment of acronyms and lists thereof. – egreg Dec 10 '12 at 10:16
  • yup, i'm looking at it now. So far, I understand that the database file is written as a .tex file with entries written with \newglossaryentry command and the desired acronym referenced with \gls command. In the main tex file, the commands \loadglsentries{} and \printglossaries are called to identify which database is used and to print the list of actually used acronyms... but i'm still figuring out how to align the list nicely – Ivan Dec 10 '12 at 10:44
  • ok, i've solved it now. Thanks for the input.. this entry can now be closed – Ivan Dec 10 '12 at 14:11
  • You may write a self-answer that can be useful to others, if you don't mind sharing your code. – egreg Dec 10 '12 at 14:13

3 Answers3

4

Just for the fun of it: here is a solution that uses the LaTeX3 module l3sort and the \pdfstrcmp primitive.

\documentclass{book}

\newcommand*\listnomenclature{Abbreviations}
\usepackage{longtable}

\usepackage{xparse,expl3}
% make @ letter and switch to expl3 syntax:
\makeatletter\ExplSyntaxOn
% variables:
\prop_new:N \l__ivan_nomenclature_prop
\seq_new:N  \l__ivan_nomenclature_seq

% function for sorting property lists according to keys:
\cs_new:Npn \ivan_sort_prop:N #1
  {
    \seq_clear:N \l_tmpa_seq
    \prop_map_inline:Nn #1
      { \seq_put_right:Nn \l_tmpa_seq { ##1 } }
    \seq_sort:Nn \l_tmpa_seq
      {
        \int_compare:nTF { \pdftex_strcmp:D { ##1 } { ##2 } = -1 }
          { \sort_return_same: }
          { \sort_return_swapped: }
      }
    \prop_clear:N \l_tmpa_prop
    \seq_map_inline:Nn \l_tmpa_seq
      {
        \prop_get:NnN #1 { ##1 } \l_tmpa_tl
        \prop_put:NnV \l_tmpa_prop { ##1 } \l_tmpa_tl
      }
    \prop_set_eq:NN #1 \l_tmpa_prop
  }

% parse the table like input:
\cs_new:Npn \__ivan_add_to_prop:Nw #1#2&#3 \q_stop
  { \prop_put:Nnn #1 { #2 } { #3 } }

% internal list command:
\cs_new:Npn \ivan_list_of_nomenclature:nn #1#2
  {
    \seq_set_split:Nnn \l__ivan_nomenclature_seq { \\ } { #2 }
    \seq_map_inline:Nn \l__ivan_nomenclature_seq
      { \__ivan_add_to_prop:Nw \l__ivan_nomenclature_prop ##1 \q_stop }
    \ivan_sort_prop:N \l__ivan_nomenclature_prop
% \btypeout{\listnomenclature} % unknown command, commented out
% \addtotoc{\listnomenclature} % unknown command, commented out
  \chapter*{ \listnomenclature }
  \@mkboth
    { \MakeUppercase\listnomenclature }
    { \MakeUppercase\listnomenclature }
  \begin{longtable}[c]{#1}
    \prop_map_inline:Nn \l__ivan_nomenclature_prop
      { ##1 & ##2 \\ }
  \end{longtable}
  \cleardoublepage
}

% document level command:
\NewDocumentCommand \listofnomenclature { m+m }
  { \ivan_list_of_nomenclature:nn { #1 } { #2 } }

% switch expl3 syntax off and make @ other again:
\ExplSyntaxOff\makeatother

\begin{document}

\listofnomenclature{ll}{
  GHG  & GreenHouse Gasses \\
  CoMP & Cooperative Multi-Point \\
  ITU  & International Telecommunication Union
}

\end{document}

enter image description here

cgnieder
  • 66,645
  • I read your solution with much interest. I'm fascinated by how Latex can be treated like a programming language and have learned a few syntax from your post. Cheers! – Ivan Dec 11 '12 at 20:22
  • 1
    You might be interested in interface3, the manual for expl3 (the programming layer of a yet to come LaTeX3). – cgnieder Dec 11 '12 at 20:34
  • i'm a newbie to Latex, but wow LaTeX3, will keep an eye on it. Thanks – Ivan Dec 11 '12 at 20:53
1

I've decided instead to maintain a database of acronyms rather than to hardcode them in each document. This is so that I can reuse them in other documents. Attached are my codes using the glossaries package. I realise it is pretty straightforward but I will share it anyway to assist anyone who finds it useful.

\usepackage[acronym,nonumberlist,shortcuts]{glossaries}
\glossarystyle{long}
\renewcommand*{\acronymname}{<whatever name you choose>} % rename title
\renewcommand*{\glspostdescription}{}                    % remove dot at the end of description
\makeglossaries

\newcommand\setacronymdb[1]{\loadglsentries{#1}}         % the name of the acronym database

\newcommand\listofnomenclature{
\printglossaries
\par
\cleardoublepage
}

and this is how it is used. Note that the acronym database name is Abbrev in this case:

\documentclass[a4paper, 12pt, oneside]
\setacronymdb{Abbrev}

\begin{document}

\listofnomenclature

\section{Introduction}
This is how I refer to the samples of acronym in the database named Abbrev: \acs{CO2}.

\end{document}

The acronym database is just a normal .tex file (Abbrev.tex) with entries having format

\newacronym{<ref>}{<abbreviated form>}{<description>}

for example

\newacronym{CO2}{CO$_{2}$}{Carbon diOxide}
\newacronym{GSM}{GSM}{Global System for Mobile Communications}

Hope this helps.

Ivan
  • 83
  • Dear Ivan, I am interested to use the code you posted here to sort the ABBREVIATIONS in the list. For now I am using Easythesis template from Sharelatex. This template has three important files 1) Thesis.cls, 2) Addministrative.tex and 3) Package.tex. I need some guidance on which file I need to modify or add your code, in order my compilation success? I tried to generate Abbrev.tex file containing list of acronyms. Then, I added the above given preamble in the Administrative.tex file. But I fail to compile. Hope I get some help or feedback. Appreciate your help in advance. – Vijay Jan 07 '15 at 17:59
0

Well I found this solution using an emacs macro.

It is not a way to sort the acronym list using Latex but solves the problem.