Debian Codegraph @

texmf-dist/tex/generic/unicode-data/load-unicode-math-classes.tex

raw
1 % File load-unicode-math-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 MathClass.txt, provided by the Unicode Consortium, and sets
15 % up the following mapping between Unicode classes and TeX math types
16 % - "L" (large) \mathop
17 % - "B" (binary) \mathbin
18 % - "V" (vary) \mathbin
19 % - "R" (relation) \mathrel
20 % - "O" (opening) \mathopen
21 % - "C" (closing) \mathclose
22 % - "P" (punctuation) \mathpunct
23 % - "A" (alphabetic) \mathalpha
24 %
25 % For each code point processed, the result is of the form
26 %
27 % \Umathcode <codepoint> = <type> 1 <codepoint>
28 %
29 % =============================================================================
30 %
31 % The data can only be loaded by Unicode engines. Currently this is limited to
32 % XeTeX and LuaTeX, both of which define \Umathcode.
33 \ifx\Umathcode\undefined
34 \expandafter\endinput
35 \fi
36 % Just in case, check for the e-TeX extensions.
37 \ifx\eTeXversion\undefined
38 \expandafter\endinput
39 \fi
40 % This file can be loaded in IniTeX mode so the category codes of |{|, |}| and
41 % |#| may not be correct. Everything is done in a group so that only the
42 % settings we want to propagate are made available generally.
43 \begingroup
44 \catcode`\{=1 %
45 \catcode`\}=2 %
46 \catcode`\#=6 %
47 % Write some basic information to the log.
48 \catcode`\^=7 %
49 \newlinechar=`\^^J %
50 \message{^^J}%
51 \message{load-unicode-math-classes.tex v1.19 (2025-09-26)^^J}%
52 \message{Reading math class data^^J}%
53 % The parser for data lines starts by skipping any comments (which start with
54 % a |#| and which will be category code~$12$).
55 \edef\hash{\string#}%
56 \def\firsttoken#1#2\relax{#1}%
57 \def\parseunicodedataI#1\relax{%
58 \unless\if\hash\firsttoken#1?\relax
59 \parseunicodedataII#1\relax
60 \fi
61 }%
62 % The first entry in each data line is a code point or range of code points:
63 % set up to find a range if present.
64 \def\parseunicodedataII#1;#2\relax{%
65 \parseunicodedataIII#1....\relax{#2}%
66 }%
67 \def\parseunicodedataIII#1..#2..#3\relax#4{%
68 \ifx\relax#2\relax
69 \parseunicodedataIV{#1}{#1}#4\relax
70 \else
71 \parseunicodedataIV{#1}{#2}#4\relax
72 \fi
73 }%
74 % Examine the Unicode class and if known set up the math code appropriately.
75 \chardef\mathclassL=1 %
76 \chardef\mathclassB=2 %
77 \chardef\mathclassV=2 %
78 \chardef\mathclassR=3 %
79 \chardef\mathclassO=4 %
80 \chardef\mathclassC=5 %
81 \chardef\mathclassP=6 %
82 \chardef\mathclassA=7 %
83 \def\parseunicodedataIV#1#2#3#4\relax{%
84 \begingroup
85 \count0="#1 %
86 \loop
87 \unless\ifnum\count0>"#2 %
88 \ifcsname mathclass#3\endcsname
89 \global\Umathcode\count0=\csname mathclass#3\endcsname 1 \count0 %
90 \fi
91 \advance\count0 by 1 %
92 \repeat
93 \endgroup
94 }%
95 % From plain: may not be defined (yet).
96 \def\loop#1\repeat{\def\body{#1}\iterate}%
97 \def\iterate{%
98 \body
99 \let\next\iterate
100 \else
101 \let\next\relax
102 \fi
103 \next
104 }%
105 \let\repeat\fi
106 % Now we can load the data.
107 \catcode`\#=12 %
108 \def\storedpar{\par}%
109 \openin0=MathClass-15.txt %
110 \read0 to \unicodedataline
111 \message{\unicodedataline ^^J}%
112 \read0 to \unicodedataline
113 \message{\unicodedataline ^^J}%
114 \loop\unless\ifeof0 %
115 \read0 to \unicodedataline
116 \unless\ifx\unicodedataline\storedpar
117 \expandafter\parseunicodedataI\unicodedataline\relax
118 \fi
119 \repeat
120 \closein0 %
121 \endgroup