summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/unicode-math/um-code-amsmath.dtx
blob: bc782ba88c415fdf27be8fb16cd944b3f853cadd (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
%%^^A%% um-code-amsmath.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>
%%^^A%% Compatibility with amsmath.

% \section{Compatibility with \pkg{amsmath}}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
% Since the mathcode of |`\-| is greater than eight bits, this piece of |\AtBeginDocument| code from \pkg{amsmath} dies if we try and set the maths font in the preamble:
%    \begin{macrocode}
\AtEndOfPackageFile * {amsmath}
  {
    \tl_remove_once:Nn \@begindocumenthook
      {
        \mathchardef\std@minus\mathcode`\-\relax
        \mathchardef\std@equal\mathcode`\=\relax
      }
    \AtBeginDocument
      {
        \Umathcharnumdef\std@minus\Umathcodenum`-
        \Umathcharnumdef\std@equal\Umathcodenum`=
      }
%    \end{macrocode}
%
%    \begin{macrocode}
    \cs_set:Npn \@cdots {\mathinner{\unicodecdots}}
    \cs_set_eq:NN \dotsb@ \cdots
%    \end{macrocode}
% This isn't as clever as the \pkg{amsmath} definition but I think it works:
%    \begin{macrocode}
%<*XE>
    \def \resetMathstrut@
      {%
        \setbox\z@\hbox{$($}%)
        \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@
      }
%    \end{macrocode}
% The |subarray| environment uses inappropriate font dimensions.
%    \begin{macrocode}
    \@@_check_and_fix:NNnnn \subarray \cs_set:Npn { #1 }
      {
        \vcenter
        \bgroup
        \Let@
        \restore@math@cr
        \default@tag
        \baselineskip \fontdimen 10~ \scriptfont \tw@
        \advance \baselineskip \fontdimen 12~ \scriptfont \tw@
        \lineskip \thr@@@@ \fontdimen 8~ \scriptfont \thr@@@@
        \lineskiplimit \lineskip
        \ialign
        \bgroup
        \ifx c #1 \hfil \fi
        $ \m@th \scriptstyle ## $
        \hfil
        \crcr
      }
      {
        \vcenter
        \c_group_begin_token
        \Let@
        \restore@math@cr
        \default@tag
        \skip_set:Nn \baselineskip
          {
%    \end{macrocode}
% Here we use stack top shift + stack bottom shift, which sounds reasonable.
%    \begin{macrocode}
            \@@_stack_num_up:N \scriptstyle
            + \@@_stack_denom_down:N \scriptstyle
          }
%    \end{macrocode}
% Here we use the minimum stack gap.
%    \begin{macrocode}
        \lineskip \@@_stack_vgap:N \scriptstyle
        \lineskiplimit \lineskip
        \ialign
        \c_group_begin_token
        \token_if_eq_meaning:NNT c #1 { \hfil }
        \c_math_toggle_token
        \m@th
        \scriptstyle
        \c_parameter_token \c_parameter_token
        \c_math_toggle_token
        \hfil
        \crcr
      }
%</XE>
%    \end{macrocode}
% The roots need a complete rework.
%    \begin{macrocode}
%<*LU>
  \@@_check_and_fix:NNnnn \plainroot@ \cs_set_nopar:Npn { #1 \of #2 }
    {
      \setbox \rootbox \hbox
        {
          $ \m@th \scriptscriptstyle { #1 } $
        }
      \mathchoice
        { \r@@@@t \displaystyle      { #2 } }
        { \r@@@@t \textstyle         { #2 } }~
        { \r@@@@t \scriptstyle       { #2 } }
        { \r@@@@t \scriptscriptstyle { #2 } }
      \egroup
    }
    {
      \bool_if:nTF
        {
          \@@_int_if_zero_p:n \uproot@ && \@@_int_if_zero_p:n \leftroot@
        }
        {
          \Uroot \c_@@_radical_sqrt_tl { #1 } { #2 }
        }
        {
          \hbox_set:Nn \rootbox
            {
              \c_math_toggle_token \m@th
              \scriptscriptstyle { #1 }
              \c_math_toggle_token
            }
          \mathchoice
            { \r@@@@t \displaystyle      { #2 } }
            { \r@@@@t \textstyle         { #2 } }
            { \r@@@@t \scriptstyle       { #2 } }
            { \r@@@@t \scriptscriptstyle { #2 } }
        }
       \c_group_end_token
    }
%</LU>
%    \end{macrocode}
%
%    \begin{macrocode}
  \@@_check_and_fix:NNnnn \r@@@@t \cs_set_nopar:Npn { #1 #2 }
    {
      \setboxz@h { $ \m@th #1 \sqrtsign { #2 } $ }
      \dimen@ \ht\z@
      \advance \dimen@ -\dp\z@
      \setbox\@ne \hbox { $ \m@th #1 \mskip \uproot@ mu $ }
      \advance \dimen@ by 1.667 \wd\@ne
      \mkern -\leftroot@ mu
      \mkern 5mu
      \raise .6\dimen@ \copy\rootbox
      \mkern -10mu
      \mkern \leftroot@ mu
      \boxz@
    }
%<*LU>
    {
      \hbox_set:Nn \l_tmpa_box
        {
          \c_math_toggle_token \m@th
            #1 \mskip \uproot@ mu
          \c_math_toggle_token
        }
      \Uroot \c_@@_radical_sqrt_tl
        {
          \box_move_up:nn { \box_wd:N \l_tmpa_box }
            {
              \hbox:n
                {
                  \c_math_toggle_token \m@th
                    \mkern -\leftroot@ mu
                    \box_use:N \rootbox
                    \mkern \leftroot@ mu
                  \c_math_toggle_token
                }
            }
        }
        { #2 }
    }
%</LU>
%<*XE>
    {
      \hbox_set:Nn \l_tmpa_box
        {
          \c_math_toggle_token \m@th
            #1 \sqrtsign { #2 }
          \c_math_toggle_token
        }
      \hbox_set:Nn \l_tmpb_box
        {
          \c_math_toggle_token \m@th
            #1 \mskip \uproot@ mu
          \c_math_toggle_token
        }
      \mkern -\leftroot@ mu
      \@@_mathstyle_scale:NnnN #1 { \kern } { \fontdimen 63 \g_@@_sqrt_font_cmd_tl } \g_@@_sqrt_font_cmd_tl
      \box_move_up:nn
        {
          \box_wd:N \l_tmpb_box + (\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
      \mkern \leftroot@ mu
      \box_use_drop:N \l_tmpa_box
    }
%</XE>
  }
%    \end{macrocode}
%
%    \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-2019  Will Robertson, LPPL "maintainer"
% Copyright 2010-2017  Philipp Stephani
% Copyright 2011-2017  Joseph Wright
% Copyright 2012-2015  Khaled Hosny
% ------------------------------------------------
%
% ©/