+local function capsule_glyph_math(p, met, class)
+ local char_data = met.char_type[class]
+ if not char_data then return nil end
+ local fwidth, pwidth = char_data.width, getfield(p, 'width')
+ fwidth = (fwidth ~= 'prop') and fwidth or pwidth
+ fshift.down = char_data.down; fshift.left = char_data.left
+ fshift = call_callback("luatexja.set_width", fshift, met, class)
+ local fheight, fdepth = char_data.height, char_data.depth
+ local y_shift, ca
+ = - getfield(p, 'yoffset') + (has_attr(p,attr_ykblshift) or 0), char_data.align
+ setfield(p, 'yoffset', -fshift.down)
+ if ca~='left' then
+ setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left
+ + (((ca=='right') and fwidth - pwidth) or round((fwidth - pwidth)*0.5)))
+ else
+ setfield(p, 'xoffset', getfield(p, 'xoffset') - fshift.left)
+ end
+ local box = node_new(id_hlist);
+ setfield(box, 'width', fwidth)
+ setfield(box, 'height', fheight)
+ setfield(box, 'depth', fdepth)
+ setfield(box, 'head', p)
+ setfield(box, 'shift', y_shift)
+ setfield(box, 'dir', tex.mathdir)
+ set_attr(box, attr_icflag, PACKED + get_pr_begin_flag(p))
+ return box
+end
+luatexja.setwidth.capsule_glyph_math = capsule_glyph_math
+
+function luatexja.setwidth.set_ja_width(ahead, adir)
+ local p = ahead; head = p; dir = adir or 'TLT'