OSDN Git Service

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