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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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



It is used in the following way:

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

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.



% make @ letter and switch to expl3 syntax:
% 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 }
    { \MakeUppercase\listnomenclature }
    { \MakeUppercase\listnomenclature }
    \prop_map_inline:Nn \l__ivan_nomenclature_prop
      { ##1 & ##2 \\ }

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

% switch expl3 syntax off and make @ other again:


 GHG     &   GreenHouse Gasses \\
 CoMP    &   Cooperative Multi-Point \\
 ITU     &   International Telecommunication Union


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
You might be interested in interface3, the manual for expl3 (the programming layer of a yet to come LaTeX3). – clemens 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

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.

\renewcommand*{\acronymname}{<whatever name you choose>} % rename title
\renewcommand*{\glspostdescription}{}                    % remove dot at the end of description

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


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

\documentclass[a4paper, 12pt, oneside]



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


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
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 7 '15 at 17:59

Your Answer


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.