I'm in the process of writing a long document and need a List of abbreviations
. I've been reading the LaTeX wiki book about this and have had a play with the packages nomencl and glossaries. What package is the most straight forward for developing a List of abbreviations
? Is there a package I've missed?
Acronyms – Best Package for Developing a List of Abbreviations
acronyms
Related Solutions
Something like this?
\documentclass[a4paper]{article}
\makeatletter
\def\@@acrodef{\@ifstar\@acrodefs\@acrodef}
\newtoks\acro@list
\newcommand{\@acrodef}[2]{%
\global\acro@list=\expandafter{\the\acro@list\@elt{#1}{#2}}%
\global\@namedef{acro@#1}{n{#1}{#2}}}
\newtoks\acro@resetlist
\newcommand{\@acrodefs}[2]{%
\global\acro@resetlist=\expandafter{\the\acro@resetlist\@elt{#1}}%
\@acrodef{#1}{#2}}
\def\acro@doresetlist{\begingroup
\def\@elt##1{\expandafter\expandafter\expandafter
\acro@reset\csname acro@##1\endcsname}\the\acro@resetlist\endgroup}
\def\acro@reset#1#2#3{\global\@namedef{acro@#2}{n{#2}{#3}}}
\newcommand{\acro}[1]{\expandafter\expandafter\expandafter
\use@acro\csname acro@#1\endcsname}
\def\use@acro#1#2#3{\ifx n#1
#3 (#2)\global\@namedef{acro@#2}{o{#2}{#3}}%
\else
#2%
\fi}
\newcommand{\listofacronyms}[1][tabular]{%
\begingroup\def\@elt##1##2{##1&##2\\}%
\@ifundefined{chapter}{\section*}{\chapter*}{\listacronymname}
\noindent\begin{#1}{@{}p{6em}p{\dimexpr\columnwidth-2\tabcolsep-6em\relax}@{}}
\the\acro@list
\end{#1}\endgroup}
\providecommand\listacronymname{List of acronyms}
\newenvironment{acronyms}{\let\acrodef\@@acrodef}{}
\newenvironment{acronyms*}{\let\acrodef\@@acrodef}{\listofacronyms}
\def\g@preto@macro#1#2{\toks0=\expandafter{#1}%
\toks2={#2}\xdef#1{\the\toks2 \the\toks0 }}
\@ifundefined{chapter}
{\g@preto@macro\section\acro@doresetlist}
{\g@preto@macro\chapter\acro@doresetlist}
\makeatother
\begin{document}
\begin{acronyms*}
\acrodef{GEOAA}{Great Example Of An abbreviations}
\acrodef{IMO}{In My Opinion}
\acrodef*{OP}{Original Poster}
\end{acronyms*}
\section{A}
\acro{GEOAA}
\acro{IMO}
\acro{IMO}
\acro{GEOAA}
\acro{OP}
\section{B}
\acro{OP}
\listofacronyms
\end{document}
Acronyms are defined in the environment acronyms
; the *-variant acronyms*
also prints directly the list. In any case the command \listofacronyms is available for printing the list at the desired place.
For acronyms that must be reset at chapters use the macro \acrodef*
that, besides doing the same as \acrodef
, puts the first argument (the acronym) into a list, so that at \chapter
the list can be executed and change the o
sentinel into n
again. The command \acro@doresetlist
is also added to \section
or \chapter
, depending if the latter is defined.
To minimize dependencies on external packages, I've defined \g@preto@macro
that is similar to \preto
of etoolbox.
It's not clear if you want the citation every time you use the acronym, or just specific instances. It's also not clear what you want to happen if you try to redefine an existing acronym. Assuming specific instances of a citation and a reset when you attempt to define an existing acronym, you could achieve this as follows. First the main tex file:
\documentclass{book}
\usepackage{natbib}
\usepackage{etoolbox}
\usepackage[acronym,smallcaps]{glossaries}
\makeglossaries
\newcommand*{\provideacronym}[4][]{%
\ifglsentryexists{#2}%
{%
\glsreset{#2}%
}%
{%
\newacronym[#1]{#2}{#3}{#4}%
}%
}
\newcommand*{\provideglossaryentry}[2]{%
\ifglsentryexists{#1}%
{}%
{%
\newglossaryentry{#1}{#2}%
}%
}
\renewcommand*{\acronymfont}[1]{#1}
\defglsdisplayfirst[acronym]{%
#1 \ifstrempty{#4}{(#3)}{\citep[#3;][]{#4}}%
}
\defglsdisplay[acronym]{%
#1\ifstrempty{#4}{}{ \citep{#4}}%
}
\title{Sample Thesis}
\author{A.N. Other}
\begin{document}
\maketitle
\include{sample1}
\include{sample2}
\printglossaries
\bibliographystyle{plainnat}
\bibliography{xampl}
\end{document}
Now the first chapter (sample1.tex
):
\chapter{First Sample Chapter}
\provideacronym{abc}{ABC}{Sample Acronym 1}%
\provideacronym{xyz}{XYZ}{Sample Acronym 2}%
\provideglossaryentry{sample}{name=sample,description=An example}%
An acronym: \gls{abc}. A \gls{sample}.
Sample acronym with a citation
\gls{xyz}[article-minimal].
Another instance with a citation
\gls{xyz}[article-minimal].
And the second chapter (sample2.tex
):
\chapter{Second Sample Chapter}
\provideacronym{abc}{ABC}{Sample Acronym 1}%
\provideglossaryentry{sample2}{name=another sample,description=Another example}%
An acronym: \gls{abc}. \Gls{sample2}.
Sample acronym with a citation
\gls{abc}[article-minimal].
Another instance with a citation
\gls{abc}[article-minimal].
Best Answer
I recommend the
glossaries
package. It provides several predefined styles and can be customized very well.Strengths of
glossaries
are:glossary
), and even an author's FAQ, plus well documented source codeWorking with
makeindex
is needed for such lists of abbreviations, which might be a hurdle to overcome. The perl script and the extensive documentation ofglossaries
are a great help regarding this step.Sources for download and documentation: