Compare commits

..

4 Commits

Author SHA1 Message Date
Marcel Fabian Krüger
8843b99ece Multiple smaller bugs 2021-04-25 15:28:27 +02:00
Marcel Fabian Krüger
933545a64a Fix example 2021-04-25 15:20:52 +02:00
Marcel Fabian Krüger
b6a2de1265 Support merging mn nodes 2021-04-25 15:20:20 +02:00
Marcel Fabian Krüger
1ab153ed8a Better support \mathord and less unnecessary mrows 2021-04-24 20:41:10 +02:00
3 changed files with 56 additions and 7 deletions

View File

@ -13,6 +13,7 @@ lua.get_functions_table()[funcid] = function()
assert(startmath.id == node.id"math") assert(startmath.id == node.id"math")
local props = assert(properties[startmath]) local props = assert(properties[startmath])
local mml = assert(props.saved_mathml_table) local mml = assert(props.saved_mathml_table)
props.saved_mathml_table = nil
table.insert(mml, 1, {[0] = 'maligngroup'}) table.insert(mml, 1, {[0] = 'maligngroup'})
if mml[0] == 'mstyle' and mml.displaystyle == true then if mml[0] == 'mstyle' and mml.displaystyle == true then
mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil
@ -46,6 +47,7 @@ lua.get_functions_table()[funcid] = function()
if not props then return end if not props then return end
if not props.mathml_row then return end if not props.mathml_row then return end
mml_row = props.mathml_row mml_row = props.mathml_row
props.mathml_row = nil
props = properties[tex.lists.align_head] props = properties[tex.lists.align_head]
if not props then if not props then
props = {} props = {}
@ -66,8 +68,9 @@ lua.get_functions_table()[funcid] = function()
local props = properties[tex.lists.align_head] local props = properties[tex.lists.align_head]
if not props then return end if not props then return end
local mml_table = props.mathml_table_node_table local mml_table = props.mathml_table_node_table
props.mathml_table_node_table = nil
if not mml_table then return end if not mml_table then return end
print(write_xml(make_root(mml_table, 2))) print(write_xml(make_root(mml_table, 0)))
end end
funcid = luatexbase.new_luafunction'luamml_last_math_alignmark:' funcid = luatexbase.new_luafunction'luamml_last_math_alignmark:'

View File

@ -106,10 +106,45 @@ local function do_sub_sup(t, core, n, cur_style)
end end
end end
local function noad_to_table(noad, sub, cur_style)
-- If we encounter a . or , after a number, test if it's followed by another number and in that case convert it into a mn
local function maybe_to_mn(noad, core)
if noad.sub or noad.sup then return end
local after = noad.next
if not after then return end
if after.id ~= noad_t then return end
if noad_sub[after.subtype] ~= 'ord' then return end
after = after.nucleus
if not after then return end
if after.id ~= math_char_t then return end
if not digit_map[remap_lookup[after.fam << 21 | after.char]] then return end
core[0] = 'mn'
end
local function noad_to_table(noad, sub, cur_style, mn)
local class = noad_sub[sub] local class = noad_sub[sub]
local nucleus, core = kernel_to_table(noad.nucleus, class == 'over' and cur_style//2*2+1 or cur_style) local nucleus, core = kernel_to_table(noad.nucleus, class == 'over' and cur_style//2*2+1 or cur_style)
if class == 'ord' then if class == 'ord' then
if core and core[0] == 'mo' then
core[0] = 'mi'
core.stretchy, core.mathvariant = nil, #core == 1 and type(core[0]) == 'string' and utf8.len(core[0]) == 1 and utf8.codepoint(core[0]) < -0x10000 and 'normal' or nil
core['tex:class'] = nil
end
if nucleus == core and #core == 1 then
if mn and core[0] == 'mi' and (core[1] == '.' or core[1] == ',') and maybe_to_mn(noad, core) or core[0] == 'mn' then
if mn then
mn[#mn+1] = core[1]
nucleus = do_sub_sup(mn, mn, noad, cur_style)
if nucleus == mn then
return nil, mn, mn
else
return nucleus, mn, false
end
elseif not noad.sub and not noad.sup then
return core, core, core
end
end
end
elseif class == 'opdisplaylimits' or class == 'oplimits' or class == 'opnolimits' or class == 'bin' or class == 'rel' or class == 'open' elseif class == 'opdisplaylimits' or class == 'oplimits' or class == 'opnolimits' or class == 'bin' or class == 'rel' or class == 'open'
or class == 'close' or class == 'punct' or class == 'inner' then or class == 'close' or class == 'punct' or class == 'inner' then
if not core or not core[0] then if not core or not core[0] then
@ -242,17 +277,23 @@ local function space_to_table(amount, sub, cur_style)
end end
function nodes_to_table(head, cur_style) function nodes_to_table(head, cur_style)
local t = {[0] = "mrow"} local t = {[0] = 'mrow'}
local result = t local result = t
local nonscript local nonscript
local core = space_like local core, mn = space_like
for n, id, sub in node.traverse(head) do for n, id, sub in node.traverse(head) do
local new_core local new_core, new_mn
local props = properties[n] props = props and props.mathml_table local props = properties[n] props = props and props.mathml_table
if props then if props then
t[#t+1], new_core = props, user_provided t[#t+1], new_core = props, user_provided
elseif id == noad_t then elseif id == noad_t then
t[#t+1], new_core = noad_to_table(n, sub, cur_style) local new_n
new_n, new_core, new_mn = noad_to_table(n, sub, cur_style, mn)
if new_mn == false then
t[#t], new_mn = new_n, nil
else
t[#t+1] = new_n -- might be nil
end
elseif id == accent_t then elseif id == accent_t then
t[#t+1], new_core = accent_to_table(n, sub, cur_style) t[#t+1], new_core = accent_to_table(n, sub, cur_style)
elseif id == style_t then elseif id == style_t then
@ -305,6 +346,11 @@ function nodes_to_table(head, cur_style)
if core and new_core ~= space_like then if core and new_core ~= space_like then
core = new_core core = new_core
end end
mn = new_mn
end
if t[0] == 'mrow' and #t == 1 then
assert(t == result)
result = t[1]
end end
return result, core return result, core
end end

View File

@ -1,5 +1,5 @@
\documentclass{article} \documentclass{article}
\usepackage{unicode-math} % \usepackage{unicode-math}
\usepackage{amsmath} \usepackage{amsmath}
\usepackage{luamml} \usepackage{luamml}
\RegisterFamilyMapping\symsymbols{oms} \RegisterFamilyMapping\symsymbols{oms}