[comp.text.tex] Acronyms

jk@cs.man.ac.uk (John Kewley ICL) (09/12/90)

Here are some macros for performing acronym expansion in LaTeX. They could
well work in TeX as well, I have never tried.

They are, hopefully fully described within the acronym.sty file.

        J.K.
 
John M. Kewley, ICL, Wenlock Way, West Gorton, Manchester. M12 5DR
Tel:   (+44) 61 223 1301 X2138  Email: jk@r6.cs.man.ac.uk / jk@nw.stl.stc.co.uk

#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	acronym.sty
# This archive created: Tue Sep 11 17:54:45 1990
export PATH; PATH=/bin:$PATH
if test -f 'acronym.sty'
then
	echo shar: will not over-write existing file "'acronym.sty'"
else
cat << \SHAR_EOF > 'acronym.sty'
% @(#)acronym.sty       1.2 9/11/90 Copyright 1989 ICL
% 
% Author: John Kewley
%
% This style file contains macros for acronyms.
%
% Two styles are supported - footnote and parenthesised.
% This can be switched using \foottrue for footnotes or
% \footfalse (default) for parenthesised.
%
% Parenthesised acronyms are used as follows:
% 	Declare acronym using:
%		\newacronym{latex name}{expanded name}[printed name]
%		(The printed name defaults to latex name).
%		e.g. \acronym{GNU}{GNU Not Unix}[\sc{gnu}]
%	When acronym is first used (\GNU), the following is printed:
%		expanded name (printed name)
%		GNU Not Unix (GNU)
%	Subsequent use yields only the printed name.
%
% Footnote acronyms work in the same way except when they are first used:
%	printed name\footnote{expanded name}
%
% Acronyms can be followed by an optional argument:
%		\newacronym{PE}{Processing Element}
%		\PE['s] gives
%		Processing Element's (PE's)
%
% They can also be followed by s to signify the plural:
%		\newacronym{PE}{Processing Element}
%		\PEs gives
%		Processing Elements (PEs)
%
% If they are to be referred to before they are first used, in a title say
% When full expansion might not look good, or in a section heading where
% the definition would not be wanted in the contents list, short and long forms
% of the acronym are defined.
%
% e.g. \section{\GNUshort\ Comings}
%
% The long version can be used where a repetition of the full name is required.
%
% Quite often acronyms are defined in a Glossary, Terminology or
% Table of Acronyms. The item command is provided for this:
%
%		\GNUitem gives
%		\item[GNU] GNU Not Unix
%
% Whenever an acronym is defined using \newacronym, all the above forms are
% available.
%
% John Kewley ICL
%
% jk@r6.cs.man.ac.uk or
% jk@nw.stl.stc.co.uk

% Auxiliary definitions:

%	\ifnextchar
%\def\ifnextchar#1#2#3{\@ifnextchar#1{#2}{#3}}

\def\namegdef#1{\expandafter\gdef\csname #1\endcsname}
\def\namedef#1{\expandafter\def\csname #1\endcsname}
\def\nameuse#1{\csname #1\endcsname}

\newif\iffoot \footfalse

\def\acitemx#1#2[#3]{\item [#1#3] #2#3}
\def\acitem#1#2{\@ifnextchar [{\acitemx{#1}{#2}}{\acitemx{#1}{#2}[]}}
\def\acfootx#1#2[#3]{#1#3\footnote{#2#3}}
\def\acfoot#1#2{\@ifnextchar [{\acfootx{#1}{#2}}{\acfootx{#1}{#2}[]}}
\def\aclongx#1#2[#3]{#1#3 (#2#3)}
\def\aclong#1#2{\@ifnextchar [{\aclongx{#1}{#2}}{\aclongx{#1}{#2}[]}}
\def\acshortx#1[#2]{#1#2}
\def\acshort#1{\@ifnextchar [{\acshortx{#1}}{\acshortx{#1}[]}}
\def\acronx#1#2[#3]{\iffoot\acfoot{#1}{#2}[#3]\else\aclong{#1}{#2}[#3]\fi}
\def\acron#1#2{\@ifnextchar [{\acronx{#1}{#2}}{\acronx{#1}{#2}[]}}

\def\newacaux#1#2{\namegdef{#1x}[##1]{#2##1}%
	\namegdef{#1}{\protect\@ifnextchar [{\protect\nameuse{#1x}}{#2}}}
\def\newac#1#2[#3]{%
	\namegdef{#1item}{\acitem{#3}{#2}}
	\namegdef{#1items}{\acitem{#3s}{#2s}}
	\namegdef{#1long}{\protect\aclong{#2}{#3}}
	\namegdef{#1longs}{\protect\aclong{#2s}{#3s}}
	\namegdef{#1short}{\protect\acshort{#3}}
	\namegdef{#1shorts}{\protect\acshort{#3s}}
	\namegdef{#1foot}{\protect\acfoot{#3}{#2}}
	\namegdef{#1foots}{\protect\acfoot{#3s}{#2s}}
	\namegdef{#1x}[##1]{\acron{#2##1}{#3##1}\newacaux{#1}{#3}}
	\namegdef{#1s}{\protect\nameuse{#1x}[s]}
	\namegdef{#1}{\protect\@ifnextchar [{\protect\nameuse{#1x}}%
		{\protect\acronx{#2}{#3}[]\protect\newacaux{#1}{#3}}}}

\def\termit#1#2[#3]{\newac{#1}{#2}[#3]\acitem{#3}{#2}}
\def\termitem#1#2{\@ifnextchar [{\termit{#1}{#2}}{\termit{#1}{#2}[#1]}}

\def\newte#1#2[#3]{\namegdef{#1item}{\acitem{#3}{#2}}}
\def\newterm#1#2{\protect\@ifnextchar [{\newte{#1}{#2}}{\newte{#1}{#2}[#1]}}

% \newacronym
%     #1 : short name
%     #2 : long name
%   [#3] : optional printed name
\def\newacronym#1#2{\@ifnextchar [{\newac{#1}{#2}}{\newac{#1}{#2}[#1]}}
SHAR_EOF
fi # end of overwriting check
#	End of shell archive
exit 0
--
        J.K.
 
John M. Kewley, ICL, Wenlock Way, West Gorton, Manchester. M12 5DR
Tel:   (+44) 61 223 1301 X2138  Email: jk@r6.cs.man.ac.uk / jk@nw.stl.stc.co.uk