Compare commits

..

5 Commits

Author SHA1 Message Date
Marcel Fabian Krüger
912173cab1 Allow more hbox material 2021-05-01 08:27:52 +02:00
Marcel Fabian Krüger
64d5adfb33 Adjust to_text interface 2021-05-01 08:04:25 +02:00
Marcel Fabian Krüger
5f9d522244 Unify to_text usage 2021-05-01 08:00:29 +02:00
Marcel Fabian Krüger
81f0b867cd Initial hbox handling 2021-05-01 07:57:03 +02:00
Marcel Fabian Krüger
623e9dbe4a Support rules 2021-05-01 02:44:50 +02:00
4 changed files with 72 additions and 24 deletions

View File

@ -53,6 +53,6 @@ lua.get_functions_table()[funcid] = function()
texio.write_nl'WARNING: Tag extraction failed' texio.write_nl'WARNING: Tag extraction failed'
return return
end end
store_tag({[0] = 'mtd', {[0] = 'mtext', last_tag}}) store_tag({[0] = 'mtd', last_tag})
last_tag = nil last_tag = nil
end end

View File

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

View File

@ -1,9 +1,10 @@
local remap_comb = require'luamml-data-combining' local remap_comb = require'luamml-data-combining'
local stretchy = require'luamml-data-stretchy' local stretchy = require'luamml-data-stretchy'
local to_text = require'luamml-lr'
local properties = node.get_properties_table() local properties = node.get_properties_table()
local kern_t, glue_t = node.id'kern', node.id'glue' local hlist_t, kern_t, glue_t, rule_t = node.id'hlist', node.id'kern', node.id'glue', node.id'rule'
local noad_t, accent_t, style_t, choice_t = node.id'noad', node.id'accent', node.id'style', node.id'choice' local noad_t, accent_t, style_t, choice_t = node.id'noad', node.id'accent', node.id'style', node.id'choice'
local radical_t, fraction_t, fence_t = node.id'radical', node.id'fraction', node.id'fence' local radical_t, fraction_t, fence_t = node.id'radical', node.id'fraction', node.id'fence'
@ -87,8 +88,13 @@ local function kernel_to_table(kernel, cur_style)
} }
return result, result return result, result
elseif id == sub_box_t then elseif id == sub_box_t then
local result = {[0] = 'mi', {[0] = 'mglyph', ['tex:box'] = kernel.list}} if kernel.list.id == hlist_t then -- We directly give up for vlists
return result, result local result = to_text(kernel.list.head)
return result, result
else
local result = {[0] = 'mi', {[0] = 'mglyph', ['tex:box'] = kernel.list}}
return result, result
end
elseif id == sub_mlist_t then elseif id == sub_mlist_t then
return nodes_to_table(kernel.list, cur_style) return nodes_to_table(kernel.list, cur_style)
else else
@ -182,8 +188,7 @@ local function noad_to_table(noad, sub, cur_style, mn)
nucleus, nucleus,
{[0] = 'mo', '\u{203E}',}, {[0] = 'mo', '\u{203E}',},
}, core }, core
elseif class == 'vcenter' then elseif class == 'vcenter' then -- Ignored. Nucleus will need special handling anyway
nucleus['tex:TODO'] = class
else else
error[[confusion]] error[[confusion]]
end end
@ -284,6 +289,24 @@ local function space_to_table(amount, sub, cur_style)
end end
end end
local running_length = -1073741824
local function rule_to_table(rule, sub, cur_style)
local width = string.format("%.3fpt", rule.width/65781.76)
local height = rule.height
if height == running_length then
height = '0.8em'
else
height = height
end
local depth = rule.depth
if depth == running_length then
depth = '0.2em'
else
depth = depth
end
return {[0] = 'mspace', mathbackground = 'currentColor', width = width, height = height, depth = depth}, space_like
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
@ -300,7 +323,8 @@ function nodes_to_table(head, cur_style)
and 'normal' or nil and 'normal' or nil
end end
local new_core, new_mn 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
@ -378,10 +402,10 @@ function nodes_to_table(head, cur_style)
t[#t+1], new_core = space_to_table(n.width, sub, cur_style) t[#t+1], new_core = space_to_table(n.width, sub, cur_style)
end end
end end
else elseif id == rule_t then
new_core = {[0] = 'tex:TODO', other = n} t[#t+1], new_core = rule_to_table(n, sub, cur_style)
t[#t+1] = new_core -- elseif id == disc_t then -- Uncommon, does not play nicely with math mode and no sensible mapping anyway
end end -- The other possible ids are whatsit, penalty, adjust, ins, mark. Ignore them.
nonscript = nil nonscript = nil
if core and new_core ~= space_like then if core and new_core ~= space_like then
core = core == space_like and new_core or nil core = core == space_like and new_core or nil

View File

@ -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, i = {}, 0 local result, subresult, i = {[0] = 'mrow'}, {}, 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
result[i] = glyph_info subresult[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,15 +23,15 @@ 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
result[i] = utf.char(uni) subresult[i] = utf.char(uni)
else else
result[i] = utf.char(table.unpack(uni)) subresult[i] = utf.char(table.unpack(uni))
end end
else else
if char < 0x110000 then if char < 0x110000 then
result[i] = utf.char(char) subresult[i] = utf.char(char)
else else
result[i] = '\u{FFFD}' subresult[i] = '\u{FFFD}'
end end
end end
-- elseif node.id'math' == id then -- elseif node.id'math' == id then
@ -41,23 +41,47 @@ 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
result[i] = ' ' subresult[i] = ' '
end end
elseif node.id'hlist' == id then elseif node.id'hlist' == id then
i = i+1 local nested = to_unicode(n.head)
result[i] = '\u{FFFD}' if nested[0] == 'mtext' and #nested == 1 and type(nested[1]) == 'string' then
i=i+1
subresult[i] = nested[1]
else
if i ~= 0 then
i = 0
result[#result+1] = {[0] = 'mtext', table.concat(subresult)}
end
if nested[0] == 'mrow' then
table.move(nested, 1, #nested, #result+1, result)
else -- should be unreachable
result[#result+1] = nested
end
end
elseif node.id'vlist' == id then elseif node.id'vlist' == id then
i = i+1 i = i+1
result[i] = '\u{FFFD}' subresult[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
result[i] = '\u{FFFD}' subresult[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
return table.concat(result) if i ~= 0 then
i = 0
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
end end
return to_unicode return to_unicode