OSDN Git Service

try to fix #42855 (not well tested)
[luatex-ja/luatexja.git] / src / luatexja.lua
1 require 'lualibs'
2 ------------------------------------------------------------------------
3 local function load_lua(fn)
4    local found = kpse.find_file(fn, 'tex')
5    if not found then
6       tex.error("LuaTeX-ja error: File `" .. fn .. "' not found")
7    else
8       texio.write_nl('(' .. found .. ')'); dofile(found)
9    end
10 end
11 luatexja.load_lua = load_lua
12 function luatexja.load_module(name) require('ltj-' .. name.. '.lua') end
13
14 do
15     local dnode = node.direct
16     local getfield, traverse = dnode.getfield, dnode.traverse
17     local node_new, set_attr, get_attr = dnode.new, dnode.set_attribute, dnode.get_attribute
18     local set_attrlist, get_attrlist = dnode.setattributelist, dnode.getattributelist
19     local unset_attr = dnode.unset_attribute
20     local attr_icflag = luatexbase.attributes['ltj@icflag']
21     local function node_inherit_attr(n, b, a)
22         if b or a then
23             local attrlist = get_attrlist(b or a)
24             local nic = get_attr(n, attr_icflag)
25             set_attrlist(n, attrlist); set_attr(n, attr_icflag, nic)
26             if b and a then
27                 for na in traverse(attrlist) do
28                     local id = getfield(na, 'number')
29                     if id and id~=attr_icflag and getfield(na, 'value')~=get_attr(a, id) then
30                         unset_attr(n, id)
31                     end
32                 end
33             end
34         end                        
35     end
36     luatexja.node_inherit_attr = node_inherit_attr
37     luatexja.dnode_new = function (id, subtype, b, a)
38         local n = node_new(id, subtype); node_inherit_attr(n, b, a); return n
39     end
40 end
41 do
42    local setfield = node.direct.setfield
43    luatexja.setglue = node.direct.setglue or
44    function(g,w,st,sh,sto,sho)
45       setfield(g,'width', w or 0); setfield(g,'stretch',st or 0); setfield(g,'shrink', sh or 0)
46       setfield(g,'stretch_order',sto or 0)
47       setfield(g,'shrink_order', sho or 0)
48    end
49    local getfield = node.direct.getfield
50    luatexja.getglue = node.direct.getglue or
51    function(g)
52       return getfield(g,'width'), getfield(g,'stretch'), getfield(g,'shrink'),
53              getfield(g,'stretch_order'), getfield(g,'shrink_order')
54    end
55 end
56
57 --- 以下は全ファイルで共有される定数
58 local icflag_table = {}
59 luatexja.icflag_table = icflag_table
60 icflag_table.ITALIC          = 1
61 icflag_table.PACKED          = 2
62 icflag_table.KINSOKU         = 3
63 icflag_table.FROM_JFM        = 4
64 icflag_table.KANJI_SKIP      = 68 -- = 4+64
65 icflag_table.KANJI_SKIP_JFM  = 69
66 icflag_table.XKANJI_SKIP     = 70
67 icflag_table.XKANJI_SKIP_JFM = 71
68 icflag_table.LINEEND         = 72
69 icflag_table.PROCESSED       = 73
70 icflag_table.IC_PROCESSED    = 74
71 icflag_table.BOXBDD          = 75
72 icflag_table.SPECIAL_JAGLUE  = 76
73 -- 段落組版中のノードリストでは通常のノード (not whatsit) だが
74 -- 和文処理グルー挿入プロセスで長さが決定されるもの
75 icflag_table.PROCESSED_BEGIN_FLAG = 4096 -- sufficiently large power of 2
76
77 local stack_ind = {}
78 luatexja.stack_table_index = stack_ind
79 stack_ind.PRE  = 0x200000 -- characterごと
80 stack_ind.POST = 0x400000 -- characterごと
81 stack_ind.KCAT = 0x600000 -- characterごと
82 stack_ind.XSP  = 0x800000 -- characterごと
83 stack_ind.RIPRE  = 0xA00000 -- characterごと,ruby pre
84 stack_ind.RIPOST = 0xC00000 -- characterごと,ruby post
85 stack_ind.JWP  = 0 -- これだけ
86 stack_ind.KSK  = 1 -- これだけ
87 stack_ind.XSK  = 2 -- これだけ
88 stack_ind.MJT  = 0x100 -- 0--255
89 stack_ind.MJS  = 0x200 -- 0--255
90 stack_ind.MJSS = 0x300 -- 0--255
91 stack_ind.KSJ  = 0x400 -- 0--9
92
93 local uid_table = {}
94 luatexja.userid_table = uid_table
95 uid_table.IHB  = luatexbase.newuserwhatsitid('inhibitglue',  'luatexja') -- \inhibitglue
96 uid_table.STCK = luatexbase.newuserwhatsitid('stack_marker', 'luatexja') -- スタック管理
97 uid_table.BPAR = luatexbase.newuserwhatsitid('begin_par',    'luatexja') -- 「段落始め」
98 uid_table.DIR  = luatexbase.newuserwhatsitid('direction',    'luatexja') -- 組方向
99 uid_table.BOXB = luatexbase.newuserwhatsitid('box_boundary', 'luatexja') -- 「ボックス始め・終わり」
100 uid_table.JA_AL_BDD = luatexbase.newuserwhatsitid('ja_al_boundary', 'luatexja')
101
102 local dir_table = {}
103 luatexja.dir_table = dir_table
104 dir_table.dir_dtou = 1
105 dir_table.dir_tate = 3
106 dir_table.dir_yoko = 4
107 dir_table.dir_math_mod    = 8
108 dir_table.dir_node_auto   = 128 -- 組方向を合わせるために自動で作られたもの
109 dir_table.dir_node_manual = 256 -- 寸法代入によって作られたもの
110 dir_table.dir_utod = dir_table.dir_tate + dir_table.dir_math_mod
111   -- 「縦数式ディレクション」 in pTeX
112 --- 定義終わり
113
114 local load_module = luatexja.load_module
115 load_module 'base';      local ltjb = luatexja.base
116 if tex.outputmode==0 then
117     ltjb.package_error('luatexja',
118       'DVI output is not supported in LuaTeX-ja',
119       'Use lua*tex instead dvilua*tex.')
120 end
121 load_module 'rmlgbm';    local ltjr = luatexja.rmlgbm -- must be 1st
122 if luatexja_debug then load_module('debug') end
123 load_module 'lotf_aux';  local ltju = luatexja.lotf_aux
124 load_module 'charrange'; local ltjc = luatexja.charrange
125 load_module 'stack';     local ltjs = luatexja.stack
126 load_module 'direction'; local ltjd = luatexja.direction -- +1 hlist +1 attr_list
127 load_module 'lineskip';  local ltjl = luatexja.lineskip -- +1 hlist +1 attr_list
128 load_module 'jfont';     local ltjf = luatexja.jfont
129 load_module 'inputbuf';  local ltji = luatexja.inputbuf
130 load_module 'pretreat';  local ltjp = luatexja.pretreat
131 load_module 'setwidth';  local ltjw = luatexja.setwidth
132 load_module 'jfmglue';   local ltjj = luatexja.jfmglue -- +1 glue +1 gs +1 attr_list
133 load_module 'math';      local ltjm = luatexja.math
134 load_module 'base';      local ltjb = luatexja.base
135
136 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
137 local attr_jchar_code = luatexbase.attributes['ltj@charcode']
138 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
139 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
140 local attr_icflag = luatexbase.attributes['ltj@icflag']
141 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
142 local attr_dir = luatexbase.attributes['ltj@dir']
143 local cat_lp = luatexbase.catcodetables['latex-package']
144
145 -- Three aux. functions, borrowed from tex.web
146
147 local floor = math.floor
148 local function print_scaled(s)
149    local out, delta = '', 10
150    if s<0 then s, out = -s, out..'-' end
151    out=out..tostring(floor(s/65536)) .. '.'
152    s=10*(s%65536)+5
153    repeat
154       if delta>65536 then s=s+32768-50000 end
155       out=out .. tostring(floor(s/65536))
156       s=10*(s%65536); delta=delta*10
157    until s<=delta
158    return out
159 end
160 luatexja.print_scaled = print_scaled
161
162 local function print_glue(d,order)
163    local out=print_scaled(d)
164    if order>0 then
165       out=out..'fi'
166       while order>1 do out=out..'l'; order=order-1 end
167    else out=out..'pt'
168    end
169    return out
170 end
171
172 local function print_spec(p)
173    local out=print_scaled(p.width)..'pt'
174    if p.stretch~=0 then
175       out=out..' plus '..print_glue(p.stretch,p.stretch_order)
176    end
177    if p.shrink~=0 then
178       out=out..' minus '..print_glue(p.shrink,p.shrink_order)
179    end
180 return out
181 end
182
183
184 ------------------------------------------------------------------------
185 -- CODE FOR GETTING/SETTING PARAMETERS
186 ------------------------------------------------------------------------
187
188 -- EXT: print parameters that don't need arguments
189 do
190    local tex_getattr = tex.getattribute
191    local function getattr(a)
192       local r = tex_getattr(a)
193       return (r==-0x7FFFFFFF) and 0 or r
194    end 
195    luatexja.unary_pars = {
196       yalbaselineshift = function(t)
197          return print_scaled(getattr('ltj@yablshift'))..'pt'
198       end,
199       yjabaselineshift = function(t)
200          return print_scaled(getattr('ltj@ykblshift'))..'pt'
201       end,
202       talbaselineshift = function(t)
203          return print_scaled(getattr('ltj@tablshift'))..'pt'
204       end,
205       tjabaselineshift = function(t)
206          return print_scaled(getattr('ltj@tkblshift'))..'pt'
207       end,
208       kanjiskip = function(t)
209          return print_spec(ltjs.get_stack_skip(stack_ind.KSK, t))
210       end,
211       xkanjiskip = function(t)
212          return print_spec(ltjs.get_stack_skip(stack_ind.XSK, t))
213       end,
214       jcharwidowpenalty = function(t)
215          return ltjs.get_stack_table(stack_ind.JWP, 0, t)
216       end,
217       autospacing = function(t)
218          return getattr('ltj@autospc')
219       end,
220       autoxspacing = function(t)
221          return getattr('ltj@autoxspc')
222       end,
223       differentjfm = function(t)
224          local f, r = luatexja.jfmglue.diffmet_rule, '???'
225          if f == math.max then r = 'large'
226          elseif f == math.min then r = 'small'
227          elseif f == math.two_average then r = 'average'
228          elseif f == math.two_paverage then r = 'paverage'
229          elseif f == math.two_pleft then r = 'pleft'
230          elseif f == math.two_pright then r = 'pright'
231          elseif f == math.two_add then r = 'both'
232          end
233          return r
234       end,
235       direction = function()
236          local v = ltjd.get_dir_count()
237          if math.abs(tex.nest[tex.nest.ptr].mode) == ltjs.mmode and v == dir_table.dir_tate then
238             v = dir_table.dir_utod
239          end
240          return v
241       end,
242       adjustdir = ltjd.get_adjust_dir_count,
243    }
244
245    local unary_pars = luatexja.unary_pars
246    local scan_arg = token.scan_argument
247    function luatexja.ext_get_parameter_unary()
248       local k= scan_arg()
249       if unary_pars[k] then
250          tex.write(tostring(unary_pars[k](tex.getcount('ltj@@stack'))))
251       end
252       ltjb.stop_time_measure('get_par')
253    end
254 end
255
256
257 -- EXT: print parameters that need arguments
258 do
259    luatexja.binary_pars = {
260       jacharrange = function(c, t)
261          if type(c)~='number' or c<-1 or c>31*ltjc.ATTR_RANGE then
262             -- 0, -1 はエラーにしない(隠し)
263             ltjb.package_error('luatexja',
264                                'invalid character range number (' .. tostring(c) .. ')',
265                                'A character range number should be in the range 1..'
266                                .. 31*ltjc.ATTR_RANGE .. ",\n"..
267                                'So I changed this one to ' .. 31*ltjc.ATTR_RANGE .. ".")
268             c=0 -- external range 217 == internal range 0
269          elseif c==31*ltjc.ATTR_RANGE then c=0
270          end
271       -- 負の値は <U+0080 の文字の文字範囲,として出てくる.この時はいつも欧文文字なので 1 を返す
272          return (c<0) and 1 or ltjc.get_range_setting(c)
273       end,
274       prebreakpenalty = function(c, t)
275          return ltjs.get_stack_table(stack_ind.PRE + ltjb.in_unicode(c, true), 0, t)
276       end,
277       postbreakpenalty = function(c, t)
278          return ltjs.get_stack_table(stack_ind.POST + ltjb.in_unicode(c, true), 0, t)
279       end,
280       kcatcode = function(c, t)
281          return ltjs.get_stack_table(stack_ind.KCAT + ltjb.in_unicode(c, false), 0, t)
282       end,
283       chartorange = function(c, t)
284          return ltjc.char_to_range(ltjb.in_unicode(c, false))
285       end,
286       jaxspmode = function(c, t)
287          return ltjs.get_stack_table(stack_ind.XSP + ltjb.in_unicode(c, true), 3, t)
288       end,
289       boxdir = function(c, t)
290          if type(c)~='number' or c<0 or c>65535 then
291             ltjb.package_error('luatexja',
292                                'Bad register code (' .. tostring(c) .. ')',
293                                'A register must be between 0 and 65535.\n'..
294                                'I changed this one to zero.')
295             c=0
296          end
297          return ltjd.get_register_dir(c)
298       end,
299    }
300    local binary_pars = luatexja.binary_pars
301    local scan_arg, scan_int = token.scan_argument, token.scan_int
302    binary_pars.alxspmode = binary_pars.jaxspmode
303    function luatexja.ext_get_parameter_binary(k, c)
304       if binary_pars[k] then
305          tex.write(tostring(binary_pars[k](c,tex.getcount('ltj@@stack'))))
306       end
307       ltjb.stop_time_measure('get_par')
308    end
309 end
310
311 -- EXT: print \global if necessary
312 function luatexja.ext_print_global()
313    if luatexja.isglobal=='global' then tex.sprint(cat_lp, '\\global') end
314 end
315
316
317 -- main process
318 do
319    local start_time_measure, stop_time_measure
320       = ltjb.start_time_measure, ltjb.stop_time_measure
321    local nullfunc = function (n) return n end
322    local to_node = node.direct.tonode
323    local to_direct = node.direct.todirect
324    local ensure_tex_attr = ltjb.ensure_tex_attr
325
326    -- mode = true iff main_process is called from pre_linebreak_filter
327    local function main_process(head, mode, dir, gc)
328       ensure_tex_attr(attr_icflag, 0)
329       if gc == 'fin_row' then return head
330       else
331             start_time_measure('jfmglue')
332             local p = ltjj.main(to_direct(head),mode, dir)
333             stop_time_measure('jfmglue')
334             return to_node(p)
335       end
336    end
337
338    local function adjust_icflag(h)
339       -- kern from luaotfload will have icflag = 1
340       -- (same as italic correction)
341       ensure_tex_attr(attr_icflag, 1)
342       return h
343    end
344
345    -- callbacks
346    ltjb.add_to_callback(
347       'pre_linebreak_filter',
348       function (head,groupcode)
349          return main_process(head, true, tex.textdir, groupcode)
350       end,'ltj.main',
351       luatexbase.priority_in_callback('pre_linebreak_filter', 'luaotfload.node_processor')+1)
352    ltjb.add_to_callback(
353       'hpack_filter',
354       function (head,groupcode,size,packtype, dir)
355          return main_process(head, false, dir, groupcode)
356       end,'ltj.main',
357       luatexbase.priority_in_callback('hpack_filter', 'luaotfload.node_processor')+1)
358    ltjb.add_to_callback('pre_linebreak_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
359    ltjb.add_to_callback('hpack_filter', adjust_icflag, 'ltj.adjust_icflag', 1)
360 end
361
362 -- lastnodechar
363 do
364    local id_glyph = node.id('glyph')
365    function luatexja.pltx_composite_last_node_char()
366       local n = tex.nest[tex.nest.ptr].tail
367       local r = '-1'
368       if n then
369          if n.id==id_glyph then
370             while n.componetns and  n.subtype and n.subtype%4 >= 2 do
371                n = node.tail(n)
372             end
373             r = tostring(n.char)
374          end
375       end
376       tex.sprint(-2, r)
377    end
378 end
379
380 do
381     local cache_ver = 3 -- must be same as ltj-kinsoku.tex
382     local cache_outdate_fn = function (t) return t.version~=cache_ver end
383     local t = ltjs.charprop_stack_table
384     function luatexja.load_kinsoku()
385         for i,_ in pairs(t) do t[i]=nil end
386         local kinsoku = ltjb.load_cache('ltj-kinsoku_default',cache_outdate_fn)
387         if kinsoku and kinsoku[1] then
388             t[0] = kinsoku[1]
389         else
390             t[0] = {}; tex.print(cat_lp, '\\input ltj-kinsoku.tex\\relax')
391         end
392         luatexja.load_kinsoku=nil
393     end
394 end
395
396 -- debug
397
398 do
399
400 local node_type = node.type
401 local node_next = node.next
402 local has_attr = node.has_attribute
403
404 local id_penalty = node.id('penalty')
405 local id_glyph = node.id('glyph')
406 local id_glue = node.id('glue')
407 local id_kern = node.id('kern')
408 local id_hlist = node.id('hlist')
409 local id_vlist = node.id('vlist')
410 local id_rule = node.id('rule')
411 local id_math = node.id('math')
412 local id_whatsit = node.id('whatsit')
413 local sid_user = node.subtype('user_defined')
414
415 local prefix, inner_depth
416 local utfchar = utf.char
417 local function debug_show_node_X(p,print_fn, limit, inner_depth)
418    local k = prefix
419    local s
420    local pt, pic = node_type(p.id), (has_attr(p, attr_icflag) or 0) % icflag_table.PROCESSED_BEGIN_FLAG
421    local base = prefix .. string.format('%X', pic) .. ' ' .. pt .. ' ' .. tostring(p.subtype) .. ' '
422    if pt == 'glyph' then
423       s = base .. ' ' 
424           .. (p.char<0xF0000 and utfchar(p.char) or '') 
425           .. string.format(' (U+%X) ', p.char)
426           .. tostring(p.font) .. ' (' .. print_scaled(p.height) .. '+'
427           .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
428       if p.xoffset~=0 or p.yoffset~=0 then
429          s = s .. ' off: (' .. print_scaled(p.xoffset)
430                .. ',' .. print_scaled(p.yoffset) .. ')'
431       end
432       print_fn(s)
433    elseif pt=='hlist' or pt=='vlist' or pt=='unset'or pt=='ins' then
434       if pt=='ins' then
435          s = base .. '(' .. print_scaled(p.height) .. '+'
436             .. print_scaled(p.depth) .. ')'
437             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
438       else
439          s = base .. '(' .. print_scaled(p.height) .. '+'
440             .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
441             .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
442       end
443       if (p.shift or 0)~=0 then
444          s = s .. ', shifted ' .. print_scaled(p.shift)
445       end
446       if p.glue_set and p.glue_sign ==2 or ( p.glue_sign==1 and p.glue_set>0) then
447          s = s .. ' glue set '
448          if p.glue_sign == 2 then s = s .. '-' end
449          s = s .. tostring(floor(p.glue_set*10000)/10000)
450          if p.glue_order == 0 then s = s .. 'pt'
451          else
452             s = s .. 'fi'
453             for i = 2, p.glue_order do s = s .. 'l' end
454          end
455       end
456       if pic == icflag_table.PACKED then s = s .. ' (packed)' end
457       print_fn(s);
458       local bid = inner_depth
459       prefix, inner_depth = prefix.. '.', inner_depth + 1
460       if inner_depth < limit then
461          for q in node.traverse(p.head) do
462             debug_show_node_X(q, print_fn, limit, inner_depth)
463          end
464       end
465       prefix=k
466    elseif pt=='rule' then
467       s = base .. '(' .. print_scaled(p.height) .. '+'
468          .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
469          .. ', dir=' .. tostring(node.has_attribute(p, attr_dir))
470       print_fn(s)
471    elseif pt=='disc' then
472       print_fn(s)
473       local bid = inner_depth
474       if inner_depth < limit then
475          prefix, inner_depth = k.. 'p.', inner_depth + 1
476          for q in node.traverse(p.pre) do
477             debug_show_node_X(q, print_fn, limit, inner_depth)
478          end
479          prefix = k.. 'P.'
480          for q in node.traverse(p.post) do
481             debug_show_node_X(q, print_fn, limit, inner_depth)
482          end
483          prefix = k.. 'R.'
484          for q in node.traverse(p.replace) do
485             debug_show_node_X(q, print_fn, limit, inner_depth)
486          end
487       end
488       prefix=k
489    elseif pt == 'glue' then
490       s = base .. ' ' ..  print_spec(p)
491       if pic>icflag_table.KINSOKU and pic<icflag_table.KANJI_SKIP then
492          s = s .. ' (from JFM: priority ' .. pic-icflag_table.FROM_JFM .. ')'
493       elseif pic==icflag_table.KANJI_SKIP then
494          s = s .. ' (kanjiskip)'
495       elseif pic==icflag_table.KANJI_SKIP_JFM then
496          s = s .. ' (kanjiskip, JFM specified)'
497       elseif pic==icflag_table.XKANJI_SKIP then
498          s = s .. ' (xkanjiskip)'
499       elseif pic==icflag_table.XKANJI_SKIP_JFM then
500          s = s .. ' (xkanjiskip, JFM specified)'
501       end
502       print_fn(s)
503    elseif pt == 'kern' then
504       s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
505       if p.subtype==2 then
506          s = s .. ' (for accent)'
507       elseif pic==icflag_table.IC_PROCESSED then
508          s = s .. ' (italic correction)'
509       elseif pic==icflag_table.LINEEND then
510          s = s .. ' (end-of-line)'
511       elseif pic>icflag_table.KINSOKU
512          and pic<icflag_table.KANJI_SKIP then
513          s = s .. ' (from JFM: priority ' .. pic-icflag_table.FROM_JFM .. ')'
514       end
515       print_fn(s)
516    elseif pt == 'penalty' then
517       s = base .. ' ' .. tostring(p.penalty)
518       if pic==icflag_table.KINSOKU then s = s .. ' (for kinsoku)' end
519       print_fn(s)
520    elseif pt == 'dir' then
521       print_fn(base .. ' ' .. tostring(p.dir) .. ' (level ' .. tostring(p.level) .. ')')
522    elseif pt == 'whatsit' then
523       s = base
524       if p.subtype==sid_user then
525          local t = tostring(p.user_id) .. ' (' ..
526             luatexbase.get_user_whatsit_name(p.user_id) .. ') '
527          if p.type ~= 110 then
528             s = s .. ' userid:' .. t .. p.value
529             print_fn(s)
530          else
531             s = s .. ' userid:' .. t .. '(node list)'
532             if p.user_id==uid_table.DIR then
533                s = s .. ' dir: ' .. tostring(node.has_attribute(p, attr_dir))
534             end
535             print_fn(s)
536             local bid = inner_depth
537             prefix, inner_depth = prefix.. '.', inner_depth + 1
538             if inner_depth < limit then
539                for q in node.traverse(p.value) do
540                   debug_show_node_X(q, print_fn, limit, inner_depth)
541                end
542             end
543             prefix, inner_depth = k, bid
544          end
545       else
546          s = s .. (node.subtype(p.subtype) or '')
547          if p.subtype==1 then
548             s = s .. ' stream=' .. p.stream
549             print_fn(s)
550             for i=1,#p.data do
551                print_fn(s .. '  [' .. i .. '] = ' .. tostring(p.data[i] and p.date[i].csname))
552             end
553          elseif p.subtype==16 then
554             s = s .. ' mode=' .. p.mode .. ', literal="' .. p.data .. '"'
555             print_fn(s)
556          else
557             print_fn(s)
558          end
559       end
560    -------- math node --------
561    elseif pt=='noad' then
562       print_fn(base)
563       if p.nucleus then
564          prefix = k .. 'N'; debug_show_node_X(p.nucleus, print_fn, limit, inner_depth);
565       end
566       if p.sup then
567          prefix = k .. '^'; debug_show_node_X(p.sup, print_fn, limit, inner_depth);
568       end
569       if p.sub then
570          prefix = k .. '_'; debug_show_node_X(p.sub, print_fn, limit, inner_depth);
571       end
572       prefix = k;
573    elseif pt=='math_char' then
574       s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utfchar(p.char)
575       print_fn(s)
576    elseif pt=='sub_box' or pt=='sub_mlist' then
577       print_fn(base)
578       if p.head then
579          prefix = k .. '.';
580          for q in node.traverse(p.head) do
581             debug_show_node_X(q, print_fn, limit, inner_depth)
582          end
583       end
584    else
585       print_fn(base)
586    end
587    p=node_next(p)
588 end
589 function luatexja.ext_show_node_list(head,depth,print_fn, lim)
590    prefix = depth
591    inner_depth = 0
592    if head then
593       while head do
594          debug_show_node_X(head, print_fn, lim or 1/0, inner_depth); head = node_next(head)
595       end
596    else
597       print_fn(prefix .. ' (null list)')
598    end
599 end
600 function luatexja.ext_show_node(head,depth,print_fn, lim)
601    prefix = depth
602    inner_depth = 0
603    if head then
604       debug_show_node_X(head, print_fn, lim or 1/0, inner_depth)
605    else
606       print_fn(prefix .. ' (null list)')
607    end
608 end
609
610 end