summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/base/utf8ienc.dtx
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2015-10-01 22:00:12 +0000
committerKarl Berry <karl@freefriends.org>2015-10-01 22:00:12 +0000
commitb0a27fa1b235b8769c32d6a4af90697503bc5f7f (patch)
tree8d46da006822aaf3f3637823712a86f545512feb /Master/texmf-dist/source/latex/base/utf8ienc.dtx
parentdc8208998ecb52e2206b7943b322681502dd0ced (diff)
latex 2015/10/01
git-svn-id: svn://tug.org/texlive/trunk@38512 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/base/utf8ienc.dtx')
-rw-r--r--Master/texmf-dist/source/latex/base/utf8ienc.dtx166
1 files changed, 155 insertions, 11 deletions
diff --git a/Master/texmf-dist/source/latex/base/utf8ienc.dtx b/Master/texmf-dist/source/latex/base/utf8ienc.dtx
index a6756eabd4a..0c12a5d211b 100644
--- a/Master/texmf-dist/source/latex/base/utf8ienc.dtx
+++ b/Master/texmf-dist/source/latex/base/utf8ienc.dtx
@@ -47,7 +47,7 @@
%</driver>
% \fi
%
-% \CheckSum{1232}
+% \CheckSum{1361}
%
% \newpage
%
@@ -219,7 +219,7 @@
%<+ts1> \ProvidesFile{ts1enc.dfu}
%<+x2> \ProvidesFile{x2enc.dfu}
%<+all> \ProvidesFile{utf8enc.dfu}
- [2015/06/27 v1.1n UTF-8 support for inputenc]
+ [2015/09/07 v1.1p UTF-8 support for inputenc]
% \end{macrocode}
%
% \begin{macrocode}
@@ -295,8 +295,11 @@
% can't produce multiline strings without some precaution.
% \changes{v1.1b}{2004/02/09}{No newlines allowed in error messages}
% \changes{v1.1g}{2005/09/27}{Real spaces do not show up so use \cs{space}}
+% \changes{v1.1o}{2015/08/28}{Show Unicode number of character in hex}
% \begin{macrocode}
- \PackageError{inputenc}{Unicode\space char\space \string#1\space
+ \PackageError{inputenc}{Unicode\space char\space\expandafter
+ \UTFviii@splitcsname\string#1\relax
+ \MessageBreak
not\space set\space up\space
for\space use\space with\space LaTeX}\@eha
\else\expandafter
@@ -508,7 +511,8 @@
% totally (and we are too lazy to reread the Unicode book to see if
% this is the correct algorithm).\footnote{We were hoping to also
% find in his work the \TeX{} code for going the other way: from
-% UTF-8 octets to Unicode slot number, but no luck!}
+% UTF-8 octets to Unicode slot number, but no luck!
+% This has now been added as \cs{decode@UTFviii}}
% \begin{macrocode}
\else\ifnum\count@<"800\relax
\parse@UTFviii@a,%
@@ -554,12 +558,134 @@
\uccode`#3\count@
\uppercase{\gdef\UTFviii@tmp{#2#3#4}}}
% \end{macrocode}
+% \end{macro}
%
+% \begin{macro}{\decode@UTFviii}
+% \changes{v1.1o}{2015/08/28}{Macro added}
+% In the reverse direction, take a sequence of octects(bytes)
+% representing a character in UTF-8 and construct the Unicode number.
+% The sequence is terminated by |\relax|.
+%
+% In this version, if the sequence is not valid UTF-8 you probably
+% get a low level arithmetic error from |\numexpr| or stray characters
+% at the end. Getting a better error message would be somewhat expensive.
+% As the main use is for reporting characters in messages, this is done
+% just using expansion, so |\numexpr| is used, A stub returning 0 is defined
+% if |\numexpr| is not available.
% \begin{macrocode}
-\endgroup
+\ifx\numexpr\@undefined
+% \end{macrocode}
+%
+% \begin{macrocode}
+\gdef\decode@UTFviii#1{0}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\else
+% \end{macrocode}
+%
+% If the input is malformed UTF-8 there may not be enough closing ) so
+% add 5 so there are always some remaining then cleanup and remove
+% any remaining ones at the end. This avoids |\numexpr| parse errors
+% while outputting a package error.
+% \begin{macrocode}
+\gdef\decode@UTFviii#1\relax{%
+ \expandafter\UTFviii@cleanup
+ \the\numexpr\dec@de@UTFviii#1\relax)))))\@empty}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\gdef\UTFviii@cleanup#1)#2\@empty{#1}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\gdef\dec@de@UTFviii#1{%
+\ifx\relax#1%
+\else
+ \ifnum`#1>"EF
+ ((((`#1-"F0)%
+ \else
+ \ifnum`#1>"DF
+ (((`#1-"E0)%
+ \else
+ \ifnum`#1>"BF
+ ((`#1-"C0)%
+ \else
+ \ifnum`#1>"7F
+ )*64+(`#1-"80)%
+ \else
+ +`#1 %
+ \fi
+ \fi
+ \fi
+ \fi
+ \expandafter\dec@de@UTFviii
+\fi}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\fi
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\UTFviii@hexnumber}
+% \changes{v1.1o}{2015/08/28}{Macro added}
+% Convert a number to a sequence of uppercase hex digits.
+% If |\numexpr| is not available, it returns its argument unchanged.
+% \begin{macrocode}
+\ifx\numexpr\@undefined
+% \end{macrocode}
+% \begin{macrocode}
+\global\let\UTFviii@hexnumber\@firstofone
+\global\UTFviii@hexdigit\hexnumber@
+% \end{macrocode}
+% \begin{macrocode}
+\else
+% \end{macrocode}
+% \begin{macrocode}
+\gdef\UTFviii@hexnumber#1{%
+\ifnum#1>15 %
+\expandafter\UTFviii@hexnumber\expandafter{\the\numexpr(#1-8)/16\relax}%
+\fi
+\UTFviii@hexdigit{\numexpr#1\ifnum#1>0-((#1-8)/16)*16\fi\relax}%
+}
+% \end{macrocode}
+%
+% Almost but not quite |\hexnumber@|.
+% \begin{macrocode}
+\gdef\UTFviii@hexdigit#1{\ifcase\numexpr#1\relax
+ 0\or1\or2\or3\or4\or5\or6\or7\or8\or9\or
+ A\or B\or C\or D\or E\or F\fi}
+% \end{macrocode}
+%
+% \begin{macrocode}
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\UTFviii@splitcsname}
+% \changes{v1.1o}{2015/08/28}{Macro added}
+% Split a csname representing a unicode character and return
+% the character and (if |\numexpr| is defined) the unicode number in hex.
+% \begin{macrocode}
+\ifx\numexpr\@undefined
+\gdef\UTFviii@splitcsname#1:#2\relax{#2}}
+\else
+\gdef\UTFviii@splitcsname#1:#2\relax{%
+% \end{macrocode}
+% Need to pre-expand the argument to ensure cleanup in case of mal-formed UTF-8.
+% \begin{macrocode}
+#2 (U+\expandafter\UTFviii@hexnumber\expandafter{%
+ \the\numexpr\decode@UTFviii#2\relax})
+}
+\fi
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\endgroup
+% \end{macrocode}
+%
% \begin{macrocode}
\@onlypreamble\DeclareUnicodeCharacter
% \end{macrocode}
@@ -692,10 +818,6 @@
% and ultimately what a character is and what a character representation
% and/or name is.
%
-% Viewed this a way, the result has, perhaps puzzling, just two (we think)
-% gaps in the second 128 `Unicode slots' (00A0 and 00AD): neither of these
-% is really a character, of course.
-%
% It is unclear the extent to which entries in this table should
% resemble the closely related ones in the 8-bit \texttt{inputenc} files.
% The Unicode standard claims that the first 256 slots `are' ASCII and
@@ -709,12 +831,14 @@
%
% \subsection{The mapping table}
%
-% Note that the first argument must be a 4-hex-digit number greater
-% than \texttt{00BF}.
+% Note that the first argument must be a hex-digit number greater
+% than \texttt{00BF} and at most \texttt{10FFFF}.
%
% There are few notes about inconsistencies etc at the end of the table.
%
+% \changes{v1.1o}{2015/08/28}{Add U+00A0 and U+00AD}
% \begin{macrocode}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{00A0}{\nobreakspace}
%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{00A1}{\textexclamdown}
%<all,ts1,ly1>\DeclareUnicodeCharacter{00A2}{\textcent}
%<all,ts1,t1,ot1,ly1>\DeclareUnicodeCharacter{00A3}{\textsterling}
@@ -729,6 +853,7 @@
\DeclareUnicodeCharacter{00AB}{\guillemotleft}
%</all,x2,t2c,t2b,t2a,t1,ot2,ly1,lcy>
%<all,ts1>\DeclareUnicodeCharacter{00AC}{\textlnot}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{00AD}{\-}
%<all,ts1,ly1,utf8>\DeclareUnicodeCharacter{00AE}{\textregistered}
%<all,ts1>\DeclareUnicodeCharacter{00AF}{\textasciimacron}
%<all,ts1,ly1>\DeclareUnicodeCharacter{00B0}{\textdegree}
@@ -869,6 +994,14 @@
%<all,t1>\DeclareUnicodeCharacter{016F}{\r u}
%<all,t1>\DeclareUnicodeCharacter{0170}{\H U}
%<all,t1>\DeclareUnicodeCharacter{0171}{\H u}
+% \end{macrocode}
+%
+% \changes{v1.1p}{2015/09/07}{Welsh circumflex combinations}
+% \begin{macrocode}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0174}{\^W}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0175}{\^w}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0176}{\^Y}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0177}{\^y}
%<all,t1,ly1>\DeclareUnicodeCharacter{0178}{\"Y}
%<all,t1>\DeclareUnicodeCharacter{0179}{\@tabacckludge'Z}
%<all,t1>\DeclareUnicodeCharacter{017A}{\@tabacckludge'z}
@@ -877,6 +1010,17 @@
%<all,t1,ly1>\DeclareUnicodeCharacter{017D}{\v Z}
%<all,t1,ly1>\DeclareUnicodeCharacter{017E}{\v z}
%<all,ts1,ly1>\DeclareUnicodeCharacter{0192}{\textflorin}
+% \end{macrocode}
+%
+% \changes{v1.1o}{2015/08/28}{comma accent latex/4414}
+% \begin{macrocode}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0218}{\textcommabelow S}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{0219}{\textcommabelow s}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{021A}{\textcommabelow T}
+%<all,t1,ot1,ly1>\DeclareUnicodeCharacter{021B}{\textcommabelow t}
+% \end{macrocode}
+%
+% \begin{macrocode}
%<all,ly1,utf8>\DeclareUnicodeCharacter{02C6}{\textasciicircum}
%<all,ts1>\DeclareUnicodeCharacter{02C7}{\textasciicaron}
%<all,ly1,utf8>\DeclareUnicodeCharacter{02DC}{\textasciitilde}