3

I have the following code and can't find out the command to sort my abbreviation list alphabetically.

\documentclass [11pt, a4paper] {article}

\usepackage{acro} %list of abbreviations
\acsetup{first-style=short} %list of abbreviations

\input{abbreviations.tex} %define abbreviations in this file.

\begin{document}

\addcontentsline{toc}{section}{\numberline{}List of Abbreviations}
\acuseall %to make all abbreviations appear in list of abbreviations (formally uses all of them)

\printacronyms[heading=none,include-classes={abbrev},sort=true] % print list of abbreviations

\end{document}

Currently, the compiled document looks like this:

enter image description here

EDIT

Here are some lines from the abbreviations.tex:

%------------------------------------
% DEFINING ABBREVIATIONS
%------------------------------------
\DeclareAcronym{1}{ % every abbreviation must be defined this way
    short = {LDL} , % abbreviation shown in the list of abbrev
    long  = {Low-density lipoprotein} , % long text shown in the list of abbrev
    class = {abbrev}
}
\DeclareAcronym{2}{
    short = {HDL} ,
    long = {High-density lipoprotein},
    class = {abbrev}
}
\DeclareAcronym{3}{
    short = {RYGB} ,
    long = {Roux-en-Y gastric bypass},
    class = {abbrev}
}

1 Answers1

6

The first argument to \DeclareAcronym is used for sorting.

\documentclass [11pt, a4paper] {article}
\usepackage{acro} %list of abbreviations

\acsetup{first-style=short} %\input{abbreviations.tex} %define abbreviations in this file.

\DeclareAcronym{LDL}{ % every abbreviation must be defined this way short = {LDL}, % abbreviation shown in the list of abbrev long = {Low-density lipoprotein}, % long text shown in the list of abbrev class = {abbrev} } \DeclareAcronym{HDL}{ short = {HDL}, long = {High-density lipoprotein}, class = {abbrev} } \DeclareAcronym{RYGB}{ short = {RYGB}, long = {Roux-en-Y gastric bypass}, class = {abbrev} } \begin{document}

\acuseall

\cleardoublepage \addcontentsline{toc}{section}{\protect\numberline{}List of Abbreviations} \printacronyms[heading=none,include-classes={abbrev},sort=true]

\end{document}

Note the final changes.

enter image description here

Update

With new versions of the acro package, something has changed. In particular, the ID is no longer used for sorting, but short is. However, one can add a sort key to solve sorting issues. If not specified, the entry is sorted by the short key. Also classes now is tag and include-classes is include. In the example code below, the sort keys are commented because not really needed.

\documentclass [11pt, a4paper] {article}
\usepackage{acro} %list of abbreviations

\acsetup{first-style=short} %\input{abbreviations.tex} %define abbreviations in this file.

\DeclareAcronym{LDL}{ % every abbreviation must be defined this way short = {LDL}, % abbreviation shown in the list of abbrev long = {Low-density lipoprotein}, % long text shown in the list of abbrev tag = {abbrev}, %sort = {LDL}, } \DeclareAcronym{HDL}{ short = {HDL}, long = {High-density lipoprotein}, tag = {abbrev}, %sort = {HDL}, } \DeclareAcronym{RYGB}{ short = {RYGB}, long = {Roux-en-Y gastric bypass}, tag = {abbrev}, %sort = {RYGB}, } \begin{document}

\acuseall

\cleardoublepage \addcontentsline{toc}{section}{\protect\numberline{}List of Abbreviations} \printacronyms[heading=none,include=abbrev,sort]

\end{document}

egreg
  • 1,121,712
  • The sorting mechanism of acro seems to have changed . With newer versions (as far as I could tell, with the update to version 3?), the alphabetical order seems to be determined using the value of short instead of using the ID. You might want to externd your answer with a short remark on that change. – leandriis Nov 14 '20 at 22:49
  • 1
    @leandriis Thanks for noting. I also added some more changes. – egreg Nov 14 '20 at 23:53