\ProvidesPackage{texnansi}[1998/05/30 v0.2 texnansi and ansinew support]

\RequirePackage[LY1]{fontenc}

\@tempcnta=224
\@tempcntb=192

\loop
\ifnum\@tempcnta<255
  \lccode\@tempcnta=\@tempcnta
  \lccode\@tempcntb=\@tempcnta
  \uccode\@tempcntb=\@tempcntb
  \uccode\@tempcnta=\@tempcntb
  \advance\@tempcnta\@ne
  \advance\@tempcntb\@ne
\repeat

% Then there are just a few odd ones that don't fit this pattern

% OE, oe
\lccode140=156\lccode156=156
\uccode140=140\uccode156=140
% Ydieresis, ydieresis
\lccode159=255\lccode255=255
\uccode159=159\uccode255=159
% Scaron, scaron
\lccode138=154\lccode154=154
\uccode138=138\uccode154=138
% Zcaron, zcaron
\lccode142=158\lccode158=158
\uccode158=142\uccode142=142
% Lslash, lslash
\lccode128=144\lccode144=144
\uccode144=128\uccode128=128

\DeclareOption{ansinew}{\let\caronfake\relax}

\ProcessOptions

% Stop here unless ansinew being used.
\ifx\caronfake\relax\else\endinput\fi

% Issue a warning in this case.
\PackageWarningNoLine{fontenc}{%
  Modifying LY1 encoding for ansinew rather than texnansi}

% Use the `high' copies of these
\DeclareTextSymbol{\oe}{LY1}                {156}
\DeclareTextSymbol{\OE}{LY1}                {140}
\DeclareTextSymbol{\ss}{LY1}                {223}

% Take out some characters.
% Some of the `fakes' used here are so bad it may be better to
% do nothing, but do this for now.
\DeclareTextCommand{\i}{LY1}{%
  \TextSymbolUnavailable\i i}
\DeclareTextCommand{\l}{LY1}{%
  \TextSymbolUnavailable\l \leavevmode\rlap-l}
\DeclareTextCommand{\L}{LY1}{%
  \TextSymbolUnavailable\L \leavevmode\rlap-L}

\def\accentfake#1#2#3#4#5{%
  \TextSymbolUnavailable#1%
  {\let\vtop\vbox
   \oalign{%
     \hfil
     \dimen@\f@size\p@
     \fontsize{#2\dimen@}\z@\selectfont
     \smash{\lower#3\dimen@\hbox{#4}}\hfil\cr\hfil#5\hfil}}}

\def\caronfake{\accentfake\v{.4}{.1}{$\vee$}}
\DeclareTextCommand{\v}{LY1}[1]{\caronfake{#1}}
\DeclareTextComposite{\v}{LY1}{S}           {138}
\DeclareTextComposite{\v}{LY1}{s}           {154}
% \DeclareTextCompositeCommand{\v}{LY1}{Z}{\caronfake{Z}}
% \DeclareTextCompositeCommand{\v}{LY1}{z}{\caronfake{z}}
\DeclareTextComposite{\v}{LY1}{Z}           {142}
\DeclareTextComposite{\v}{LY1}{z}           {158}

\DeclareTextCommand{\r}{LY1}[1]{\accentfake\r{.75}{.3}{\char176}{#1}}
\DeclareTextComposite{\r}{LY1}{A}           {197}
\DeclareTextComposite{\r}{LY1}{a}           {229}

\DeclareTextCommand{\H}{LY1}[1]{\TextSymbolUnavailable\H\"{#1}}

\DeclareTextCommand{\u}{LY1}[1]{\accentfake\u{.3}{.1}{$\smile$}{#1}}
\DeclareTextCommand{\k}{LY1}[1]{\TextSymbolUnavailable\k\c{#1}}
\DeclareTextCommand{\.}{LY1}[1]{\accentfake\.{1}{0}{.}{#1}}


% Need to deal with prime in math mode since 39 is remapped to 146

{\catcode146=\active \gdef^^92{{^\bgroup\prim@s}}}
\mathcode146="8000 % ^\prime

\chardef\lq=145 \chardef\rq=146

% Note that \lq and \rq also provide access to ` and '

% `quoteright' has moved from 39 to 146 
% make space for `quotesingle' in ANSI:

{\catcode`\'=\active \global\chardef'=146}

% `quoteleft' has moved from 96 to 145
% make space for `grave' in ANSI:

{\catcode`\`=\active \global\chardef`=145}

% Delay making ` and ' active until after packages read.
% So they can be used in octal and character code numbers.
\AtBeginDocument{\catcode`\'\active \catcode`\`\active}

