%       ABBREVIATIONS

% general punctuation-depedent treatment of abbreviated phrases
% just use macro in text as if it were a word, with puctuation if required,
% no escaped spaces needed

\let\then\relax

\def\abbrev
#1%     / for italic, | for roman
#2%     the word itself (omit \it, \/ and final full-stop)
#3%     . for final (suppressible) full-stop, - for none
#4{%    ~ for unbreakable space, _ for breakable space, - for no space
\ifx    #1/%
\then   \let\abbrev@font\it\let\abbrev@corr\/% italic
\else   \let\abbrev@font\empty\let\abbrev@corr\empty
\fi
\def\abbrev@word{#2}%     save the word
\ifx    #3.% the full stop (if required) does not end a sentence
\then   \def\abbrev@stop{.\spacefactor=1000 }%
\else   \let\abbrev@stop\empty
\fi
\ifx    #4~%
\then   \def\abbrev@space{~\ignorespaces}%       tied space (& dont spoil it!)
\else   \ifx#4_%
\then   \def\abbrev@space{\ }%                   breakable space
\else   \let\abbrev@space\ignorespaces%          no space at all
\fi\fi
\futurelet\abbrev@punct        % what punctuation follows?
\do@abbrev               % carry on ...
}

\def\do@abbrev{%
\reset@abbrev    % alter full stop and space wrt following punctuation
{\abbrev@font    % italic, perhaps
\abbrev@word     % the word
\abbrev@stopa    % full stop if needed
\abbrev@corra}%  % italic correction
\abbrev@spacea}  % whatever kind of space at the end

\def\reset@abbrev{%
%
% ., suppress space, italic correction and full-stop
\let\abbrev@spacea\ignorespaces\let\abbrev@stopa\empty\let\abbrev@corra\empty
\ifx\abbrev@punct.%
%
% ,  suppress space and italic correction
\else\ifx\abbrev@punct,\let\abbrev@stopa\abbrev@stop%
%
% ;:?/! suppress space and full-stop
\else\let\abbrev@corra\abbrev@corr
\ifx\abbrev@punct;\else
\ifx\abbrev@punct:\else
\ifx\abbrev@punct?\else
\ifx\abbrev@punct/\else
\ifx\abbrev@punct!%
%
% })]'"- and explicit space (~ & \ ) suppress space but not full-stop 
\else\let\abbrev@stopa\abbrev@stop
\ifx\abbrev@punct)\else
\ifx\abbrev@punct~\else
%\ifx\abbrev@punct-\else  % ``\etc ---'' shoulw have a space
\ifx\abbrev@punct]\else
\ifx\abbrev@punct'\else
\ifx\abbrev@punct"\else
\ifx\abbrev@punct\ \else
\ifx\abbrev@punct\egroup%
%
% default case: something to be treated as the ``next word''
\else\let\abbrev@spacea\abbrev@space
\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%\fi
}

\ifx\dotless@i\undefined\let\dotless@i\i\fi

%#1 / italic, | roman
%#2 the word itself
%#3 . for final (suppressible) full-stop, - for none
%#4 ~ for unbreakable space, _ for breakable space, - for no space
\def\adhoc      {\abbrev/{ad~hoc}-_}
\def\adinf      {\abbrev/{ad~inf}._}
%\def\afortiori  {\abbrev/{\^a~fortiori}-_}
\def\afortiori  {\abbrev/{a~fortiori}-_}
\def\ala        {\abbrev/{\`a~la}-~}
\def\alias      {\abbrev/{alias}-_}
%\def\apriori    {\abbrev/{\^a~priori}-_}
\def\apriori    {\abbrev/{a~priori}-_}
%\def\archaic    {\abbrev|{archa\kern.05em\"\dotless@i c}-_}
\def\archaic    {\abbrev|{archaic}-_}
\def\bonafide   {\abbrev/{bona fide}-_}
\def\cf         {\abbrev/{cf}.~}
\def\circa      {\abbrev/{circa}-~}
\def\defacto    {\abbrev/{de facto}-_}
\def\eg         {\abbrev/{e.g}.~}
\def\etal       {\abbrev/{et~al}._}
\def\etc        {\abbrev/{etc}._}
\def\etseq      {\abbrev/{et~seq}._}
\def\fiat       {\abbrev/{fiat}-_}
\def\ibid       {\abbrev/{ibid}._}
\def\ie         {\abbrev/{i.e}.~}
\def\insitu     {\abbrev/{in~sit\^u}-_}
\def\loccit     {\abbrev/{loc.~cit}._}
\def\naive      {\abbrev|{na\"\dotless@i ve}-_}
\def\naively    {\abbrev|{na\"\dotless@i vely}-_}
\def\opcit      {\abbrev/{op.~cit}._}
\def\qua        {\abbrev/{qu\^a}-~}
\def\qv         {\abbrev/{q.v}._}
%\def\role      {\abbrev|{r\^ole}-_}
%\def\roles     {\abbrev|{r\^oles}-_}
\def\role       {\abbrev|{role}-_}
\def\roles      {\abbrev|{roles}-_}
\def\sic        {\abbrev/{sic}-_}
\def\versus     {\abbrev/{versus}-_}
\def\via        {\abbrev/{via}-~}
\def\viceversa  {\abbrev/{vice versa}-_}
\def\visavis    {\abbrev/{vis \`a~vis}-_}
\def\viz        {\abbrev/{viz}.~}
\def\wolog      {\abbrev|{w.l.o.g}.~}% \wlog = ``write to log'' TeXbook p347
\def\wrt        {\abbrev|{w.r.t}.~}
%\def\Afortiori  {\abbrev/{\=A~fortiori}-_}
\def\Afortiori  {\abbrev/{A~fortiori}-_}
%\def\Apriori    {\abbrev/{\^A~priori}-_}
\def\Apriori    {\abbrev/{A~priori}-_}
\def\Cf         {\abbrev/{Cf}.~}
\def\Eg         {\abbrev/{E.g}.~}
\def\Naive      {\abbrev|{Na\"\dotless@i ve}-_}
\def\Naively    {\abbrev|{Na\"\dotless@i vely}-_}
\def\Wolog      {\abbrev|{W.l.o.g}.~}

