Compare commits

..

No commits in common. "b9105dcc4a98e4b1f1b2767e6921c9dca9d75855" and "5c4bc21c0cee25ffbaac047f8ad9826ed7ab9600" have entirely different histories.

4 changed files with 58 additions and 91 deletions

View File

@ -1,9 +1,6 @@
local write_xml = require'luamml-xmlwriter'
local make_root = require'luamml-convert'.make_root
local save_result = require'luamml-tex'.save_result
local store_column = require'luamml-table'.store_column
local store_tag = require'luamml-table'.store_tag
local get_table = require'luamml-table'.get_table
local properties = node.get_properties_table()
@ -15,16 +12,62 @@ lua.get_functions_table()[funcid] = function()
local boxnum = 0
local startmath = tex.box[boxnum].list
assert(startmath.id == node.id"math")
store_column(startmath, true)
local props = assert(properties[startmath])
local mml = assert(props.saved_mathml_table)
props.saved_mathml_table = nil
if mml[0] == 'mstyle' and mml.displaystyle == true then
mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil
else
if mml[0] ~= 'mstyle' then
mml = {[0] = 'mstyle', displaystyle = false, mml}
end
mml = {[0] = 'mtd', mml}
end
local row_temp = tex.nest[tex.nest.ptr-1]
props = properties[row_temp]
if not props then
props = {}
properties[row_temp] = props
end
if not props.mathml_row then
props.mathml_row = {[0] = 'mtr'}
end
mml_row = props.mathml_row
table.insert(mml_row, mml)
end
funcid = luatexbase.new_luafunction'__luamml_amsmath_finalize_row:'
token.set_lua('__luamml_amsmath_finalize_row:', funcid, 'protected')
lua.get_functions_table()[funcid] = function()
-- TODO: Error handling etc
local row_temp = tex.nest[tex.nest.ptr-1]
local props = properties[row_temp]
if not props then return end
if not props.mathml_row then return end
mml_row = props.mathml_row
props.mathml_row = nil
props = properties[tex.lists.align_head]
if not props then
props = {}
properties[tex.lists.align_head] = props
end
local mml_table = props.mathml_table_node_table
if not mml_table then
mml_table = {[0] = 'mtable', displaystyle = true}
props.mathml_table_node_table = mml_table
end
table.insert(mml_table, mml_row)
end
funcid = luatexbase.new_luafunction'__luamml_amsmath_finalize_table:'
token.set_lua('__luamml_amsmath_finalize_table:', funcid)
lua.get_functions_table()[funcid] = function()
-- TODO: Error handling etc
local mml_table = get_table()
local props = properties[tex.lists.align_head]
if not props then return end
local mml_table = props.mathml_table_node_table
props.mathml_table_node_table = nil
if not mml_table then return end
mml_table.displaystyle = true
local columns = node.count(node.id'align_record', tex.lists.align_head)//2
mml_table.columnalign = string.rep('right left', columns, ' ')
local spacing = {}
@ -66,6 +109,12 @@ lua.get_functions_table()[funcid] = function()
texio.write_nl'WARNING: Tag extraction failed'
return
end
store_tag({[0] = 'mtd', {[0] = 'mtext', last_tag}})
local row_temp = tex.nest[tex.nest.ptr-1]
local props = properties[row_temp]
if not props then return end
if not props.mathml_row then return end
mml_row = props.mathml_row
mml_row[0] = 'mlabeledtr'
table.insert(mml_row, 1, {[0] = 'mtd', {[0] = 'mtext', last_tag}})
last_tag = nil
end

View File

@ -83,7 +83,7 @@ local function kernel_to_table(kernel, cur_style)
local result = {[0] = elem,
char,
['tex:family'] = fam ~= 0 and fam or nil,
mathvariant = utf8.len(char) == 1 and elem == 'mi' and utf8.codepoint(char) < 0x10000 and 'normal' or nil
mathvariant = #char == 1 and elem == 'mi' and utf8.codepoint(char) < 0x10000 and 'normal' or nil
}
return result, result
elseif id == sub_box_t then

View File

@ -75,6 +75,7 @@
\place@tag
\__luamml_amsmath_set_tag:
\fi
\__luamml_amsmath_finalize_row:
\ifst@rred
\else
\global \@eqnswtrue

View File

@ -1,83 +0,0 @@
local write_xml = require'luamml-xmlwriter'
local make_root = require'luamml-convert'.make_root
local save_result = require'luamml-tex'.save_result
local properties = node.get_properties_table()
local function store_get_row()
local row_temp = tex.nest[tex.nest.ptr-1].head
local props = properties[row_temp]
if not props then
props = {}
properties[row_temp] = props
end
local mml_row = props.mathml_row
if not mml_row then
mml_row = {[0] = 'mtr'}
props.mathml_row = mml_row
end
return mml_row
end
local function store_column(startmath, display)
local props = properties[startmath]
if not props then return end
local mml = props.saved_mathml_table
if not mml then return end
props.saved_mathml_table = nil
if display and mml[0] == 'mstyle' and mml.displaystyle == true then
mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil
else
if display and mml[0] ~= 'mstyle' then
mml = {[0] = 'mstyle', displaystyle = false, mml}
end
mml = {[0] = 'mtd', mml}
end
table.insert(store_get_row(), mml)
end
local function store_tag(xml)
local mml_row = store_get_row()
mml_row[0] = 'mlabeledtr'
table.insert(mml_row, 1, xml)
last_tag = nil
end
luatexbase.add_to_callback('hpack_filter', function(_, group)
if group ~= 'fin_row' then return true end
local temp = tex.nest.top.head
local props = properties[temp]
if not props then return true end
local mml_row = props.mathml_row
if not mml_row then return true end
props.mathml_row = nil
props = properties[tex.lists.align_head]
if not props then
props = {}
properties[tex.lists.align_head] = props
end
local mml_table = props.mathml_table_node_table
if not mml_table then
mml_table = {[0] = 'mtable'}
props.mathml_table_node_table = mml_table
end
table.insert(mml_table, mml_row)
return true
end, 'mathml amsmath processing')
local function get_table()
-- TODO: Error handling etc
local props = properties[tex.lists.align_head]
if not props then return end
local mml_table = props.mathml_table_node_table
props.mathml_table_node_table = nil
return mml_table
end
return {
store_column = store_column,
store_tag = store_tag,
get_table = get_table,
}