Generate nested <math> in <mtext>
This commit is contained in:
parent
ccedfba57a
commit
77b607e2e2
@ -1,7 +1,7 @@
|
|||||||
local properties = node.get_properties_table()
|
local properties = node.get_properties_table()
|
||||||
|
|
||||||
local function to_unicode(head, tail)
|
local function to_unicode(head, tail)
|
||||||
local result, subresult, i = {[0] = 'mrow'}, {}, 0
|
local result, subresult, i = {[0] = 'mtext'}, {}, 0
|
||||||
local characters, last_fid
|
local characters, last_fid
|
||||||
local iter, state, n = node.traverse(head)
|
local iter, state, n = node.traverse(head)
|
||||||
while true do
|
while true do
|
||||||
@ -10,7 +10,7 @@ local function to_unicode(head, tail)
|
|||||||
local props = properties[n]
|
local props = properties[n]
|
||||||
if props and props.glyph_info then
|
if props and props.glyph_info then
|
||||||
i = i+1
|
i = i+1
|
||||||
subresult[i] = glyph_info
|
result[i] = glyph_info
|
||||||
else
|
else
|
||||||
local char, fid = node.is_glyph(n)
|
local char, fid = node.is_glyph(n)
|
||||||
if char then
|
if char then
|
||||||
@ -23,27 +23,23 @@ local function to_unicode(head, tail)
|
|||||||
i = i+1
|
i = i+1
|
||||||
if uni then
|
if uni then
|
||||||
if type(uni) == 'number' then
|
if type(uni) == 'number' then
|
||||||
subresult[i] = utf.char(uni)
|
result[i] = utf.char(uni)
|
||||||
else
|
else
|
||||||
subresult[i] = utf.char(table.unpack(uni))
|
result[i] = utf.char(table.unpack(uni))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if char < 0x110000 then
|
if char < 0x110000 then
|
||||||
subresult[i] = utf.char(char)
|
result[i] = utf.char(char)
|
||||||
else
|
else
|
||||||
subresult[i] = '\u{FFFD}'
|
result[i] = '\u{FFFD}'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif node.id'math' == id then
|
elseif node.id'math' == id then
|
||||||
if props then
|
if props then
|
||||||
local mml = props.saved_mathml_table or props.saved_mathml_core
|
local mml = props.saved_mathml_table or props.saved_mathml_core
|
||||||
if mml then
|
if mml then
|
||||||
if i ~= 0 then
|
i = i+1
|
||||||
result[#result+1] = {[0] = 'mtext', table.concat(subresult)}
|
result[i] = mml
|
||||||
for j = i, 1, -1 do subresult[j] = nil end
|
|
||||||
i = 0
|
|
||||||
end
|
|
||||||
result[#result+1] = mml
|
|
||||||
n = node.end_of_math(n)
|
n = node.end_of_math(n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -52,46 +48,23 @@ local function to_unicode(head, tail)
|
|||||||
elseif node.id'glue' == id then
|
elseif node.id'glue' == id then
|
||||||
if n.width > 1000 then -- FIXME: Coordinate constant with tagpdf
|
if n.width > 1000 then -- FIXME: Coordinate constant with tagpdf
|
||||||
i = i+1
|
i = i+1
|
||||||
subresult[i] = '\u{00A0}' -- non breaking space... There is no real reason why it has to be non breaking, except that MathML often ignore other spaces
|
result[i] = '\u{00A0}' -- non breaking space... There is no real reason why it has to be non breaking, except that MathML often ignore other spaces
|
||||||
end
|
end
|
||||||
elseif node.id'hlist' == id then
|
elseif node.id'hlist' == id then
|
||||||
local nested = to_unicode(n.head)
|
local nested = to_unicode(n.head)
|
||||||
if nested[0] == 'mtext' and #nested == 1 and type(nested[1]) == 'string' then
|
table.move(nested, 1, #nested, i+1, result)
|
||||||
i=i+1
|
i = i+#nested
|
||||||
subresult[i] = nested[1]
|
|
||||||
else
|
|
||||||
if i ~= 0 then
|
|
||||||
result[#result+1] = {[0] = 'mtext', table.concat(subresult)}
|
|
||||||
for j = i, 1, -1 do subresult[j] = nil end
|
|
||||||
i = 0
|
|
||||||
end
|
|
||||||
if nested[0] == 'mrow' then
|
|
||||||
table.move(nested, 1, #nested, #result+1, result)
|
|
||||||
else -- should be unreachable (propbably actually is reachable if the inner list only contains math
|
|
||||||
result[#result+1] = nested
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif node.id'vlist' == id then
|
elseif node.id'vlist' == id then
|
||||||
i = i+1
|
i = i+1
|
||||||
subresult[i] = '\u{FFFD}'
|
result[i] = '\u{FFFD}'
|
||||||
elseif node.id'rule' == id then
|
elseif node.id'rule' == id then
|
||||||
if n.width ~= 0 then
|
if n.width ~= 0 then
|
||||||
i = i+1
|
i = i+1
|
||||||
subresult[i] = '\u{FFFD}'
|
result[i] = '\u{FFFD}'
|
||||||
end
|
end
|
||||||
end -- CHECK: Everything else can probably be ignored, otherwise shout at me
|
end -- CHECK: Everything else can probably be ignored, otherwise shout at me
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if i ~= 0 then
|
|
||||||
result[#result+1] = {[0] = 'mtext', table.concat(subresult)}
|
|
||||||
end
|
|
||||||
if #result == 0 then
|
|
||||||
local r = {[0] = 'mtext', ''}
|
|
||||||
return r, r
|
|
||||||
elseif #result == 1 then
|
|
||||||
result = result[1]
|
|
||||||
if result[1] == 'mtext' then return result, result end
|
|
||||||
end
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
|
|||||||
style = flag & 4 == 4 and flag>>5 & 0x7 or display and 0 or 2
|
style = flag & 4 == 4 and flag>>5 & 0x7 or display and 0 or 2
|
||||||
local xml, core = process_mlist(mlist, style)
|
local xml, core = process_mlist(mlist, style)
|
||||||
if flag & 2 == 2 then
|
if flag & 2 == 2 then
|
||||||
save_result(shallow_copy(xml), display)
|
xml = save_result(shallow_copy(xml), display)
|
||||||
else
|
else
|
||||||
local element_type = token.get_macro'l__luamml_root_tl'
|
local element_type = token.get_macro'l__luamml_root_tl'
|
||||||
if element_type ~= 'mrow' then
|
if element_type ~= 'mrow' then
|
||||||
|
Loading…
Reference in New Issue
Block a user