summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/unicode-math/um-code-compat.dtx
blob: 72ce5186da13a82515fea0d14a2cb41fde4456a2 (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
%%^^A%% um-code-compat.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>
%%^^A%% Compatibility with 3rd party packages.

% \section{Compatibility}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%
% \section{Patching/augmenting 3rd-party packages}
%
% \subsection{\pkg{url}}
% Here we need to get \pkg{url} in a state such that
% when it switches to math mode and enters \ascii\ characters, the maths
% setup (i.e., \pkg{unicode-math}) doesn't remap the symbols into Plane 1.
% Which is what \cs{symliteral} is intended to do.
% This is the same as writing, e.g., |\def\UrlFont{\ttfamily\@@_switch_to:n{literal}}|
% but activates automatically so documents that might change the \cs{url}
% font through the standard interface still work correctly.
%    \begin{macrocode}
\@@_after_package:nNn {url} \@@_patch_url:
  {
    \tl_put_left:Nn \Url@FormatString { \@@_switch_to:n {literal} }
    \tl_put_right:Nn \UrlSpecials
      {
        \do \` { \mathchar`\` }
        \do \' { \mathchar`\' }
        \do \$ { \mathchar`\$ }
        \do \& { \mathchar`\& }
      }
  }
%    \end{macrocode}
%
%
% \subsection{\pkg{mathtools}}
%
% \pkg{mathtools}’s |\cramped| command and others that make use of its internal version use an incorrect font dimension.
%
% The \XeTeX\ version is pretty similar to the legacy version, only using the correct font dimensions.
% Note we used `\verb|\XeTeXradical|' with the family 255 to be almost sure
% that the radical rule width is not set. Former use of `\verb|\newfam|' had an
% upsetting effect on legacy math alphabets.
%    \begin{macrocode}
%<*XE>
\@@_after_package:nNn { mathtools } \@@_patch_mathtools_A:
  {
    \cs_set_nopar:Npn \MT_cramped_internal:Nn ##1 ##2
     {
       \hbox_set:Nn \l_tmpa_box
         {
           \color@setgroup \c_math_toggle_token \m@th
             ##1
             \dim_zero:N \nulldelimiterspace
             \XeTeXradical 255 ~ 0 ~ { ##2 }
           \c_math_toggle_token \color@endgroup
         }
       \box_set_ht:Nn \l_tmpa_box
         {
           \box_ht:N \l_tmpa_box - \@@_radical_vgap:N ##1
         }
       \box_use_drop:N \l_tmpa_box
     }
  }
%</XE>
%    \end{macrocode}
%
% \begin{macro}{\overbracket}
% \begin{macro}{\underbracket}
%   \pkg{mathtools}’s |\overbracket| and |\underbracket| take optional
%   arguments and are defined in terms of rules, so we keep them, and rename
%   ours to |\Uoverbracket| and |\Uunderbracket|.
%
%   Original definition used the height of |\braceld| which is not available
%   with Unicode fonts, so we are hard coding the $5/18$ex suggested by
%   \pkg{mathtools}’s documentation.
%    \begin{macrocode}
\@@_after_package:nNn { mathtools } \@@_patch_mathtools_B:
  {
    \cs_set_eq:NN \MToverbracket  \overbracket
    \cs_set_eq:NN \MTunderbracket \underbracket

    \AtBeginDocument
      {
        \msg_warning:nn { unicode-math } { mathtools-overbracket }

    	  \cs_set:Npn \downbracketfill ##1 ##2
	        {
            \tl_set:Nn \l_MT_bracketheight_fdim {.27ex}
            \downbracketend {##1} {##2}
            \leaders \vrule \@height ##1 \@depth \z@ \hfill
            \downbracketend {##1} {##2}
          }

	      \cs_set:Npn \upbracketfill ##1 ##2
	        {
            \tl_set:Nn \l_MT_bracketheight_fdim {.27ex}
            \upbracketend {##1} {##2}
            \leaders \vrule \@height \z@ \@depth ##1 \hfill
            \upbracketend {##1} {##2}
          }

	      \cs_set_eq:NN \Uoverbracket  \overbracket
	      \cs_set_eq:NN \Uunderbracket \underbracket
        \cs_set_eq:NN \overbracket   \MToverbracket
        \cs_set_eq:NN \underbracket  \MTunderbracket
     }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\dblcolon}
% \begin{macro}{\coloneqq}
% \begin{macro}{\Coloneqq}
% \begin{macro}{\eqqcolon}
%   \pkg{mathtools} defines several commands as combinations of colons and
%   other characters, but with meanings incompatible to \pkg{unicode-math}.
%   Thus we issue a warning.  Note \pkg{mathtools} uses
%   \cmd{\providecommand} \cmd{\AtBeginDocument}.
%    \begin{macrocode}
\@@_after_package:nNn { mathtools } \@@_patch_mathtools_C:
  {
    \msg_warning:nn { unicode-math } { mathtools-colon }
    \DeclareDocumentCommand \dblcolon { } { \Colon }
    \DeclareDocumentCommand \coloneqq { } { \coloneq }
    \DeclareDocumentCommand \Coloneqq { } { \Coloneq }
    \DeclareDocumentCommand \eqqcolon { } { \eqcolon }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \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-2019  Will Robertson, LPPL "maintainer"
% Copyright 2010-2017  Philipp Stephani
% Copyright 2011-2017  Joseph Wright
% Copyright 2012-2015  Khaled Hosny
% ------------------------------------------------
%
% ©/