summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/unicode-math/um-code-fontopt.dtx
blob: 59805971ee78257de1bc7150e195ffcfb4967f93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
%%^^A%% um-code-fontopt.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>

% \section{Font loading options}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% \subsection{Math version}
%    \begin{macrocode}
\keys_define:nn {unicode-math}
  {
    version .code:n =
      {
        \tl_set:Nn \l_@@_mversion_tl {#1}
        \DeclareMathVersion {\l_@@_mversion_tl}
      }
  }
%    \end{macrocode}
%
% \subsection{Script and scriptscript font options}
%    \begin{macrocode}
\keys_define:nn {unicode-math}
 {
  script-features  .tl_set:N =  \l_@@_script_features_tl ,
  sscript-features .tl_set:N = \l_@@_sscript_features_tl ,
       script-font .tl_set:N =      \l_@@_script_font_tl ,
      sscript-font .tl_set:N =     \l_@@_sscript_font_tl ,
 }
%    \end{macrocode}
%
% \subsection{Range processing}
% \seclabel{rangeproc}
%
%    \begin{macrocode}
\keys_define:nn {unicode-math}
 {
  range .code:n =
   {
    \bool_set_false:N \l_@@_init_bool
%    \end{macrocode}
% Set processing functions if we're not defining the full Unicode math repetoire.
% Math symbols are defined with \cmd\_@@_sym:nnn; see \secref{mathsymbol}
% for the individual definitions
%    \begin{macrocode}
    \int_incr:N \g_@@_fam_int
    \tl_set:Nx \l_@@_symfont_label_tl {@@_fam\int_use:N\g_@@_fam_int}
    \cs_set_eq:NN \_@@_sym:nnn \@@_process_symbol_parse:nnn
    \cs_set_eq:NN \@@_set_mathalphabet_char:Nnn \@@_mathmap_parse:Nnn
    \cs_set_eq:NN \@@_remap_symbol:nnn \@@_remap_symbol_parse:nnn
    \cs_set_eq:NN \@@_maybe_init_alphabet:n \use_none:n
    \cs_set_eq:NN \@@_map_char_single:nn \@@_map_char_parse:nn
    \cs_set_eq:NN \@@_assign_delcode:nn \@@_assign_delcode_parse:nn
    \cs_set_eq:NN \@@_make_mathactive:nNN \@@_make_mathactive_parse:nNN
%    \end{macrocode}
% Proceed by filling up the various `range' seqs according to the user options.
%    \begin{macrocode}
    \seq_clear:N \l_@@_char_range_seq
    \seq_clear:N \l_@@_mclass_range_seq
    \seq_clear:N \l_@@_cmd_range_seq
    \seq_clear:N \l_@@_mathalph_seq

    \clist_map_inline:nn {#1}
     {
      \@@_if_mathalph_decl:nTF {##1}
       {
        \seq_put_right:Nx \l_@@_mathalph_seq
         {
          { \exp_not:V \l_@@_tmpa_tl }
          { \exp_not:V \l_@@_tmpb_tl }
          { \exp_not:V \l_@@_tmpc_tl }
         }
       }
       {
%    \end{macrocode}
% Four cases:
% math class matching the known list;
% single item that is a control sequence---command name;
% single item that isn't---edge case, must be 0--9;
% none of the above---char range.
%    \begin{macrocode}
        \seq_if_in:NnTF \g_@@_mathclasses_seq {##1}
          { \seq_put_right:Nn \l_@@_mclass_range_seq {##1} }
          {
            \bool_lazy_and:nnTF { \tl_if_single_p:n {##1} } { \token_if_cs_p:N ##1 }
              { \seq_put_right:Nn \l_@@_cmd_range_seq {##1} }
              { \seq_put_right:Nn \l_@@_char_range_seq {##1} }
          }
       }
     }
   }
 }
%    \end{macrocode}
%
%
% \begin{macro}{\@@_if_mathalph_decl:nTF}
% Possible forms of input:\\
% |\mathscr|\\
% |\mathscr->\mathup|\\
% |\mathscr/{Latin}|\\
% |\mathscr/{Latin}->\mathup|\\
% Outputs:\\
% |tmpa|: math style (\eg, |\mathscr|)\\
% |tmpb|: alphabets (\eg, |Latin|)\\
% |tmpc|: remap style (\eg, |\mathup|). Defaults to |tmpa|.
%
% The remap style can also be |\mathcal->stixcal|, which I marginally prefer
% in the general case.
%    \begin{macrocode}
\prg_new_conditional:Nnn \@@_if_mathalph_decl:n {TF}
 {
  \tl_set:Nn  \l_@@_tmpa_tl {#1}
  \tl_clear:N \l_@@_tmpb_tl
  \tl_clear:N \l_@@_tmpc_tl

  \tl_if_in:NnT \l_@@_tmpa_tl {->}
   { \exp_after:wN \@@_split_arrow:w \l_@@_tmpa_tl \q_nil }

  \tl_if_in:NnT \l_@@_tmpa_tl {/}
   { \exp_after:wN \@@_split_slash:w \l_@@_tmpa_tl \q_nil }

  \tl_set:Nx \l_@@_tmpa_tl { \tl_to_str:N \l_@@_tmpa_tl }
  \exp_args:NNx \tl_remove_all:Nn \l_@@_tmpa_tl { \token_to_str:N \math }
  \exp_args:NNx \tl_remove_all:Nn \l_@@_tmpa_tl { \token_to_str:N \sym }
  \tl_trim_spaces:N \l_@@_tmpa_tl

  \tl_if_empty:NT \l_@@_tmpc_tl
   { \tl_set_eq:NN \l_@@_tmpc_tl \l_@@_tmpa_tl }

  \seq_if_in:NVTF \g_@@_named_ranges_seq \l_@@_tmpa_tl
   { \prg_return_true: } { \prg_return_false: }
 }
%    \end{macrocode}
%    \begin{macrocode}
\cs_set:Npn \@@_split_arrow:w #1->#2 \q_nil
 {
  \tl_set:Nx \l_@@_tmpa_tl { \tl_trim_spaces:n {#1} }
  \tl_set:Nx \l_@@_tmpc_tl { \tl_trim_spaces:n {#2} }
 }
%    \end{macrocode}
%    \begin{macrocode}
\cs_set:Npn \@@_split_slash:w #1/#2 \q_nil
 {
  \tl_set:Nx \l_@@_tmpa_tl { \tl_trim_spaces:n {#1} }
  \tl_set:Nx \l_@@_tmpb_tl { \tl_trim_spaces:n {#2} }
 }
%    \end{macrocode}
% \end{macro}
%
% Pretty basic comma separated range processing.
% Donald Arseneau's \pkg{selectp} package has a cleverer technique.
%
% \begin{macro}{\@@_if_char_spec:nNNT}
% \darg{Unicode character slot}
% \darg{control sequence (character macro)}
% \darg{control sequence (math class)}
% \darg{code to execute}
% This macro expands to |#4|
% if any of its arguments are contained in \cmd\l_@@_char_range_seq.
% This list can contain either character ranges (for checking with |#1|) or control sequences.
% These latter can either be the command name of a specific character, \emph{or} the math
% type of one (\eg, \cmd\mathbin).
%
% Character ranges are passed to \cs{@@_if_char_spec:nNNT}, which accepts input in the form shown in \tabref{ranges}.
%
% \begin{table}[htbp]
% \centering
% \topcaption{Ranges accepted by \cs{@@_if_char_spec:nNNT}.}
% \label{tab:ranges}
% \begin{tabular}{>{\ttfamily}cc}
% \textrm{Input} & Range \\
% \hline
% x & $r=x$ \\
% x- & $r\geq x$ \\
% -y & $r\leq y$ \\
% x-y & $x \leq r \leq y$ \\
% \end{tabular}
% \end{table}
%
% We have three tests, performed sequentially in order of execution time.
% Any test finding a match jumps directly to the end.
%    \begin{macrocode}
\cs_new:Nn \@@_if_char_spec:nNNT
  {
    % math class:
    \seq_if_in:NnT \l_@@_mclass_range_seq {#3}
      { \use_none_delimit_by_q_nil:w }

    % command name:
    \seq_if_in:NnT \l_@@_cmd_range_seq {#2}
      { \use_none_delimit_by_q_nil:w }

    % character slot:
    \seq_map_inline:Nn \l_@@_char_range_seq
      {
        \@@_int_if_slot_in_range:nnT {#1} {##1}
          { \seq_map_break:n { \use_none_delimit_by_q_nil:w } }
      }

    % the following expands to nil if no match was found:
    \use_none:nnn
    \q_nil
    \use:n
      {
        \clist_put_right:Nx \l_@@_char_nrange_clist { \int_eval:n {#1} }
        #4
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_int_if_slot_in_range:nnT}
% A `numrange' is like |-2,5-8,12,17-| (can be unsorted).
%
% Four cases, four argument types:
% \begin{Verbatim}
% input    #2     #3      #4
% "1  "   [ 1] - [qn] - [   ] qs
% "1- "   [ 1] - [  ] - [qn-] qs
% " -3"   [  ] - [ 3] - [qn-] qs
% "1-3"   [ 1] - [ 3] - [qn-] qs
% \end{Verbatim}
%
%    \begin{macrocode}
\cs_new:Nn \@@_int_if_slot_in_range:nnT
  { \@@_numrange_parse:nwT {#1} #2 - \q_nil - \q_stop {#3} }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Npn \@@_numrange_parse:nwT #1 #2 - #3 - #4 \q_stop #5
  {
    \tl_if_empty:nTF {#4} { \int_compare:nT {#1=#2} {#5} }
      {
    \tl_if_empty:nTF {#3} { \int_compare:nT {#1>=#2} {#5} }
      {
    \tl_if_empty:nTF {#2} { \int_compare:nT {#1<=#3} {#5} }
      {
    \int_compare:nT {#1>=#2} { \int_compare:nT {#1<=#3} {#5} }
      } } }
  }
%    \end{macrocode}
% \end{macro}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}

\endinput

% /©
%
% ------------------------------------------------
% The UNICODE-MATH package  <wspr.io/unicode-math>
% ------------------------------------------------
% This package is free software and may be redistributed and/or modified under
% the conditions of the LaTeX Project Public License, version 1.3c or higher
% (your choice): <http://www.latex-project.org/lppl/>.
% ------------------------------------------------
% Copyright 2006-2017  Will Robertson, LPPL "maintainer"
% Copyright 2010-2017  Philipp Stephani
% Copyright 2011-2017  Joseph Wright
% Copyright 2012-2015  Khaled Hosny
% ------------------------------------------------
%
% ©/