| 1 |
% File load-unicode-xetex-classes.tex |
| 2 |
% |
| 3 |
% Copyright 2015-2025 The LaTeX Project |
| 4 |
% |
| 5 |
% It may be distributed and/or modified under the conditions of |
| 6 |
% the LaTeX Project Public License (LPPL), either version 1.3c of |
| 7 |
% this license or (at your option) any later version. The latest |
| 8 |
% version of this license is in the file |
| 9 |
% http://www.latex-project.org/lppl.txt. |
| 10 |
% |
| 11 |
% Issues with this file should be reported at |
| 12 |
% https://github.com/latex3/unicode-data |
| 13 |
% |
| 14 |
% This file parses EastAsianWidth.txt and LineBreak.txt, provided by the |
| 15 |
% Unicode Consortium, and when used with XeTeX sets \XeTeXcharclass for |
| 16 |
% the following classes of code point: |
| 17 |
% - "ID" (ideographic) |
| 18 |
% - "CJ" (conditional Japanese starter) |
| 19 |
% - "OP" (opener) |
| 20 |
% - "CL" (closer) |
| 21 |
% - "NS" (non-starter) |
| 22 |
% - "EX" (exclamation) |
| 23 |
% - "IS" (infix separator) |
| 24 |
% - "CM" (combining marks) |
| 25 |
% |
| 26 |
% All code points of classes "ID" and "CJ" are assigned to a \XeTeXcharclass, |
| 27 |
% but for other classes this only occurs when they fall into east Asian width |
| 28 |
% type "F", "H" or "W" (full-, half- and wide-width). |
| 29 |
% |
| 30 |
% The following mappings between Unicode and XeTeX classes occur |
| 31 |
% - "ID" and "CJ" are class 1 |
| 32 |
% - "OP" is class 2 |
| 33 |
% - "CL", "NS", "EX", "IS" are class 3 |
| 34 |
% - "CM" is class 256 (ignored) |
| 35 |
% as standard: these may be over-ridden by defining \XeTeXcharclass<class> |
| 36 |
% as required. (If classes "ID" or "CL" are explicitly set, the other members |
| 37 |
% of the same groups above will inherit these values.) |
| 38 |
% |
| 39 |
% This file does _not_ activate XeTeX's inter-character token mechanism |
| 40 |
% (\XeTeXinterchartokenstate is not set) nor does it install any material in |
| 41 |
% the inter-character token registers. |
| 42 |
% |
| 43 |
% Note that this file is separate from the main loader as the data structure |
| 44 |
% here may need more refinement at the macro level. |
| 45 |
% |
| 46 |
% ============================================================================= |
| 47 |
% |
| 48 |
% The data loaded here can currently only be used by XeTeX: check for the |
| 49 |
% appropriate primitive. |
| 50 |
\ifx\XeTeXcharclass\undefined |
| 51 |
\expandafter\endinput |
| 52 |
\fi |
| 53 |
% Just in case, check for the e-TeX extensions. |
| 54 |
\ifx\eTeXversion\undefined |
| 55 |
\expandafter\endinput |
| 56 |
\fi |
| 57 |
% This file can be loaded in IniTeX mode so the category codes of |{|, |}| and |
| 58 |
% |#| may not be correct. Everything is done in a group so that only the |
| 59 |
% settings we want to propagate are made available generally. |
| 60 |
\begingroup |
| 61 |
\catcode`\{=1 % |
| 62 |
\catcode`\}=2 % |
| 63 |
% Write some basic information to the log. |
| 64 |
\catcode`\^=7 % |
| 65 |
\newlinechar=`\^^J % |
| 66 |
\message{^^J}% |
| 67 |
\message{load-unicode-xetex-classes.tex v1.19 (2025-09-26)^^J}% |
| 68 |
\message{Reading Unicode east Asian character class data^^J}% |
| 69 |
% A string version of |#| will be needed to look for comment lines in the |
| 70 |
% source. Once that is done proper parsing can begin. |
| 71 |
\catcode`\#=12 % |
| 72 |
\def\hash{#}% |
| 73 |
\catcode`\#=6 % |
| 74 |
\def\firsttoken#1#2\relax{#1}% |
| 75 |
\def\parseunicodedataI#1\relax{% |
| 76 |
\unless\if\hash\firsttoken#1?\relax |
| 77 |
\parseunicodedataII#1\relax |
| 78 |
\fi |
| 79 |
}% |
| 80 |
% Both files to be parsed here have potential ranges of code points: find the |
| 81 |
% first entry and search for the second. |
| 82 |
\def\parseunicodedataII#1; #2 #3\relax{% |
| 83 |
\parseunicodedataIII#1....\relax{#2}% |
| 84 |
}% |
| 85 |
% From plain: may not be defined (yet). |
| 86 |
\def\loop#1\repeat{\def\body{#1}\iterate}% |
| 87 |
\def\iterate{% |
| 88 |
\body |
| 89 |
\let\next\iterate |
| 90 |
\else |
| 91 |
\let\next\relax |
| 92 |
\fi |
| 93 |
\next |
| 94 |
}% |
| 95 |
\let\repeat\fi |
| 96 |
% A shared routine for reading the data files: only one part of the parser |
| 97 |
% has to be altered. |
| 98 |
\def\storedpar{\par}% |
| 99 |
\def\readandparse#1{% |
| 100 |
\openin0=#1.txt % |
| 101 |
% Read two lines from the source file to extract the version information |
| 102 |
\catcode`\#=12 % |
| 103 |
\read0 to \unicodedataline |
| 104 |
\message{\unicodedataline ^^J}% |
| 105 |
\read0 to \unicodedataline |
| 106 |
\message{\unicodedataline ^^J}% |
| 107 |
\loop\unless\ifeof0 % |
| 108 |
\read0 to \unicodedataline |
| 109 |
\unless\ifx\unicodedataline\storedpar |
| 110 |
\expandafter\parseunicodedataI\unicodedataline\relax |
| 111 |
\fi |
| 112 |
\repeat |
| 113 |
\catcode`\#=6 % |
| 114 |
\closein0 % |
| 115 |
}% |
| 116 |
% Set up the different line break classes recognised. |
| 117 |
\ifdefined\XeTeXcharclassID |
| 118 |
\else |
| 119 |
\chardef\XeTeXcharclassID=1 % |
| 120 |
\fi |
| 121 |
\ifdefined\XeTeXcharclassCJ |
| 122 |
\else |
| 123 |
\let\XeTeXcharclassCJ\XeTeXcharclassID |
| 124 |
\fi |
| 125 |
\ifdefined\XeTeXcharclassOP |
| 126 |
\else |
| 127 |
\chardef\XeTeXcharclassOP=2 % |
| 128 |
\fi |
| 129 |
\ifdefined\XeTeXcharclassCL |
| 130 |
\else |
| 131 |
\chardef\XeTeXcharclassCL=3 % |
| 132 |
\fi |
| 133 |
\ifdefined\XeTeXcharclassEX |
| 134 |
\else |
| 135 |
\let\XeTeXcharclassEX\XeTeXcharclassCL |
| 136 |
\fi |
| 137 |
\ifdefined\XeTeXcharclassIS |
| 138 |
\else |
| 139 |
\let\XeTeXcharclassIS\XeTeXcharclassCL |
| 140 |
\fi |
| 141 |
\ifdefined\XeTeXcharclassNS |
| 142 |
\else |
| 143 |
\let\XeTeXcharclassNS\XeTeXcharclassCL |
| 144 |
\fi |
| 145 |
\ifdefined\XeTeXcharclassCM |
| 146 |
\else |
| 147 |
\chardef\XeTeXcharclassCM=256 % |
| 148 |
\fi |
| 149 |
% Check the line break class and if necessary the east Asian width for the |
| 150 |
% current code point. For code points of class |ID| or |CJ| there may be a |
| 151 |
% range to set, and these are always recorded. In other cases if the code point |
| 152 |
% is one of those we may need to set up then save it for checking against the |
| 153 |
% list of east Asian widths. |
| 154 |
\def\ID{ID}% |
| 155 |
\def\CJ{CJ}% |
| 156 |
\def\parseunicodedataIII#1..#2..#3\relax#4{% |
| 157 |
\def\temp{#4}% |
| 158 |
\ifnum 0% |
| 159 |
\ifx\temp\ID 1\fi |
| 160 |
\ifx\temp\CJ 1\fi |
| 161 |
>0 % |
| 162 |
\ifx\relax#2\relax |
| 163 |
\parseunicodedataIV{#1}{#1}{#4}% |
| 164 |
\else |
| 165 |
\parseunicodedataIV{#1}{#2}{#4}% |
| 166 |
\fi |
| 167 |
\else |
| 168 |
\ifcsname XeTeXcharclass#4\endcsname |
| 169 |
\ifx\relax#2\relax |
| 170 |
\expandafter\def\csname LB@\number"#1\endcsname{#4}% |
| 171 |
\else |
| 172 |
\let\savedbody\body |
| 173 |
\count0="#1 % |
| 174 |
\loop |
| 175 |
\unless\ifnum\count0>"#2 % |
| 176 |
\expandafter\def\csname LB@\number\count0 \endcsname{#4}% |
| 177 |
\advance\count0 by 1 % |
| 178 |
\repeat |
| 179 |
\let\body\savedbody |
| 180 |
\fi |
| 181 |
\fi |
| 182 |
\fi |
| 183 |
}% |
| 184 |
% As we are inside a loop already, there needs to be a group here to preserve |
| 185 |
% the iterator. |
| 186 |
\def\parseunicodedataIV#1#2#3{% |
| 187 |
\begingroup |
| 188 |
\count0="#1 % |
| 189 |
\loop |
| 190 |
\unless\ifnum\count0>"#2 % |
| 191 |
\global\XeTeXcharclass\count0=\csname XeTeXcharclass#3\endcsname |
| 192 |
\advance\count0 by 1 % |
| 193 |
\repeat |
| 194 |
\endgroup |
| 195 |
}% |
| 196 |
\readandparse{LineBreak}% |
| 197 |
% For |EastAsianWidth.txt|, action is only needed if the character has width |
| 198 |
% |F|, |H| or |W|. Once again there may be a range of characters to handle. |
| 199 |
\def\parseunicodedataIII#1..#2..#3\relax#4{% |
| 200 |
\ifnum 0% |
| 201 |
\if F\firsttoken#4\relax 1\fi |
| 202 |
\if H\firsttoken#4\relax 1\fi |
| 203 |
\if W\firsttoken#4\relax 1\fi |
| 204 |
>0 % |
| 205 |
\ifx\relax#2\relax |
| 206 |
\parseunicodedataIV{"#1}% |
| 207 |
\else |
| 208 |
\begingroup |
| 209 |
\count0="#1 % |
| 210 |
\loop |
| 211 |
\unless\ifnum\count0>"#2 % |
| 212 |
\parseunicodedataIV{\count0}% |
| 213 |
\advance\count0 by 1 % |
| 214 |
\repeat |
| 215 |
\endgroup |
| 216 |
\fi |
| 217 |
\fi |
| 218 |
}% |
| 219 |
% Only take action if a line breaking class was previously saved: that will |
| 220 |
% map to the correct class number. |
| 221 |
\def\parseunicodedataIV#1{% |
| 222 |
\ifcsname LB@\number#1\endcsname |
| 223 |
\global\XeTeXcharclass#1= |
| 224 |
\csname XeTeXcharclass\csname LB@\number#1\endcsname\endcsname |
| 225 |
\fi |
| 226 |
}% |
| 227 |
\readandparse{EastAsianWidth}% |
| 228 |
\endgroup |