OSDN Git Service

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