% File load-unicode-xetex-classes.tex % % Copyright 2015,2016 The LaTeX3 Project % % It may be distributed and/or modified under the conditions of % the LaTeX Project Public License (LPPL), either version 1.3c of % this license or (at your option) any later version. The latest % version of this license is in the file % http://www.latex-project.org/lppl.txt. % % Issues with this file should be reported at % https://github.com/latex3/unicode-data % % This file parses EastAsianWidth.txt and LineBreak.txt, provided by the % Unicode Consortium, and when used with XeTeX sets \XeTeXcharclass for % the following classes of code point: % - "ID" (ideographic) % - "OP" (opener) % - "CL" (closer) % - "NS" (non-starter) % - "EX" (exclamation) % - "IS" (infix separator) % - "CM" (combining marks) % % All code points of class "ID" are assigned to a \XeTeXcharclass, but for % other classes this only occurs when they fall into east Asian width type % "F", "H" or "W" (full-, half- and wide-width). % % The following mappings between Unicode and XeTeX classes occur % - "ID" is class 1 % - "OP" is class 2 % - "CL", "NS", "EX", "IS" are class 3 % - "CM" is class 256 (ignored) % as standard: these may be over-ridden by defining \XeTeXcharclass % as required. % % This file does _not_ activate XeTeX's inter-character token mechanism % (\XeTeXinterchartokenstate is not set) nor does it install any material in % the inter-character token registers. % % Note that this file is separate from the main loader as the data structure % here may need more refinement at the macro level. % % ============================================================================= % % The data loaded here can currently only be used by XeTeX: check for the % appropriate primitive. \ifx\XeTeXcharclass\undefined \expandafter\endinput \fi % Just in case, check for the e-TeX extensions. \ifx\eTeXversion\undefined \expandafter\endinput \fi % This file can be loaded in IniTeX mode so the category codes of |{|, |}| and % |#| may not be correct. Everything is done in a group so that only the % settings we want to propagate are made available generally. \begingroup \catcode`\{=1 % \catcode`\}=2 % % Write some basic information to the log. \catcode`\^=7 % \newlinechar=`\^^J % \message{^^J}% \message{load-unicode-xetex-classes.tex v1.1a (2016-01-06)^^J}% \message{Reading Unicode east Asian character class data^^J}% % A string version of |#| will be needed to look for comment lines in the % source. Once that is done proper parsing can begin. \catcode`\#=12 % \def\hash{#}% \catcode`\#=6 % \def\firsttoken#1#2\relax{#1}% \def\parseunicodedataI#1\relax{% \unless\if\hash\firsttoken#1?\relax \parseunicodedataII#1\relax \fi }% % Both files to be parsed here have potential ranges of code points: find the % first entry and search for the second. \def\parseunicodedataII#1;#2 #3\relax{% \parseunicodedataIII#1....\relax{#2}% }% % From plain: may not be defined (yet). \def\loop#1\repeat{\def\body{#1}\iterate}% \def\iterate{% \body \let\next\iterate \else \let\next\relax \fi \next }% \let\repeat\fi % For the East Asian width data, save the class of the current token. \def\parseunicodedataIII#1..#2..#3\relax#4{% \expandafter\def\csname EAW@\number"#1\endcsname{#4}% \ifx\relax#2\relax \else \let\savedbody\body \count0="#1 % \loop \ifnum\count0<"#2 % \advance\count0 by 1 % \expandafter\def\csname EAW@\number\count0\endcsname{#4}% \repeat \let\body\savedbody \fi }% % A shared routine for reading the data files: only one part of the parser % has to be altered. \def\storedpar{\par}% \def\readandparse#1{% \openin0=#1.txt % % Read two lines from the source file to extract the version information \catcode`\#=12 % \read0 to \unicodedataline \message{\unicodedataline ^^J}% \read0 to \unicodedataline \message{\unicodedataline ^^J}% \loop\unless\ifeof0 % \read0 to \unicodedataline \unless\ifx\unicodedataline\storedpar \expandafter\parseunicodedataI\unicodedataline\relax \fi \repeat \catcode`\#=6 % \closein0 % }% % Read the east Asian width data: no settings are made at this stage. \readandparse{EastAsianWidth}% % Set up the different line break classes recognised. \ifdefined\XeTeXcharclassID \else \chardef\XeTeXcharclassID=1 % \fi \ifdefined\XeTeXcharclassOP \else \chardef\XeTeXcharclassOP=2 % \fi \ifdefined\XeTeXcharclassCL \else \chardef\XeTeXcharclassCL=3 % \fi \ifdefined\XeTeXcharclassEX \else \chardef\XeTeXcharclassEX=3 % \fi \ifdefined\XeTeXcharclassIS \else \chardef\XeTeXcharclassIS=3 % \fi \ifdefined\XeTeXcharclassNS \else \chardef\XeTeXcharclassNS=3 % \fi \ifdefined\XeTeXcharclassCM \else \chardef\XeTeXcharclassCM=256 % \fi % Check the line break class and if necessary the east Asian width for the % current code point. For code points of class |ID| there may be a range to % set, and these are always recorded. In other cases check the east Asian width % and set the class if appropriate. \def\ID{ID}% \def\parseunicodedataIII#1..#2..#3\relax#4{% \def\temp{#4}% \ifx\temp\ID \ifx\relax#2\relax \parseunicodedataIV{#1}{#1}% \else \parseunicodedataIV{#1}{#2}% \fi \else \ifnum 0% \if F\csname EAW@\number"#1\endcsname 1\fi \if H\csname EAW@\number"#1\endcsname 1\fi \if W\csname EAW@\number"#1\endcsname 1\fi >0 % \global\XeTeXcharclass"#1=\csname XeTeXcharclass#4\endcsname \fi \fi }% % As we are inside a loop already, there needs to be a group here to preserve % the iterator. \def\parseunicodedataIV#1#2{% \begingroup \count0="#1 % \loop \ifnum\count0<"#2 % \global\XeTeXcharclass\count0=\XeTeXcharclassID \advance\count0 by 1 % \repeat \endgroup }% \readandparse{LineBreak}% \endgroup