2 local floor = math.floor
6 ------------------------------------------------------------------------
8 -- ext_... : called from \directlua{}
9 -- int_... : called from other Lua codes, but not from \directlua{}
10 -- (other) : only called from this file
12 function luatexja.load_lua(fn)
13 local found = kpse.find_file(fn, 'tex')
15 error("File `" .. fn .. "' not found")
17 texio.write('(' .. found .. ')')
22 local load_module = luatexja.load_module
23 load_module('base'); local ltjb = luatexja.base
24 load_module('rmlgbm'); local ltjr = luatexja.rmlgbm -- must be 1st
25 load_module('charrange'); local ltjc = luatexja.charrange
26 load_module('jfont'); local ltjf = luatexja.jfont
27 load_module('inputbuf'); local ltji = luatexja.inputbuf
28 load_module('stack'); local ltjs = luatexja.stack
29 load_module('pretreat'); local ltjp = luatexja.pretreat
30 load_module('jfmglue'); local ltjj = luatexja.jfmglue
31 load_module('setwidth'); local ltjw = luatexja.setwidth
32 load_module('math'); local ltjm = luatexja.math
33 load_module('tangle'); local ltjb = luatexja.base
36 local node_type = node.type
37 local node_new = node.new
38 local node_prev = node.prev
39 local node_next = node.next
40 local has_attr = node.has_attribute
41 local node_insert_before = node.insert_before
42 local node_insert_after = node.insert_after
43 local node_hpack = node.hpack
45 local id_penalty = node.id('penalty')
46 local id_glyph = node.id('glyph')
47 local id_glue_spec = node.id('glue_spec')
48 local id_glue = node.id('glue')
49 local id_kern = node.id('kern')
50 local id_hlist = node.id('hlist')
51 local id_vlist = node.id('vlist')
52 local id_rule = node.id('rule')
53 local id_math = node.id('math')
54 local id_whatsit = node.id('whatsit')
55 local sid_user = node.subtype('user_defined')
57 local attr_jchar_class = luatexbase.attributes['ltj@charclass']
58 local attr_curjfnt = luatexbase.attributes['ltj@curjfnt']
59 local attr_yablshift = luatexbase.attributes['ltj@yablshift']
60 local attr_icflag = luatexbase.attributes['ltj@icflag']
61 local attr_uniqid = luatexbase.attributes['ltj@uniqid']
62 local cat_lp = luatexbase.catcodetables['latex-package']
72 local IC_PROCESSED = 9
76 -- Three aux. functions, bollowed from tex.web
78 local function print_scaled(s)
84 out=out..tostring(floor(s/unity)) .. '.'
87 if delta>unity then s=s+32768-50000 end
88 out=out .. tostring(floor(s/unity))
95 local function print_glue(d,order)
96 local out=print_scaled(d)
100 out=out..'l'; order=order-1
108 local function print_spec(p)
109 local out=print_scaled(p.width)..'pt'
111 out=out..' plus '..print_glue(p.stretch,p.stretch_order)
114 out=out..' minus '..print_glue(p.shrink,p.shrink_order)
119 function math.two_add(a,b) return a+b end
120 function math.two_average(a,b) return (a+b)/2 end
122 ---- table: charprop_stack_table [stack_level].{pre|post|xsp}[chr_code]
124 ------------------------------------------------------------------------
125 -- CODE FOR GETTING/SETTING PARAMETERS
126 ------------------------------------------------------------------------
128 -- EXT: print parameters that don't need arguments
129 function luatexja.ext_get_parameter_unary(k)
130 if k == 'yalbaselineshift' then
131 tex.write(print_scaled(tex.getattribute('ltj@yablshift'))..'pt')
132 elseif k == 'yjabaselineshift' then
133 tex.write(print_scaled(tex.getattribute('ltj@ykblshift'))..'pt')
134 elseif k == 'kanjiskip' then
135 tex.write(print_spec(ltjs.get_skip_table('kanjiskip', tex.getcount('ltj@@stack'))))
136 elseif k == 'xkanjiskip' then
137 tex.write(print_spec(ltjs.get_skip_table('xkanjiskip', tex.getcount('ltj@@stack'))))
138 elseif k == 'jcharwidowpenalty' then
139 tex.write(ltjs.get_penalty_table('jwp', 0, 0, tex.getcount('ltj@@stack')))
140 elseif k == 'autospacing' then
141 tex.write(tex.getattribute('ltj@autospc'))
142 elseif k == 'autoxspacing' then
143 tex.write(tex.getattribute('ltj@autoxspc'))
144 elseif k == 'differentjfm' then
145 if luatexja.jfmglue.diffmet_rule == math.max then
147 elseif luatexja.jfmglue.diffmet_rule == math.min then
149 elseif luatexja.jfmglue.diffmet_rule == math.two_average then
151 elseif luatexja.jfmglue.diffmet_rule == math.two_add then
153 else -- This can't happen.
160 -- EXT: print parameters that need arguments
161 function luatexja.ext_get_parameter_binary(k,c)
162 if k == 'jacharrange' then
164 ltjb.package_error('luatexja',
165 'invalid character range number (' .. c .. ')',
166 'A character range number should be in the range 0..216,\n'..
167 'So I changed this one to zero.')
170 tex.write(ltjc.get_range_setting(c))
172 if c<0 or c>0x10FFFF then
173 ltjb.package_error('luatexja',
174 'bad character code (' .. c .. ')',
175 'A character number must be between -1 and 0x10ffff.\n'..
176 "(-1 is used for denoting `math boundary')\n"..
177 'So I changed this one to zero.')
180 if k == 'prebreakpenalty' then
181 tex.write(ltjs.get_penalty_table('pre', c, 0, tex.getcount('ltj@@stack')))
182 elseif k == 'postbreakpenalty' then
183 tex.write(ltjs.get_penalty_table('post', c, 0, tex.getcount('ltj@@stack')))
184 elseif k == 'kcatcode' then
185 tex.write(ltjs.get_penalty_table('kcat', c, 0, tex.getcount('ltj@@stack')))
186 elseif k == 'chartorange' then
187 tex.write(ltjc.char_to_range(c))
188 elseif k == 'jaxspmode' or k == 'alxspmode' then
189 tex.write(ltjs.get_penalty_table('xsp', c, 3, tex.getcount('ltj@@stack')))
194 -- EXT: print \global if necessary
195 function luatexja.ext_print_global()
196 if isglobal=='global' then tex.sprint(cat_lp, '\\global') end
200 -- mode = true iff main_process is called from pre_linebreak_filter
201 local function main_process(head, mode, dir)
203 p = ltjj.main(p,mode)
204 p = ltjw.set_ja_width(p, dir)
210 luatexbase.add_to_callback('pre_linebreak_filter',
211 function (head,groupcode)
212 return main_process(head, true, tex.textdir)
213 end,'ltj.pre_linebreak_filter',
214 luatexbase.priority_in_callback('pre_linebreak_filter',
215 'luaotfload.pre_linebreak_filter') + 1)
216 luatexbase.add_to_callback('hpack_filter',
217 function (head,groupcode,size,packtype, dir)
218 return main_process(head, false, dir)
219 end,'ltj.hpack_filter',
220 luatexbase.priority_in_callback('hpack_filter',
221 'luaotfload.hpack_filter') + 1)
226 local function debug_show_node_X(p,print_fn)
227 local k = debug_depth
229 local pt=node_type(p.id)
230 local base = debug_depth .. string.format('%X', has_attr(p,attr_icflag) or 0)
231 .. ' ' .. string.format('%X', has_attr(p, attr_uniqid) or 0)
232 .. ' ' .. node.type(p.id) .. ' ' .. tostring(p.subtype )
233 if pt == 'glyph' then
234 s = base .. ' ' .. utf.char(p.char) .. ' ' .. tostring(p.font)
235 .. ' (' .. print_scaled(p.height) .. '+'
236 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width)
238 elseif pt=='hlist' or pt=='vlist' then
239 s = base .. '(' .. print_scaled(p.height) .. '+'
240 .. print_scaled(p.depth) .. ')x' .. print_scaled(p.width) .. p.dir
242 s = s .. ', shifted ' .. print_scaled(p.shift)
244 if p.glue_sign >= 1 then
245 s = s .. ' glue set '
246 if p.glue_sign == 2 then s = s .. '-' end
247 s = s .. tostring(floor(p.glue_set*10000)/10000)
248 if p.glue_order == 0 then
252 for i = 2, p.glue_order do s = s .. 'l' end
255 if has_attr(p, attr_icflag, PACKED) then
260 debug_depth=debug_depth.. '.'
262 debug_show_node_X(q, print_fn); q = node_next(q)
265 elseif pt == 'glue' then
266 s = base .. ' ' .. print_spec(p.spec)
267 if has_attr(p, attr_icflag)==FROM_JFM then
268 s = s .. ' (from JFM)'
269 elseif has_attr(p, attr_icflag)==KANJI_SKIP then
270 s = s .. ' (kanjiskip)'
271 elseif has_attr(p, attr_icflag)==XKANJI_SKIP then
272 s = s .. ' (xkanjiskip)'
275 elseif pt == 'kern' then
276 s = base .. ' ' .. print_scaled(p.kern) .. 'pt'
278 s = s .. ' (for accent)'
279 elseif has_attr(p, attr_icflag)==IC_PROCESSED then
280 s = s .. ' (italic correction)'
281 -- elseif has_attr(p, attr_icflag)==ITALIC then
282 -- s = s .. ' (italic correction)'
283 elseif has_attr(p, attr_icflag)==FROM_JFM then
284 s = s .. ' (from JFM)'
285 elseif has_attr(p, attr_icflag)==LINE_END then
286 s = s .. " (from 'lineend' in JFM)"
289 elseif pt == 'penalty' then
290 s = base .. ' ' .. tostring(p.penalty)
291 if has_attr(p, attr_icflag)==KINSOKU then
292 s = s .. ' (for kinsoku)'
295 elseif pt == 'whatsit' then
296 s = base .. ' subtype: ' .. tostring(p.subtype)
297 if p.subtype==sid_user then
298 if p.type ~= 110 then
299 s = s .. ' user_id: ' .. p.user_id .. ' ' .. p.value
301 s = s .. ' user_id: ' .. p.user_id .. ' (node list)'
304 s = s .. node.subtype(p.subtype)
307 -------- math node --------
308 elseif pt=='noad' then
309 s = base ; print_fn(s)
311 debug_depth = k .. 'N'; debug_show_node_X(p.nucleus, print_fn);
314 debug_depth = k .. '^'; debug_show_node_X(p.sup, print_fn);
317 debug_depth = k .. '_'; debug_show_node_X(p.sub, print_fn);
320 elseif pt=='math_char' then
321 s = base .. ' fam: ' .. p.fam .. ' , char = ' .. utf.char(p.char)
323 elseif pt=='sub_box' then
326 debug_depth = k .. '.'; debug_show_node_X(p.head, print_fn);
333 function luatexja.ext_show_node_list(head,depth,print_fn)
337 debug_show_node_X(head, print_fn); head = node_next(head)
340 print_fn(debug_depth .. ' (null list)')
343 function luatexja.ext_show_node(head,depth,print_fn)
346 debug_show_node_X(head, print_fn)
348 print_fn(debug_depth .. ' (null list)')