OSDN Git Service

ltj-math.lua: bugfix of math style
authorHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 2 Oct 2022 09:13:43 +0000 (18:13 +0900)
committerHironori Kitagawa <h_kitagawa2001@yahoo.co.jp>
Sun, 2 Oct 2022 09:13:43 +0000 (18:13 +0900)
src/ltj-math.lua
src/ltj-setwidth.lua
test/test07-math.pdf
test/test07-math.tex

index ea2857f..a8664d7 100644 (file)
@@ -89,7 +89,8 @@ local function conv_vcenter(sb)
 end
 
 local cjhh_A
--- sty : 0 (display or text), 1 (script), >=2 (scriptscript)
+local max, min = math.max, math.min
+-- sty : -1 (display), 0 (text), 1 (script), >=2 (scriptscript)
 local function conv_jchar_to_hbox(head, sty)
    for p in node_traverse(head) do
       local pid = getid(p)
@@ -99,8 +100,8 @@ local function conv_jchar_to_hbox(head, sty)
          else
             setnucleus(p, cjh_A(getnucleus(p), sty))
          end
-         setsub(p, cjh_A(getsub(p), sty+1))
-         setsup(p, cjh_A(getsup(p), sty+1))
+         setsub(p, cjh_A(getsub(p), max(sty+1,1)))
+         setsup(p, cjh_A(getsup(p), max(sty+1,1)))
       elseif pid == id_choice then
          setfield(p, 'display', cjh_A(getfield(p, 'display'), -1))
          setfield(p, 'text', cjh_A(getfield(p, 'text'), 0))
@@ -111,10 +112,10 @@ local function conv_jchar_to_hbox(head, sty)
          setfield(p, 'denom', cjh_A(getfield(p, 'denom'), sty+1))
       elseif pid == id_radical then
          setnucleus(p, cjh_A(getnucleus(p), sty))
-         setsub(p, cjh_A(getsub(p), sty+1))
-         setsup(p, cjh_A(getsup(p), sty+1))
+         setsub(p, cjh_A(getsub(p), max(sty+1,1)))
+         setsup(p, cjh_A(getsup(p), max(sty+1,1)))
          if getfield(p, 'degree') then
-            setfield(p, 'degree', cjh_A(getfield(p, 'degree'), sty + 1))
+            setfield(p, 'degree', cjh_A(getfield(p, 'degree'), 2))
          end
       elseif pid == id_style then
          local ps = getfield(p, 'style')
@@ -139,7 +140,6 @@ local is_ucs_in_japanese_char = ltjc.is_ucs_in_japanese_char_direct
 local setfont = node.direct.setfont
 local setchar = node.direct.setchar
 
-local max = math.max
 cjh_A = function (p, sty)
    if not p then return nil
    else
@@ -151,7 +151,7 @@ cjh_A = function (p, sty)
       elseif pid == id_mchar then
          local pc, fam = getchar (p), get_attr(p, attr_jfam) or -1
          if (not is_math_letters[pc]) and is_ucs_in_japanese_char(p) and fam>=0 then
-            local f = ltjs.get_stack_table(MJT + 0x100 * max(sty,0) + fam, -1, getcount(cnt_stack))
+            local f = ltjs.get_stack_table(MJT + 0x100 * min(max(sty,0),2) + fam, -1, getcount(cnt_stack))
             if f ~= -1 then
                local q = node_new(id_sub_box)
                local r = node_new(id_glyph, 256); setnext(r, nil); setfont(r, f, pc)
@@ -172,13 +172,13 @@ cjh_A = function (p, sty)
 end
 
 do
-  local function mlist_callback_ltja(n)
+  local function mlist_callback_ltja(n, display_type)
     local n = to_direct(n); list_dir = ltjd_get_dir_count()
     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); if not n then return nil end
     end
-    return to_node(conv_jchar_to_hbox(n, 0))
+    return to_node(conv_jchar_to_hbox(n, (display_type=='display') and -1 or 0))
   end
   -- LaTeX 2020-02-02 seems to have pre_mlist_to_hlist_filter callback
   if luatexbase.callbacktypes['pre_mlist_to_hlist_filter'] then
index 2fa882f..dd83d7e 100644 (file)
@@ -244,16 +244,15 @@ end
 luatexja.setwidth.capsule_glyph_tate = capsule_glyph_tate
 
 do
-local font_getfont = font.getfont
+local font_getfont, famfont = font.getfont, node.family_font
 local cap_math_aux = {
-  [-1]=function() return 1 end,
-  [0]=function() return 1 end,
+  [-1]=function() return 1 end, [0]=function() return 1 end,
   [1]=function()
-     local sf, tf = node.family_font(2,1), node.family_font(2,0)
+     local sf, tf = famfont(2,1), famfont(2,0)
      return font_getfont(sf).size/font_getfont(tf).size
   end,
   [2]=function()
-     local ssf, tf = node.family_font(2,2), node.family_font(2,0)
+     local ssf, tf = famfont(2,2), famfont(2,0)
      return font_getfont(ssf).size/font_getfont(tf).size
   end
 }
index b77e4d8..679244c 100644 (file)
Binary files a/test/test07-math.pdf and b/test/test07-math.pdf differ
index 55f5a49..957f6cc 100644 (file)
@@ -69,5 +69,15 @@ mathgt: $\mathgt{あいうえおabcde}$
 \vrule height 0.1pt width 200pt depth 0pt\kern-200pt%
 あs${\scriptstyle 漢X}{漢Y^{うE}_{えO}}A^E_O12=a\pi \dfrac{aあ}{iい}$
 
+
+\ltjsetparameter{yalbaselineshift=0pt,yjabaselineshift=0pt}
+$aあ^{iい}_{uう}\Uroot \symoperators "0221A {3お} {oお}$
+\[
+aあ^{iい}_{uう}\Uroot \symoperators "0221A {3お} {oお}
+\textstyle aあ^{iい}_{uう}\Uroot \symoperators "0221A {3お} {oお}
+\scriptstyle aあ^{iい}_{uう}\Uroot \symoperators "0221A {3お} {oお}
+\scriptscriptstyle aあ^{iい}_{uう}\Uroot \symoperators "0221A {3お} {oお}
+\]
+
 \end{document}