OSDN Git Service

Added \utod direction (same as "tate math direction" in pTeX)
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 20 Jul 2014 08:17:35 +0000 (17:17 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 20 Jul 2014 08:17:35 +0000 (17:17 +0900)
 * direction -> int:
    dir_dtou = 1
    dir_tate = 3
    dir_yoko = 4
    dir_utod = 11
 * pTeX has "yoko math direction", but LuaTeX-ja doesn't.
 * I didn't tested \ltjgetwd, \ltjsetwd with \utod direction.
   I'll test and fix them in the next commit.

src/ltj-direction.lua
src/ltj-math.lua
src/luatexja-core.sty
src/luatexja.lua

index 936d85d..f72789a 100644 (file)
@@ -33,6 +33,7 @@ local traverse = Dnode.traverse
 local traverse_id = Dnode.traverse_id
 local start_time_measure, stop_time_measure 
    = ltjb.start_time_measure, ltjb.stop_time_measure
+local abs = math.abs
 
 local id_kern = node.id('kern')
 local id_hlist = node.id('hlist')
@@ -54,6 +55,7 @@ local DIR  = luatexja.userid_table.DIR
 local dir_tate = luatexja.dir_table.dir_tate
 local dir_yoko = luatexja.dir_table.dir_yoko
 local dir_dtou = luatexja.dir_table.dir_dtou
+local dir_utod = luatexja.dir_table.dir_utod
 local dir_node_auto   = luatexja.dir_table.dir_node_auto
 local dir_node_manual = luatexja.dir_table.dir_node_manual
 
@@ -99,7 +101,6 @@ do
       end
       return page_direction
    end
-   local abs = math.abs
    function get_adjust_dir_count()
       for i=tex_nest.ptr, 1, -1 do
          local v = tex_nest[i]
@@ -123,9 +124,14 @@ do
    local function set_list_direction(v, name)
       local lv, w = tex_nest.ptr, tex.lists.page_head
       if not v then 
-         v,name  = get_dir_count(), nil 
+         v,name  = get_dir_count(), nil
       elseif v=='adj' then
          v,name = get_adjust_dir_count(), nil
+      elseif v=='math' then
+        v,name  = get_dir_count(), nil
+        if abs(tex_nest[lv].mode) == ltjs.mmode and v == dir_tate then
+           v = dir_utod
+        end
       end
       if tex.currentgrouptype==6 then
         ltjb.package_error(
@@ -367,6 +373,25 @@ do
               { 'whatsit', sid_restore },
            },
          },
+        [dir_utod] = { -- utod 中で組む
+           width  = get_w,
+           height = get_h,
+           depth  = get_d,
+           [id_hlist] = {
+              { 'nop' },
+              { 'nop' },
+              { 'nop' },
+              { 'box', zero },
+              { 'nop' },
+           },
+           [id_vlist] = {
+              { 'nop' },
+              { 'nop' },
+              { 'nop' },
+              { 'box', zero },
+              { 'nop' },
+           },
+        }
       },
       [dir_dtou] = { -- dtou を
         [dir_yoko] = { -- yoko 中で組む
@@ -411,6 +436,10 @@ do
         },
       },
    }
+   dir_node_aux[dir_yoko][dir_utod] = dir_node_aux[dir_yoko][dir_tate]
+   dir_node_aux[dir_dtou][dir_utod] = dir_node_aux[dir_dtou][dir_tate]
+   dir_node_aux[dir_tate][dir_tate] = dir_node_aux[dir_tate][dir_utod]
+   dir_node_aux[dir_utod] = dir_node_aux[dir_tate]
 end
 
 -- 1st ret val: b の組方向
@@ -585,6 +614,9 @@ do
                elseif cmd=='box' then
                   nn = b; setfield(b, 'next', nil)
                  setfield(nn, 'shift', getfield(nn, 'shift') + arg(w,h,d))
+              elseif cmd=='nop' then
+                  nn = node_new(id_kern)
+                  setfield(nn, 'kern', 0)
                end
                if db_head then
                   insert_after(db_head, db_tail, nn)
index df28db0..e32f432 100644 (file)
@@ -13,6 +13,7 @@ local Dnode = node.direct or node
 local setfield = (Dnode ~= node) and Dnode.setfield or function(n, i, c) n[i] = c end
 local getfield = (Dnode ~= node) and Dnode.getfield or function(n, i) return n[i] end
 local getid = (Dnode ~= node) and Dnode.getid or function(n) return n.id end
+local getsubtype = (Dnode ~= node) and Dnode.getsubtype or function(n) return n.subtype end
 -- getlist cannot be used for sub_box nodes. Use instead λp. getfield(p, 'head')
 local getchar = (Dnode ~= node) and Dnode.getchar or function(n) return n.char end
 
@@ -46,6 +47,9 @@ local id_style   = node.id('style')
 local id_frac    = node.id('fraction')
 local id_simple  = node.id('noad')
 local id_sub_mlist = node.id('sub_mlist')
+local id_whatsit = node.id('whatsit')
+local sid_user = node.subtype('user_defined')
+local DIR  = luatexja.userid_table.DIR
 
 local PROCESSED  = luatexja.icflag_table.PROCESSED
 
@@ -135,11 +139,17 @@ function (p, sty)
    return p
 end
 
+local node_remove = Dnode.remove
 luatexbase.add_to_callback('mlist_to_hlist',
    function (n, display_type, penalties)
-      local head = to_node(conv_jchar_to_hbox(to_direct(n), 0))
-      head = node.mlist_to_hlist(head, display_type, penalties)
-      return head
+      n = to_direct(n)
+      if getid(n)==id_whatsit and getsubtype(n)==sid_user and
+      getfield(n, 'user_id') == DIR then
+        local old_n = n; n = node_remove(n, n); node_free(old_n)
+      end
+      return node.mlist_to_hlist(
+        to_node(conv_jchar_to_hbox(n, 0)),
+        display_type, penalties)
    end,'ltj.mlist_to_hlist', 1)
 
 luatexja.math = { is_math_letters = is_math_letters }
index a6fee46..dab9a75 100644 (file)
   \directlua{% This value depends on the version of LuaTeX.
     luatexja.stack.hmode = -tex.nest[tex.nest.ptr].mode
   }%
+  $\directlua{% This value depends on the version of LuaTeX.
+    luatexja.stack.mmode = -tex.nest[tex.nest.ptr].mode
+  }$% 
 }
 \setbox0\vbox{%
   \directlua{% This value depends on the version of LuaTeX.
 \protected\def\dtou{%
   \directlua{luatexja.direction.set_list_direction(1, 'dtou')}%
 }
+\protected\def\utod{% 「縦数式ディレクション」
+  \directlua{luatexja.direction.set_list_direction(11, 'utod')}%
+}
 \define@key[ltj]{japaram}{direction}{%% always local
   \directlua{luatexja.direction.set_list_direction(1, 'ltjsetparameter')}%
 }
     end
   }%
 }
+%%%% 縦数式ディレクションの実装
+\everymath{%
+  \directlua{luatexja.direction.set_list_direction('math')}%
+}
+\everydisplay{%
+  \directlua{luatexja.direction.set_list_direction('math')}%
+}
+
 
 %%%% \raise, \lower, \moveleft, \moveright
 \let\ltj@@orig@raise=\raise
   }\ltj@afterbox\ltj@@moveleft@a}
 
 
-%%%% unhbox and unvbox
+%%%% \unhbox and \unvbox
 \let\ltj@@orig@unhbox=\unhbox
 \let\ltj@@orig@unvbox=\unvbox
 \protected\def\unhbox{\ltj@reset@globaldefs\afterassignment\ltj@@unhbox\ltj@tempcnta}
index 68b2dd2..5becb54 100644 (file)
@@ -65,8 +65,9 @@ luatexja.dir_table = dir_table
 dir_table.dir_dtou = 1
 dir_table.dir_tate = 3
 dir_table.dir_yoko = 4
-dir_table.dir_node_auto   = 16 -- 組方向を合わせるために自動で作られたもの
-dir_table.dir_node_manual = 32 -- 寸法代入によって作られたもの
+dir_table.dir_utod = 11 -- 「縦数式ディレクション」 in pTeX
+dir_table.dir_node_auto   = 128 -- 組方向を合わせるために自動で作られたもの
+dir_table.dir_node_manual = 256 -- 寸法代入によって作られたもの
 
 
 ------------------------------------------------------------------------