OSDN Git Service

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