2021-04-24 16:53:50 +02:00
|
|
|
local write_xml = require'luamml-xmlwriter'
|
|
|
|
local make_root = require'luamml-convert'.make_root
|
2021-04-25 18:09:13 +02:00
|
|
|
local save_result = require'luamml-tex'.save_result
|
2021-04-28 22:03:40 +02:00
|
|
|
local store_column = require'luamml-table'.store_column
|
|
|
|
local store_tag = require'luamml-table'.store_tag
|
|
|
|
local get_table = require'luamml-table'.get_table
|
2021-04-24 16:53:50 +02:00
|
|
|
|
|
|
|
local properties = node.get_properties_table()
|
|
|
|
|
2021-04-27 17:33:22 +02:00
|
|
|
local funcid = luatexbase.new_luafunction'__luamml_amsmath_add_box_to_row:'
|
|
|
|
token.set_lua('__luamml_amsmath_add_box_to_row:', funcid, 'protected')
|
2021-04-24 16:53:50 +02:00
|
|
|
lua.get_functions_table()[funcid] = function()
|
|
|
|
-- TODO: Error handling etc
|
|
|
|
-- local box = token.scan_int()
|
|
|
|
local boxnum = 0
|
|
|
|
local startmath = tex.box[boxnum].list
|
|
|
|
assert(startmath.id == node.id"math")
|
2021-04-28 22:03:40 +02:00
|
|
|
store_column(startmath, true)
|
2021-04-24 16:53:50 +02:00
|
|
|
end
|
|
|
|
|
2021-04-27 17:33:22 +02:00
|
|
|
funcid = luatexbase.new_luafunction'__luamml_amsmath_finalize_table:'
|
|
|
|
token.set_lua('__luamml_amsmath_finalize_table:', funcid)
|
2021-04-24 16:53:50 +02:00
|
|
|
lua.get_functions_table()[funcid] = function()
|
|
|
|
-- TODO: Error handling etc
|
2021-04-28 22:03:40 +02:00
|
|
|
local mml_table = get_table()
|
2021-04-24 16:53:50 +02:00
|
|
|
if not mml_table then return end
|
2021-04-28 22:03:40 +02:00
|
|
|
mml_table.displaystyle = true
|
2021-04-25 18:09:13 +02:00
|
|
|
local columns = node.count(node.id'align_record', tex.lists.align_head)//2
|
|
|
|
mml_table.columnalign = string.rep('right left', columns, ' ')
|
2021-04-27 03:30:08 +02:00
|
|
|
local spacing = {}
|
|
|
|
for n in node.traverse_id(node.id'glue', tex.lists.align_head) do
|
|
|
|
spacing[#spacing+1] = n.width == 0 and '0' or '.8em'
|
|
|
|
end
|
|
|
|
mml_table.columnspacing = table.concat(spacing, ' ', 2, #spacing-2)
|
2021-04-25 18:09:13 +02:00
|
|
|
save_result(mml_table, 0)
|
2021-04-24 16:53:50 +02:00
|
|
|
end
|
|
|
|
|
2021-04-27 17:33:22 +02:00
|
|
|
local last_tag
|
|
|
|
|
|
|
|
funcid = luatexbase.new_luafunction'__luamml_amsmath_save_tag:'
|
|
|
|
token.set_lua('__luamml_amsmath_save_tag:', funcid, 'protected')
|
2021-04-24 16:53:50 +02:00
|
|
|
lua.get_functions_table()[funcid] = function()
|
2021-04-27 17:33:22 +02:00
|
|
|
local nest = tex.nest.top
|
|
|
|
local chars = {}
|
|
|
|
for n, id, sub in node.traverse(nest.head.next) do
|
|
|
|
if id == node.id'glyph' then
|
|
|
|
if sub >= 0x100 then
|
|
|
|
texio.write_nl'WARNING: Already shaped glyph detected in tag. This might lead to wrong output.'
|
|
|
|
end
|
|
|
|
chars[#chars+1] = n.char
|
|
|
|
elseif id == node.id'glue' then
|
|
|
|
chars[#chars+1] = 0x20
|
|
|
|
elseif id == node.id'kern' then
|
|
|
|
else
|
|
|
|
print(n)
|
|
|
|
texio.write_nl'WARNING: Unsupported node in tag dropped'
|
|
|
|
end
|
2021-04-24 16:53:50 +02:00
|
|
|
end
|
2021-04-27 17:33:22 +02:00
|
|
|
last_tag = utf8.char(table.unpack(chars))
|
|
|
|
end
|
|
|
|
|
|
|
|
funcid = luatexbase.new_luafunction'__luamml_amsmath_set_tag:'
|
|
|
|
token.set_lua('__luamml_amsmath_set_tag:', funcid, 'protected')
|
|
|
|
lua.get_functions_table()[funcid] = function()
|
|
|
|
if not last_tag then
|
|
|
|
texio.write_nl'WARNING: Tag extraction failed'
|
|
|
|
return
|
|
|
|
end
|
2021-04-28 22:03:40 +02:00
|
|
|
store_tag({[0] = 'mtd', {[0] = 'mtext', last_tag}})
|
2021-04-27 17:33:22 +02:00
|
|
|
last_tag = nil
|
2021-04-24 16:53:50 +02:00
|
|
|
end
|