OSDN Git Service

Adapted to unicode-math v0.8c (2015/09/24)
[luatex-ja/luatexja.git] / src / patches / lltjp-unicode-math.sty
index ff8ad2d..db9361a 100644 (file)
@@ -3,34 +3,69 @@
 %
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{lltjp-unicode-math}[2011/11/22 Patch to unicode-math for LuaLaTeX-ja]
+\ProvidesPackage{lltjp-unicode-math}[2015/10/28 Patch to unicode-math for LuaTeX-ja]
 
 \RequirePackage{unicode-math,luatexja}
 
 \ExplSyntaxOn
-\cs_set:Npn \um_set_mathcode:nnnn #1#2#3#4 {
-  \Umathcode \int_eval:n {#1} =
-  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
-  \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
-}
-\cs_set:Npn \um_set_mathcode:nnn #1#2#3 {
-  \Umathcode \int_eval:n {#1} =
-  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#1} \scan_stop:
-  \directlua{luatexja.math.is_math_letters[\int_eval:n {#1}]=true}
-}
-\cs_set:Npn \um_set_mathchar:NNnn #1#2#3#4 {
-  \Umathchardef #1 =
-  \mathchar@type#2 \csname sym#3\endcsname \int_eval:n {#4} \scan_stop:
-  \directlua{luatexja.math.is_math_letters[\int_eval:n {#4}]=true}
-}
+
 \group_begin:
-  \char_set_catcode_other:N \^
-  \gdef\q{hoge}\gdef\r{piyo}
-  \cs_gset:Npn \um_cs_set_eq_active_char:Nw #1 = "#2 \q_nil {%"
-    \tl_set:Nn \l_tmpa_tl {\ifmmode\char"#2\else\ltjalchar"#2\relax\fi}
-    \cs_gset_eq:NN #1 \l_tmpa_tl
+  \bool_new:N \lltjp_um_patch_mathgroup_bool
+\@ifpackagelater{unicode-math}{2015/09/24}{%
+%%%%%%%% 2015/09/24 0.8c
+  \bool_set_true:N \lltjp_um_patch_mathgroup_bool
+  \cs_gset:Nn \__um_define_math_chars: {
+    \group_begin:
+      \cs_set:Npn \__um_sym:nnn ##1##2##3
+       {
+        \tl_if_in:nnT
+         { \mathord \mathalpha \mathbin \mathrel \mathpunct \mathop \mathfence }
+         {##3}
+        {
+          \exp_last_unbraced:NNx \cs_gset_eq:NN ##2 { \Ucharcat ##1 ~ 12 ~ }
+          \ltjsetmathletter{ ##1 }
+        }
+       }
+      \__um_input_math_symbol_table:
+    \group_end:
+  }
+}{
+  \cs_if_exist:cTF { __um_cs_set_eq_active_char:Nw } {
+    \tl_set:Nn \l_tmpa_tl { __um_cs_set_eq_active_char:Nw }
+    \bool_set_true:N \lltjp_um_patch_mathgroup_bool
+  }{
+    \tl_set:Nn \l_tmpa_tl { um_cs_set_eq_active_char:Nw }
   }
+  \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} }
+    \group_end:
+  }
+}
+
+\bool_if:NT \lltjp_um_patch_mathgroup_bool {
+  \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!
+     {
+      \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:
 
 \ExplSyntaxOff
+
 \endinput