# How to define acronyms in ConTeXt?

The acronym packages allows one to easily create and display acronyms, with a simple syntax, like \ac{usb}. The first time this is called, is will say “Universal Serial Bus (USB)”, but after that, just “USB”. I found nothing about this in the documentation, but this article on PDF-strings seems to offer similar functionality, but the example seems incomplete. How can I define and display acronyms in ConTeXt?

-
See manual chapter 12.2 - Synonyms –  Marco May 9 '12 at 12:18

The context version of this functionality is called 'synonyms', types of which are defined using \definesynonyms. The wiki page for definesynonyms contains some examples, but in short:

\definesynonyms[acronym][acronyms][\infull]

\acronym[VVV]{vvv}{Bureau of Tourist Information}
\starttext
The Dutch \VVV\ (\infull{VVV}) can provide you with the tourist information on Hasselt.
\stoptext


There now also a \setupsynonyms[acronyms] and \placelistofacronyms. That are used to produce a list of (used or all) acronyms.

As far as I know, ConTeXt does not have a built-in feature for 'first use'.

-

I had the same question but needed indexing. Also, my project contains many loose files, so I don't want to search for first occurances myself.

\definesynonyms[acron][acronyms][\fullac] % Define acronyms as context synonyms

% Define a new macro
\def\ac#1{
\ifcsname AcroUsed#1\endcsname
% If the acro was already used, return the acronym
\csname #1\endcsname
\else
% Otherwise, set as used, print full and acro
\fullacro{#1} (\csname #1\endcsname)
\expandafter\def\csname AcroUsed#1\endcsname{1}
\fi
}

-

The theory behind this is easy, if you don't need to index the acronyms.

\def\newacronym#1#2#3{% #1 = key, #2 = abbreviated form, #3 = expanded form
\expandafter\def\csname ac@#1\endcsname{%
#3~(#2)%
\expandafter\gdef\csname ac@#1\endcsname{#2}%
}%
}
\def\ac#1{\csname ac@#1\endcsname}

\newacronym{usb}{USB}{Universal Serial Bus}
\newacronym{ml}{ML}{Murphy's Law}

Here's \ac{usb} and \ac{ml}; let's see that \ac{usb} works
not according to \ac{ml}.

\bye


-