Debian Codegraph @

texmf-dist/source/latex/unicode-math/um-code-fontopt.dtx

raw
1 %%^^A%% um-code-fontopt.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>
2 %%^^A%% Keyval for `\setmathfont`
3
4 % \section{Font loading options}
5 %
6 % \begin{macrocode}
7 %<*package>
8 % \end{macrocode}
9 %
10 % \subsection{Math version}
11 % \begin{macrocode}
12 \keys_define:nn {unicode-math}
13 {
14 version .code:n =
15 {
16 \tl_set:Nn \l_@@_mversion_tl {#1}
17 \DeclareMathVersion {\l_@@_mversion_tl}
18 }
19 }
20 % \end{macrocode}
21 %
22 % \subsection{Script and scriptscript font options}
23 % \begin{macrocode}
24 \keys_define:nn {unicode-math}
25 {
26 script-features .tl_set:N = \l_@@_script_features_tl ,
27 sscript-features .tl_set:N = \l_@@_sscript_features_tl ,
28 script-font .tl_set:N = \l_@@_script_font_tl ,
29 sscript-font .tl_set:N = \l_@@_sscript_font_tl ,
30 }
31 % \end{macrocode}
32 %
33 % \subsection{Range processing}
34 % \seclabel{rangeproc}
35 %
36 % Locally redefined all math symbol commands to their slot number prefixed by a quark.
37 % Similarly for the math classes.
38 % \begin{macrocode}
39 \keys_define:nn {unicode-math}
40 {
41 range .code:n =
42 {
43 \bool_if:NF \g_@@_main_font_defined_bool { \@@_error:n {no-main-font} }
44 \bool_gset_false:N \g_@@_init_bool
45 \@@_range_init:
46 \group_begin:
47 \seq_map_inline:Nn \g_@@_mathclasses_seq
48 {
49 \cs_set:Npn ##1 { \use_none:n \q_unicode_math \exp_not:N ##1 }
50 }
51 \cs_set:Npn \_@@_sym:nnn ##1 ##2 ##3
52 {
53 \cs_set:Npn ##2 { \use_none:n \q_unicode_math ##1 }
54 }
55 \@@_input_math_symbol_table:
56 \@@_range_process:n {#1}
57 \group_end:
58 }
59 }
60 % \end{macrocode}
61 %
62 % \begin{macro}{\@@_range_init:}
63 % Set processing functions if we're not defining the full Unicode math repetoire.
64 % Math symbols are defined with \cmd\_@@_sym:nnn; see \secref{mathsymbol}
65 % for the individual definitions
66 % \begin{macrocode}
67 \@@_cs_new:Nn \@@_range_init:
68 {
69 \int_gincr:N \g_@@_fam_int
70 \tl_set:Nx \l_@@_symfont_label_tl {@@_fam\int_use:N\g_@@_fam_int}
71 \cs_set_eq:NN \_@@_sym:nnn \@@_process_symbol_parse:nnn
72 \cs_set_eq:NN \@@_remap_symbol:nnn \@@_remap_symbol_parse:nnn
73 \cs_set_eq:NN \@@_maybe_init_alphabet:n \use_none:n
74 \cs_set_eq:NN \@@_assign_delcode:nn \@@_assign_delcode_parse:nn
75 \cs_set_eq:NN \@@_make_mathactive:nNN \@@_make_mathactive_parse:nNN
76 % \end{macrocode}
77 % Proceed by filling up the various `range' seqs according to the user options.
78 % \begin{macrocode}
79 \seq_gclear:N \g_@@_char_range_seq
80 \seq_gclear:N \g_@@_mclass_range_seq
81 \seq_gclear:N \g_@@_mathalph_seq
82 }
83 % \end{macrocode}
84 % \end{macro}
85 %
86 % \begin{macro}{\@@_range_process:}
87 % \begin{macrocode}
88 \cs_new:Nn \@@_range_process:n
89 {
90 \clist_map_inline:nn {#1}
91 {
92 \@@_mathalph_decl:nF {##1} { \@@_range_decl:n {##1} }
93 }
94 }
95 % \end{macrocode}
96 % \end{macro}
97 %
98 % \begin{macro}{\@@_mathalph_decl:nF}
99 % Possible forms of input:\\
100 % |\mathscr|\\
101 % |\mathscr->\mathup|\\
102 % |\mathscr/{Latin}|\\
103 % |\mathscr/{Latin}->\mathup|\\
104 % Outputs:\\
105 % |tmpa|: math style (\eg, |\mathscr|)\\
106 % |tmpb|: alphabets (\eg, |Latin|)\\
107 % |tmpc|: remap style (\eg, |\mathup|). Defaults to |tmpa|.
108 %
109 % The remap style can also be |\mathcal->stixcal|, which I marginally prefer
110 % in the general case.
111 % \begin{macrocode}
112 \cs_new:Nn \@@_mathalph_decl:nF
113 {
114 \tl_set:Nn \l_@@_tmpa_tl {#1}
115 \tl_clear:N \l_@@_tmpb_tl
116 \tl_clear:N \l_@@_tmpc_tl
117
118 \tl_if_in:NnT \l_@@_tmpa_tl {->}
119 { \exp_after:wN \@@_split_arrow:w \l_@@_tmpa_tl \q_nil }
120
121 \tl_if_in:NnT \l_@@_tmpa_tl {/}
122 { \exp_after:wN \@@_split_slash:w \l_@@_tmpa_tl \q_nil }
123
124 \tl_set:Nx \l_@@_tmpa_tl { \tl_to_str:N \l_@@_tmpa_tl }
125 \exp_args:NNx \tl_remove_all:Nn \l_@@_tmpa_tl { \token_to_str:N \math }
126 \exp_args:NNx \tl_remove_all:Nn \l_@@_tmpa_tl { \token_to_str:N \sym }
127 \tl_trim_spaces:N \l_@@_tmpa_tl
128
129 \tl_if_empty:NT \l_@@_tmpc_tl
130 { \tl_set_eq:NN \l_@@_tmpc_tl \l_@@_tmpa_tl }
131
132 \clist_if_in:NVT \g_@@_bad_alpha_clist \l_@@_tmpa_tl { \@@_error:n {range-not-bf-sf} }
133
134 \prop_if_exist:cTF {g_@@_named_range_ \l_@@_tmpa_tl _prop}
135 {
136 \seq_gput_right:Nx \g_@@_mathalph_seq
137 {
138 { \exp_not:V \l_@@_tmpa_tl }
139 { \exp_not:V \l_@@_tmpb_tl }
140 { \exp_not:V \l_@@_tmpc_tl }
141 }
142 }
143 {#2}
144 }
145 % \end{macrocode}
146 %
147 % \begin{macrocode}
148 \cs_set:Npn \@@_split_arrow:w #1->#2 \q_nil
149 {
150 \tl_set:Nx \l_@@_tmpa_tl { \tl_trim_spaces:n {#1} }
151 \tl_set:Nx \l_@@_tmpc_tl { \tl_trim_spaces:n {#2} }
152 }
153 % \end{macrocode}
154 % \begin{macrocode}
155 \cs_set:Npn \@@_split_slash:w #1/#2 \q_nil
156 {
157 \tl_set:Nx \l_@@_tmpa_tl { \tl_trim_spaces:n {#1} }
158 \tl_set:Nx \l_@@_tmpb_tl { \tl_trim_spaces:n {#2} }
159 }
160 % \end{macrocode}
161 % \end{macro}
162 %
163 % \begin{macro}{\@@_range_decl:n}
164 % \begin{macrocode}
165 \cs_new_protected:Nn \@@_range_decl:n
166 {
167 \bool_lazy_and:nnTF { \tl_if_single_p:n {#1} } { \token_if_cs_p:N #1 }
168 % IF A CSNAME:
169 {
170 \tl_if_in:VnTF #1 { \q_unicode_math }
171 {
172 \seq_if_in:NnTF \g__um_mathclasses_seq {#1}
173 { \seq_gput_right:Nn \g_@@_mclass_range_seq {#1} }
174 { \seq_gput_right:Nx \g_@@_char_range_seq { #1 } }
175 }
176 { \@@_error:nx {bad-cs-in-range} { \tl_to_str:n {#1} } }
177 }
178 % ELSE ASSUME NUMERIC INPUT:
179 {
180 \seq_gput_right:Nx \g_@@_char_range_seq { #1 }
181 }
182 }
183 % \end{macrocode}
184 % \end{macro}
185 %
186 %
187 % \begin{macro}{\@@_if_char_spec:nNT}
188 % \darg{Unicode character slot}
189 % \darg{control sequence (math class)}
190 % \darg{code to execute}
191 % This macro expands to |#3|
192 % if any of its arguments are contained in \cmd\g_@@_char_range_seq.
193 % This list can contain either character ranges (for checking with |#1|) or control sequences.
194 % These latter can either be the command name of a specific character, \emph{or} the math
195 % type of one (\eg, \cmd\mathbin).
196 %
197 % Character ranges are passed to \cs{@@_if_char_spec:nNT}, which accepts input in the form shown in \tabref{ranges}.
198 %
199 % \begin{table}[htbp]
200 % \centering
201 % \topcaption{Ranges accepted by \cs{@@_if_char_spec:nNT}.}
202 % \label{tab:ranges}
203 % \begin{tabular}{>{\ttfamily}cc}
204 % \textrm{Input} & Range \\
205 % \hline
206 % x & $r=x$ \\
207 % x- & $r\geq x$ \\
208 % -y & $r\leq y$ \\
209 % x-y & $x \leq r \leq y$ \\
210 % \end{tabular}
211 % \end{table}
212 %
213 % We have three tests, performed sequentially in order of execution time.
214 % Any test finding a match jumps directly to the end.
215 % \begin{macrocode}
216 \cs_new:Nn \@@_if_char_spec:nNT
217 {
218 % math class:
219 \seq_if_in:NnT \g_@@_mclass_range_seq {#2}
220 { \use_none_delimit_by_q_nil:w }
221
222 % character slot:
223 \seq_map_inline:Nn \g_@@_char_range_seq
224 {
225 \@@_int_if_slot_is_last_in_range:nnT {#1} {##1}
226 { \seq_gremove_all:Nn \g_@@_char_range_seq {##1} }
227
228 \@@_int_if_slot_in_range:nnT {#1} {##1}
229 { \seq_map_break:n { \use_none_delimit_by_q_nil:w } }
230 }
231
232 % the following expands to nil if no match was found:
233 \use_none:nnn
234 \q_nil
235 \use:n
236 {
237 \cs_if_eq:NNT #2 \mathalpha
238 {
239 \clist_put_right:Nx \l_@@_mathmap_charints_clist { \int_eval:n {#1} }
240 }
241 #3
242 }
243 }
244 % \end{macrocode}
245 % \end{macro}
246 %
247 % \begin{macro}{\@@_int_if_slot_in_range:nnT}
248 % Pretty basic comma separated range processing.
249 % Donald Arseneau's \pkg{selectp} package has a cleverer technique.
250 %
251 % A `numrange' is like |-2,5-8,12,17-| (can be unsorted).
252 %
253 % Four cases, four argument types:
254 % \begin{Verbatim}
255 % input #2 #3 #4
256 % "1 " [ 1] - [qn] - [ ] qs
257 % "1- " [ 1] - [ ] - [qn-] qs
258 % " -3" [ ] - [ 3] - [qn-] qs
259 % "1-3" [ 1] - [ 3] - [qn-] qs
260 % \end{Verbatim}
261 %
262 % \begin{macrocode}
263 \cs_new:Nn \@@_int_if_slot_in_range:nnT
264 {
265 \@@_numrange_parse:nwT {#1} #2 - \q_nil - \q_stop {#3}
266 }
267 % \end{macrocode}
268 %
269 % \begin{macrocode}
270 \cs_set:Npn \@@_numrange_parse:nwT #1 #2 - #3 - #4 \q_stop #5
271 {
272 \tl_if_empty:nTF {#4} { \int_compare:nT {#1=#2} {#5} }
273 {
274 \tl_if_empty:nTF {#3} { \int_compare:nT {#1>=#2} {#5} }
275 {
276 \tl_if_empty:nTF {#2} { \int_compare:nT {#1<=#3} {#5} }
277 {
278 \int_compare:nT {#1>=#2} { \int_compare:nT {#1<=#3} {#5} }
279 } } }
280 }
281 % \end{macrocode}
282 % \end{macro}
283 %
284 %
285 % \begin{macrocode}
286 \cs_new:Nn \@@_int_if_slot_is_last_in_range:nnT
287 {
288 \@@_numrange_last_parse:nwT {#1} #2 - \q_nil - \q_stop {#3}
289 }
290 % \end{macrocode}
291 %
292 % \begin{macrocode}
293 \cs_set:Npn \@@_numrange_last_parse:nwT #1 #2 - #3 - #4 \q_stop #5
294 {
295 \tl_if_empty:nTF {#4} { \int_compare:nT {#1==#2} {#5} }
296 {
297 \tl_if_empty:nTF {#2} { \int_compare:nT {#1==#3} {#5} }
298 {
299 \int_compare:nT {#1==#3} {#5}
300 } }
301 }
302 % \end{macrocode}
303 % \end{macro}
304 %
305 % \begin{macrocode}
306 %</package>
307 % \end{macrocode}
308
309 \endinput
310
311 % /©
312 %
313 % ------------------------------------------------
314 % The UNICODE-MATH package <wspr.io/unicode-math>
315 % ------------------------------------------------
316 % This package is free software and may be redistributed and/or modified under
317 % the conditions of the LaTeX Project Public License, version 1.3c or higher
318 % (your choice): <http://www.latex-project.org/lppl/>.
319 % ------------------------------------------------
320 % Copyright 2006-2019 Will Robertson, LPPL "maintainer"
321 % Copyright 2010-2017 Philipp Stephani
322 % Copyright 2011-2017 Joseph Wright
323 % Copyright 2012-2015 Khaled Hosny
324 % ------------------------------------------------
325 %
326 % ©/