%% filename: cyracc.def
%% version: 2.2b
%% date: 2001/10/01
%%
%% American Mathematical Society
%% Technical Support
%% Publications Technical Group
%% 201 Charles Street
%% Providence, RI 02904
%% USA
%% tel: (401) 455-4080
%%      (800) 321-4267 (USA and Canada only)
%% fax: (401) 331-3842
%% email: tech-support@ams.org
%% 
%% Copyright 1996, 2001, 2009 American Mathematical Society.
%% 
%% Unlimited copying and redistribution of this file are permitted as
%% long as this file is not modified.  Modifications, and distribution
%% of modified versions, are permitted, but only if the resulting file
%% is renamed.
%%
%% ====================================================================
%%
%%    This file is intended for use only with Plain TeX and AMS-TeX.
%%    It is not compatible with LaTeX.
%%
%%    The \font specification(s) should be made elsewhere, and should include
%%            \newfam\cyrfam
%%            \font\...cyr=wncyr...   (e.g. \font\tencyr=wncyr10 )
%%    An appropriate definition for cyrillic, usable in math and text, is
%%            \def\cyr{\fam\cyrfam\...cyr\cyracc}
%%    More extensive instructions for using cyrillic fonts are included
%%    in the AMSFonts 2.2 User's Guide.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\chardef\tempcat=\the\catcode`\@
\catcode`\@=11

%  The first set of definitions is what will be in effect outside of cyrillic,
%  i.e., in transliterated text.

%  Definition of \cydot is not ideal; real dot should be in an accent font.
\def\cydot{{\mathsurround=0pt$\cdot$}}

%  \ubar is the definition of \b from PLAIN; it may not work in math mode.
\def\ubar#1{\oalign{#1\crcr\hidewidth
    \vbox to.2ex{\hbox{\char22}\vss}\hidewidth}}

%  Soft and hard signs are represented in transliteration by prime and
%  double prime respectively.
\def\cprime{\/{\mathsurround=0pt$'$}}
\def\Cprime{{\mathsurround=0pt$'$}}
\def\cdprime{\/{\mathsurround=0pt$''$}}
\def\Cdprime{{\mathsurround=0pt$\ubar{\hbox{$''$}}$}}

\def\dbar{dj}           % make real barred d when accent font available
\def\Dbar{Dj}           %  ""

%  It would be nice to make these control sequences unnecessary; that will
%  probably require d to become active.
\def\dz{dz}
\def\Dz{Dz}
\def\dzh{dzh\cydot }
\def\Dzh{Dzh\cydot }


%  Stress marks are sometimes used in cyrillic text, mainly for pedagogic
%  reasons.  These definitions support stress marks within {\cyr ...};
%  in transliteration, they are suppressed.  Stress is indicated in
%  input by \! preceding a letter on which a stress mark is to appear;
%  an acute accent will appear in the output.  Since \! is also a plain
%  command, for negative thin space in math mode, test for math mode and
%  include the plain definition as appropriate.

\def\@gobble#1{}
\def\@testgrave{\`}
\def\@stressit{\futurelet\chartest\@stresschar }

\def\@stresschar#1{%
  \ifx #1y\def\result{\futurelet\chartest\@yligature}%
  \else \ifx #1Y\def\result{\futurelet\chartest\@Yligature}%
  \else \ifx\chartest\@testgrave \def\result{\accent"26 }%
  \else \def\result{\accent"26 #1}%
  \fi \fi \fi
  \result }

\def\@yligature{%
  \ifx a\chartest \def\result{\accent"26 \char"1F \@gobble}%
  \else \ifx u\chartest \def\result{\accent"26 \char"18 \@gobble}%
  \else \def\result{\accent"26 y}%
  \fi \fi
  \result }

\def\@Yligature{%
  \ifx a\chartest \def\result{\accent"26 \char"17 \@gobble}%
  \else \ifx A\chartest \def\result{\accent"26 \char"17 \@gobble}%
  \else \ifx u\chartest \def\result{\accent"26 \char"10 \@gobble}%
  \else \ifx U\chartest \def\result{\accent"26 \char"10 \@gobble}%
  \else \def\result{\accent"26 Y}%
  \fi \fi \fi \fi
  \result }

\def\!{\ifmmode \mskip-\thinmuskip \fi}


%  These are the definitions that will produce cyrillic letters within
%  {\cyr ...} for letters represented in input by control sequences and
%  accented latin letters.

\def\cyracc{%
  \def\cydot{{\kern0pt}}%
  \def\cprime{\char"7E }\def\Cprime{\char"5E }%
  \def\cdprime{\char"7F }\def\Cdprime{\char"5F }%
  \def\dbar{dj}\def\Dbar{Dj}%
  \def\dz{\char"1E }\def\Dz{\char"16 }%
  \def\dzh{\char"0A }\def\Dzh{\char"02 }%
  \def\'##1{\if c##1\char"0F %
    \else \if C##1\char"07 %
    \else \accent"26 ##1\fi \fi }%
  \def\`##1{\if e##1\char"0B %
    \else \if E##1\char"03 %
    \else \errmessage{accent \string\` not defined in cyrillic}%
        ##1\fi \fi }%
  \def\=##1{\if e##1\char"0D %
    \else \if E##1\char"05 %
    \else \if \i##1\char"0C %
    \else \if I##1\char"04 %
    \else \errmessage{accent \string\= not defined in cyrillic}%
        ##1\fi \fi \fi \fi }%
  \def\u##1{\if \i##1\accent"24 i%
    \else \accent"24 ##1\fi }%
  \def\"##1{\if \i##1\accent"20 \char"3D %
    \else \if I##1\accent"20 \char"04 %
    \else \accent"20 ##1\fi \fi }%
  \def\!{\ifmmode \def\result{\mskip-\thinmuskip}%
    \else \def\result{\@stressit}\fi \result}}


%       If cyrillic strings are to be included in \mark's, the accents need
%       to be kept in unexpanded form until the \mark's are interpreted.
%       See note on \mark below for details.

\def\keep@cyracc{\let\cyr=\relax \let\i=\relax
        \let\ubar=\relax \let\cydot=\relax
        \let\cprime=\relax \let\Cprime=\relax
        \let\cdprime=\relax \let\Cdprime=\relax
        \let\dbar=\relax \let\Dbar=\relax
        \let\dz=\relax \let\Dz=\relax
        \let\dzh=\relax \let\Dzh=\relax
        \let\'=\relax \let\`=\relax \let\==\relax
        \let\u=\relax \let\"=\relax \let\!=\relax }


\catcode`\@=\tempcat
\endinput

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%                       *****   CYRACC.DEF      *****
%
%  Access to the cyrillic is through the MR 1980 transliteration scheme,
%  using TeX/Metafont ligature capability.  (An alternate set of ligatures
%  exists, for accessing letters beyond the 26 located in the font positions
%  of the 26 roman letters.  An authoritative list of the ligature rules is
%  given below, under the heading Ligatures.)  Successful use of this file
%  requires appropriate cyrillic and accent fonts, arranged according to
%  the AMS/MR scheme.
%
%  There are some weaknesses in this ligaturing and accent system.
%  The following are known to be less than satisfactory:
%
%       the intermediate `ligatures' for shch access numerals;
%       primes (transliteration of hard/soft signs) use math mode;
%       underbar on `cap' double prime is too low (hard sign);
%       thorn d's don't yet exist;
%       \cydot uses math mode;
%       this scheme is not compatible with automatic Russian hyphenation.
%
%
%  Notes on the macros:
%
%       The single space following each hex character code is necessary
%       to prevent the next input character from being gobbled.
%
%
%  Note on \mark :
%
%       Control sequences such as these cyrillic accents should remain
%       unexpanded when generating \mark's; otherwise, the definition of
%       the expanded strings in effect when the \mark is used may be
%       inappropriate.  By \let\...=\relax , the \... takes on the important
%       characteristic of a primitive that it will not be expanded further.
%       The following code has been shown to generate correct \mark entries
%       that can be used successfully in running heads:
%
%       \newtoks\marktoks
%       \def\domark{\keep@cyracc \mark{\the\marktoks}}
%
%       In running heads, the marks should be accessed using \the to expand
%       the tokens strings properly.
%
%
%  Ligatures
%
%  This is a list of all the letter ligatures in the AMS cyrillic fonts,
%  and in other cyrillic fonts (such as those developed at the University
%  of Washington that use the AMS arrangement).
%
%  LOWER CASE LIGATURES
%
%    A.  All-letter ligatures
%
%  ch = `q
%  dj = '016
%  kh = `h
%  lj = '011
%  nj = '010
%  sh = `x; xc = `7 (shc); 7h = `w (shch)
%  ts = `c
%  ya = '037
%  yu = '030
%  zh = '031
%
%    B.  Ligatures with keyed numerals
%
%  c1 = '017
%  d1 = '016 (dj); d2 = '012 (dzh); d3 = '036 (dz)
%  e0 = '033; e1 = '013; e2 = '015
%  i0 = '032; i1 = '014
%  j1 = '037 (ya); j2 = '030 (yu)
%  l1 = '011 (lj)
%  n1 = '010 (nj)
%  p1 = '176; p2 = '177
%  z1 = '031 (zh)
%
%  UPPER CASE LIGATURES
%    A.  All-letter ligatures
%
%  CH, Ch = `Q
%  KH, Kh = `H
%  LJ, Lj = '001
%  NJ, Nj = '000
%  SH, Sh = `X; XH, Xh = `6 (SHC, SHc, Shc);
%            6H, 6h = `W (SHCH, SHCh, SHch, Shch)
%  TS, Ts = `C
%  YA, Ya = '027
%  YU, Yu = '020
%  ZH, Zh = '021
%
%    B.  Ligatures with keyed numerals
%
%  C1 = '007
%  D1 = '006 (DJ); D2 = '002 (DZH); D3 = '026 (DZ)
%  E0 = '023; E1 = '003; E2 = '005
%  I0 = '022; I1 = '004
%  J1 = '027 (YA); J2 = '020 (YU)
%  L1 = '001 (LJ)
%  N0 = '175 (Number sign); N1 = '000 (NJ)
%  P1 = '136; P2 = '137
%  Z1 = '021 (ZH)
%
%  DEACTIVATED LIGATURES
%
%  The dzh and DZH ligatures were originally built in the following manner,
%  but the results were not compatible with desired keyboarding schemes.
%
%  dz = '036; '036(roman s)h = '012 (dzh)
%  DZ = '026; '026(roman S)H = '002 (DZH)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
