| 1 |
%%^^A%% um-code-opening.dtx -- part of UNICODE-MATH <wspr.io/unicode-math> |
| 2 |
%%^^A%% Assorted initialisation tasks, including some low-level function definitions. |
| 3 |
|
| 4 |
% \section{Start of the package code} |
| 5 |
% |
| 6 |
% The prefix for \pkg{unicode-math} is \texttt{um}: |
| 7 |
% \begin{macrocode} |
| 8 |
%<@@=um> |
| 9 |
% \end{macrocode} |
| 10 |
% |
| 11 |
% \begin{macrocode} |
| 12 |
%<*package> |
| 13 |
% \end{macrocode} |
| 14 |
% |
| 15 |
% \paragraph{Packages} |
| 16 |
% Assuming people are running up-to-date packages. |
| 17 |
% \begin{macrocode} |
| 18 |
\RequirePackage{xparse,l3keys2e} |
| 19 |
\RequirePackage{fontspec} |
| 20 |
\RequirePackage{fix-cm} |
| 21 |
\RequirePackage{amsmath} |
| 22 |
%<LU>\RequirePackage{lualatex-math} |
| 23 |
% \end{macrocode} |
| 24 |
% |
| 25 |
% \begin{macrocode} |
| 26 |
\cs_set_protected:Npn \@@_after_package:nNn #1 #2 #3 |
| 27 |
{ |
| 28 |
\AtBeginDocument |
| 29 |
{ |
| 30 |
\cs_new_protected:Npn #2 {#3} |
| 31 |
\@ifpackageloaded {#1} {#2} {} |
| 32 |
} |
| 33 |
} |
| 34 |
% \end{macrocode} |
| 35 |
% |
| 36 |
% \subsection{\pkg{expl3} variants} |
| 37 |
% |
| 38 |
% Variants needed from \pkg{expl3}: |
| 39 |
% \begin{macrocode} |
| 40 |
\cs_set_protected_nopar:Npn \exp_last_unbraced:NNx { \::N \::x_unbraced \::: } |
| 41 |
% \end{macrocode} |
| 42 |
% |
| 43 |
% For \pkg{fontspec}: |
| 44 |
% \begin{macrocode} |
| 45 |
\cs_generate_variant:Nn \fontspec_set_family:Nnn {Nx,Nxx} |
| 46 |
\cs_generate_variant:Nn \prop_get:NnNTF {cx} |
| 47 |
\cs_generate_variant:Nn \tl_if_eq:nnF {o} |
| 48 |
% \end{macrocode} |
| 49 |
% |
| 50 |
% |
| 51 |
% \subsection{Low level commands} |
| 52 |
% |
| 53 |
% \begin{macrocode} |
| 54 |
\cs_set_eq:NN \@@_group_begin: \group_begin: |
| 55 |
\cs_set_protected:Npn \@@_group_end:n #1 { #1 \group_end: } |
| 56 |
\cs_set_eq:NN \@@_group_begin_frozen: \@@_group_begin: |
| 57 |
\cs_set_eq:NN \@@_group_end_frozen:n \@@_group_end:n |
| 58 |
% \end{macrocode} |
| 59 |
% |
| 60 |
% |
| 61 |
% \subsection{Primitive font commands} |
| 62 |
% |
| 63 |
% What might end up being provided by the kernel. |
| 64 |
% |
| 65 |
% \begin{macro}{\@@_glyph_if_exist:NnTF} |
| 66 |
% \begin{macrocode} |
| 67 |
\prg_new_conditional:Nnn \@@_glyph_if_exist:Nn {p,TF,T,F} |
| 68 |
{ |
| 69 |
\tex_iffontchar:D #1 #2 \scan_stop: |
| 70 |
\prg_return_true: |
| 71 |
\else: |
| 72 |
\prg_return_false: |
| 73 |
\fi: |
| 74 |
} |
| 75 |
% \end{macrocode} |
| 76 |
% \end{macro} |
| 77 |
% |
| 78 |
% \begin{macro}{\@@_fontface_gset_eq:NN} |
| 79 |
% \begin{macrocode} |
| 80 |
\cs_set_protected:Nn \@@_fontface_gset_eq:NN |
| 81 |
{ |
| 82 |
\tex_global:D \tex_let:D #1 #2 |
| 83 |
} |
| 84 |
\cs_generate_variant:Nn \@@_fontface_gset_eq:NN {cN} |
| 85 |
% \end{macrocode} |
| 86 |
% \end{macro} |
| 87 |
% |
| 88 |
% \subsubsection{Mathcode and friends} |
| 89 |
% |
| 90 |
% \begin{macro}{\@@_set_mathcode:nnnn} |
| 91 |
% \begin{macro}{\@@_set_mathcode:nnn} |
| 92 |
% These are all wrappers for the primitive commands that take numerical |
| 93 |
% input only. |
| 94 |
% \begin{macrocode} |
| 95 |
\cs_set:Npn \@@_set_mathcode:nnnn #1#2#3#4 |
| 96 |
{ |
| 97 |
\Umathcode \int_eval:n {#1} = |
| 98 |
\mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop: |
| 99 |
} |
| 100 |
% \end{macrocode} |
| 101 |
% |
| 102 |
% \begin{macrocode} |
| 103 |
\cs_set:Npn \@@_set_mathcode:nnn #1#2#3 |
| 104 |
{ |
| 105 |
\Umathcode \int_eval:n {#1} = |
| 106 |
\mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#1} \scan_stop: |
| 107 |
} |
| 108 |
% \end{macrocode} |
| 109 |
% \end{macro} |
| 110 |
% \end{macro} |
| 111 |
% |
| 112 |
% \begin{macro}{\@@_set_mathchar:NNnn} |
| 113 |
% \begin{macro}{\@@_set_mathchar:cNnn} |
| 114 |
% \begin{macrocode} |
| 115 |
\cs_set:Npn \@@_set_mathchar:NNnn #1#2#3#4 |
| 116 |
{ |
| 117 |
\Umathchardef #1 = |
| 118 |
\mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop: |
| 119 |
} |
| 120 |
% \end{macrocode} |
| 121 |
% \end{macro} |
| 122 |
% \end{macro} |
| 123 |
% |
| 124 |
% \begin{macrocode} |
| 125 |
\cs_generate_variant:Nn \@@_set_mathchar:NNnn {c} |
| 126 |
% \end{macrocode} |
| 127 |
% |
| 128 |
% \begin{macro}{\@@_set_delcode:nnn} |
| 129 |
% \begin{macrocode} |
| 130 |
\cs_new:Nn \@@_set_delcode:nnn |
| 131 |
{ |
| 132 |
\Udelcode#2 = \csname sym#1\endcsname #3 \scan_stop: |
| 133 |
} |
| 134 |
% \end{macrocode} |
| 135 |
% \end{macro} |
| 136 |
% |
| 137 |
% \begin{macro}{\@@_radical:nn} |
| 138 |
% \begin{macrocode} |
| 139 |
\cs_new:Nn \@@_radical:nn |
| 140 |
{ |
| 141 |
\Uradical \csname sym#1\endcsname #2 \scan_stop: |
| 142 |
} |
| 143 |
% \end{macrocode} |
| 144 |
% \end{macro} |
| 145 |
% |
| 146 |
% \begin{macro}{\@@_delimiter:Nnn} |
| 147 |
% \begin{macrocode} |
| 148 |
\cs_new:Nn \@@_delimiter:Nnn |
| 149 |
{ |
| 150 |
\Udelimiter \mathchar@type#1 \csname sym#2\endcsname #3 \scan_stop: |
| 151 |
} |
| 152 |
% \end{macrocode} |
| 153 |
% \end{macro} |
| 154 |
% |
| 155 |
% \begin{macro}{\@@_accent:nnn} |
| 156 |
% \begin{macrocode} |
| 157 |
\cs_new:Nn \@@_accent:nnn |
| 158 |
{ |
| 159 |
\Umathaccent #1~ \mathchar@type\mathaccent \use:c { sym #2 } #3 \scan_stop: |
| 160 |
} |
| 161 |
% \end{macrocode} |
| 162 |
% \end{macro} |
| 163 |
% |
| 164 |
% \begin{macro}{\@@_char_gmake_mathactive:N} |
| 165 |
% \begin{macro}{\@@_char_gmake_mathactive:n} |
| 166 |
% \begin{macrocode} |
| 167 |
\cs_new:Nn \@@_char_gmake_mathactive:N |
| 168 |
{ |
| 169 |
\tex_global:D \tex_mathcode:D `#1 = "8000 \scan_stop: |
| 170 |
} |
| 171 |
% \end{macrocode} |
| 172 |
% \begin{macrocode} |
| 173 |
\cs_new:Nn \@@_char_gmake_mathactive:n |
| 174 |
{ |
| 175 |
\tex_global:D \tex_mathcode:D \int_eval:n {#1} = "8000 \scan_stop: |
| 176 |
} |
| 177 |
% \end{macrocode} |
| 178 |
% \end{macro} |
| 179 |
% \end{macro} |
| 180 |
% |
| 181 |
% \begin{macro}{\@@_mathactive_remap:nn} |
| 182 |
% Makes |#1| math-active and defines its meaning to be |#2|. |
| 183 |
% This is a global operation. |
| 184 |
% \begin{macrocode} |
| 185 |
\cs_new:Nn \@@_mathactive_remap:nn |
| 186 |
{ |
| 187 |
\group_begin: |
| 188 |
\cs_set_protected:Npn \@@_tmp: {#2} |
| 189 |
\@@_char_gmake_mathactive:n {#1} |
| 190 |
\char_gset_active_eq:nN {#1} \@@_tmp: |
| 191 |
\group_end: |
| 192 |
} |
| 193 |
% \end{macrocode} |
| 194 |
% |
| 195 |
% \subsubsection{NFSS-related interfaces} |
| 196 |
% |
| 197 |
% \begin{macro}{\@@_mathgroup_set:n} |
| 198 |
% Remember that \cs{mathgroup} is just \cs{fam}! |
| 199 |
% \begin{macrocode} |
| 200 |
\cs_new_protected:Nn \@@_mathgroup_set:n |
| 201 |
{ |
| 202 |
\tex_fam:D #1 \scan_stop: |
| 203 |
} |
| 204 |
% \end{macrocode} |
| 205 |
% \end{macro} |
| 206 |
% |
| 207 |
% \subsubsection{Font parameters} |
| 208 |
% |
| 209 |
% \begin{macro}{\@@_copy_fontdimen:nnN} |
| 210 |
% \begin{macrocode} |
| 211 |
\cs_new:Nn \@@_copy_fontdimen:nnN |
| 212 |
{ |
| 213 |
\fontdimen #1 \font = \the \fontdimen #2 #3 \relax |
| 214 |
} |
| 215 |
% \end{macrocode} |
| 216 |
% \end{macro} |
| 217 |
% |
| 218 |
% \begin{macro}{\@@_zero_fontdimen:n} |
| 219 |
% \begin{macrocode} |
| 220 |
\cs_new:Nn \@@_zero_fontdimen:n |
| 221 |
{ |
| 222 |
\fontdimen #1 \font = 0pt\relax |
| 223 |
} |
| 224 |
% \end{macrocode} |
| 225 |
% \end{macro} |
| 226 |
% |
| 227 |
%^^A \begin{function}[EXP, added = 2019-01-19]{\@@_int_if_zero_p:n, \@@_int_if_zero:nTF} |
| 228 |
%^^A \begin{syntax} |
| 229 |
%^^A \cs{int_if_zero_p:n} \Arg{intexpr} |
| 230 |
%^^A \cs{int_if_zero:nTF} \Arg{intexpr} \Arg{true code} \Arg{false code} |
| 231 |
%^^A \end{syntax} |
| 232 |
%^^A A conditional for testing if the \meta{intexpr} evaluates to zero. |
| 233 |
%^^A This is simply a shorthand for |
| 234 |
%^^A \begin{verbatim} |
| 235 |
%^^A \int_compare_p:nNn {intexpr} = {0} |
| 236 |
%^^A \end{verbatim} |
| 237 |
%^^A \end{function} |
| 238 |
% |
| 239 |
% \begin{macro}{\@@_int_if_zero_p:n} |
| 240 |
% \begin{macro}{\@@_int_if_zero:nTF} |
| 241 |
% \begin{macrocode} |
| 242 |
\prg_new_conditional:Nnn \@@_int_if_zero:n {p,TF,T,F} |
| 243 |
{ |
| 244 |
\int_compare:nNnTF {#1} = 0 {\prg_return_true:} {\prg_return_false:} |
| 245 |
} |
| 246 |
% \end{macrocode} |
| 247 |
% \end{macro} |
| 248 |
% \end{macro} |
| 249 |
% |
| 250 |
% |
| 251 |
% \subsection{Alphabet Unicode positions (USVs)} |
| 252 |
% |
| 253 |
% Before we begin, let's define the positions of the various Unicode |
| 254 |
% alphabets so that our code is a little more readable.\footnote{`\textsc{u.s.v.}' stands |
| 255 |
% for `Unicode scalar value'.} |
| 256 |
% |
| 257 |
% \begin{macro}{\usv_set:nnn,\@@_to_usv:nn} |
| 258 |
% Rather than `readable', in the end, this makes the code more extensible. |
| 259 |
% \begin{macrocode} |
| 260 |
\cs_new:Nn \usv_set:nnn { \tl_const:cn { c_@@_#1_#2_usv } {#3} } |
| 261 |
\cs_new:Nn \@@_to_usv:nn { \use:c { c_@@_#1_#2_usv } } |
| 262 |
% \end{macrocode} |
| 263 |
% \end{macro} |
| 264 |
% |
| 265 |
% \begin{macro}{\@@_usv_if_exist:nnTF} |
| 266 |
% \begin{macrocode} |
| 267 |
\prg_new_conditional:Nnn \@@_usv_if_exist:nn {T,F,TF} |
| 268 |
{ |
| 269 |
\cs_if_exist:cTF { c_@@_#1_#2_usv } |
| 270 |
\prg_return_true: \prg_return_false: |
| 271 |
} |
| 272 |
% \end{macrocode} |
| 273 |
% \end{macro} |
| 274 |
% |
| 275 |
% |
| 276 |
% \subsection{Overcoming \texorpdfstring{\cmd\@onlypreamble}{\textbackslash @onlypreamble}} |
| 277 |
% |
| 278 |
% The requirement of only setting up the maths fonts in the preamble is lifted. |
| 279 |
% (Perhaps unwisely.) |
| 280 |
% \begin{macrocode} |
| 281 |
\tl_map_inline:nn |
| 282 |
{ |
| 283 |
\new@mathgroup\cdp@list\cdp@elt\DeclareMathSizes |
| 284 |
\@DeclareMathSizes\newmathalphabet\newmathalphabet@@\newmathalphabet@@@ |
| 285 |
\DeclareMathVersion\define@mathalphabet\define@mathgroup\addtoversion |
| 286 |
\version@list\version@elt\alpha@list\alpha@elt |
| 287 |
\restore@mathversion\init@restore@version\dorestore@version\process@table |
| 288 |
\new@mathversion\DeclareSymbolFont\group@list\group@elt |
| 289 |
\new@symbolfont\SetSymbolFont\SetSymbolFont@\get@cdp |
| 290 |
\DeclareMathAlphabet\new@mathalphabet\SetMathAlphabet\SetMathAlphabet@ |
| 291 |
\DeclareMathAccent\set@mathaccent\DeclareMathSymbol\set@mathchar |
| 292 |
\set@mathsymbol\DeclareMathDelimiter\@xxDeclareMathDelimiter |
| 293 |
\@DeclareMathDelimiter\@xDeclareMathDelimiter\set@mathdelimiter |
| 294 |
\set@@mathdelimiter\DeclareMathRadical\mathchar@type |
| 295 |
\DeclareSymbolFontAlphabet\DeclareSymbolFontAlphabet@ |
| 296 |
} |
| 297 |
{ |
| 298 |
\tl_remove_once:Nn \@preamblecmds {\do#1} |
| 299 |
} |
| 300 |
% \end{macrocode} |
| 301 |
% |
| 302 |
% |
| 303 |
% \subsection{Wrappers for kernel commands} |
| 304 |
% |
| 305 |
% Messages themselves are defined in \secref{codemsg}. |
| 306 |
% |
| 307 |
% \begin{macrocode} |
| 308 |
\cs_new:Npn \@@_error:n { \msg_error:nn {unicode-math} } |
| 309 |
\cs_new:Npn \@@_error:nx { \msg_error:nnx {unicode-math} } |
| 310 |
\cs_new:Npn \@@_warning:n { \msg_warning:nn {unicode-math} } |
| 311 |
\cs_new:Npn \@@_warning:nnn { \msg_warning:nnxx {unicode-math} } |
| 312 |
\cs_new:Npn \@@_log:n { \msg_log:nn {unicode-math} } |
| 313 |
\cs_new:Npn \@@_log:nx { \msg_log:nnx {unicode-math} } |
| 314 |
% \end{macrocode} |
| 315 |
% |
| 316 |
% \begin{macrocode} |
| 317 |
\cs_generate_variant:Nn \msg_new:nnn {nnx} |
| 318 |
\cs_generate_variant:Nn \msg_new:nnnn {nnxx} |
| 319 |
\cs_new:Nn \@@_msg_new:nn { \msg_new:nnx {unicode-math} {#1} { \tl_trim_spaces:n {#2} } } |
| 320 |
% \end{macrocode} |
| 321 |
% |
| 322 |
% |
| 323 |
% \begin{macro}{\@@_cs_new:Nn} |
| 324 |
% \begin{macrocode} |
| 325 |
%<*debug> |
| 326 |
\int_new:N \g_@@_debug_nest_int |
| 327 |
\cs_new:Nn \@@_debug:n |
| 328 |
{ |
| 329 |
\typeout{ <UM~DEBUG>~\prg_replicate:nn \g_@@_debug_nest_int {::}~ #1} |
| 330 |
} |
| 331 |
\cs_new:Nn \@@_debug_start:n |
| 332 |
{ |
| 333 |
\int_gincr:N \g_@@_debug_nest_int |
| 334 |
\@@_debug:n {#1} |
| 335 |
} |
| 336 |
\cs_new:Nn \@@_debug_end:n |
| 337 |
{ |
| 338 |
\int_gdecr:N \g_@@_debug_nest_int |
| 339 |
} |
| 340 |
%</debug> |
| 341 |
% \end{macrocode} |
| 342 |
% |
| 343 |
% \begin{macrocode} |
| 344 |
\cs_new:Npn \@@_cs_set:Nn #1 #2 |
| 345 |
{ |
| 346 |
\cs_if_exist:NF #1 { \ERROR{CS~ DOES~ NOT~ EXIST,~ USE~ "NEW"} } |
| 347 |
\cs_set_protected:Nn #1 |
| 348 |
{ |
| 349 |
%<debug>\@@_debug_start:n { \cs_to_str:N #1 } |
| 350 |
#2 |
| 351 |
%<debug>\@@_debug_end:n { \cs_to_str:N #1 } |
| 352 |
} |
| 353 |
} |
| 354 |
\cs_new:Npn \@@_cs_new:Nn #1 #2 |
| 355 |
{ |
| 356 |
\cs_new_protected:Nn #1 |
| 357 |
{ |
| 358 |
%<debug>\@@_debug_start:n { \cs_to_str:N #1 } |
| 359 |
#2 |
| 360 |
%<debug>\@@_debug_end:n { \cs_to_str:N #1 } |
| 361 |
} |
| 362 |
} |
| 363 |
% \end{macrocode} |
| 364 |
% \end{macro} |
| 365 |
% |
| 366 |
% |
| 367 |
% \begin{macrocode} |
| 368 |
%</package> |
| 369 |
% \end{macrocode} |
| 370 |
|
| 371 |
\endinput |
| 372 |
|
| 373 |
|
| 374 |
% /© |
| 375 |
% |
| 376 |
% ------------------------------------------------ |
| 377 |
% The UNICODE-MATH package <wspr.io/unicode-math> |
| 378 |
% ------------------------------------------------ |
| 379 |
% This package is free software and may be redistributed and/or modified under |
| 380 |
% the conditions of the LaTeX Project Public License, version 1.3c or higher |
| 381 |
% (your choice): <http://www.latex-project.org/lppl/>. |
| 382 |
% ------------------------------------------------ |
| 383 |
% Copyright 2006-2019 Will Robertson, LPPL "maintainer" |
| 384 |
% Copyright 2010-2017 Philipp Stephani |
| 385 |
% Copyright 2011-2017 Joseph Wright |
| 386 |
% Copyright 2012-2015 Khaled Hosny |
| 387 |
% ------------------------------------------------ |
| 388 |
% |
| 389 |
% ©/ |