| 1 |
% utf8unkn.tex |
| 2 |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 |
% Feb. 6. 2003 Petr Olsak |
| 4 |
% |
| 5 |
% Oct. 2012: More robust macros by \long, \noexpand, \badutfinput (P.O.) |
| 6 |
% |
| 7 |
% This macro sets all others UTF-8 codes (not declared formerly or |
| 8 |
% later) as "unknown" by encTeX primitives. You need the version |
| 9 |
% Feb. 2003 of encTeX or later. |
| 10 |
% |
| 11 |
% You can re-define the \warntwobytes and \warnthreebytes macros |
| 12 |
% if you need it. The default value of these macros is that |
| 13 |
% the black box is typeset and warning is printed by \message |
| 14 |
% and the unknown code is printed without any change to \write files. |
| 15 |
|
| 16 |
\def\setunknowncodes {\bgroup |
| 17 |
\def\a ##1{\mubyte \warntwobytes ####2 ##1\endmubyte} |
| 18 |
\a ^^c2 \a ^^c3 \a ^^c4 \a ^^c5 \a ^^c6 \a ^^c7 |
| 19 |
\a ^^c8 \a ^^c9 \a ^^ca \a ^^cb \a ^^cc \a ^^cd \a ^^ce \a ^^cf |
| 20 |
\a ^^d0 \a ^^d1 \a ^^d2 \a ^^d3 \a ^^d4 \a ^^d5 \a ^^d6 \a ^^d7 |
| 21 |
\a ^^d8 \a ^^d9 \a ^^da \a ^^db \a ^^dc \a ^^dd \a ^^de \a ^^df |
| 22 |
\def\a ##1{\mubyte \warnthreebytes ####3 ##1\endmubyte} |
| 23 |
\a ^^e0 \a ^^e1 \a ^^e2 \a ^^e3 \a ^^e4 \a ^^e5 \a ^^e6 \a ^^e7 |
| 24 |
\a ^^e8 \a ^^e9 \a ^^ea \a ^^eb \a ^^ec \a ^^ed \a ^^ee \a ^^ef |
| 25 |
\egroup} |
| 26 |
|
| 27 |
\mubyte \writeparameter \relax \endmubyte \def\writeparameter{} |
| 28 |
|
| 29 |
\long\def\warntwobytes #1#2{% |
| 30 |
\ifx\writeparameter\relax % write parameter copies unknown code |
| 31 |
\expandafter\noconvert\noexpand#1% |
| 32 |
\expandafter\noconvert\noexpand#2% to output without any change |
| 33 |
\else |
| 34 |
\if\noexpand#2\relax \badutfinput \else |
| 35 |
\ifnum`#2<128 \badutfinput \else |
| 36 |
\missingutfchar{\expandafter\noconvert\noexpand#1% |
| 37 |
\expandafter\noconvert\noexpand#2}% |
| 38 |
\fi\fi\fi} |
| 39 |
\long\def\warnthreebytes #1#2#3{\ifx\writeparameter\relax |
| 40 |
\expandafter\noconvert\noexpand#1% |
| 41 |
\expandafter\noconvert\noexpand#2% |
| 42 |
\expandafter\noconvert\noexpand#3% |
| 43 |
\else |
| 44 |
\if\noexpand#2\relax \badutfinput \else |
| 45 |
\ifnum`#2<128 \badutfinput \else |
| 46 |
\missingutfchar{\expandafter\noconvert\noexpand#1% |
| 47 |
\expandafter\noconvert\noexpand#2% |
| 48 |
\expandafter\noconvert\noexpand#3}% |
| 49 |
\fi\fi\fi} |
| 50 |
\def\badutfinput{{\errorcontextlines=-1 |
| 51 |
\errhelp={Try to set mubytein=0 or input utf8off or input mixcodes.} |
| 52 |
\errmessage{UTF-8 INPUT IS CORRUPTED ! |
| 53 |
\space May be you are using another input encoding}}} |
| 54 |
\def\missingutfchar#1{{\day=0 |
| 55 |
\ifnum\day=0 % this makes me more robust in message prameter |
| 56 |
\newlinechar=`^^J \chardef\$=\xprncode255 |
| 57 |
\xprncodes=1 \message{WARNING: unknown UTF-8 code: `#1 =}% |
| 58 |
\xprncodes=0 \message{#1' (line: \the\inputlineno)}% |
| 59 |
\xprncodes=\$ |
| 60 |
\leavevmode\hbox{\kern.05em\vrule width.5em height.5em\kern.05em}% |
| 61 |
\else unknown UTF-8 code `#1'\fi}} |
| 62 |
|
| 63 |
% \xprncodes=1 or \xprncodes=0 .. set/unset printability of 128..255 chars |
| 64 |
|
| 65 |
\def\xprncodes=#1 {% |
| 66 |
\count255=128 |
| 67 |
\loop \xprncode\count255=#1\advance\count255 by 1 |
| 68 |
\ifnum \count255<256 \repeat |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
\ifx\unknowncodes\relax \endinput \fi % you can \let\unknowncodes\relax |
| 73 |
% if you don't want to active |
| 74 |
% the warncodes immediatelly |
| 75 |
\setunknowncodes |
| 76 |
|
| 77 |
\endinput |