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.

As usual I have quite a number of abbreviations (acronyms, initialism, ...) in my thesis and I'm not happy with the way I have to do it with glossaries.

I 'only' need the following:

  1. Abbreviations are defined as simple pairs of the abbreviations and its full version. Example: 'GEOAA' -> 'Great Example Of An abbreviations'
  2. The very first time I use the abbreviations the long form followed by the short form in parentheses should be used: "Great Example Of An Abbreviations (GEOAA)". Afterwards only the short form.
  3. For some important abbreviations I like to be able to reset this (2.) for every chapter.
  4. A need a "List of Abbreviations", i.e. a \chapter* heading and a two-column table (supertabular, longtable, ...) which lists this abbreviations in alphabetic order.
  5. Bonus: Abbreviations should be "easily" sharable between different documents, but this is not that important.

I found some material about how to do this with glossaries, but it is actually overkill for simple abbreviations. Also there is never a good instruction on how to handle the table. I hacked the following together which read the abbreviations file twice, once for the definition and once for the table. This kind of works (but no sorting etc.) but I really think we should have a better solution for this common task here on TeX.sx.

% thesis.tex (main file; preamble)
\usepackage[shortcuts]{glossaries}
\newcommand*{\myacronym}[3][]{%
    \newacronym[#1]{#2}{#2}{#3}%
}
\loadglsentries{acronyms}
% acronyms.tex
\myacronym{ADC}{analog-to-digital converter}
\myacronym{ASCII}{american standard code for information interchange}
\myacronym{ASIC}{application specific integrated circuit}
\myacronym{BUFG}{global clock buffer}
\myacronym{CLB}{configurable logic block}
% ...
% abbreviations.tex (loaded where the List Of Abbreviations should be displayed) 
\chapter*{Abbreviations}
\thispagestyle{fancy}
\begingroup
\renewcommand{\myacronym}[2]{{#1} & {#2}\\}%

\par\noindent
\tablehead{\textbf{Abbreviation} & \textbf{Meaning}\\}%
\begin{supertabular}{@{}ll}
    \input{acronyms}\\
\end{supertabular}
\endgroup

(PS: please don't mind the file names; I know the difference between abbreviations and acronyms.)

share|improve this question
    
I have the funny idea in my mind to define an own tabular like environment using \halign which defines and typesets the abbreviations. Sorting is as always an issue, but I don't mind an occasional manual :%!sort command in Vim. –  Martin Scharrer Jul 20 '11 at 14:12

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer

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.