OSDN Git Service

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