summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bxbase/bxutf8.def
blob: 9fd21684250ea4cad69218ed5e3de6002680a8ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
%%
%% This is file 'bxutf8.def'.
%%
%
%% file declaration
\ProvidesFile{bxutf8.def}[2017/05/29 v1.1 BX UTF-8 input encoding]
%
% Note: All definitions in this file should be local.
% This file should not spill any spaces or \par.
%
%% code guards
% Here spaces are set back to effective. So great care must be taken
% so spaces should not be spilt out (in horizontal mode).
\catcode32=10\relax
\edef\bxus@i@restore@codes{%
  \catcode33=\the\catcode33%
  \catcode34=\the\catcode34%
  \catcode39=\the\catcode39%
  \catcode45=\the\catcode45%
  \catcode46=\the\catcode46%
  \catcode47=\the\catcode47%
  \catcode58=\the\catcode58%
  \catcode63=\the\catcode63%
  \catcode96=\the\catcode96%
\relax}
\catcode33=12 % <!>
\catcode34=12 % <">
\catcode39=12 % <'>
\catcode45=12 % <->
\catcode46=12 % <.>
\catcode47=12 % </>
\catcode58=12 % <:>
\catcode63=12 % <?>
\catcode96=12 % <`>
\g@addto@macro\bxus@i@restore@codes{%
  \let\bxus@i@restore@codes\@undefined}%
%
%--------------------------------------- dynamic part
%
% abort when this is first loaded after \begin{document}
\def\bxus@i@error{\PackageError{inputenc}}%
\ifx\@nodocument\relax
  \ifx\bxus@bxutf@loaded\@undefined
    \bxus@i@error
     {cannot load `bxutf8' after \string\begin{document}}\@eha
    \bxus@i@restore@codes\endinput\fi\fi
%
%% load 'utf8' encoding
\InputIfFileExists{utf8.def}{}%
  {\bxus@i@error{input encoding `utf8' unavailable}\@eha
    \bxus@i@restore@codes\endinput}%
\makeatletter     % is this needed??
%\@inpenc@test  % This is done in utf8.def
%
%% attach the hook
\def\UTFviii@two@octets#1#2{\expandafter\bxus@choice
  \csname u8:#1\string#2\endcsname#1#2.@}%
\def\UTFviii@three@octets#1#2#3{\expandafter\bxus@choice
  \csname u8:#1\string#2\string#3\endcsname#1#2#3@}%
\def\UTFviii@four@octets#1#2#3#4{\expandafter\bxus@choice@four
  \csname u8:#1\string#2\string#3\string#4\endcsname#1#2#3#4@}%
%
% When this file is reloaded, the 'static' part will be skipped.
\ifx\bxus@bxutf@loaded\@undefined\else
  \bxus@i@restore@codes\endinput \fi
\let\bxus@bxutf@loaded=t%
%
%--------------------------------------- static part
%
%% error messages
\def\bxus@err@uknbc{\bxus@i@error
  {Unknown non-BMP character found}%
  {bxutf8 cannot handle non-BMP characters.}}%
\def\bxus@err@nodrv{\bxus@i@error
  {Unicode driver not found}\@ehb}%
%
%% make tables for 'nybble conversion'
\def\bxus@fornbl{%
  \bxus@fornbl@a00001102203310411512613720821922A23B30C31D32E33FXXX}%
\def\bxus@fornbl@a#1#2#3{%
  \if X#1\else
  \@namedef{bxus@*#1#2}{#3}%
  \bxus@defchr{F#3}{0#1#2}\bxus@defchr{E#3}{#1#2}%
  \bxus@defchr{C#3}{000#1#2}\bxus@defchr{D#3}{001#1#2}%
  \bxus@defchr{8#3}{0#1#2}\bxus@defchr{9#3}{1#1#2}%
  \bxus@defchr{A#3}{2#1#2}\bxus@defchr{B#3}{3#1#2}%
  \expandafter\bxus@fornbl@a\fi}%
\def\bxus@defchr#1#2{%
  {\lccode`\!="#1%
   \lowercase{\expandafter\gdef\csname bxus@@!\endcsname{#2}}}}%
\bxus@fornbl \@namedef{bxus@@.}{}%
%
%% \bxcs@choice
% Called in the form
%   \bxus@choice[\u8:??]??.@  (2-byte) or
%   \bxus@choice[\u8:???]???@ (3-byte)
% where ?? is a (TF-8 byte string and [\u8:...] denotes a single
% control word. This macro expands to the control word if it is
% defined; otherwise expands to \bxus@proc.
\def\bxus@choice#1#2@{%
  \ifx#1\relax \bxus@proc#2%
  \else\expandafter#1\fi}%
%
%% \bxus@choice@four
\def\bxus@choice@four#1#2@{%
  \ifx#1\relax \bxus@prociv#2%
  \else\expandafter#1\fi}%
%
%% \bxus@proc
% When ??? is the UTF-8 string of U+XXXX (padded to length 3 with
% a dot), then \bxus@proc@a??? fully expands to \bxUHex{XXXX}.
% (\bxUHex should be robust.)
\def\bxus@proc#1#2#3{%
  \expandafter\bxus@proc@b\csname bxus@@\string#1\expandafter\endcsname
  \csname bxus@@\string#2\expandafter\endcsname
  \csname bxus@@\string#3\endcsname}%
\def\bxus@proc@b#1#2#3{%
  \expandafter\expandafter\expandafter\expandafter
  \expandafter\expandafter\expandafter\bxus@proc@c
  \expandafter\expandafter\expandafter#1%
  \expandafter#2#3}%
\def\bxus@proc@c#1#2#3#4#5#6#7#8{%
  \expandafter\bxus@proc@d\csname bxus@*#1#2\expandafter\endcsname
  \csname bxus@*#3#4\expandafter\endcsname
  \csname bxus@*#5#6\expandafter\endcsname
  \csname bxus@*#7#8\endcsname}%
\def\bxus@proc@d#1#2{%
  \expandafter\expandafter\expandafter\bxus@proc@e
  \expandafter#1#2\@nil}%
\def\bxus@proc@e#1\@nil#2#3{%
  \bxus@proc@f#2#3#1\@nil}%
\def\bxus@proc@f#1#2{%
  \expandafter\expandafter\expandafter\bxus@proc@g
  \expandafter#1#2\@nil}%
\def\bxus@proc@g#1\@nil#2\@nil{%
  \bxUHex{#2#1}}%
%
%% \bxus@prociv
% The variant of \bxus@proc that is adapted to 4-octet sequences.
\def\bxus@prociv#1#2#3#4{%
  \expandafter\bxus@prociv@a\csname bxus@@\string#1\expandafter\endcsname
  \csname bxus@@\string#2\expandafter\endcsname
  \csname bxus@@\string#3\expandafter\endcsname
  \csname bxus@@\string#4\endcsname}%
\def\bxus@prociv@a#1#2#3#4{%
  \expandafter\expandafter\expandafter\bxus@prociv@b
  \expandafter#3#4@#1#2}%
\def\bxus@prociv@b#1@#2#3{%
  \expandafter\expandafter\expandafter\bxus@prociv@c
  \expandafter#2#3#1@@}%
\def\bxus@prociv@c#1#2#3#4{%
  \expandafter\bxus@prociv@d\csname bxus@*#1#2\expandafter\endcsname
  \csname bxus@*#3#4\endcsname}%
\def\bxus@prociv@d#1#2{%
  \expandafter\expandafter\expandafter\bxus@prociv@e
  \expandafter#1#2}%
\def\bxus@prociv@e#1#2#3@#4@{\bxus@prociv@f#3@#4#1#2@}%
\def\bxus@prociv@f#1#2#3#4{%
  \expandafter\bxus@prociv@g\csname bxus@*#1#2\expandafter\endcsname
  \csname bxus@*#3#4\endcsname}%
\def\bxus@prociv@g#1#2{%
  \expandafter\expandafter\expandafter\bxus@prociv@h
  \expandafter#1#2}%
\def\bxus@prociv@h#1#2#3@#4@{\bxus@prociv@i#3@#4#1#2@}%
\def\bxus@prociv@i#1#2#3#4{%
  \expandafter\bxus@prociv@j\csname bxus@*#1#2\expandafter\endcsname
  \csname bxus@*#3#4\endcsname}%
\def\bxus@prociv@j#1#2{%
  \expandafter\expandafter\expandafter\bxus@prociv@k
  \expandafter#1#2}%
\def\bxus@prociv@k#1#2@#3@{\bxUHex{#3#1#2}}%
%
%
%% default (useless) Unicode driver
% Note: this \bxUHex definition is used for check.
\providecommand*\bxUHex{\bxUHexDummyBxutf}%
\newcommand*\bxUHexDummyBxutf[1]{?\protect\bxus@err@nodrv}%
%
%--------------------------------------- all done
\bxus@i@restore@codes
\endinput
%% EOF