% File ucode.tex: 
%  (0) sets \czech, \slovak to Cork encoded hyphen-pattern numbers,
%  (1) sets \catcode, \l/uccode for characters (code by Cork),
%  (2) defines \csaccents for new behavior of \v, \', etc (code by Cork),
%  (3) defines some \sequences for special characters.
%  (4) redefines character-like macros from plainTeX as \chardef
%
% Created by Petr Olsak <olsak@math.feld.cvut.cz>,       November 2012

\def\tmp#1#2\relax{\def\tmp{#2}}\tmp ^^^^abcd\relax
\ifx\tmp\empty \else
   \errhelp={The ucode.tex file expects the TeX engine which works in Unicode
             internally.}
   \errmessage{Sorry, the Unicoded TeX engine (like luatex, xetex) is not detected}
   \endinput \fi

\message{Font encoding set to Unicode.}

\let\unicoded\font % macros can do \ifx\font\unicoded ...\else...\fi

%% (0) \czech, \slovak. You can use \chyph, \shyph after this file is loaded.
\ifx\czUnicode\undefined 
  \message{WARNING: czech+slovak hyphenation patterns are not loaded in Unicode.}
\else
  \csname unicodelangs\endcsname
\fi

%% (1a) \catcodes:
\catcode225=11  % a-acute       
\catcode193=11  % A-acute       
\catcode228=11  % a-diaeresis   
\catcode196=11  % A-diaeresis   
\catcode269=11  % c-caron       
\catcode268=11  % C-caron       
\catcode271=11  % d-caron       
\catcode270=11  % D-caron       
\catcode233=11  % e-acute       
\catcode201=11  % E-acute       
\catcode283=11  % e-caron       
\catcode282=11  % E-caron       
\catcode237=11  % i-acute       
\catcode205=11  % I-acute       
\catcode314=11  % l-acute       
\catcode313=11  % L-acute       
\catcode318=11  % l-caron       
\catcode317=11  % L-caron       
\catcode328=11  % n-caron       
\catcode327=11  % N-caron       
\catcode243=11  % o-acute       
\catcode211=11  % O-acute       
\catcode244=11  % o-circumflex  
\catcode212=11  % O-circumflex  
\catcode246=11  % o-diaeresis   
\catcode214=11  % O-diaeresis   
\catcode341=11  % r-acute       
\catcode340=11  % R-acute       
\catcode345=11  % r-caron       
\catcode344=11  % R-caron       
\catcode353=11  % s-caron       
\catcode352=11  % S-caron       
\catcode357=11  % t-caron       
\catcode356=11  % T-caron       
\catcode250=11  % u-acute       
\catcode218=11  % U-acute       
\catcode367=11  % u-ring        
\catcode366=11  % U-ring        
\catcode252=11  % u-diaeresis   
\catcode220=11  % U-diaeresis   
\catcode253=11  % y-acute       
\catcode221=11  % Y-acute       
\catcode382=11  % z-caron       
\catcode381=11  % Z-caron       

%% (1b) \lccodes, \uccodes
\def\tmp #1 #2 {\lccode#1=#1 \lccode#2=#1 \uccode#1=#2 \uccode#2=#2 }
\tmp 225 193
\tmp 228 196
\tmp 269 268
\tmp 271 270
\tmp 233 201
\tmp 283 282
\tmp 237 205
\tmp 314 313
\tmp 318 317
\tmp 328 327
\tmp 243 211
\tmp 244 212
\tmp 246 214
\tmp 341 340
\tmp 345 344
\tmp 353 352
\tmp 357 356
\tmp 250 218
\tmp 367 366
\tmp 252 220
\tmp 253 221
\tmp 382 381


%% (2) \csaccents, \cmaccents
\def\accentscommands{\string\^,\string\`,\string\',\string\v,\string\",% 
  \string\r,\string\c,\string\~,\string\H,\string\u,% 
  \string\. and \string\k}
\def\csaccentsmessage{%
  \message{The \accentscommands\space expands to characters by Unicode.}}
\ifx\cmaccentsmessage\undefined 
  \def\cmaccentsmessage{%
    \message{The \accentscommands\space are defined similar as plainTeX.}}
\fi
\def\csaccents{\csaccentsmessage
  \def\^##1{\ifx o##1^^f4\else
            \ifx O##1^^d4\else
            \ifx a##1^^e2\else
            \ifx A##1^^c2\else
            \ifx e##1^^ea\else
            \ifx E##1^^ca\else
            \ifx i##1^^ee\else
            \ifx I##1^^ce\else
            \ifx u##1^^fb\else
            \ifx U##1^^db\else
       {\accent"005E ##1}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}\let\^^D=\^%
  \def\`##1{\ifx a##1^^e0\else
            \ifx A##1^^c0\else
            \ifx e##1^^e8\else
            \ifx E##1^^c8\else
            \ifx i##1^^ec\else
            \ifx I##1^^cc\else
            \ifx o##1^^f2\else
            \ifx O##1^^d2\else
            \ifx u##1^^f9\else
            \ifx U##1^^d9\else
      {\accent"0060 ##1}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}%
  \def\'##1{\ifx a##1^^e1\else
            \ifx e##1^^e9\else
            \ifx\i##1^^ed\else
            \ifx i##1^^ed\else
            \ifx o##1^^f3\else
            \ifx u##1^^fa\else
            \ifx y##1^^fd\else
            \ifx r##1^^^^0155\else
            \ifx l##1^^^^013a\else
            \ifx A##1^^c1\else
            \ifx E##1^^c9\else
            \ifx I##1^^cd\else
            \ifx O##1^^d3\else
            \ifx U##1^^da\else
            \ifx Y##1^^dd\else
            \ifx R##1^^^^0154\else
            \ifx L##1^^^^0139\else
            \ifx C##1^^^^0106\else
            \ifx N##1^^^^0143\else
            \ifx S##1^^^^015a\else
            \ifx Z##1^^^^0179\else
            \ifx c##1^^^^0107\else
            \ifx n##1^^^^0144\else
            \ifx s##1^^^^015b\else
            \ifx z##1^^^^017a\else
       {\accent"00B4 ##1}%
            \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
            \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}%
  \def\v##1{\ifx e##1^^^^011b\else
            \ifx s##1^^^^0161\else
            \ifx c##1^^^^010d\else
            \ifx r##1^^^^0159\else
            \ifx z##1^^^^017e\else
            \ifx d##1^^^^010f\else
            \ifx t##1^^^^0165\else
            \ifx l##1^^^^013e\else
            \ifx n##1^^^^0148\else
            \ifx E##1^^^^011a\else
            \ifx S##1^^^^0160\else
            \ifx C##1^^^^010c\else
            \ifx R##1^^^^0158\else
            \ifx Z##1^^^^017d\else
            \ifx D##1^^^^010e\else
            \ifx T##1^^^^0164\else
            \ifx L##1^^^^013d\else
            \ifx N##1^^^^0147\else
                    {\accent"02C7 ##1}%
            \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi
            \fi\fi\fi\fi\fi\fi}\let\^^_=\v%
  \def\"##1{\ifx a##1^^e4\else
            \ifx o##1^^f6\else
            \ifx u##1^^fc\else
            \ifx A##1^^c4\else
            \ifx O##1^^d6\else
            \ifx U##1^^dc\else
            \ifx Y##1^^^^0178\else
            \ifx E##1^^cb\else
            \ifx I##1^^cf\else
            \ifx y##1^^b8\else
            \ifx e##1^^eb\else
            \ifx i##1^^ef\else
      {\accent"00A8 ##1}\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi}%
  \def\r##1{\ifx u##1^^^^016f\else
            \ifx U##1^^^^016e\else
            \ifx A##1^^c5\else
            \ifx a##1^^e5\else
       {\accent"00B0 ##1}\fi\fi\fi\fi}%
  \def\c##1{\ifx C##1^^c7\else
            \ifx c##1^^e7\else
            \ifx S##1^^^^015e\else
            \ifx s##1^^^^015f\else
            \ifx T##1^^^^0162\else
            \ifx t##1^^^^0163\else
         {\char"00B8 ##1}\fi\fi\fi\fi\fi\fi}%
  \def\~##1{\ifx A##1^^c3\else
            \ifx N##1^^d1\else
            \ifx O##1^^d5\else
            \ifx a##1^^e3\else
            \ifx n##1^^f1\else
            \ifx o##1^^f5\else
       {\accent"007E  ##1}\fi\fi\fi\fi\fi\fi}%
  \def\H##1{\ifx O##1^^^^0150\else
            \ifx U##1^^^^0170\else
            \ifx o##1^^^^0151\else
            \ifx u##1^^^^0171\else
      {\accent"02DD  ##1}\fi\fi\fi\fi}%
  \def\u##1{\ifx A##1^^^^0102\else
            \ifx G##1^^^^011e\else
            \ifx a##1^^^^0103\else
            \ifx g##1^^^^011f\else
       {\accent"02D8  ##1}\fi\fi\fi\fi}%
  \def\=##1{\ifx d##1^^^^0111\else
       {\accent"00AF  ##1}\fi}%
  \def\.##1{\ifx i##1^^69\else
            \ifx z##1^^^^017c\else
            \ifx I##1^^^^0130\else
            \ifx Z##1^^^^017b\else
       {\accent"02D9 ##1}\fi\fi\fi\fi}%
  \def\k##1{\ifx A##1^^^^0104\else
            \ifx E##1^^^^0118\else
            \ifx a##1^^^^0105\else
            \ifx e##1^^^^0119\else
         {\char"02DB ##1}\fi\fi\fi\fi}%
  %% for backward compatibility:
  \def\softd{\v{d}}\def\softt{\v{t}}\def\ou{\r{u}}%
  \def\softl{\v{l}}\def\softL{\v{L}}}
\def\cmaccents{\cmaccentsmessage
  \def\^##1{{\accent94 ##1}}\let\^^D=\^%
  \def\`##1{{\accent18 ##1}}%
  \def\'##1{{\accent19 ##1}}%
  \def\v##1{{\accent20 ##1}}\let\^^_=\v%
  \def\"##1{{\accent"7F ##1}}%
  \let\r=\undefined\def\ou{{\accent6u}}}

\ifx\r\undefined \else \csaccents \fi  %% re-set \csaccents

%% (3) special \sequences for UNICODEd fonts.
       %% Czech left a right double qoutes
\chardef\clqq="201E   \sfcode"201E=0
\chardef\crqq="201C   \sfcode"201C=0
       %% French double quotes
\chardef\flqq="00AB   \sfcode"00AB=0
\chardef\frqq="00BB   \sfcode"00BB=0
       %% Other characters
\def\ogonek #1{\setbox0\hbox{#1}\ifdim\ht0=1ex\accent"02DB #1%
   \else{\ooalign{\unhbox0\crcr\hss\char"02DB}}\fi}
\chardef\promile="2030
       %% Alternative \hyphenchar ("je-li" is no "je\hyphenchar li").
\let\extrahyphenchar=\undefined
\let\extrahyphens=\undefined
       %% The czech quotes:
\def\uv{\bgroup\aftergroup\closequotes\leavevmode
        \afterassignment\clqq\let\next=}
\def\closequotes{\unskip\crqq\relax}

%% (4) re-definition character-like macros from plainTeX:

\chardef \S  167
\chardef \P  182
\chardef \ss 223
\chardef \L  321
\chardef \l  322
\chardef \ae 230   
\chardef \oe 339
\chardef \o  248 
\chardef \AE 198   
\chardef \OE 338    
\chardef \O  216   
\chardef \i  305
\chardef \j  567
\chardef \aa 229
\chardef \AA 197   

\chardef \ellipsis   8230
\chardef \dag        8224
\chardef \ddag       8225
\chardef \textbullet 8226
\chardef \euro       8364
\chardef \trademark  8482
\chardef \copyright  169
\chardef \registered 174
\chardef \currency   164

% characters from T1 encoding:

\chardef \Eth       272
\chardef \NG        330
\chardef \Thorn     222
\chardef \eth       273
\chardef \ng        331
\chardef \thorn     254
\chardef \flq      8249
\chardef \frq      8250
\chardef \clq      8218
\chardef \crq      8216 % corrected form 8219, which is mirrored 9, no 6
\chardef \elqq     8220
\chardef \erqq     8221
\chardef \sterling  163  
\let\pound=\sterling

\endinput
