From f15ab98da224024bdcb9d2b70a263c7f6143a91b Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sun, 7 Jan 2018 23:46:58 +0000
Subject: unicode-math (7jan18)

git-svn-id: svn://tug.org/texlive/trunk@46240 c570f23f-e606-0410-a88d-b1316a301751
---
 .../source/latex/unicode-math/um-code-main.dtx     | 518 +++++++++++++--------
 1 file changed, 329 insertions(+), 189 deletions(-)

(limited to 'Master/texmf-dist/source/latex/unicode-math/um-code-main.dtx')

diff --git a/Master/texmf-dist/source/latex/unicode-math/um-code-main.dtx b/Master/texmf-dist/source/latex/unicode-math/um-code-main.dtx
index 942ea4771fa..2ae228df24e 100644
--- a/Master/texmf-dist/source/latex/unicode-math/um-code-main.dtx
+++ b/Master/texmf-dist/source/latex/unicode-math/um-code-main.dtx
@@ -1,4 +1,5 @@
 %%^^A%% um-code-main.dtx -- part of UNICODE-MATH <wspr.io/unicode-math>
+%%^^A%% Definition of `\setmainfont`.
 
 % \section{The main \cs{setmathfont} macro}
 %
@@ -6,103 +7,75 @@
 %<*package>
 %    \end{macrocode}
 %
-% Using a |range| including large character sets such as \cmd\mathrel,
-% \cmd\mathalpha, \etc, is \emph{very slow}!
-% I hope to improve the performance somehow.
-%
 % \begin{macro}{\@@_setmathfont:nn}
+% \darg{keyval options}
+% \darg{font name/file}
 %    \begin{macrocode}
 \cs_set:Nn \@@_setmathfont:nn
   {
-    \tl_set:Nn \l_@@_fontname_tl {#2}
 %    \end{macrocode}
+% \begin{itemize}
+% \item Initialise all local variables.
+% \item
 % Erase any conception \LaTeX\ has of previously defined math symbol fonts;
 % this allows \cmd\DeclareSymbolFont\ at any point in the document.
-%    \begin{macrocode}
-    \cs_set_eq:NN \glb@currsize \scan_stop:
-%    \end{macrocode}
-% Initialise all local variabes:
-%    \begin{macrocode}
-    \@@_init:
-%    \end{macrocode}
+% \item
 % Grab the current size information:
 % (is this robust enough? Maybe it should be preceded by \cmd\normalsize).
 % The macro \cmd\S@\meta{size}
 % contains the definitions of the sizes used for maths letters, subscripts and subsubscripts in
 % \cmd\tf@size, \cmd\sf@size, and \cmd\ssf@size, respectively.
+% \end{itemize}
 %    \begin{macrocode}
+
+    \@@_init:n {#2}
+    \cs_set_eq:NN \glb@currsize \scan_stop:
     \cs_if_exist:cF { S@ \f@size } { \calculate@math@sizes }
-    \csname S@\f@size\endcsname
-%    \end{macrocode}
-% Parse options and tell people what's going on:
-%    \begin{macrocode}
+    \use:c { S@ \f@size }
+
     \keys_set_known:nnN {unicode-math} {#1} \l_@@_unknown_keys_clist
-    \bool_if:NT \l_@@_init_bool { \@@_log:n {default-math-font} }
-%    \end{macrocode}
-% Use \pkg{fontspec} to select a font to use.
-% After loading the font, we detect what sizes it recommends for scriptsize and scriptscriptsize, so after setting those values appropriately, we reload the font to take these into account.
-%    \begin{macrocode}
-%<debug>  \csname TIC\endcsname
-    \@@_fontspec_select_font:
-%<debug>  \csname TOC\endcsname
-    \bool_if:nT { \l_@@_ot_math_bool && !\g_@@_mainfont_already_set_bool }
+
+    \bool_if:NT \l_@@_init_bool
       {
+        \@@_fontspec_trial_font:
         \@@_declare_math_sizes:
-        \@@_fontspec_select_font:
       }
-%    \end{macrocode}
-% Now define |\l_@@_symfont_label_tl| as the \LaTeX\ math font to access everything:
-%    \begin{macrocode}
-    \cs_if_exist:cF { sym \l_@@_symfont_label_tl }
-      {
-        \DeclareSymbolFont{\l_@@_symfont_label_tl}
-          {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
-      }
-    \SetSymbolFont{\l_@@_symfont_label_tl}{\l_@@_mversion_tl}
-      {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
-%    \end{macrocode}
-% Set the bold math version.
-%    \begin{macrocode}
-    \str_if_eq_x:nnT {\l_@@_mversion_tl} {normal}
-      {
-        \SetSymbolFont{\l_@@_symfont_label_tl}{bold}
-          {\encodingdefault}{\l_@@_family_tl}{\bfdefault}{\updefault}
-      }
-%    \end{macrocode}
-% Declare the math sizes (i.e., scaling of superscripts) for the specific
-% values for this font,
-% and set defaults for math fams two and three for legacy compatibility:
-%    \begin{macrocode}
-    \bool_if:nT { \l_@@_ot_math_bool && !\g_@@_mainfont_already_set_bool }
+    \@@_fontspec_select_font:
+    \@@_setup_math_fam:
+    \bool_if:NT \l_@@_init_bool
       {
-        \bool_set_true:N \g_@@_mainfont_already_set_bool
         \@@_setup_legacy_fam_two:
         \@@_setup_legacy_fam_three:
       }
-%    \end{macrocode}
-% And now we input every single maths char.
-%    \begin{macrocode}
-%<debug>  \csname TIC\endcsname
+
     \@@_input_math_symbol_table:
-%<debug>  \csname TOC\endcsname
+
 %    \end{macrocode}
-% Finally,
 % \begin{itemize}
+% \item the `once-off' setup that doesn't need to be per-font
 % \item remap symbols that don't take their natural mathcode;
 % \item activate any symbols that need to be math-active;
 % \item assign delimiter codes for symbols that need to grow;
 % \item setup the maths alphabets (\cs{symbf} etc.) ---
 %       this is an extensive part of the code; see Section~\ref{sec:mathmap};
-% \item setup negations, which are handled on an ad hoc basis; see Section~\ref{sec:negations}.
 % \end{itemize}
 %    \begin{macrocode}
+    \bool_if:NT \l_@@_init_bool \@@_onceoff_setup:
     \@@_remap_symbols:
     \@@_setup_mathactives:
     \@@_setup_delcodes:
-%<debug>  \csname TIC\endcsname
     \@@_setup_alphabets:
-%<debug>  \csname TOC\endcsname
-    \@@_setup_negations:
+
+    %% TODO: what of the above should only be run for the "default"/"main" font?
+
+    \bool_if:NTF \l_@@_init_bool
+      {
+%<LU>   \@@_mathparam_store:
+        \@@_log:n {default-math-font}
+      }
+      {
+%<LU>   \@@_mathparam_restore:
+      }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -118,9 +91,8 @@
   {
     \cs_if_exist:NF \l_@@_fontname_tl
       {
-        % TODO: update this when lmmath-bold.otf is released
-        \setmathfont{latinmodern-math.otf}[BoldFont={latinmodern-math.otf}]
-        \bool_set_false:N \g_@@_mainfont_already_set_bool
+        \setmathfont{latinmodern-math.otf}
+          [BoldFont={latinmodern-math.otf}]
       }
   }
 %    \end{macrocode}
@@ -129,78 +101,192 @@
 %
 % TODO: need a better way to do this for the general case. (Maybe a `reset' command option?)
 %
-% \begin{macro}{\@@_init:}
+% \begin{macro}{\@@_init:n}
+% Reset local variables.
+% Default to defining the font for every math symbol character.
 %    \begin{macrocode}
-\cs_new:Nn \@@_init:
+\cs_new:Nn \@@_init:n
   {
+    \tl_set:Nn \l_@@_fontname_tl {#1}
     \bool_set_true:N  \l_@@_ot_math_bool
-    \tl_set:Nn \l_@@_mversion_tl {normal}
+    \tl_set:Nn \l_@@_mversion_tl      {normal}
     \tl_set:Nn \l_@@_symfont_label_tl {operators}
-%    \end{macrocode}
-% Defaults for the script and scriptscript font.
-%    \begin{macrocode}
+
     \tl_set:Nn    \l_@@_script_features_tl  {Style=MathScript}
     \tl_set:Nn    \l_@@_sscript_features_tl {Style=MathScriptScript}
     \tl_set_eq:NN \l_@@_script_font_tl      \l_@@_fontname_tl
     \tl_set_eq:NN \l_@@_sscript_font_tl     \l_@@_fontname_tl
-%    \end{macrocode}
-% Default to defining the font for every math symbol character.
-%    \begin{macrocode}
+
     \bool_set_true:N \l_@@_init_bool
-    \seq_clear:N     \l_@@_char_range_seq
-    \clist_clear:N   \l_@@_char_nrange_clist
-    \seq_clear:N     \l_@@_mathalph_seq
+    \seq_gclear:N    \g_@@_char_range_seq
+    \clist_clear:N   \l_@@_mathmap_charints_clist
+    \seq_gclear:N    \g_@@_mathalph_seq
     \seq_clear:N     \l_@@_missing_alph_seq
-%    \end{macrocode}
-% Other range initialisations.
-%    \begin{macrocode}
-    \cs_set_eq:NN \_@@_sym:nnn \@@_process_symbol_noparse:nnn
-    \cs_set_eq:NN \@@_set_mathalphabet_char:nnn \@@_mathmap_noparse:nnn
-    \cs_set_eq:NN \@@_remap_symbol:nnn \@@_remap_symbol_noparse:nnn
-    \cs_set_eq:NN \@@_maybe_init_alphabet:n \@@_init_alphabet:n
-    \cs_set_eq:NN \@@_map_char_single:nn \@@_map_char_noparse:nn
-    \cs_set_eq:NN \@@_assign_delcode:nn \@@_assign_delcode_noparse:nn
-    \cs_set_eq:NN \@@_make_mathactive:nNN \@@_make_mathactive_noparse:nNN
+
+    \cs_set_eq:NN \_@@_sym:nnn                  \@@_process_symbol_noparse:nnn
+    \cs_set_eq:NN \@@_remap_symbol:nnn          \@@_remap_symbol_noparse:nnn
+    \cs_set_eq:NN \@@_maybe_init_alphabet:n     \@@_init_alphabet:n
+    \cs_set_eq:NN \@@_assign_delcode:nn         \@@_assign_delcode_noparse:nn
+    \cs_set_eq:NN \@@_make_mathactive:nNN       \@@_make_mathactive_noparse:nNN
   }
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\@@_declare_math_sizes:}
 % Set the math sizes according to the recommended font parameters.
-% TODO: this shouldn't need to be per-engine; check out why the wrappers aren't used.
 %    \begin{macrocode}
+\tl_new:N \g_@@_main_font_cmd_tl
 \cs_new:Nn \@@_declare_math_sizes:
   {
-%<*LU>
-    \fp_compare:nF { \@@_script_style_size:n {ScriptPercentScaleDown} == 0 }
+    \dim_compare:nF { \fontdimen 10 \g_@@_trial_font == 0pt }
       {
         \DeclareMathSizes { \f@size } { \f@size }
-          { \@@_script_style_size:n {ScriptPercentScaleDown} }
-          { \@@_script_style_size:n {ScriptScriptPercentScaleDown} }
+          { \@@_fontdimen_to_scale:nN {10} \g_@@_trial_font }
+          { \@@_fontdimen_to_scale:nN {11} \g_@@_trial_font }
       }
-%</LU>
-%<*XE>
-    \dim_compare:nF { \fontdimen 10 \l_@@_font == 0pt }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+%
+%
+% \begin{macro}{\@@_fontspec_trial_font:}
+%    \begin{macrocode}
+\cs_new:Nn \@@_fontspec_trial_font:
+  {
+    \tl_set:Nx \l_@@_font_keyval_tl
       {
-        \DeclareMathSizes { \f@size } { \f@size }
-          { \@@_fontdimen_to_scale:nn {10} {\l_@@_font} }
-          { \@@_fontdimen_to_scale:nn {11} {\l_@@_font} }
+%<LU>   Renderer = Basic,
+        BoldItalicFont = {}, ItalicFont = {},
+        Script = Math,
+%<LU>   FontAdjustment = { \g_@@_luatex_copy_fontdimens_tl },
+        \l_@@_unknown_keys_clist
+      }
+
+    \fontspec_set_family:Nxn \l_@@_trial_family_tl {\l_@@_font_keyval_tl} {\l_@@_fontname_tl}
+
+    \group_begin:
+      \fontfamily { \l_@@_trial_family_tl } \selectfont
+      \@@_fontface_gset_eq:NV \g_@@_trial_font \font@name
+      \fontspec_if_script:nF {math}
+        {
+          \bool_gset_false:N \l_@@_ot_math_bool
+          \bool_gset_false:N \l_@@_init_bool
+        }
+    \group_end:
+
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_fontspec_select_font:}
+%    \begin{macrocode}
+\cs_new:Nn \@@_fontspec_select_font:
+  {
+    \fp_gset:Nn \g_@@_size_tfsf_fp   { (\f@size +\sf@size )/2 }
+    \fp_gset:Nn \g_@@_size_sfssf_fp  { (\sf@size+\ssf@size)/2 }
+
+    \tl_set:Nx \l_@@_font_keyval_tl
+      {
+%<LU>   Renderer = Basic,
+        BoldItalicFont = {}, ItalicFont = {},
+        Script = Math,
+        SizeFeatures =
+          {
+            {
+              Size = \fp_use:N \g_@@_size_tfsf_fp -
+            } ,
+            {
+              Size = \fp_use:N \g_@@_size_sfssf_fp - \fp_use:N \g_@@_size_tfsf_fp ,
+              Font = \l_@@_script_font_tl ,
+              \l_@@_script_features_tl
+            } ,
+            {
+              Size = - \fp_use:N \g_@@_size_sfssf_fp ,
+              Font = \l_@@_sscript_font_tl ,
+              \l_@@_sscript_features_tl
+            }
+          } ,
+%<LU>   FontAdjustment = { \g_@@_luatex_copy_fontdimens_tl },
+        \l_@@_unknown_keys_clist
       }
-%</XE>
+
+    \fontspec_set_family:Nxn \l_@@_family_tl {\l_@@_font_keyval_tl} {\l_@@_fontname_tl}
+
+    \int_gincr:N \g_@@_fonts_used_int
+    \group_begin:
+      \fontfamily { \l_@@_family_tl } \selectfont
+      \@@_fontface_gset_eq:cV {g_@@_mathfont_ \int_use:N \g_@@_fonts_used_int _font} \font@name
+      \tl_gset:Nx \g_@@_curr_font_cmd_tl { \exp_not:c {g_@@_mathfont_ \int_use:N \g_@@_fonts_used_int _font} }
+      \bool_if:NT \l_@@_init_bool
+				{
+					\@@_fontface_gset_eq:NV \l_@@_font \font@name
+				}
+      \fontspec_if_script:nF {math}
+        {
+          \bool_gset_false:N \l_@@_ot_math_bool
+          \bool_gset_false:N \l_@@_init_bool
+        }
+    \group_end:
   }
 %    \end{macrocode}
 % \end{macro}
 %
-% \begin{macro}{\@@_script_style_size:n}
-% Determine script- and scriptscriptstyle sizes using luaotfload:
-%   \begin{macrocode}
+%    \begin{macrocode}
+\tl_set:Nn \g_@@_main_font_cmd_tl  { \l_@@_font }
+\tl_set:Nn \g_@@_sqrt_font_cmd_tl  { \l_@@_font }
+\tl_set:Nn \g_@@_prime_font_cmd_tl { \l_@@_font }
+%    \end{macrocode}
+%
+% \begin{macro}{\g_@@_luatex_copy_fontdimens_tl}
+%    \begin{macrocode}
 %<*LU>
-\cs_new:Nn \@@_script_style_size:n
+\tl_const:Nn \g_@@_luatex_copy_fontdimens_tl
   {
-    \fp_eval:n {\directlua{tex.sprint(luaotfload.aux.get_math_dimension("l_@@_font","#1"))} * \f@size / 100 }
+    \@@_fontdimen_from_param:nn {10} {ScriptPercentScaleDown}
+    \@@_fontdimen_from_param:nn {11} {ScriptScriptPercentScaleDown}
+    \@@_fontdimen_from_param:nn {15} {AxisHeight}
+    \@@_fontdimen_from_param:nn {18} {SubscriptShiftDown}
+    \@@_fontdimen_from_param:nn {20} {SubscriptBaselineDropMin}
+    \@@_fontdimen_from_param:nn {21} {SuperscriptShiftUp}
+    \@@_fontdimen_from_param:nn {22} {SuperscriptShiftUpCramped}
+    \@@_fontdimen_from_param:nn {24} {SuperscriptBaselineDropMax}
+    \@@_fontdimen_from_param:nn {28} {UpperLimitGapMin}
+    \@@_fontdimen_from_param:nn {29} {UpperLimitBaselineRiseMin}
+    \@@_fontdimen_from_param:nn {30} {LowerLimitGapMin}
+    \@@_fontdimen_from_param:nn {31} {LowerLimitBaselineDropMin}
+    \@@_fontdimen_from_param:nn {32} {StackTopShiftUp}
+    \@@_fontdimen_from_param:nn {42} {FractionNumeratorShiftUp}
+    \@@_fontdimen_from_param:nn {43} {FractionNumeratorDisplayStyleShiftUp}
+    \@@_fontdimen_from_param:nn {44} {FractionDenominatorShiftDown}
+    \@@_fontdimen_from_param:nn {45} {FractionDenominatorDisplayStyleShiftDown}
+    \@@_fontdimen_from_param:nn {48} {FractionRuleThickness}
   }
 %</LU>
-%   \end{macrocode}
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_setup_math_fam:}
+%    \begin{macrocode}
+\cs_new:Nn \@@_setup_math_fam:
+  {
+    \cs_if_exist:cF { sym \l_@@_symfont_label_tl }
+      {
+        \DeclareSymbolFont{\l_@@_symfont_label_tl}
+          {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
+      }
+    \SetSymbolFont{\l_@@_symfont_label_tl}{\l_@@_mversion_tl}
+      {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
+%    \end{macrocode}
+% Set the bold math version.
+%    \begin{macrocode}
+    \str_if_eq_x:nnT {\l_@@_mversion_tl} {normal}
+      {
+        \SetSymbolFont{\l_@@_symfont_label_tl}{bold}
+          {\encodingdefault}{\l_@@_family_tl}{\bfdefault}{\updefault}
+      }
+  }
+%    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\@@_setup_legacy_fam_two:}
@@ -208,37 +294,37 @@
 %    \begin{macrocode}
 \cs_new:Nn \@@_setup_legacy_fam_two:
   {
-    \fontspec_set_family:Nxn \l_@@_family_tl
+    \fontspec_set_family:Nxn \l_@@_fam_two_tl
       {
         \l_@@_font_keyval_tl,
         Scale=1.00001,
         FontAdjustment =
           {
-            \@@_copy_fontparam:nnn { 8} {43} {FractionNumeratorDisplayStyleShiftUp}\relax
-            \@@_copy_fontparam:nnn { 9} {42} {FractionNumeratorShiftUp}\relax
-            \@@_copy_fontparam:nnn {10} {32} {StackTopShiftUp}\relax
-            \@@_copy_fontparam:nnn {11} {45} {FractionDenominatorDisplayStyleShiftDown}\relax
-            \@@_copy_fontparam:nnn {12} {44} {FractionDenominatorShiftDown}\relax
-            \@@_copy_fontparam:nnn {13} {21} {SuperscriptShiftUp}\relax
-            \@@_copy_fontparam:nnn {14} {21} {SuperscriptShiftUp}\relax
-            \@@_copy_fontparam:nnn {15} {22} {SuperscriptShiftUpCramped}\relax
-            \@@_copy_fontparam:nnn {16} {18} {SubscriptShiftDown}\relax
-            \@@_copy_fontparam:nnn {17} {18} {SubscriptShiftDownWithSuperscript}\relax
-            \@@_copy_fontparam:nnn {18} {24} {SuperscriptBaselineDropMax}\relax
-            \@@_copy_fontparam:nnn {19} {20} {SubscriptBaselineDropMin}\relax
-            \@@_zero_fontparam:n   {20} % delim1 = FractionDelimiterDisplaySize
-            \@@_zero_fontparam:n   {21} % delim2 = FractionDelimiterSize
-            \@@_copy_fontparam:nnn {22} {15} {AxisHeight}\relax
+            \@@_copy_fontdimen:nnN { 8} {43} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN { 9} {42} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {10} {32} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {11} {45} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {12} {44} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {13} {21} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {14} {21} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {15} {22} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {16} {18} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {17} {18} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {18} {24} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {19} {20} \g_@@_main_font_cmd_tl
+            \@@_copy_fontdimen:nnN {22} {15} \g_@@_main_font_cmd_tl
+            \@@_zero_fontdimen:n   {20} % delim1 = FractionDelimiterDisplaySize
+            \@@_zero_fontdimen:n   {21} % delim2 = FractionDelimiterSize
          }
       } {\l_@@_fontname_tl}
 
     \SetSymbolFont{symbols}{\l_@@_mversion_tl}
-      {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
+      {\encodingdefault}{\l_@@_fam_two_tl}{\mddefault}{\updefault}
 
     \str_if_eq_x:nnT {\l_@@_mversion_tl} {normal}
       {
         \SetSymbolFont{symbols}{bold}
-          {\encodingdefault}{\l_@@_family_tl}{\bfdefault}{\updefault}
+          {\encodingdefault}{\l_@@_fam_two_tl}{\bfdefault}{\updefault}
       }
   }
 %    \end{macrocode}
@@ -249,70 +335,37 @@
 %    \begin{macrocode}
 \cs_new:Nn \@@_setup_legacy_fam_three:
   {
-    \fontspec_set_family:Nxn \l_@@_family_tl
+    \fontspec_set_family:Nxn \l_@@_fam_three_tl
       {
         \l_@@_font_keyval_tl,
         Scale=0.99999,
         FontAdjustment = {
-          \@@_copy_fontparam:nnn { 8} {48} {FractionRuleThickness}\relax
-          \@@_copy_fontparam:nnn { 9} {28} {UpperLimitGapMin}\relax
-          \@@_copy_fontparam:nnn {10} {30} {LowerLimitGapMin}\relax
-          \@@_copy_fontparam:nnn {11} {29} {UpperLimitBaselineRiseMin}\relax
-          \@@_copy_fontparam:nnn {12} {31} {LowerLimitBaselineDropMin}\relax
-          \@@_zero_fontparam:n   {13}
+          \@@_copy_fontdimen:nnN { 8} {48} \g_@@_main_font_cmd_tl
+          \@@_copy_fontdimen:nnN { 9} {28} \g_@@_main_font_cmd_tl
+          \@@_copy_fontdimen:nnN {10} {30} \g_@@_main_font_cmd_tl
+          \@@_copy_fontdimen:nnN {11} {29} \g_@@_main_font_cmd_tl
+          \@@_copy_fontdimen:nnN {12} {31} \g_@@_main_font_cmd_tl
+          \@@_zero_fontdimen:n   {13}
        }
       } {\l_@@_fontname_tl}
 
     \SetSymbolFont{largesymbols}{\l_@@_mversion_tl}
-      {\encodingdefault}{\l_@@_family_tl}{\mddefault}{\updefault}
+      {\encodingdefault}{\l_@@_fam_three_tl}{\mddefault}{\updefault}
 
     \str_if_eq_x:nnT {\l_@@_mversion_tl} {normal}
       {
         \SetSymbolFont{largesymbols}{bold}
-          {\encodingdefault}{\l_@@_family_tl}{\bfdefault}{\updefault}
+          {\encodingdefault}{\l_@@_fam_three_tl}{\bfdefault}{\updefault}
       }
   }
 %    \end{macrocode}
 % \end{macro}
 %
-%
-% \begin{macro}{\@@_fontspec_select_font:}
-% Select the font with \cs{fontspec} and define \cs{l_@@_font} from it.
+% \begin{macro}{\@@_onceoff_setup:}
 %    \begin{macrocode}
-\cs_new:Nn \@@_fontspec_select_font:
+\cs_new:Nn \@@_onceoff_setup:
   {
-    \tl_set:Nx \l_@@_font_keyval_tl {
-%<LU>     Renderer = Basic,
-      BoldItalicFont = {}, ItalicFont = {},
-      Script = Math,
-      SizeFeatures =
-        {
-          {
-            Size = \tf@size-
-          } ,
-          {
-            Size = \sf@size-\tf@size ,
-            Font = \l_@@_script_font_tl ,
-            \l_@@_script_features_tl
-          } ,
-          {
-            Size = -\sf@size ,
-            Font = \l_@@_sscript_font_tl ,
-            \l_@@_sscript_features_tl
-          }
-        } ,
-      \l_@@_unknown_keys_clist
-    }
-
-  \fontspec_set_fontface:NNxn \l_@@_font \l_@@_family_tl
-    {\l_@@_font_keyval_tl} {\l_@@_fontname_tl}
-%    \end{macrocode}
-% Check whether we're using a real maths font:
-%    \begin{macrocode}
-    \group_begin:
-      \fontfamily{\l_@@_family_tl}\selectfont
-      \fontspec_if_script:nF {math} {\bool_gset_false:N \l_@@_ot_math_bool}
-    \group_end:
+    \@@_set_delcode:nnn {operators} {`\.} {\c_zero}
   }
 %    \end{macrocode}
 % \end{macro}
@@ -334,7 +387,7 @@
 %    \begin{macrocode}
 \cs_set:Nn \@@_process_symbol_parse:nnn
   {
-    \@@_if_char_spec:nNNT {#1} {#2} {#3}
+    \@@_if_char_spec:nNT {#1} {#3}
       {
         \@@_process_symbol_noparse:nnn {#1} {#2} {#3}
       }
@@ -344,28 +397,29 @@
 % \end{macro}
 %
 % \begin{macro}{\@@_remap_symbols:}
-% \begin{macro}{\@@_remap_symbol_noparse:nnn}
-% \begin{macro}{\@@_remap_symbol_parse:nnn}
 % This function is used to define the mathcodes for those chars which should
 % be mapped to a different glyph than themselves.
 %    \begin{macrocode}
-\cs_new:Npn \@@_remap_symbols:
+\cs_new:Nn \@@_remap_symbols:
   {
-    \@@_remap_symbol:nnn{`\-}{\mathbin}{"02212}% hyphen to minus
-    \@@_remap_symbol:nnn{`\*}{\mathbin}{"02217}% text asterisk to "centred asterisk"
+    \@@_remap_symbol:nnn {`\-} {\mathbin} {"2212}
+    \@@_remap_symbol:nnn {`\*} {\mathbin} {"02217}% text asterisk to "centred asterisk"
     \bool_if:NF \g_@@_literal_colon_bool
       {
-        \@@_remap_symbol:nnn{`\:}{\mathrel}{"02236}% colon to ratio (i.e., punct to rel)
+        \@@_remap_symbol:nnn {`\:} {\mathrel} {"02236}% colon to ratio (i.e., punct to rel)
       }
   }
 %    \end{macrocode}
 % \end{macro}
+%
+% \begin{macro}{\@@_remap_symbol_noparse:nnn}
+% \begin{macro}{\@@_remap_symbol_parse:nnn}
 % Where |\@@_remap_symbol:nnn| is defined to be one of these two, depending
 % on the range setup:
 %    \begin{macrocode}
 \cs_new:Nn \@@_remap_symbol_parse:nnn
   {
-    \@@_if_char_spec:nNNT {#3} {\@nil} {#2}
+    \@@_if_char_spec:nNT {#3} {#2}
       { \@@_remap_symbol_noparse:nnn {#1} {#2} {#3} }
   }
 \cs_new:Nn \@@_remap_symbol_noparse:nnn
@@ -383,16 +437,18 @@
 % But they don't need to be able to be typeset directly.
 %
 % \begin{macro}{\@@_setup_mathactives:}
+% TODO: if not an OpenType math font, we should ignore doing anything with primes.
+% This needs a revamped `range` feature, I think.
 %    \begin{macrocode}
 \cs_new:Npn \@@_setup_mathactives:
   {
-    \@@_make_mathactive:nNN {"2032} \@@_prime_single_mchar \mathord
-    \@@_make_mathactive:nNN {"2033} \@@_prime_double_mchar \mathord
-    \@@_make_mathactive:nNN {"2034} \@@_prime_triple_mchar \mathord
-    \@@_make_mathactive:nNN {"2057} \@@_prime_quad_mchar   \mathord
-    \@@_make_mathactive:nNN {"2035} \@@_backprime_single_mchar \mathord
-    \@@_make_mathactive:nNN {"2036} \@@_backprime_double_mchar \mathord
-    \@@_make_mathactive:nNN {"2037} \@@_backprime_triple_mchar \mathord
+		\@@_make_mathactive:nNN {"2032} \@@_prime_single_mchar \mathord
+		\@@_make_mathactive:nNN {"2033} \@@_prime_double_mchar \mathord
+		\@@_make_mathactive:nNN {"2034} \@@_prime_triple_mchar \mathord
+		\@@_make_mathactive:nNN {"2057} \@@_prime_quad_mchar   \mathord
+		\@@_make_mathactive:nNN {"2035} \@@_backprime_single_mchar \mathord
+		\@@_make_mathactive:nNN {"2036} \@@_backprime_double_mchar \mathord
+		\@@_make_mathactive:nNN {"2037} \@@_backprime_triple_mchar \mathord
     \@@_make_mathactive:nNN {`\'} \mathstraightquote \mathord
     \@@_make_mathactive:nNN {`\`} \mathbacktick      \mathord
   }
@@ -406,7 +462,7 @@
 %    \begin{macrocode}
 \cs_new:Nn \@@_make_mathactive_parse:nNN
   {
-    \@@_if_char_spec:nNNT {#1} #2 #3
+    \@@_if_char_spec:nNT {#1} #3
       { \@@_make_mathactive_noparse:nNN {#1} #2 #3 }
   }
 %    \end{macrocode}
@@ -420,6 +476,7 @@
 %    \end{macrocode}
 % \end{macro}
 %
+%
 % \subsection{Delimiter codes}
 %
 % \begin{macro}{\@@_assign_delcode:nn}
@@ -433,7 +490,7 @@
 %    \begin{macrocode}
 \cs_new:Nn \@@_assign_delcode_parse:nn
   {
-    \@@_if_char_spec:nNNT {#2} {\@nil} {\@nil}
+    \@@_if_char_spec:nNT {#2} \@nil
       {
         \@@_assign_delcode_noparse:nn {#1} {#2}
       }
@@ -456,10 +513,6 @@
 %    \begin{macrocode}
 \cs_new:Npn \@@_setup_delcodes:
   {
-    % ensure \left. and \right. work:
-    \@@_set_delcode:nnn \l_@@_symfont_label_tl {`\.} {\c_zero}
-    % this is forcefully done to fix a bug -- indicates a larger problem!
-
     \@@_assign_delcode:nn {`\/}   {\g_@@_slash_delimiter_usv}
     \@@_assign_delcode:nn {"2044} {\g_@@_slash_delimiter_usv} % fracslash
     \@@_assign_delcode:nn {"2215} {\g_@@_slash_delimiter_usv} % divslash
@@ -538,6 +591,93 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \subsection{Fontdimens}
+%
+%    \begin{macrocode}
+%<*LU>
+%    \end{macrocode}
+%
+% \begin{macro}{\@@_mathparam_restore:}
+%    \begin{macrocode}
+\cs_set:Nn \@@_mathparam_restore:
+  {
+    \check@mathfonts
+    \tl_use:N \g_@@_mathparam_store_tl
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_mathparam_store:}
+%    \begin{macrocode}
+\cs_set:Nn \@@_mathparam_store:
+  {
+    \check@mathfonts
+    \tl_gset:Nx \g_@@_mathparam_store_tl
+      {
+        \@@_mathparam_store_aux:N \displaystyle
+        \@@_mathparam_store_aux:N \textstyle
+        \@@_mathparam_store_aux:N \scriptstyle
+        \@@_mathparam_store_aux:N \scriptscriptstyle
+      }
+  }
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\cs_set:Nn \@@_mathparam_store_aux:N
+  {
+    \Umathquad                #1 = \the \Umathquad                #1
+    \Umathaxis                #1 = \the \Umathaxis                #1
+    \Umathoperatorsize        #1 = \the \Umathoperatorsize        #1
+    \Umathoverbarkern         #1 = \the \Umathoverbarkern         #1
+    \Umathoverbarrule         #1 = \the \Umathoverbarrule         #1
+    \Umathoverbarvgap         #1 = \the \Umathoverbarvgap         #1
+    \Umathunderbarkern        #1 = \the \Umathunderbarkern        #1
+    \Umathunderbarrule        #1 = \the \Umathunderbarrule        #1
+    \Umathunderbarvgap        #1 = \the \Umathunderbarvgap        #1
+    \Umathradicalkern         #1 = \the \Umathradicalkern         #1
+    \Umathradicalrule         #1 = \the \Umathradicalrule         #1
+    \Umathradicalvgap         #1 = \the \Umathradicalvgap         #1
+    \Umathradicaldegreebefore #1 = \the \Umathradicaldegreebefore #1
+    \Umathradicaldegreeafter  #1 = \the \Umathradicaldegreeafter  #1
+    \Umathradicaldegreeraise  #1 = \the \Umathradicaldegreeraise  #1
+    \Umathstackvgap           #1 = \the \Umathstackvgap           #1
+    \Umathstacknumup          #1 = \the \Umathstacknumup          #1
+    \Umathstackdenomdown      #1 = \the \Umathstackdenomdown      #1
+    \Umathfractionrule        #1 = \the \Umathfractionrule        #1
+    \Umathfractionnumvgap     #1 = \the \Umathfractionnumvgap     #1
+    \Umathfractionnumup       #1 = \the \Umathfractionnumup       #1
+    \Umathfractiondenomvgap   #1 = \the \Umathfractiondenomvgap   #1
+    \Umathfractiondenomdown   #1 = \the \Umathfractiondenomdown   #1
+    \Umathfractiondelsize     #1 = \the \Umathfractiondelsize     #1
+    \Umathlimitabovevgap      #1 = \the \Umathlimitabovevgap      #1
+    \Umathlimitabovebgap      #1 = \the \Umathlimitabovebgap      #1
+    \Umathlimitabovekern      #1 = \the \Umathlimitabovekern      #1
+    \Umathlimitbelowvgap      #1 = \the \Umathlimitbelowvgap      #1
+    \Umathlimitbelowbgap      #1 = \the \Umathlimitbelowbgap      #1
+    \Umathlimitbelowkern      #1 = \the \Umathlimitbelowkern      #1
+    \Umathoverdelimitervgap   #1 = \the \Umathoverdelimitervgap   #1
+    \Umathoverdelimiterbgap   #1 = \the \Umathoverdelimiterbgap   #1
+    \Umathunderdelimitervgap  #1 = \the \Umathunderdelimitervgap  #1
+    \Umathunderdelimiterbgap  #1 = \the \Umathunderdelimiterbgap  #1
+    \Umathsubshiftdrop        #1 = \the \Umathsubshiftdrop        #1
+    \Umathsubshiftdown        #1 = \the \Umathsubshiftdown        #1
+    \Umathsupshiftdrop        #1 = \the \Umathsupshiftdrop        #1
+    \Umathsupshiftup          #1 = \the \Umathsupshiftup          #1
+    \Umathsubsupshiftdown     #1 = \the \Umathsubsupshiftdown     #1
+    \Umathsubtopmax           #1 = \the \Umathsubtopmax           #1
+    \Umathsupbottommin        #1 = \the \Umathsupbottommin        #1
+    \Umathsupsubbottommax     #1 = \the \Umathsupsubbottommax     #1
+    \Umathsubsupvgap          #1 = \the \Umathsubsupvgap          #1
+    \Umathspaceafterscript    #1 = \the \Umathspaceafterscript    #1
+    \Umathconnectoroverlapmin #1 = \the \Umathconnectoroverlapmin #1
+  }
+%    \end{macrocode}
+% \end{macro}
+%
+%    \begin{macrocode}
+%</LU>
+%    \end{macrocode}
+%
 %    \begin{macrocode}
 %</package>
 %    \end{macrocode}
@@ -553,7 +693,7 @@
 % the conditions of the LaTeX Project Public License, version 1.3c or higher
 % (your choice): <http://www.latex-project.org/lppl/>.
 % ------------------------------------------------
-% Copyright 2006-2017  Will Robertson, LPPL "maintainer"
+% Copyright 2006-2018  Will Robertson, LPPL "maintainer"
 % Copyright 2010-2017  Philipp Stephani
 % Copyright 2011-2017  Joseph Wright
 % Copyright 2012-2015  Khaled Hosny
-- 
cgit v1.2.3

