| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% Copyright (C) 2026 by Marcel Krueger |
| 4 |
%% |
| 5 |
%% This file may be distributed and/or modified under the |
| 6 |
%% conditions of the LaTeX Project Public License, either |
| 7 |
%% version 1.3c of this license or (at your option) any later |
| 8 |
%% version. The latest version of this license is in: |
| 9 |
%% |
| 10 |
%% http://www.latex-project.org/lppl.txt |
| 11 |
%% |
| 12 |
%% and version 1.3 or later is part of all distributions of |
| 13 |
%% LaTeX version 2005/12/01 or later. |
| 14 |
% |
| 15 |
%<*gobble> |
| 16 |
\expandafter\ifx\csname @currname\endcsname\empty |
| 17 |
\csname fi\endcsname |
| 18 |
%</gobble> |
| 19 |
%<*driver> |
| 20 |
\documentclass[full,a4paper]{l3doc} |
| 21 |
\usepackage{booktabs} |
| 22 |
\usepackage{lua-unicode-math} |
| 23 |
\MakeShortVerb{\|} |
| 24 |
\begin{document} |
| 25 |
\DocInput{lua-unicode-math.dtx} |
| 26 |
% \PrintIndex |
| 27 |
% \PrintChanges |
| 28 |
\end{document} |
| 29 |
%</driver> |
| 30 |
%<*gobble> |
| 31 |
\fi |
| 32 |
%</gobble> |
| 33 |
% \fi |
| 34 |
% |
| 35 |
% \GetFileInfo{lua-unicode-math.sty} |
| 36 |
% \title{The \pkg{lua-unicode-math} package\thanks{This document |
| 37 |
% corresponds to \pkg{lua-unicode-math}~\fileversion, dated~\filedate.}} |
| 38 |
% \author{Marcel Kr\"uger \\ \href{mailto:[email protected]}{[email protected]} \\ \url{https://github.com/zauguin/lua-unicode-math}} |
| 39 |
% |
| 40 |
% \let\fntname\texttt |
| 41 |
% \maketitle |
| 42 |
% \begin{documentation} |
| 43 |
% Modern fonts are usually provided in OpenType format and are designed for Unicode |
| 44 |
% based input. For mathematical fonts this usually means the use of fonts with an OpenType MATH table: |
| 45 |
% Fonts containing special metadata needed to make them usable in a mathematical context. |
| 46 |
% |
| 47 |
% In Lua\TeX{} such fonts have traditionally been loaded with the \pkg{unicode-math} package. |
| 48 |
% While this works, is very flexible and allows to use the same document in Xe\TeX{} and Lua\TeX{} it has performance issues and it sometimes has unexpected interactions with the use of math versions. The \pkg{lua-unicode-math} is a specific Lua\LaTeX{} specific alternative which aims for higher performance and better integration with native Lua\TeX{} features. |
| 49 |
% |
| 50 |
% \section{Usage instructions} |
| 51 |
% \subsection{Font packages} |
| 52 |
% For most Opentype the recommended way to load them with \pkg{lua-unicode-math} is to use a dedicated package. |
| 53 |
% Currently the following packages are shipped with \pkg{lua-unicode-math}: |
| 54 |
% \begin{tabular}{ll} |
| 55 |
% \toprule |
| 56 |
% Font & Package \\ |
| 57 |
% \midrule |
| 58 |
% Latin Modern Math & lum-lmodern \\ |
| 59 |
% New Computer Modern Math & lum-newcomputermodern \\ |
| 60 |
% New Computer Modern Sans Math & lum-newcomputermodernsans \\ |
| 61 |
% STIX2 & lum-stix2 \\ |
| 62 |
% XITS & lum-xits \\ |
| 63 |
% TeX Gyre Pagella Math & lum-pagella \\ |
| 64 |
% TeX Gyre DejaVu Math & lum-dejavu \\ |
| 65 |
% TeX Gyre Bonum Math & lum-bonum \\ |
| 66 |
% TeX Gyre Schola Math & lum-schola \\ |
| 67 |
% TeX Gyre Termes Math & lum-termes \\ |
| 68 |
% Fira Math & lum-fira \\ |
| 69 |
% GFS Neohellenic Math & lum-gfsneohellenic \\ |
| 70 |
% Erewhon Math & lum-erewhon \\ |
| 71 |
% XCharter Math & lum-xcharter \\ |
| 72 |
% Concrete Math & lum-concrete \\ |
| 73 |
% Euler Math & lum-euler \\ |
| 74 |
% Arsenal Math & lum-arsenal \\ |
| 75 |
% Asana Math & lum-asana \\ |
| 76 |
% Garamond Math & lum-garamond \\ |
| 77 |
% Lete Sans Math & lum-lete-sans \\ |
| 78 |
% Luciole Math & lum-luciole \\ |
| 79 |
% Old Standard Math & lum-oldstandard \\ |
| 80 |
% IBM Plex Math & lum-plex \\ |
| 81 |
% Libertinus Math & lum-libertinus \\ |
| 82 |
% KpMath Sans & lum-kpmath-sans \\ |
| 83 |
% \bottomrule |
| 84 |
% \end{tabular} |
| 85 |
% |
| 86 |
% \subsection{Loading fonts by name} |
| 87 |
% If you want to use a custom font, you can load \pkg{fontspec} and \pkg{lua-unicode-math} |
| 88 |
% using |
| 89 |
% \begin{verbatim} |
| 90 |
% \usepackage{fontspec,lua-unicode-math} |
| 91 |
% \end{verbatim} |
| 92 |
% This will load \fntname{Latin Modern Math} by default. Another math font can be loaded using \cs{setmathfont} using the same options as \pkg{fontspec}'s \cs{newfontfamily}. |
| 93 |
% For example, you can use to to configure the current math font using |
| 94 |
% \begin{verbatim} |
| 95 |
% \setmathfont[AutoFakeBold=1]{Latin Modern Math} |
| 96 |
% \end{verbatim} |
| 97 |
% |
| 98 |
% \subsection{Writing maths} |
| 99 |
% There are two ways of entering math: You can directly input Unicode math symbols or use regular \LaTeX{} commands for symbols. |
| 100 |
% All Unicode symbols are supported with the same commands as in \pkg{unicode-math}. For a full list see \texttt{texdoc unimath-symbols}. |
| 101 |
% |
| 102 |
% \subsection{Selecting math style} |
| 103 |
% \textit{Selecting math style is considered experimental and the interface is not stable.} |
| 104 |
% |
| 105 |
% The \pkg{unicode-math} package allows to configure a math style through package options. It is |
| 106 |
% used to configure which characters are upright or italic in the default math alphabet (\texttt{\symnormal}). |
| 107 |
% To configure similar settings in \pkg{lua-unicode-math}, you can select an instance of the \texttt{lua-unicode-math-style} template. |
| 108 |
% |
| 109 |
% There are four supported styles: |
| 110 |
% \begin{description} |
| 111 |
% \item[TeX] Attempt to be compatible with traditional \TeX{} conventions. This is the default. Everything is italic by default except for capital greek letters which are upright. |
| 112 |
% \item[ISO80000-2] Attempt to be compliant with ISO 80000-2 rules. Everything is italic. |
| 113 |
% \item[french] Latin lowercase is italic, everything else is upright. |
| 114 |
% \item[upright] Everything is upright. |
| 115 |
% \end{description} |
| 116 |
% One of the styles can be selected by running \texttt{\cs{UseInstance}\{lua-unicode-math-style\}\{\meta{style}\}} in your preamble, e.g. |
| 117 |
% \begin{verbatim} |
| 118 |
% \UseInstance{lua-unicode-math-style}{ISO80000-2} |
| 119 |
% \end{verbatim} |
| 120 |
% \end{documentation} |
| 121 |
% \begin{implementation} |
| 122 |
% \section{Implementation} |
| 123 |
% \begin{macrocode} |
| 124 |
\ProvidesExplPackage |
| 125 |
{lua-unicode-math} |
| 126 |
{2026-03-24} |
| 127 |
{0.8} |
| 128 |
{Opentype Math support for LuaLaTeX} |
| 129 |
|
| 130 |
%<@@=l_uni_math> |
| 131 |
\int_new:N \g__l_uni_math_font_count_int |
| 132 |
\tl_new:N \l__l_uni_math_main_family_tl |
| 133 |
\tl_new:N \l__l_uni_math_script_family_tl |
| 134 |
\tl_new:N \l__l_uni_math_scriptscript_family_tl |
| 135 |
|
| 136 |
\cs_generate_variant:Nn \tl_if_eq:nnT {o} |
| 137 |
|
| 138 |
\msg_new:nnn { lua-unicode-math } { engine-unsupported } { |
| 139 |
lua-unicode-math~can~only~be~used~with~LuaTeX. |
| 140 |
} |
| 141 |
|
| 142 |
\sys_if_engine_luatex:F { |
| 143 |
\msg_critical:nn { lua-unicode-math } { engine-unsupported } |
| 144 |
} |
| 145 |
|
| 146 |
\msg_new:nnn { lua-unicode-math } { unicode-math-suppressed } { |
| 147 |
You~tried~to~load~both~lua-unicode-math~and~unicode-math~ |
| 148 |
in~the~same~document.~This~is~not~supported,~unicode-math~ |
| 149 |
will~be~suppressed.~There~is~a~good~chance~that~this~will~ |
| 150 |
break~your~document.~Change~your~document~to~only~use~lua-unicode-math~ |
| 151 |
so~solve~this. |
| 152 |
} |
| 153 |
\msg_new:nnn { lua-unicode-math } { unicode-math-loaded } { |
| 154 |
You~tried~to~load~lua-unicode-math~while~unicode-math~ |
| 155 |
was~already~loaded.~This~does~not~work.~Please~avoid~loading~ |
| 156 |
unicode-math.~If~that~is~not~possible~and~you~are~feeling~adventurous~ |
| 157 |
you~can~try~loading~the~lua-unicode-math~package~at~the~beginning~ |
| 158 |
of~your~document~instead~to~suppress~unicode-math. |
| 159 |
} |
| 160 |
\disable@package@load{unicode-math} { |
| 161 |
\msg_warning:nn { lua-unicode-math } {unicode-math-suppressed } |
| 162 |
} |
| 163 |
\IfPackageLoadedTF {unicode-math} { |
| 164 |
\msg_critical:nn { lua-unicode-math } {unicode-math-loaded } |
| 165 |
} {} |
| 166 |
|
| 167 |
|
| 168 |
\IfFormatAtLeastTF{2026/01/01}{}{ |
| 169 |
\cs_set:Npn \DeclareMathScriptfontMapping #1 #2 #3 #4 #5 #6 { |
| 170 |
\cs_gset:cpn { __nfss_mapped_scriptfont_family_sf_ #1 / #2 } { #3 / #4 } |
| 171 |
\cs_gset:cpn { __nfss_mapped_scriptfont_family_ssf_ #1 / #2 } { #5 / #6 } |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
\hook_gput_code:nnn { package/fontspec/after } {.} { |
| 176 |
\bool_gset_false:N \g__fontspec_math_bool |
| 177 |
|
| 178 |
\NewDocumentCommand \setmathfont { O{} m O{} } { |
| 179 |
\int_incr:N \g__l_uni_math_font_count_int |
| 180 |
\exp_args:Nc \newfontfamily |
| 181 |
{ g__l_uni_math_font_ \int_use:N \g__l_uni_math_font_count_int _text_font } |
| 182 |
{ #2 } |
| 183 |
[ #1, #3, Script = Math, Renderer = Base ] |
| 184 |
\tl_set_eq:NN \l__l_uni_math_main_family_tl \l_fontspec_family_tl |
| 185 |
|
| 186 |
\exp_args:Nc \newfontfamily |
| 187 |
{ g__l_uni_math_font_ \int_use:N \g__l_uni_math_font_count_int _script_font } |
| 188 |
{ #2 } |
| 189 |
[ #1, #3, Script = Math, Renderer = Base, Style = MathScript ] |
| 190 |
\tl_set_eq:NN \l__l_uni_math_script_family_tl \l_fontspec_family_tl |
| 191 |
|
| 192 |
\exp_args:Nc \newfontfamily |
| 193 |
{ g__l_uni_math_font_ \int_use:N \g__l_uni_math_font_count_int _scriptscript_font } |
| 194 |
{ #2 } |
| 195 |
[ #1, #3, Script = Math, Renderer = Base, Style = MathScriptScript ] |
| 196 |
\tl_set_eq:NN \l__l_uni_math_scriptscript_family_tl \l_fontspec_family_tl |
| 197 |
|
| 198 |
\DeclareMathScriptfontMapping {TU} {\l__l_uni_math_main_family_tl} {TU} {\l__l_uni_math_script_family_tl} {TU} {\l__l_uni_math_scriptscript_family_tl} |
| 199 |
|
| 200 |
\exp_args:NnnV \DeclareSymbolFont {lummain} {TU} \l__l_uni_math_main_family_tl {m} {n} |
| 201 |
\exp_args:NnnnV \SetSymbolFont {lummain} {bold} {TU} \l__l_uni_math_main_family_tl {b} {n} |
| 202 |
} |
| 203 |
|
| 204 |
\cs_set:Nn \__fontspec_setmainfont_hook:nn |
| 205 |
{ |
| 206 |
\tl_if_eq:onT {\g__fontspec_mathrm_tl} {\rmdefault} |
| 207 |
{ |
| 208 |
\fontspec_gset_family:Nnn \g__fontspec_mathrm_tl {Renderer=Basic,#1} {#2} |
| 209 |
\__fontspec_setmathrm_hook:nn {#1} {#2} |
| 210 |
} |
| 211 |
} |
| 212 |
\cs_set:Nn \__fontspec_setsansfont_hook:nn |
| 213 |
{ |
| 214 |
\tl_if_eq:onT {\g__fontspec_mathsf_tl} {\sfdefault} |
| 215 |
{ |
| 216 |
\fontspec_gset_family:Nnn \g__fontspec_mathsf_tl {Renderer=Basic,#1} {#2} |
| 217 |
\__fontspec_setmathsf_hook:nn {#1} {#2} |
| 218 |
} |
| 219 |
} |
| 220 |
\cs_set:Nn \__fontspec_setmonofont_hook:nn |
| 221 |
{ |
| 222 |
\tl_if_eq:onT {\g__fontspec_mathtt_tl} {\ttdefault} |
| 223 |
{ |
| 224 |
\fontspec_gset_family:Nnn \g__fontspec_mathtt_tl {Renderer=Basic,#1} {#2} |
| 225 |
\__fontspec_setmathtt_hook:nn {#1} {#2} |
| 226 |
} |
| 227 |
} |
| 228 |
\cs_set:Nn \__fontspec_setmathrm_hook:nn |
| 229 |
{ |
| 230 |
\SetMathAlphabet \mathrm { normal } \g_fontspec_encoding_tl \g__fontspec_mathrm_tl { \mdseries@rm } \shapedefault |
| 231 |
\SetMathAlphabet \mathit { normal } \g_fontspec_encoding_tl \g__fontspec_mathrm_tl { \mdseries@rm } \itdefault |
| 232 |
\SetMathAlphabet \mathbf { normal } \g_fontspec_encoding_tl \g__fontspec_mathrm_tl { \bfseries@rm } \shapedefault |
| 233 |
} |
| 234 |
\cs_set:Nn \__fontspec_setboldmathrm_hook:nn |
| 235 |
{ |
| 236 |
\SetMathAlphabet \mathrm { bold } \g_fontspec_encoding_tl \g__fontspec_bfmathrm_tl { \mdseries@rm } \shapedefault |
| 237 |
\SetMathAlphabet \mathit { bold } \g_fontspec_encoding_tl \g__fontspec_bfmathrm_tl { \mdseries@rm } \itdefault |
| 238 |
\SetMathAlphabet \mathbf { bold } \g_fontspec_encoding_tl \g__fontspec_bfmathrm_tl { \bfseries@rm } \shapedefault |
| 239 |
} |
| 240 |
\cs_set:Nn \__fontspec_setmathsf_hook:nn |
| 241 |
{ |
| 242 |
\SetMathAlphabet \mathsf { normal } \g_fontspec_encoding_tl \g__fontspec_mathsf_tl { \mdseries@rm } \shapedefault |
| 243 |
\SetMathAlphabet \mathsf { bold } \g_fontspec_encoding_tl \g__fontspec_mathsf_tl { \bfseries@rm } \shapedefault |
| 244 |
} |
| 245 |
\cs_set:Nn \__fontspec_setmathtt_hook:nn |
| 246 |
{ |
| 247 |
\SetMathAlphabet \mathtt { normal } \g_fontspec_encoding_tl \g__fontspec_mathtt_tl { \mdseries@rm } \shapedefault |
| 248 |
\SetMathAlphabet \mathtt { bold } \g_fontspec_encoding_tl \g__fontspec_mathtt_tl { \bfseries@rm } \shapedefault |
| 249 |
} |
| 250 |
% |
| 251 |
\__fontspec_setmathrm_hook:nn {} {} |
| 252 |
\__fontspec_setmathsf_hook:nn {} {} |
| 253 |
\__fontspec_setmathtt_hook:nn {} {} |
| 254 |
} |
| 255 |
|
| 256 |
\cs_set_protected:Npn \operator@font { |
| 257 |
\@fontswitch { \font@warning{Math~mode~required~for~\string\operator@font.} } { \mathtextrm } |
| 258 |
} |
| 259 |
|
| 260 |
\DeclareSymbolFont {lummain} {TU} {lmm} {m} {n} |
| 261 |
\SetSymbolFont {lummain} {bold} {TU} {lmm} {b} {n} |
| 262 |
|
| 263 |
\newattribute \mathfamattr |
| 264 |
|
| 265 |
\cs_if_exist:NF \slimits@ { |
| 266 |
\cs_set_eq:NN \slimits@ \displaylimits |
| 267 |
} |
| 268 |
\cs_if_exist:NF \ilimits@ { |
| 269 |
\cs_set_eq:NN \ilimits@ \nolimits |
| 270 |
} |
| 271 |
\chardef \g_l_uni_math_dots_binary_char = `⋯ |
| 272 |
\chardef \g_l_uni_math_dots_comma_char = `… |
| 273 |
\chardef \g_l_uni_math_dots_int_char = `⋯ |
| 274 |
\chardef \g_l_uni_math_dots_other_char = `… |
| 275 |
|
| 276 |
\cs_set_protected:Npn \DOTSB { |
| 277 |
\__l_uni_math_set_previous_dots_type:w \g_l_uni_math_dots_binary_char |
| 278 |
} |
| 279 |
|
| 280 |
\cs_set_protected:Npn \DOTSX { |
| 281 |
\__l_uni_math_set_previous_dots_type:w \g_l_uni_math_dots_other_char |
| 282 |
} |
| 283 |
|
| 284 |
\cs_set_protected:Npn \DOTSI { |
| 285 |
\__l_uni_math_set_previous_dots_type:w \g_l_uni_math_dots_int_char |
| 286 |
} |
| 287 |
|
| 288 |
\cs_set_protected:Npn \DOTSC { |
| 289 |
\__l_uni_math_set_previous_dots_type:w \g_l_uni_math_dots_comma_char |
| 290 |
} |
| 291 |
|
| 292 |
\lua_load_module:n { lua-unicode-math } |
| 293 |
|
| 294 |
\cs_new_protected:Npn \__l_uni_math_define_mathstyle_cmd:n #1 { |
| 295 |
\cs_new_protected:cpx { sym #1 } ##1 { |
| 296 |
\group_begin: |
| 297 |
\mathfamattr = \use:c { c__l_uni_math_attribute_sym #1 _int } |
| 298 |
##1 |
| 299 |
\group_end: |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
\int_new:N \g__l_uni_math_max_mathstyle_int |
| 304 |
\int_gset:Nn \g__l_uni_math_max_mathstyle_int { 1024 } |
| 305 |
\cs_new:Npn \__l_uni_math_provide_mathstyle_id:n #1 { |
| 306 |
\cs_if_exist:cF { c__l_uni_math_attribute_sym #1 _int } { |
| 307 |
\int_const:cn { c__l_uni_math_attribute_sym #1 _int } { \g__l_uni_math_max_mathstyle_int } |
| 308 |
\int_incr:N \g__l_uni_math_max_mathstyle_int |
| 309 |
\__l_uni_math_define_mathstyle_cmd:n { #1 } |
| 310 |
} |
| 311 |
} |
| 312 |
|
| 313 |
% This should be |
| 314 |
% \tex_Umathcharnumdef:D \c__l_uni_math_attribute_symnormal_int = -"7FFFFFFF \scan_stop |
| 315 |
% but LuaTeX is too buggy to save this correctly. |
| 316 |
\tex_Umathchardef:D \c__l_uni_math_attribute_symnormal_int = "0 "80 "1 \scan_stop: |
| 317 |
\__l_uni_math_define_mathstyle_cmd:n {normal} |
| 318 |
\cs_gset:Npn \mathnormal { \symnormal } |
| 319 |
|
| 320 |
\seq_set_from_clist:Nn \l_tmpa_seq { |
| 321 |
up, rm, it, tt, bf, sf |
| 322 |
} |
| 323 |
\seq_map_inline:Nn \l_tmpa_seq { |
| 324 |
\cs_new_eq:cc { mathtext #1 } { math #1 } |
| 325 |
} |
| 326 |
\prop_set_from_keyval:Nn \l_tmpa_prop { |
| 327 |
up = 0, bfup = 1, it = 2, bfit = 3, |
| 328 |
sfup = 4, bfsfup = 5, sfit = 6, bfsfit = 7, |
| 329 |
cal = 8, bfcal = 9, |
| 330 |
scr = 12, bfscr = 13, |
| 331 |
frak = 16, bffrak = 17, |
| 332 |
tt = 20, |
| 333 |
bb = 24, |
| 334 |
} |
| 335 |
\prop_map_inline:Nn \l_tmpa_prop { |
| 336 |
\int_const:cn { c__l_uni_math_attribute_sym #1 _int } { #2 } |
| 337 |
\__l_uni_math_define_mathstyle_cmd:n { #1 } |
| 338 |
\cs_set_eq:cc { math #1 } { sym #1 } |
| 339 |
} |
| 340 |
\cs_set_eq:NN \symrm \symup |
| 341 |
\cs_set_eq:NN \mathtextup \mathtextrm |
| 342 |
\cs_set_eq:NN \mathtextsf \mathsf |
| 343 |
\cs_set:Npn \mathbfsf { \symbfsf } |
| 344 |
|
| 345 |
\seq_map_inline:Nn \l_tmpa_seq { |
| 346 |
\cs_set_eq:cc { math #1 } { mathtext #1 } |
| 347 |
} |
| 348 |
|
| 349 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathord :nn } #1 #2 { |
| 350 |
\cs_set:Npx #1 { |
| 351 |
\char_generate:nn {#2} {12} |
| 352 |
} |
| 353 |
} |
| 354 |
\tl_map_inline:nn {\mathbin \mathclose \mathpunct \mathrel} { |
| 355 |
\cs_new_eq:cc |
| 356 |
{ __l_uni_math_UnicodeMathSymbol_ \token_to_str:N #1 :nn } |
| 357 |
{ __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathord :nn } |
| 358 |
} |
| 359 |
|
| 360 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathop :nn } #1 #2 { |
| 361 |
\exp_args:Nc \Umathchardef { \cs_to_str:N #1 op } 1~\symlummain #2~ |
| 362 |
\cs_set:Npx #1 { |
| 363 |
\char_generate:nn {#2} {12} |
| 364 |
} |
| 365 |
\mathcode #2 = "8000~ |
| 366 |
\cs_set:cpx { \char_generate:nn {"FFFF} {12} \char_generate:nn {#2} {12} } { |
| 367 |
\__l_uni_math_is_integral_cp:wTF #2 { \DOTSI } { \DOTSB } |
| 368 |
\use:c { \cs_to_str:N #1 op } |
| 369 |
\__l_uni_math_is_integral_cp:wTF #2 { \ilimits@ } { \slimits@ } |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathopen :nn } #1 #2 { |
| 374 |
\token_if_eq_meaning:NNTF #1 \sqrt { |
| 375 |
\cs_set:Npx \sqrtsign { |
| 376 |
\Uradical \symlummain #2~ |
| 377 |
} |
| 378 |
\cs_set:Npx \root ##1 \of { |
| 379 |
\Uroot \symlummain #2~ { ##1 } |
| 380 |
} |
| 381 |
}{ |
| 382 |
\cs_set:Npx #1 { |
| 383 |
\char_generate:nn {#2} {12} |
| 384 |
} |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
% For a \mathalpha command starting with \mup like \mupalpha this will be called as |
| 389 |
% \__l_uni_math_uproot_assign_mup_char:nNn {alpha} \Alpha {"...} |
| 390 |
\cs_new_protected:Npn \__l_uni_math_uproot_assign_mup_char:nNn #1 #2 #3 { |
| 391 |
\cs_set:Npx #2 { |
| 392 |
\symup {\char_generate:nn {#3} {12}} |
| 393 |
} |
| 394 |
\cs_set:cpx {#1} { |
| 395 |
\char_generate:nn {#3} {12} |
| 396 |
} |
| 397 |
} |
| 398 |
|
| 399 |
% For a \mathalpha command not starting with \mup this will be called as \__l_uni_math_uproot_assign_mup_char:nNn {} \cmd {"...} |
| 400 |
\cs_new_protected:Npn \__l_uni_math_uproot_assign_nonmup_alpha:nNn #1 #2 #3 { |
| 401 |
\cs_set:Npx #2 { |
| 402 |
\char_generate:nn {#3} {12} |
| 403 |
} |
| 404 |
} |
| 405 |
|
| 406 |
\group_begin: |
| 407 |
\cs_set:Npn \l_tmp_cs:n #1 { |
| 408 |
\group_end: |
| 409 |
|
| 410 |
\cs_new_protected:Npn \__l_uni_math__check_mup_helper:w ##1 #1 ##2 \q_mark ##3 ##4 \q_stop { |
| 411 |
##3 {##2} |
| 412 |
} |
| 413 |
|
| 414 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathalpha :nn } ##1 { |
| 415 |
\exp_after:wN \__l_uni_math__check_mup_helper:w \token_to_str:N ##1 \q_mark \__l_uni_math_uproot_assign_mup_char:nNn #1 \q_mark \__l_uni_math_uproot_assign_nonmup_alpha:nNn \q_stop ##1 |
| 416 |
} |
| 417 |
} |
| 418 |
|
| 419 |
\exp_args:No \l_tmp_cs:n { |
| 420 |
\token_to_str:N \mup |
| 421 |
} |
| 422 |
|
| 423 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathfence :nn } #1 #2 { |
| 424 |
\cs_set:Npx #1 { |
| 425 |
\char_generate:nn {#2} {12} |
| 426 |
} |
| 427 |
\cs_set:cpx {l \cs_to_str:N #1} { |
| 428 |
\Udelimiter 4 ~ \symlummain #2 ~ |
| 429 |
} |
| 430 |
\cs_set:cpx {r \cs_to_str:N #1} { |
| 431 |
\Udelimiter 5 ~ \symlummain #2 ~ |
| 432 |
} |
| 433 |
} |
| 434 |
|
| 435 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathaccent :nn } #1 #2 { |
| 436 |
\cs_set_protected:Npx #1 { |
| 437 |
\Umathaccent fixed 0 ~ \symlummain #2 ~ |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathbotaccent :nn } #1 #2 { |
| 442 |
\cs_set:Npx #1 { |
| 443 |
\Umathaccent bottom~fixed 0 ~ \symlummain #2 ~ |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathaccentwide :nn } #1 #2 { |
| 448 |
\cs_set:Npx #1 { |
| 449 |
\Umathaccent 0 ~ \symlummain #2 ~ |
| 450 |
} |
| 451 |
} |
| 452 |
|
| 453 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathbotaccentwide :nn } #1 #2 { |
| 454 |
\cs_set:Npx #1 { |
| 455 |
\Umathaccent bottom 0 ~ \symlummain #2 ~ |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathaccentoverlay :nn } #1 #2 { |
| 460 |
\cs_set:Npx #1 { |
| 461 |
\Umathaccent overlay 0 ~ \symlummain #2 ~ |
| 462 |
} |
| 463 |
} |
| 464 |
|
| 465 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathover :nn } #1 #2 { |
| 466 |
\cs_set:Npx #1 ##1 { |
| 467 |
\mathop { |
| 468 |
\Udelimiterover \symlummain #2 { ##1 } |
| 469 |
} |
| 470 |
\limits |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
\cs_new:cpn { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N \mathunder :nn } #1 #2 { |
| 475 |
\cs_set:Npx #1 ##1 { |
| 476 |
\mathop { |
| 477 |
\Udelimiterunder \symlummain #2 { ##1 } |
| 478 |
} |
| 479 |
\limits |
| 480 |
} |
| 481 |
} |
| 482 |
|
| 483 |
\cs_generate_variant:Nn \exp_args:Ne {c} |
| 484 |
\cs_new:Npn \UnicodeMathSymbol #1 #2 #3 #4 { |
| 485 |
\use:c { __l_uni_math_UnicodeMathSymbol_ \token_to_str:N #3 :nn } |
| 486 |
{#2} {#1} |
| 487 |
} |
| 488 |
\input {unicode-math-table} |
| 489 |
\cs_undefine:N \UnicodeMathSymbol |
| 490 |
|
| 491 |
\cs_set_protected:Npn \triangle { \mathord { \bigtriangleup } } |
| 492 |
\cs_set_protected:Npn \mathellipsis { \mathinner { \unicodeellipsis } } |
| 493 |
\cs_set_protected:Npn \cdots { \mathinner { \unicodecdots } } |
| 494 |
|
| 495 |
\clist_map_inline:nn { |
| 496 |
\to \rightarrow, |
| 497 |
\le \leq, |
| 498 |
\ge \geq, |
| 499 |
\neq \ne, |
| 500 |
\bigcirc \mdlgwhtcircle, |
| 501 |
\circ \vysmwhtcircle, |
| 502 |
\bullet \smblkcircle, |
| 503 |
\mathyen \yen, |
| 504 |
\mathsterling \sterling, |
| 505 |
\diamond \smwhtdiamond, |
| 506 |
\emptyset \varnothing, |
| 507 |
\hbar \hslash, |
| 508 |
\land \wedge, |
| 509 |
\lor \vee, |
| 510 |
\owns \ni, |
| 511 |
\gets \leftarrow, |
| 512 |
\mathring \ocirc, |
| 513 |
\lnot \neg, |
| 514 |
\longdivision \longdivisionsign, |
| 515 |
\backepsilon \upbackepsilon, |
| 516 |
\eth \matheth, |
| 517 |
\dotsb@ \cdots, |
| 518 |
\@cdots \cdots, |
| 519 |
} { |
| 520 |
\cs_set_eq:NN #1 |
| 521 |
} |
| 522 |
|
| 523 |
\cs_set_protected:cpx { \char_generate:nn {"FFFF} {12} ' } { |
| 524 |
\prime_helper:w "2032~ |
| 525 |
} |
| 526 |
|
| 527 |
\cs_set_protected:Npn \uproot #1 { |
| 528 |
\__l_uni_math_uproot:w #1 \scan_stop: |
| 529 |
} |
| 530 |
|
| 531 |
\cs_set_protected:Npn \leftroot #1 { |
| 532 |
\__l_uni_math_leftroot:w #1 \scan_stop: |
| 533 |
} |
| 534 |
% \end{macrocode} |
| 535 |
% Some fixes for \pkg{amsmath}: Since \pkg{amsmath} is defining \cs{leftroot}, |
| 536 |
% \cs{uproot} and \cs{root} with non Unicode definitions, we need to hide our definitions |
| 537 |
% and restore them afterwards. |
| 538 |
% We define \cs{varGamma} to stop \pkg{amsmath} from trying to define greek letter variants. |
| 539 |
% \begin{macrocode} |
| 540 |
\tl_const:Nn \c__l_uni_math_amsmath_cmds_tl { |
| 541 |
\uproot |
| 542 |
\leftroot |
| 543 |
\iint |
| 544 |
\iiint |
| 545 |
\iiiint |
| 546 |
\dddot |
| 547 |
\ddddot |
| 548 |
\overleftrightarrow |
| 549 |
\underrightarrow |
| 550 |
\underleftarrow |
| 551 |
\underleftrightarrow |
| 552 |
\hat |
| 553 |
\check |
| 554 |
\tilde |
| 555 |
\acute |
| 556 |
\grave |
| 557 |
\dot |
| 558 |
\ddot |
| 559 |
\breve |
| 560 |
\bar |
| 561 |
\vec |
| 562 |
\mathring |
| 563 |
\DOTSC |
| 564 |
\DOTSI |
| 565 |
\DOTSX |
| 566 |
\DOTSB |
| 567 |
\mdots@ |
| 568 |
} |
| 569 |
\tl_const:Nn \c__l_uni_math_amsmath_cmds_defined_tl { |
| 570 |
\prod |
| 571 |
\coprod |
| 572 |
\bigwedge |
| 573 |
\bigvee |
| 574 |
\bigcap |
| 575 |
\bigcup |
| 576 |
\bigodot |
| 577 |
\bigoplus |
| 578 |
\bigotimes |
| 579 |
\bigsqcup |
| 580 |
\root |
| 581 |
\int |
| 582 |
\oint |
| 583 |
\overrightarrow |
| 584 |
\overleftarrow |
| 585 |
} |
| 586 |
\hook_gput_code:nnn { package/amsmath/before } {.} { |
| 587 |
\tl_map_inline:Nn \c__l_uni_math_amsmath_cmds_tl { |
| 588 |
\cs_new_eq:cN { __l_uni_math_saved_ \cs_to_str:N #1 } #1 |
| 589 |
\cs_undefine:N #1 |
| 590 |
} |
| 591 |
\tl_map_inline:Nn \c__l_uni_math_amsmath_cmds_defined_tl { |
| 592 |
\cs_new_eq:cN { __l_uni_math_saved_ \cs_to_str:N #1 } #1 |
| 593 |
} |
| 594 |
\cs_set:Npn \varGamma { \temporary_definition_do_not_use } |
| 595 |
} |
| 596 |
\hook_gput_code:nnn { package/amsmath/after } {.} { |
| 597 |
\tl_map_inline:Nn \c__l_uni_math_amsmath_cmds_tl { |
| 598 |
\cs_set_eq:Nc #1 { __l_uni_math_saved_ \cs_to_str:N #1 } |
| 599 |
\cs_undefine:c { __l_uni_math_saved_ \cs_to_str:N #1 } |
| 600 |
} |
| 601 |
\tl_map_inline:Nn \c__l_uni_math_amsmath_cmds_defined_tl { |
| 602 |
\cs_set_eq:Nc #1 { __l_uni_math_saved_ \cs_to_str:N #1 } |
| 603 |
\cs_undefine:c { __l_uni_math_saved_ \cs_to_str:N #1 } |
| 604 |
} |
| 605 |
\cs_undefine:N \varGamma |
| 606 |
} |
| 607 |
\addto@hook \every@math@size { |
| 608 |
\__l_uni_math_every_math_size: |
| 609 |
} |
| 610 |
% \end{macrocode} |
| 611 |
% \subsection{Customization} |
| 612 |
% We defined templates to customize the behavior of \pkg{lua-unicode-math}. |
| 613 |
% The main customization point for the user is the \texttt{lua-unicode-math-style} which |
| 614 |
% selects how \cs{symnormal} and \cs{symbf} behave. |
| 615 |
% \begin{macrocode} |
| 616 |
\NewTemplateType {lua-unicode-math-style} {0} |
| 617 |
% \end{macrocode} |
| 618 |
% |
| 619 |
% In the default interface \texttt{substyles} a mathstyle is defined in terms of |
| 620 |
% two nested instances of type \texttt{lua-unicode-math-style-cmd}. This template allows to |
| 621 |
% define or redefine a mathstyle like \texttt{normal}, \texttt{bf} or \texttt{up} with corresponding |
| 622 |
% \cs{sym...} command. |
| 623 |
% \begin{macrocode} |
| 624 |
\NewTemplateType {lua-unicode-math-style-cmd} {1} |
| 625 |
\DeclareTemplateInterface {lua-unicode-math-style} {substyles} {0} { |
| 626 |
normal: instance {lua-unicode-math-style-cmd}, |
| 627 |
bf: instance {lua-unicode-math-style-cmd}, |
| 628 |
sf: instance {lua-unicode-math-style-cmd}, |
| 629 |
bfsf: instance {lua-unicode-math-style-cmd}, |
| 630 |
} |
| 631 |
% \end{macrocode} |
| 632 |
% |
| 633 |
% By default a new style command instance is defined by defining mappings for the five main |
| 634 |
% math alphabets to existing styles. |
| 635 |
% \begin{macrocode} |
| 636 |
\DeclareTemplateInterface {lua-unicode-math-style-cmd} {alphabet-style-mapping} {1} { |
| 637 |
Latin: tokenlist, |
| 638 |
latin: tokenlist, |
| 639 |
Greek: tokenlist, |
| 640 |
greek: tokenlist, |
| 641 |
digit: tokenlist, |
| 642 |
} |
| 643 |
% \end{macrocode} |
| 644 |
% |
| 645 |
% By default a new style command instance is defined by defining mappings for the five main |
| 646 |
% math alphabets to existing styles. |
| 647 |
% \begin{macrocode} |
| 648 |
\DeclareTemplateCode {lua-unicode-math-style} {substyles} {0} { |
| 649 |
normal = \__l_uni_math_instance_normal:n, |
| 650 |
bf = \__l_uni_math_instance_bf:n, |
| 651 |
sf = \__l_uni_math_instance_sf:n, |
| 652 |
bfsf = \__l_uni_math_instance_bfsf:n, |
| 653 |
} { |
| 654 |
\__l_uni_math_instance_normal:n { normal } |
| 655 |
\__l_uni_math_instance_bf:n { bf } |
| 656 |
\__l_uni_math_instance_sf:n { sf } |
| 657 |
\__l_uni_math_instance_bfsf:n { bfsf } |
| 658 |
} |
| 659 |
\cs_generate_variant:Nn \__l_uni_math_set_mathstyle_mappings:NNNNNN { cccccc } |
| 660 |
\tl_new:N \l__l_uni_math_Latin_style_tl |
| 661 |
\tl_new:N \l__l_uni_math_latin_style_tl |
| 662 |
\tl_new:N \l__l_uni_math_Greek_style_tl |
| 663 |
\tl_new:N \l__l_uni_math_greek_style_tl |
| 664 |
\tl_new:N \l__l_uni_math_digit_style_tl |
| 665 |
\DeclareTemplateCode {lua-unicode-math-style-cmd} {alphabet-style-mapping} {1} { |
| 666 |
Latin = \l__l_uni_math_Latin_style_tl, |
| 667 |
latin = \l__l_uni_math_latin_style_tl, |
| 668 |
Greek = \l__l_uni_math_Greek_style_tl, |
| 669 |
greek = \l__l_uni_math_greek_style_tl, |
| 670 |
digit = \l__l_uni_math_digit_style_tl, |
| 671 |
} { |
| 672 |
\__l_uni_math_provide_mathstyle_id:n { #1 } |
| 673 |
\__l_uni_math_set_mathstyle_mappings:cccccc |
| 674 |
{ c__l_uni_math_attribute_sym #1 _int } |
| 675 |
{ c__l_uni_math_attribute_sym \l__l_uni_math_Latin_style_tl _int } |
| 676 |
{ c__l_uni_math_attribute_sym \l__l_uni_math_latin_style_tl _int } |
| 677 |
{ c__l_uni_math_attribute_sym \l__l_uni_math_Greek_style_tl _int } |
| 678 |
{ c__l_uni_math_attribute_sym \l__l_uni_math_greek_style_tl _int } |
| 679 |
{ c__l_uni_math_attribute_sym \l__l_uni_math_digit_style_tl _int } |
| 680 |
} |
| 681 |
% \end{macrocode} |
| 682 |
% |
| 683 |
% Finally we define some defaults. |
| 684 |
% \begin{macrocode} |
| 685 |
\DeclareInstance{lua-unicode-math-style}{TeX}{substyles}{ |
| 686 |
normal = TeX, |
| 687 |
bf = TeX-bf, |
| 688 |
sf = upright-sf, |
| 689 |
bfsf = upright-bfsf, |
| 690 |
} |
| 691 |
\DeclareInstance{lua-unicode-math-style}{ISO80000-2}{substyles}{ |
| 692 |
normal = ISO80000-2, |
| 693 |
bf = ISO80000-2-bf, |
| 694 |
sf = italic-sf, |
| 695 |
bfsf = italic-bfsf, |
| 696 |
} |
| 697 |
\DeclareInstance{lua-unicode-math-style}{french}{substyles}{ |
| 698 |
normal = french, |
| 699 |
bf = upright-bf, |
| 700 |
sf = upright-sf, |
| 701 |
bfsf = upright-bfsf, |
| 702 |
} |
| 703 |
\DeclareInstance{lua-unicode-math-style}{upright}{substyles}{ |
| 704 |
normal = upright, |
| 705 |
bf = upright-bf, |
| 706 |
sf = upright-sf, |
| 707 |
bfsf = upright-bfsf, |
| 708 |
} |
| 709 |
\DeclareInstance{lua-unicode-math-style-cmd}{TeX}{alphabet-style-mapping}{ |
| 710 |
Latin = it, |
| 711 |
latin = it, |
| 712 |
Greek = up, |
| 713 |
greek = it, |
| 714 |
digit = up, |
| 715 |
} |
| 716 |
\DeclareInstance{lua-unicode-math-style-cmd}{TeX-bf}{alphabet-style-mapping}{ |
| 717 |
Latin = bfup, |
| 718 |
latin = bfup, |
| 719 |
Greek = bfup, |
| 720 |
greek = bfit, |
| 721 |
digit = bfup, |
| 722 |
} |
| 723 |
\DeclareInstance{lua-unicode-math-style-cmd}{ISO80000-2}{alphabet-style-mapping}{ |
| 724 |
Latin = it, |
| 725 |
latin = it, |
| 726 |
Greek = it, |
| 727 |
greek = it, |
| 728 |
digit = up, |
| 729 |
} |
| 730 |
\DeclareInstance{lua-unicode-math-style-cmd}{ISO80000-2-bf}{alphabet-style-mapping}{ |
| 731 |
Latin = bfit, |
| 732 |
latin = bfit, |
| 733 |
Greek = bfit, |
| 734 |
greek = bfit, |
| 735 |
digit = bfup, |
| 736 |
} |
| 737 |
\DeclareInstance{lua-unicode-math-style-cmd}{french}{alphabet-style-mapping}{ |
| 738 |
Latin = up, |
| 739 |
latin = it, |
| 740 |
Greek = up, |
| 741 |
greek = up, |
| 742 |
digit = up, |
| 743 |
} |
| 744 |
\DeclareInstance{lua-unicode-math-style-cmd}{upright}{alphabet-style-mapping}{ |
| 745 |
Latin = up, |
| 746 |
latin = up, |
| 747 |
Greek = up, |
| 748 |
greek = up, |
| 749 |
digit = up, |
| 750 |
} |
| 751 |
\DeclareInstance{lua-unicode-math-style-cmd}{upright-bf}{alphabet-style-mapping}{ |
| 752 |
Latin = bfup, |
| 753 |
latin = bfup, |
| 754 |
Greek = bfup, |
| 755 |
greek = bfup, |
| 756 |
digit = bfup, |
| 757 |
} |
| 758 |
\DeclareInstance{lua-unicode-math-style-cmd}{upright-sf}{alphabet-style-mapping}{ |
| 759 |
Latin = sfup, |
| 760 |
latin = sfup, |
| 761 |
Greek = sfup, |
| 762 |
greek = sfup, |
| 763 |
digit = sfup, |
| 764 |
} |
| 765 |
\DeclareInstance{lua-unicode-math-style-cmd}{italic-sf}{alphabet-style-mapping}{ |
| 766 |
Latin = sfit, |
| 767 |
latin = sfit, |
| 768 |
Greek = sfit, |
| 769 |
greek = sfit, |
| 770 |
digit = sfit, |
| 771 |
} |
| 772 |
\DeclareInstance{lua-unicode-math-style-cmd}{upright-bfsf}{alphabet-style-mapping}{ |
| 773 |
Latin = bfsfup, |
| 774 |
latin = bfsfup, |
| 775 |
Greek = bfsfup, |
| 776 |
greek = bfsfup, |
| 777 |
digit = bfsfup, |
| 778 |
} |
| 779 |
\DeclareInstance{lua-unicode-math-style-cmd}{italic-bfsf}{alphabet-style-mapping}{ |
| 780 |
Latin = bfsfit, |
| 781 |
latin = bfsfit, |
| 782 |
Greek = bfsfit, |
| 783 |
greek = bfsfit, |
| 784 |
digit = bfsfit, |
| 785 |
} |
| 786 |
\UseInstance {lua-unicode-math-style} {TeX} |
| 787 |
% \end{macrocode} |
| 788 |
% \end{implementation} |