%        File: cyr.sty
%      Author: H.A.Trujillo
%     Created: Sun Jun  9 13:26:03 EDT 2019
% Last Change:     25 Jun 2019
%     Purpose: Quick-and-dirty cyrillic input

%
%  The AMS-fonts provide a convenient way to input bits of Russian text,
%  using the wncy family of fonts (see amsfndoc.pdf, §6), but there are
%  two drawbacks: 
%      - the fontsizes, families and weights must be hard-coded (rather than
%        accessed using  \small, \textbf, \emph, etc.)
%      - the input must be entered as transliterated text, not in cyrillic.
%
%  This package solves both these problems.
%
% --------
%
%  Macros/Environments:
%      One macro and its corresponding environment are defined:
%
%	    \cyr{text...} 		types text in cyrillic
%	    \begin{cyrillic} ... 	idem
%
%       Within this macro/environment, one may use the usual commands:
%       \small, \textbf, \textsc, \emph, etc.
%
%  Input:
%      Text may be entered either in cyrillic or in transliteration.  This
%      requires, however, that the document be processed by lualatex rather
%      than (normal) LaTeX.   
%
%  Options:
%      translit	
%      		The "translit" option suppresses the cyrillic keystroke
%		definitions, allowing normal (LaTeX) processing.  This
%		option requires translterated input.
%      romaninput
%     		Synonymous with "translit"
%      cyrillicinput
%     		Default option: cyrillic (or mixed) input; lualatex required
%
%  Installation:
%      The following font-description files must be installed where LaTeX
%      can find them:    (eg, /usr/local/texlive/texmf-local) 
%
%	      t1wncyr.fd	(T1  roman, bold, small cap, italic)
%	      t1wncyrsf.fd	(T1  sans serif)
%	      ot1wncyr.fd	(OT1 roman, bold, small cap, italic)
%	      ot1wncyrsf.fd	(OT1 sans serif)
%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cyr} [2019/06/25 v2.1 Cyrillic Input]

\InputIfFileExists{cyracc.def} {} 
    {\typeout{^^J\space\space >>> cyracc.def  not found.  Aborting.^^J}\exit}


% ------- Font Definitions -------

\newcommand{\cyr}	[1]  {%
  \bgroup
    \renewcommand{\sfdefault}{wncyrsf}
    \fontfamily{wncyr}\selectfont #1
  \egroup}

\newenvironment{cyrillic}	     
  { \renewcommand{\sfdefault}{wncyrsf}
    \fontfamily{wncyr}\selectfont} 
  {}

% ----- Keystroke  Definitions -----

% Skip the definitions below if "translit" option is used
\let\tf@cyr\iftrue
\DeclareOption{translit}  {\let\tf@cyr\iffalse}
\DeclareOption{romaninput}{\let\tf@cyr\iffalse}
\DeclareOption{cyrillicinput} {}

\ProcessOptions\relax

  %	See either encguide.pdf (A1: OT2 table) or amsfndoc.pdf 
  %	(Appendix D, p33) for font charts.

\tf@cyr
  % Abort with an error if non-lua latex is used
  \directlua{print(" -- LuaLatex Required for cyr.sty --  ")}

  % Lower Case
  \catcode`а=\active  \chardef а=`a
  \catcode`б=\active  \chardef б=`b
  \catcode`в=\active  \chardef в=`v
  \catcode`г=\active  \chardef г=`g
  \catcode`д=\active  \chardef д=`d
  \catcode`е=\active  \chardef е=`e
  \catcode`ё=\active  \chardef ё="1B
  \catcode`ж=\active  \chardef ж="19
  \catcode`з=\active  \chardef з=`z
  \catcode`и=\active  \chardef и=`i
  \catcode`й=\active  \chardef й="1A
  \catcode`к=\active  \chardef к=`k
  \catcode`л=\active  \chardef л=`l
  \catcode`м=\active  \chardef м=`m
  \catcode`н=\active  \chardef н=`n
  \catcode`о=\active  \chardef о=`o
  \catcode`п=\active  \chardef п=`p
  \catcode`р=\active  \chardef р=`r
  \catcode`с=\active  \chardef с=`s
  \catcode`т=\active  \def т{t\null}
  \catcode`у=\active  \chardef у=`u
  \catcode`ф=\active  \chardef ф=`f
  \catcode`х=\active  \chardef х=`h
  \catcode`ц=\active  \chardef ц=`c
  \catcode`ч=\active  \chardef ч=`q
  \catcode`ш=\active  \chardef ш="78
  \catcode`щ=\active  \chardef щ="77
  \catcode`ъ=\active  \chardef ъ="7F
  \catcode`ы=\active  \chardef ы=`y
  \catcode`ь=\active  \chardef ь=`~
  \catcode`э=\active  \chardef э="7A
  \catcode`ю=\active  \chardef ю="18
  \catcode`я=\active  \chardef я="1F

  % Capitals
  \catcode`А=\active  \chardef А=`A
  \catcode`Б=\active  \chardef Б=`B
  \catcode`В=\active  \chardef В=`V
  \catcode`Г=\active  \chardef Г=`G
  \catcode`Д=\active  \chardef Д=`D
  \catcode`Е=\active  \chardef Е=`E
  \catcode`Ё=\active  \chardef Ё="13
  \catcode`Ж=\active  \chardef Ж="11
  \catcode`З=\active  \chardef З=`Z
  \catcode`И=\active  \chardef И=`I
  \catcode`Й=\active  \chardef Й="12
  \catcode`К=\active  \chardef К=`K
  \catcode`Л=\active  \chardef Л=`L
  \catcode`М=\active  \chardef М=`M
  \catcode`Н=\active  \chardef Н=`N
  \catcode`О=\active  \chardef О=`O
  \catcode`П=\active  \chardef П=`P
  \catcode`Р=\active  \chardef Р=`R
  \catcode`С=\active  \chardef С=`S
  \catcode`Т=\active  \def Т{T\null}
  \catcode`У=\active  \chardef У=`U
  \catcode`Ф=\active  \chardef Ф=`F
  \catcode`Х=\active  \chardef Х=`H
  \catcode`Ц=\active  \chardef Ц=`C
  \catcode`Ч=\active  \chardef Ч=`Q
  \catcode`Ш=\active  \chardef Ш=`X
  \catcode`Щ=\active  \chardef Щ="57
  \catcode`Ъ=\active  \chardef Ъ="5F
  \catcode`Ы=\active  \chardef Ы=`Y
  \catcode`Ь=\active  \chardef Ь="5E
  \catcode`Э=\active  \chardef Э="5A
  \catcode`Ю=\active  \chardef Ю="10
  \catcode`Я=\active  \chardef Я="17
\fi

