Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 0: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{<database file>} 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
show 2 more comments

2 Answers

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

\documentclass{book}

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

\usepackage{xparse,expl3,l3sort}
% 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_ordered: }
          { \sort_reversed: }
      }
    \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

share|improve this answer
    
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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.