summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/unicode-math/um-code-epilogue.dtx
blob: 9c10ee0ddfc4526997cac842332afe4ba6f7a874 (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
%%^^A%% um-code-epilogue.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>
%%^^A%% Assorted definitions to close up.

% \section{Epilogue}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Lots of little things to tidy up.
%
% \subsection{Resolving Greek symbol name control sequences}
%
% \begin{macro}{\@@_resolve_greek:}
% This macro defines \cmd\Alpha\dots\cmd\omega\ as their corresponding
% Unicode (mathematical italic) character. Remember that the mapping
% to upright or italic happens with the mathcode definitions, whereas these macros
% just stand for the literal Unicode characters.
%    \begin{macrocode}
\AtBeginDocument { \debug_suspend: \@@_resolve_greek: \debug_resume: }
%    \end{macrocode}
%    \begin{macrocode}
\cs_new:Npn \@@_resolve_greek:
  {
    \clist_map_inline:nn
      {
        Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,
        alpha,beta,gamma,delta,epsilon,zeta,eta,theta,iota,kappa,lambda,
        Mu,Nu,Xi,Omicron,Pi,Rho,Sigma,Tau,Upsilon,Phi,Chi,Psi,Omega,
        mu,nu,xi,omicron,pi,rho,sigma,tau,upsilon,phi,chi,psi,omega,
        varTheta,varsigma,vartheta,varkappa,varrho,varpi,varepsilon,varphi
      }
      {
        \tl_set:cx {##1} { \exp_not:c { mit ##1 } }
        \tl_set:cx {up ##1} { \exp_not:N \symup \exp_not:c { ##1 } }
        \tl_set:cx {it ##1} { \exp_not:N \symit \exp_not:c { ##1 } }
      }
  }
%    \end{macrocode}
% \end{macro}
%
%
%
% \subsection{Unicode radicals}
%
% Make sure \cs{Uroot} is defined in the case where the \LaTeX{}
% kernel doesn't make it available with its native name.
%
% \begin{macro}{\@@_redefine_radical:}
%    \begin{macrocode}
\AtBeginDocument{ \@ifpackageloaded { amsmath } { } { \@@_redefine_radical: } }
%    \end{macrocode}
%
% \begin{macro}{\r@@t}
% \darg{A mathstyle (for \cmd\mathpalette)}
% \darg{Leading superscript for the sqrt sign}
% A re-implementation of \LaTeX's hard-coded n-root sign using the appropriate \cmd\fontdimen s.
%    \begin{macrocode}
%<*XE>
\cs_new:Nn \@@_redefine_radical:
  {
    \cs_set_nopar:Npn \r@@@@t ##1 ##2
      {
        \hbox_set:Nn \l_tmpa_box
          {
            \c_math_toggle_token \m@th
            ##1 \sqrtsign { ##2 }
            \c_math_toggle_token
          }
        \@@_mathstyle_scale:NnnN ##1 { \kern } { \fontdimen 63 \g_@@_sqrt_font_cmd_tl } \g_@@_sqrt_font_cmd_tl
        \box_move_up:nn
          {
            (\box_ht:N \l_tmpa_box - \box_dp:N \l_tmpa_box) * \number \fontdimen 65 \g_@@_sqrt_font_cmd_tl / 100
          }
          { \box_use:N \rootbox }
        \@@_mathstyle_scale:NnnN ##1 { \kern } { \fontdimen 64 \g_@@_sqrt_font_cmd_tl } \g_@@_sqrt_font_cmd_tl
        \box_use_drop:N \l_tmpa_box
      }
  }
%</XE>
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\root}
% Redefine this macro for \LuaTeX, which provides us a nice primitive to use.
%    \begin{macrocode}
%<*LU>
\cs_new:Nn \@@_redefine_radical:
  {
    \cs_set:Npn \root ##1 \of ##2
      {
        \Uroot \c_@@_radical_sqrt_tl { ##1 } { ##2 }
      }
  }
%</LU>
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsubsection{Active fractions}
%
% Active fractions can be set up independently of any maths font definition;
% all it requires is a mapping from the Unicode input chars to the relevant
% \LaTeX\ fraction declaration.
%
%    \begin{macrocode}
\cs_new:Nn \@@_which_frac:nn
  {
    \bool_if:NTF \l_@@_smallfrac_bool {\tfrac} {\frac} {#1} {#2}
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_new:Npn \@@_setup_active_frac:
  {
    \@@_mathactive_remap:nn {"2189}  { \@@_which_frac:nn {0} {3}  }
    \@@_mathactive_remap:nn {"2152}  { \@@_which_frac:nn {1} {10} }
    \@@_mathactive_remap:nn {"2151}  { \@@_which_frac:nn {1} {9}  }
    \@@_mathactive_remap:nn {"215B}  { \@@_which_frac:nn {1} {8}  }
    \@@_mathactive_remap:nn {"2150}  { \@@_which_frac:nn {1} {7}  }
    \@@_mathactive_remap:nn {"2159}  { \@@_which_frac:nn {1} {6}  }
    \@@_mathactive_remap:nn {"2155}  { \@@_which_frac:nn {1} {5}  }
    \@@_mathactive_remap:nn {"00BC}  { \@@_which_frac:nn {1} {4}  }
    \@@_mathactive_remap:nn {"2153}  { \@@_which_frac:nn {1} {3}  }
    \@@_mathactive_remap:nn {"215C}  { \@@_which_frac:nn {3} {8}  }
    \@@_mathactive_remap:nn {"2156}  { \@@_which_frac:nn {2} {5}  }
    \@@_mathactive_remap:nn {"00BD}  { \@@_which_frac:nn {1} {2}  }
    \@@_mathactive_remap:nn {"2157}  { \@@_which_frac:nn {3} {5}  }
    \@@_mathactive_remap:nn {"215D}  { \@@_which_frac:nn {5} {8}  }
    \@@_mathactive_remap:nn {"2154}  { \@@_which_frac:nn {2} {3}  }
    \@@_mathactive_remap:nn {"00BE}  { \@@_which_frac:nn {3} {4}  }
    \@@_mathactive_remap:nn {"2158}  { \@@_which_frac:nn {4} {5}  }
    \@@_mathactive_remap:nn {"215A}  { \@@_which_frac:nn {5} {6}  }
    \@@_mathactive_remap:nn {"215E}  { \@@_which_frac:nn {7} {8}  }
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\AtBeginDocument { \@@_setup_active_frac: }
%    \end{macrocode}
%
%
% \subsection{Synonyms and all the rest}
%
% These are symbols with multiple names. Eventually to be taken care of
% automatically by the maths characters database.
%    \begin{macrocode}
\protected\def\to{\rightarrow}
\protected\def\le{\leq}
\protected\def\ge{\geq}
\protected\def\neq{\ne}
\protected\def\triangle{\mathord{\bigtriangleup}}
\protected\def\bigcirc{\mdlgwhtcircle}
\protected\def\circ{\vysmwhtcircle}
\protected\def\bullet{\smblkcircle}
\protected\def\mathyen{\yen}
\protected\def\mathsterling{\sterling}
\protected\def\diamond{\smwhtdiamond}
\protected\def\emptyset{\varnothing}
\protected\def\hbar{\hslash}
\protected\def\land{\wedge}
\protected\def\lor{\vee}
\protected\def\owns{\ni}
\protected\def\gets{\leftarrow}
\protected\def\mathring{\ocirc}
\protected\def\lnot{\neg}
\protected\def\longdivision{\longdivisionsign}
%    \end{macrocode}
% These are somewhat odd: (and their usual Unicode uprightness does not match their amssymb glyphs)
%    \begin{macrocode}
\protected\def\backepsilon{\upbackepsilon}
\protected\def\eth{\matheth}
%    \end{macrocode}
% These are names that are `frozen' in HTML but have dumb names:
%    \begin{macrocode}
\protected\def\dbkarow {\dbkarrow}
\protected\def\drbkarow{\drbkarrow}
\protected\def\hksearow{\hksearrow}
\protected\def\hkswarow{\hkswarrow}
%    \end{macrocode}
%
% Due to the magic of OpenType math, big operators are automatically
% enlarged when necessary. Since there isn't a separate unicode glyph for
% `small integral', I'm not sure if there is a better way to do this:
%    \begin{macrocode}
\protected\def\smallint{\mathop{\textstyle\int}\limits}
%    \end{macrocode}
%
% \begin{macro}{\underbar}
%    \begin{macrocode}
\cs_set_eq:NN \latexe_underbar:n \underbar
\renewcommand\underbar
  {
    \mode_if_math:TF \mathunderbar \latexe_underbar:n
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\colon}
% Define \cs{colon} as a mathpunct `|:|'.
% This is wrong: it should be \unichar{003A} {colon} instead!
% We hope no-one will notice.
%    \begin{macrocode}
\@ifpackageloaded{amsmath}
  {
    % define their own colon, perhaps I should just steal it. (It does look much better.)
  }
  {
    \cs_set_protected:Npn \colon
      {
        \bool_if:NTF \g_@@_literal_colon_bool {:} { \mathpunct{:} }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\digamma}
% \begin{macro}{\Digamma}
% I might end up just changing these in the table.
%    \begin{macrocode}
\protected\def\digamma{\updigamma}
\protected\def\Digamma{\upDigamma}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \paragraph{Symbols}
%
%    \begin{macrocode}
\cs_set_protected:Npn \| {\Vert}
%    \end{macrocode}
%
% \cs{mathinner} items:
%    \begin{macrocode}
\cs_set_protected:Npn \mathellipsis {\mathinner{\unicodeellipsis}}
\cs_set_protected:Npn \cdots {\mathinner{\unicodecdots}}
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set_eq:NN \@@_text_slash: \slash
\cs_set_protected:Npn \slash
  {
    \mode_if_math:TF {\mathslash} {\@@_text_slash:}
  }
%    \end{macrocode}
%
%
% \subsubsection{\cs{not}}
% \label{sec:negations}
%
% The situation of \cs{not} symbol is currently messy, in Unicode it is defined
% as a combining mark so naturally it should be treated as a math accent,
% however \XeTeX\ does not correctly place it as it needs special
% treatment compared to other accents.
% Furthermore a math accent changes the
% spacing of its nucleus, so \cs{not=} will be spaced as an ordinary not
% relational symbol, which is undesired.
%
% Here modify \cs{not} to a macro that tries to use predefined negated symbols,
% which would give better results in most cases, until there is more robust
% solution in the engines.
%
% This code is based on an answer to a TeX -- Stack Exchange question by Enrico
% Gregorio\footnote{\url{http://tex.stackexchange.com/a/47260/729}}.
%
% \begin{macro}{\not}
%    \begin{macrocode}
\DeclareDocumentCommand \not {m}
  {
    \tl_set:Nx \l_@@_not_token_name_tl { \cs_to_str:N #1 }
    \tl_if_empty:NT \l_@@_not_token_name_tl
      {
        \tl_set:Nx \l_@@_not_token_name_tl { \token_to_str:N #1 }
      }
    \cs_if_exist:cTF { not \l_@@_not_token_name_tl }
      {
        \use:c { not \l_@@_not_token_name_tl }
      }
      {
        \cs_if_exist:cTF { n \l_@@_not_token_name_tl }
          {
            \use:c { n \l_@@_not_token_name_tl }
          }
          {
            \tl_if_eq:nnTF {#1} {$} { \notaccent{} } { \notaccent } #1
          }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\NewNegationCommand}
% \begin{macro}{\RenewNegationCommand}
%    \begin{macrocode}
\DeclareDocumentCommand \NewNegationCommand {mm}
  {
    \@@_set_negation_command:Nnn \cs_new_protected:cpn {#1} {#2}
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\DeclareDocumentCommand \RenewNegationCommand {mm}
  {
    \@@_set_negation_command:Nnn \cs_set_protected:cpn {#1} {#2}
  }
%    \end{macrocode}
%
%    \begin{macrocode}
\cs_set:Nn \@@_set_negation_command:Nnn
  {
    \tl_set:Nx \l_@@_not_token_name_tl { \cs_to_str:N #2 }
    \tl_if_empty:NT \l_@@_not_token_name_tl
      {
        \tl_set:Nx \l_@@_not_token_name_tl { \token_to_str:N #2 }
      }
    #1 { not \l_@@_not_token_name_tl } { #3 }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%    \begin{macrocode}
\NewNegationCommand { = }    { \neq   }
\NewNegationCommand { < }    { \nless }
\NewNegationCommand { > }    { \ngtr  }
\NewNegationCommand { \gets     } { \nleftarrow }
\NewNegationCommand { \simeq    } { \nsime      }
\NewNegationCommand { \equal    } { \ne         }
\NewNegationCommand { \le       } { \nleq       }
\NewNegationCommand { \ge       } { \ngeq       }
\NewNegationCommand { \greater  } { \ngtr       }
\NewNegationCommand { \forksnot } { \forks      }
%    \end{macrocode}
%
%
% \subsubsection{Full-width remapping}
%
% While this could be done with the full mathcode remapping machinery used
% for the other purposes, it would be fairly redundant with plain ASCII.
% Worse, this would slow down what is already an inefficient part of \pkg{unicode-math}.
%
% Instead we use mathactive to do a plain old mapping from full-width to ASCII directly.
%
% Until I get requests for it, I've not included symbols or punctuation here.
%
% \paragraph{Numbers}
%
%    \begin{macrocode}
\int_step_inline:nnnn {0} {1} {9}
  {
    \@@_mathactive_remap:nn {"FF10+#1} {\char\int_eval:n{`\0+#1}}
  }
%    \end{macrocode}
%
% \paragraph{Letters}
%
%    \begin{macrocode}
\int_step_inline:nnnn {0} {1} {26}
  {
    \@@_mathactive_remap:nn {"FF21+#1} {\char\int_eval:n{`\A+#1}}
    \@@_mathactive_remap:nn {"FF41+#1} {\char\int_eval:n{`\a+#1}}
  }
%    \end{macrocode}
%
%
% \subsection{Legacy characters}
%
% \begin{macro}{\@@_undeclare_symbol:N}
%    \begin{macrocode}
\cs_new:Nn \@@_undeclare_symbol:N
  {
    \cs_set_protected:Npn #1
      { \@@_error:nx {legacy-char-not-supported} { \token_to_str:N #1 } }
  }
%    \end{macrocode}
% \end{macro}
%
% If you have better ideas about what to do here, please mention.
%    \begin{macrocode}
\@@_undeclare_symbol:N \arrowvert
\@@_undeclare_symbol:N \Arrowvert
\@@_undeclare_symbol:N \bracevert
%    \end{macrocode}
%
% \section{A secret hook}
% This will be executed after most if not all of the standard unicode-math setup.
%    \begin{macrocode}
\AtBeginDocument{\g_@@_secret_hook_tl}
%    \end{macrocode}
%
%    \begin{macrocode}
%</package>
%    \end{macrocode}
%
% \section*{Fin}
%
% The official end of the package:
%    \begin{macrocode}
%<package>\endinput
%    \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-2019  Will Robertson, LPPL "maintainer"
% Copyright 2010-2017  Philipp Stephani
% Copyright 2011-2017  Joseph Wright
% Copyright 2012-2015  Khaled Hosny
% ------------------------------------------------
%
% ©/