Compare commits

...

2 Commits

Author SHA1 Message Date
Marcel Fabian Krüger 743d8f85c5 Opportunistic inclusion of MathML in text content 2021-05-03 21:57:58 +02:00
Marcel Fabian Krüger 8e5cee495d Fight against XML weirdness 2021-05-03 21:53:10 +02:00
2 changed files with 18 additions and 7 deletions

View File

@ -48,7 +48,7 @@ lua.get_functions_table()[funcid] = function()
else
-- Oh no, we got text. Let't complain to the user, it's probably their fault
print'We are mathematicians, don\'t bother us with text'
store_column_xml(to_text(startmath, tex.nest.top.tail))
store_column_xml(to_text(startmath, tex.nest.top.tail)).columnalign = alignment
end
end

View File

@ -34,14 +34,25 @@ local function to_unicode(head, tail)
subresult[i] = '\u{FFFD}'
end
end
-- elseif node.id'math' == id then
-- n = node.end_of_math(n) -- Not sure yet
elseif node.id'math' == id then
if props then
local mml = props.saved_mathml_table
if mml then
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
result[#result+1] = mml
n = node.end_of_math(n)
end
end
-- elseif node.id'whatsit' == id then
-- TODO(?)
elseif node.id'glue' == id then
if n.width > 1000 then -- FIXME: Coordinate constant with tagpdf
i = i+1
subresult[i] = ' '
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
end
elseif node.id'hlist' == id then
local nested = to_unicode(n.head)
@ -50,12 +61,13 @@ local function to_unicode(head, tail)
subresult[i] = nested[1]
else
if i ~= 0 then
i = 0
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
else -- should be unreachable (propbably actually is reachable if the inner list only contains math
result[#result+1] = nested
end
end
@ -71,7 +83,6 @@ local function to_unicode(head, tail)
end
end
if i ~= 0 then
i = 0
result[#result+1] = {[0] = 'mtext', table.concat(subresult)}
end
if #result == 0 then