OSDN Git Service

luatexja-core.sty: \iftdir etc. now works in \hbox{{\tate ...}\iftdir T\fi}.
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 29 Jun 2014 02:07:15 +0000 (11:07 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 29 Jun 2014 02:07:15 +0000 (11:07 +0900)
src/ltj-direction.lua
src/luatexja-core.sty
test/test51-vtest.pdf
test/test51-vtest.tex

index fe708bb..e0d16cd 100644 (file)
@@ -74,13 +74,13 @@ local function adjust_badness(hd)
 end
 
 local get_dir_count
--- \tate, \yoko
 do
    local function get_dir_count_inner(h)
       if h then
         if h.id==id_whatsit and h.subtype==sid_user and h.user_id==DIR then
               local ic = node.has_attribute(h, attr_icflag)
-              return (ic<PROCESSED_BEGIN_FLAG) and (node.has_attribute(h,attr_dir)%dir_node_auto) or 0
+              return (ic<PROCESSED_BEGIN_FLAG) 
+                 and (node.has_attribute(h,attr_dir)%dir_node_auto) or 0
         else
            return 0
         end
@@ -99,18 +99,36 @@ do
       end
       return page_direction
    end
-   luatexja.direction.get_dir_count = get_dir_count 
+   luatexja.direction.get_dir_count = get_dir_count
+end
 
+-- \ifydir etc.
+do
+   local cs_true, cs_false = '\\iftrue', '\\iffalse'
+   luatexja.direction.dir_conditional = function(v)
+      local d = get_dir_count()
+      print(d,v)
+      tex.sprint(cat_lp, (d==v) and cs_true or cs_false )
+   end
+end
+
+-- \tate, \yoko
+do
    local node_next = node.next
    local node_set_attr = node.set_attribute
    local function set_list_direction(v, name)
       local lv, w = tex_nest.ptr, tex.lists.page_head
       if lv==0 and w then
-        if w.id==id_whatsit and w.subtype==sid_user
-        and w.user_id==DIR then
-           node_set_attr(w, attr_dir, v)
+        if (not w.next) and 
+           w.id==id_whatsit and w.subtype==sid_user and w.user_id==DIR then
+           node_set_attr(w, attr_dir, v); page_direction = v
+        else
+              ltjb.package_error(
+                 'luatexja',
+                 "Use `\\" .. name .. "' at top of list",
+                 'Direction change command by LuaTeX-ja is available\n'
+                   .. 'only when the current list is null.')
         end
-        page_direction = v
       elseif tex.currentgrouptype==6 then
         ltjb.package_error(
                  'luatexja',
@@ -118,12 +136,12 @@ do
                 "To change direction in an align, \n"
                    .. "you shold use \\hbox or \\vbox.")
       else
-        local w = node_next(tex_nest[lv].head)
+        print(v, name, tex_nest[lv].head.next)
+        local w = tex_nest[lv].head.next
         if w then
-           w = to_direct(w)
-           if getid(w)==id_whatsit and getsubtype(w)==sid_user
-           and getfield(w, 'user_id')==DIR then
-              set_attr(w, attr_dir, v)
+           if (not w.next) and 
+              w.id==id_whatsit and w.subtype==sid_user and w.user_id==DIR then
+              node_set_attr(w, attr_dir, v)
            else
               ltjb.package_error(
                  'luatexja',
@@ -473,7 +491,7 @@ end
 
 -- is_manual: 寸法変更に伴うものか?
 local function create_dir_node(b, b_dir, new_dir, is_manual)
-   print('create new node', b_dir, new_dir)
+   --print('create new node', b_dir, new_dir)
    local info = dir_node_aux[b_dir][new_dir]
    local w = getfield(b, 'width')
    local h = getfield(b, 'height')
@@ -762,7 +780,7 @@ end
 -- \ifydir, \iftdir, \ifddir
 do
    local getbox = tex.getbox
-   local function dir_conditional(n, mode)
+   local function box_dir_conditional(n, mode)
       local s = getbox(n)
       local res = false
       if s then
@@ -778,7 +796,7 @@ do
       end
       tex.sprint(cat_lp, '\\if' .. tostring(res))
    end
-   luatexja.direction.dir_conditional = dir_conditional
+   luatexja.direction.box_dir_conditional = box_dir_conditional
 end
 
 -- 縦書き用字形への変換テーブル
index 254d0cc..5346a7d 100644 (file)
 
 
 %%%%%%%% \yoko, \tate, \ifydir, \iftdir
-\newif\ifydir
-\newif\iftdir
-\newif\ifddir
 \protected\def\tate{%
   \directlua{luatexja.direction.set_list_direction(3, 'tate')}%
-  \ltj@reset@globaldefs\ltj@dir@count=3\relax
-  \ifvmode\ltj@adjdir@count=3\fi\tdirtrue\ydirfalse\ddirfalse\ltj@restore@globaldefs}
+}
 \protected\def\yoko{%
   \directlua{luatexja.direction.set_list_direction(4, 'yoko')}%
-  \ltj@reset@globaldefs\ltj@dir@count=4\relax
-  \ifvmode\ltj@adjdir@count=4\fi\ydirtrue\tdirfalse\ddirfalse\ltj@restore@globaldefs}
+}
 \protected\def\dtou{%
   \directlua{luatexja.direction.set_list_direction(1, 'dtou')}%
-  \ltj@reset@globaldefs\ltj@dir@count=1\relax
-  \ifvmode\ltj@adjdir@count=1\fi\ydirfalse\tdirfalse\ddirtrue\ltj@restore@globaldefs}
+}
 \yoko
 
+\protected\def\ifydir{\directlua{luatexja.direction.dir_conditional(4)}}
+\protected\def\iftdir{\directlua{luatexja.direction.dir_conditional(3)}}
+\protected\def\ifddir{\directlua{luatexja.direction.dir_conditional(1)}}
+
 \newcount\ltj@adjdir@count@backup
 %%%% insert
 %\let\orig@insert=\insert
 
 %%%%%%%% \ifybox, \iftbox, \ifdbox
 \def\ltj@@box@cond#1#2\fi{\fi\csname if#1\endcsname}
-\def\ifybox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 4)}%
+\def\ifybox#1{\directlua{luatexja.direction.box_dir_conditional(\the\numexpr #1\relax, 4)}%
   \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
-\def\iftbox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 3)}%
+\def\iftbox#1{\directlua{luatexja.direction.box_dir_conditional(\the\numexpr #1\relax, 3)}%
   \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
-\def\ifdbox#1{\directlua{luatexja.direction.dir_conditional(\the\numexpr #1\relax, 1)}%
+\def\ifdbox#1{\directlua{luatexja.direction.box_dir_conditional(\the\numexpr #1\relax, 1)}%
   \ltj@@box@cond{true}\else\ltj@@box@cond{false}\fi}
 
 %%------------------ Load module for the format
index 69e5ec5..eedf55c 100644 (file)
Binary files a/test/test51-vtest.pdf and b/test/test51-vtest.pdf differ
index 883d2ba..7993521 100644 (file)
@@ -1,9 +1,10 @@
-%#!luatex
+%#!luajittex
 
 \directlua{luatexja_debug = 1}
 \input luatexja.sty
 %\input lua-visual-debug.sty
 
+
 \catcode`\@=11
 \newdimen\@tempdima
 \newbox\@tempboxa
@@ -49,6 +50,7 @@
 \vrule width 4pt height 0pt depth 4pt}
 
 \message{^^JTATE, DTOU IN YOKO (HMODE))^^J}
+\yoko
 \hbox{\yoko
   横水平\H\vrule\hbox{\yoko 横水平\H }\vrule かき◆
   \vrule\hbox{\tate 縦水平\H }\message{HOGE}◆おおおお\vrule
@@ -65,7 +67,8 @@
 }
 \hbox{\yoko
   ああ\setbox0=\vtop{\yoko\hsize=30mm \ifhmode\message{H}\else\message{V}\fi 横垂直\H ああああああああああ\hfill\H}%
-  {\tracingonline1\showboxdepth2\showboxbreadth100\showbox0}かき◆\copy0 ◆
+  {\tracingonline1\showboxdepth2\showboxbreadth100\showbox0}%
+  かき◆\copy0 ◆
 }
 
 \vfill\eject
 \vbox{\tate\hsize100mm
 \tfont\f=KozMinPr6N-Regular.otf:+vert;jfm=ujisv \f
 
-\ltjsetparameter{yalbaselineshift=.25em}\baselineskip15pt
+\ltjsetparameter{yalbaselineshift=.25em}\baselineskip15pt\parindent\zw
 \LaTeX の特徴として、テキストファイルであるソースコードを入力として処理することでDVIや
 PDFなどの表示形式を出力として得ることが挙げられる。
 
@@ -193,7 +196,7 @@ PDFなどの表示形式を出力として得ることが挙げられる。
 変えることができるなど、文書内容データの再利用性が高い。一度スタイル設定を決めてしまえば、
 あとは文書内容の記述に専念することができるという利点もある。論文などの投稿では、学術雑
 誌のスタイルを記述したファイル(パッケージファイル)を Web からダウンロードして利用するこ
-とで、統一されたスタイルで論文xを投稿することができ、論文の投稿者と雑誌の編集者とのやり取り
+とで、統一されたスタイルで論文を投稿することができ、論文の投稿者と雑誌の編集者とのやり取り
 を簡略化できる。Kile、TeXShop、TeXworks、EasyTeX、WinShell などの \TeX 用エ
 ディタや、野鳥(やてふ、YaTeX)、TeXlipse、KaTeX(花鳥、かてふ)、祝鳥
 (のりてふ)、M's TeX Helper 2など の\TeX 用テキストエディタマクロを兼用することに
@@ -287,11 +290,15 @@ abc&かきくけこ&xyz\cr}}%
 \setbox0=\hbox{\yoko pF}
 \setbox1=\hbox{\tate\box0}
 \fbox{\copy1}
-\unhcopy1\setbox1=\lastbox %% box1: dir_node
+\unhcopy1\setbox1=\lastbox
+{\obeylines\seventt\baselineskip=10pt
+\directlua{luatexja.ext_show_node_list(tex.box[1], 'lastbox>   ', tex.print)}\par}
 \setbox0=\hbox{\yoko \ltjsetwd1=50pt}
+{\obeylines\seventt\baselineskip=10pt
+\directlua{luatexja.ext_show_node_list(tex.box[1], 'dir node1> ', tex.print)}\par}
 \setbox0=\hbox{\dtou \ltjsetwd1=2pt}
 {\obeylines\seventt\baselineskip=10pt
-\directlua{luatexja.ext_show_node_list(tex.box[1], 'dir node ', tex.print)}\par}
+\directlua{luatexja.ext_show_node_list(tex.box[1], 'dir node2> ', tex.print)}\par}
 
 \setbox0=\hbox{\yoko \ltjsetht1=30pt}
 {\obeylines\seventt\baselineskip=10pt
@@ -337,5 +344,8 @@ p\kern-.15em\TeX\ bug (2011-02-24)
 \vbox{\tate\hsize=4\zw\R\R\R\R}
 ABCDE
 
+%\tracingall
+\hbox{\tate {\dtou 感じ\ifddir D\fi\iftdir T\fi}\ifddir D\fi\iftdir T\fi}
+
 \end