OSDN Git Service

lltjp-unicode-math.sty: moved \ltjsetmathletter
[luatex-ja/luatexja.git] / src / patches / lltjp-unicode-math.sty
index 0b6e556..85524c0 100644 (file)
 %
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lltjp-unicode-math}[2015/08/27 Patch to unicode-math for LuaTeX-ja]
+\ProvidesPackage{lltjp-unicode-math}[2018/08/21 Patch to unicode-math for LuaTeX-ja]
 
-\RequirePackage{unicode-math,luatexja}
+\RequirePackage{unicode-math,luatexja,etoolbox}
 
 \ExplSyntaxOn
 
 \group_begin:
-  \tl_set:Nn \l_tmpa_tl { um_cs_set_eq_active_char:Nw }
-  \cs_if_exist:cT { __um_cs_set_eq_active_char:Nw } {
-    \tl_set:Nn \l_tmpa_tl { __um_cs_set_eq_active_char:Nw }
-    \cs_gset:Npn \use@mathgroup #1 #2
-     {
-      \mode_if_math:T % <- not sure if this is really necessary since we've just checked for mmode and raised an error if not!
+  \bool_new:N \__lltjp_um_patch_mathgroup_bool
+  \bool_set_true:N \__lltjp_um_patch_mathgroup_bool
+  \cs_gset:Nn \__um_set_delcode:nnn
+    {
+      \Udelcode#2 = \csname sym#1\endcsname #3 \scan_stop:
+      \ltjsetmathletter{ #3 }
+    }
+  \cs_gset:Nn \__um_radical:nn
+    {
+      \Uradical \csname sym#1\endcsname #2 \scan_stop:
+      \ltjsetmathletter{ #2 }
+    }
+  \cs_gset:Nn \__um_delimiter:Nnn
+    {
+      \Udelimiter \mathchar@type#1 \csname sym#2\endcsname #3 \scan_stop:
+      \ltjsetmathletter{ #3 }
+    }
+  \cs_gset:Nn \__um_accent:nnn
+    {
+      \Umathaccent #1~ \mathchar@type\mathaccent \use:c { sym #2 } #3 \scan_stop:
+      \ltjsetmathletter{ #3 }
+    }
+  \cs_gset:Nn \__um_define_math_chars: {
+    \group_begin:
+      \cs_set:Npn \__um_sym:nnn ##1##2##3
        {
-        \math@bgroup
-          \cs_if_eq:cNF {M@\f@encoding} #1 {#1}
-          \__um_switchto_literal:
-          \ltj@tempcnta=#2 \expandafter\ltj@@mathJapaneseFonts\string#1\relax%
-          \ifin@ \jfam #2 \relax \else \mathgroup #2 \relax \fi
-        \math@egroup
+        \tl_if_in:nnT
+         { \mathord \mathalpha \mathbin \mathrel \mathpunct \mathop \mathfence }
+         {##3}
+        {
+          \exp_last_unbraced:NNx \cs_gset_eq:NN ##2 { \char_generate:nn {##1} {12} }
+          \ltjsetmathletter{ ##1 }
+        }
        }
-     }
-  }
-  \cs_gset:cpn { \tl_use:N \l_tmpa_tl } #1 = "#2 \q_nil {%"
-    \group_begin:
-      %\typeout {um: \string#1, \int_from_hexadecimal:n {#2}, #2}% <- for debug
-      \char_set_lccode:nn { `! } { "#2 }%"
-      \tex_lowercase:D {
-        \tl_set:Nn \l_tmpa_tl {  \relax
-          \ifmmode!\else{\directlua{tex.globaldefs = 0}\ltj@allalchar!}\fi}
-        \cs_gset_eq:NN #1 \l_tmpa_tl
-      }
-      \ltjsetmathletter{ \int_from_hexadecimal:n {#2} }
+      \__um_input_math_symbol_table:
     \group_end:
   }
+
+\bool_if:NT \__lltjp_um_patch_mathgroup_bool {
+  \cs_gset:Npn \use@mathgroup #1 #2
+   {
+    %\typeout{UM <#1><#2>}
+    \mode_if_math:T % <- not sure if this is really necessary since we've just checked for mmode and raised an error if not!
+     {
+      \math@bgroup
+        \cs_if_eq:cNF {M@\f@encoding} #1 {#1}
+        \__um_switchto_literal:
+        \ltj@tempcnta=#2 \expandafter\ltj@@mathJapaneseFonts\string#1\relax%
+        \ifin@ \jfam #2 \relax \else \mathgroup #2 \relax \fi
+      \math@egroup
+     }
+   }
+}
 \group_end:
 
+\ifcsname jsc@mag@xrealtrue \endcsname \else
+    \expandafter\expandafter\expandafter \ExplSyntaxOff \expandafter \endinput
+\fi
+\ifjsc@mag@xreal
+    \cs_if_exist:cTF { ltjs@orig@get@external@font } {
+         % ltjsclasses: use lua
+         \cs_new:Nn \lltjp_um_unmag_fsize:
+           {
+                 \cs_gset:Nx \lltjp_um_f@size: {\directlua{luatexja.ltjs_unmagnify_fsize(\f@size)}}
+                 \cs_gset:Nx \lltjp_um_sf@size: {\directlua{luatexja.ltjs_unmagnify_fsize(\sf@size)}}
+                 \cs_gset:Nx \lltjp_um_ssf@size: {\directlua{luatexja.ltjs_unmagnify_fsize(\ssf@size)}}
+               }
+       }{
+         % bxjscls: use \jsc@preadjust@extract@font
+         \cs_new:Nn \lltjp_um_unmag_fsize:
+           {
+                 \group_begin:
+                   \jsc@preadjust@extract@font
+                   \cs_gset_eq:NN \lltjp_um_f@size: \f@size
+                 \group_end:
+                 \group_begin:
+                   \cs_set_eq:NN \f@size \sf@size \jsc@preadjust@extract@font
+                   \cs_gset_eq:NN \lltjp_um_sf@size: \f@size
+                 \group_end:
+                 \group_begin:
+                   \cs_set_eq:NN \f@size \ssf@size \jsc@preadjust@extract@font
+                   \cs_gset_eq:NN \lltjp_um_ssf@size: \f@size
+                 \group_end:
+               }
+       }
+    \pretocmd { \__um_fontspec_select_font: } {
+         \cs_set_eq:NN \lltjp_um_orig_fsize: \f@size
+         \lltjp_um_unmag_fsize:
+         \cs_set_eq:NN \f@size \lltjp_um_f@size:
+         \cs_set_eq:NN \tf@size \lltjp_um_f@size:
+         \cs_set_eq:NN \sf@size \lltjp_um_sf@size:
+         \cs_set_eq:NN \ssf@size \lltjp_um_ssf@size:
+       } {} {}
+    \apptocmd { \__um_fontspec_select_font: } {
+         \cs_set_eq:NN \f@size \lltjp_um_orig_fsize:
+       } {} {}
+\fi
+
 \ExplSyntaxOff
 
 \endinput