Handle many TODOs
This commit is contained in:
parent
098811063c
commit
165c6bd9ad
167
mlist_to_mml.lua
167
mlist_to_mml.lua
@ -9,6 +9,9 @@ local fence_sub = node.subtypes'fence'
|
|||||||
|
|
||||||
local nodes_to_table
|
local nodes_to_table
|
||||||
|
|
||||||
|
local function sub_style(s) return s//4*2+5 end
|
||||||
|
local function sup_style(s) return s//4*2+4+s%2 end
|
||||||
|
|
||||||
-- We ignore large_... since they aren't used for modern fonts
|
-- We ignore large_... since they aren't used for modern fonts
|
||||||
local function delim_to_table(delim)
|
local function delim_to_table(delim)
|
||||||
if not delim then return end
|
if not delim then return end
|
||||||
@ -16,7 +19,7 @@ local function delim_to_table(delim)
|
|||||||
return {[0] = 'mo', utf8.char(delim.small_char), ['tex:family'] = fam ~= 0 and fam or nil }
|
return {[0] = 'mo', utf8.char(delim.small_char), ['tex:family'] = fam ~= 0 and fam or nil }
|
||||||
end
|
end
|
||||||
|
|
||||||
local function kernel_to_table(kernel)
|
local function kernel_to_table(kernel, cur_style)
|
||||||
if not kernel then return end
|
if not kernel then return end
|
||||||
local id = kernel.id
|
local id = kernel.id
|
||||||
if id == math_char_t then
|
if id == math_char_t then
|
||||||
@ -27,15 +30,15 @@ local function kernel_to_table(kernel)
|
|||||||
elseif id == sub_box_t then
|
elseif id == sub_box_t then
|
||||||
return {[0] = 'mi', {[0] = 'mglyph', ['tex:box'] = kernel.list}}
|
return {[0] = 'mi', {[0] = 'mglyph', ['tex:box'] = kernel.list}}
|
||||||
elseif id == sub_mlist_t then
|
elseif id == sub_mlist_t then
|
||||||
return nodes_to_table(kernel.list)
|
return nodes_to_table(kernel.list, cur_style)
|
||||||
else
|
else
|
||||||
error'confusion'
|
error'confusion'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_sub_sup(t, n)
|
local function do_sub_sup(t, n, cur_style)
|
||||||
sub = kernel_to_table(n.sub)
|
local sub = kernel_to_table(n.sub, sub_style(cur_style))
|
||||||
sup = kernel_to_table(n.sup)
|
local sup = kernel_to_table(n.sup, sup_style(cur_style))
|
||||||
if sub then
|
if sub then
|
||||||
if sup then
|
if sup then
|
||||||
return {[0] = 'msubsup', t, sub, sup}
|
return {[0] = 'msubsup', t, sub, sup}
|
||||||
@ -49,14 +52,11 @@ local function do_sub_sup(t, n)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function noad_to_table(noad, sub)
|
local function noad_to_table(noad, sub, cur_style)
|
||||||
local class = noad_sub[sub]
|
local class = noad_sub[sub]
|
||||||
local nucleus = kernel_to_table(noad.nucleus)
|
local nucleus = kernel_to_table(noad.nucleus, class == 'over' and cur_style//2*2+1 or cur_style)
|
||||||
if class == 'ord' then
|
if class == 'ord' then
|
||||||
-- elseif class == 'opdisplaylimits' then
|
elseif class == 'opdisplaylimits' or class == 'oplimits' or class == 'opnolimits' or class == 'bin' or class == 'rel' or class == 'open'
|
||||||
-- elseif class == 'oplimits' then
|
|
||||||
-- elseif class == 'opnolimits' then
|
|
||||||
elseif 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 nucleus[0] == 'mrow' then
|
if nucleus[0] == 'mrow' then
|
||||||
-- TODO
|
-- TODO
|
||||||
@ -64,19 +64,73 @@ local function noad_to_table(noad, sub)
|
|||||||
nucleus[0] = 'mo'
|
nucleus[0] = 'mo'
|
||||||
end
|
end
|
||||||
nucleus['tex:class'] = class
|
nucleus['tex:class'] = class
|
||||||
-- elseif class == 'under' then
|
|
||||||
-- elseif class == 'over' then
|
if (noad.sup or noad.sub) and (class == 'opdisplaylimits' or class == 'oplimits') then
|
||||||
-- elseif class == 'vcenter' then
|
nucleus.movablelimits = class == 'opdisplaylimits'
|
||||||
else
|
local sub = kernel_to_table(noad.sub, sub_style(cur_style))
|
||||||
-- error[[confusion]]
|
local sup = kernel_to_table(noad.sup, sup_style(cur_style))
|
||||||
nucleus['tex:TODO'] = class
|
return {[0] = sup and (sub and 'munderover' or 'mover') or 'munder',
|
||||||
|
nucleus,
|
||||||
|
sub or sup,
|
||||||
|
sub and sup,
|
||||||
|
}
|
||||||
end
|
end
|
||||||
return do_sub_sup(nucleus, noad)
|
elseif class == 'under' then
|
||||||
|
return {[0] = 'munder',
|
||||||
|
nucleus,
|
||||||
|
{[0] = 'mo', '_',},
|
||||||
|
}
|
||||||
|
elseif class == 'over' then
|
||||||
|
return {[0] = 'mover',
|
||||||
|
nucleus,
|
||||||
|
{[0] = 'mo', '\u{203E}',},
|
||||||
|
}
|
||||||
|
elseif class == 'vcenter' then
|
||||||
|
nucleus['tex:TODO'] = class
|
||||||
|
else
|
||||||
|
error[[confusion]]
|
||||||
|
end
|
||||||
|
return do_sub_sup(nucleus, noad, cur_style)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function radical_to_table(radical, sub)
|
local function accent_to_table(accent, sub, cur_style)
|
||||||
|
local nucleus = kernel_to_table(accent.nucleus, cur_style//2*2+1)
|
||||||
|
local top_acc = kernel_to_table(accent.accent, cur_style)
|
||||||
|
local bot_acc = kernel_to_table(accent.bot_accent, cur_style)
|
||||||
|
if top_acc then
|
||||||
|
top_acc[0] = 'mo'
|
||||||
|
if sub & 1 == 1 then
|
||||||
|
top_acc.stretchy = 'false'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if bot_acc then
|
||||||
|
bot_acc[0] = 'mo'
|
||||||
|
if sub & 2 == 2 then
|
||||||
|
bot_acc.stretchy = 'false'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return {[0] = top_acc and (bot_acc and 'munderover' or 'mover') or 'munder',
|
||||||
|
nucleus,
|
||||||
|
bot_acc or top_acc,
|
||||||
|
bot_acc and top_acc,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local style_table = {
|
||||||
|
display = {displaystyle = "true", scriptlevel = "0"},
|
||||||
|
text = {displaystyle = "false", scriptlevel = "0"},
|
||||||
|
script = {displaystyle = "false", scriptlevel = "1"},
|
||||||
|
scriptscript = {displaystyle = "false", scriptlevel = "2"},
|
||||||
|
}
|
||||||
|
|
||||||
|
style_table.crampeddisplay, style_table.crampedtext,
|
||||||
|
style_table.crampedscript, style_table.crampedscriptscript =
|
||||||
|
style_table.display, style_table.text,
|
||||||
|
style_table.script, style_table.scriptscript
|
||||||
|
|
||||||
|
local function radical_to_table(radical, sub, cur_style)
|
||||||
local kind = radical_sub[sub]
|
local kind = radical_sub[sub]
|
||||||
local nucleus = kernel_to_table(radical.nucleus)
|
local nucleus = kernel_to_table(radical.nucleus, cur_style//2*2+1)
|
||||||
local left = delim_to_table(radical.left)
|
local left = delim_to_table(radical.left)
|
||||||
local elem
|
local elem
|
||||||
if kind == 'radical' or kind == 'uradical' then
|
if kind == 'radical' or kind == 'uradical' then
|
||||||
@ -96,14 +150,13 @@ local function radical_to_table(radical, sub)
|
|||||||
else
|
else
|
||||||
error[[confusion]]
|
error[[confusion]]
|
||||||
end
|
end
|
||||||
return do_sub_sup(elem, radical)
|
return do_sub_sup(elem, radical, cur_style)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fraction_to_table(fraction, sub)
|
local function fraction_to_table(fraction, sub, cur_style)
|
||||||
local num = kernel_to_table(fraction.num)
|
local num = kernel_to_table(fraction.num, sup_style(cur_style))
|
||||||
local denom = kernel_to_table(fraction.denom)
|
local denom = kernel_to_table(fraction.denom, sub_style(cur_style))
|
||||||
local left = delim_to_table(fraction.left)
|
local left = delim_to_table(fraction.left)
|
||||||
-- local middle = delim_to_table(fraction.middle)
|
|
||||||
local right = delim_to_table(fraction.right)
|
local right = delim_to_table(fraction.right)
|
||||||
local mfrac = {[0] = 'mfrac',
|
local mfrac = {[0] = 'mfrac',
|
||||||
linethickness = fraction.width and fraction.width == 0 and 0 or nil,
|
linethickness = fraction.width and fraction.width == 0 and 0 or nil,
|
||||||
@ -127,46 +180,58 @@ local function fraction_to_table(fraction, sub)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function fence_to_table(fraction, sub)
|
local function fence_to_table(fence, sub, cur_style)
|
||||||
error[[TODO]]
|
local delim = delim_to_table(fence.delimiter)
|
||||||
return {
|
delim.stretchy = 'true'
|
||||||
kind = fence_sub[sub],
|
delim.fence = 'true'
|
||||||
}
|
return delim
|
||||||
end
|
end
|
||||||
|
|
||||||
function nodes_to_table(head)
|
function nodes_to_table(head, cur_style)
|
||||||
local t = {[0] = "mrow"}
|
local t = {[0] = "mrow"}
|
||||||
|
local result = t
|
||||||
for n, id, sub in node.traverse(head) do
|
for n, id, sub in node.traverse(head) do
|
||||||
if id == noad_t then
|
if id == noad_t then
|
||||||
t[#t+1] = noad_to_table(n, sub)
|
t[#t+1] = noad_to_table(n, sub, cur_style)
|
||||||
elseif id == accent_t then
|
elseif id == accent_t then
|
||||||
print(n)
|
t[#t+1] = accent_to_table(n, sub, cur_style)
|
||||||
t[#t+1] = {[0] = 'TODO', accent = n}
|
|
||||||
elseif id == style_t then
|
elseif id == style_t then
|
||||||
print(n)
|
if #t ~= 0 then
|
||||||
t[#t+1] = {[0] = 'TODO', style = n}
|
local new_t = {[0] = 'mstyle'}
|
||||||
elseif id == choice_t then
|
t[#t+1] = new_t
|
||||||
print(n)
|
t = new_t
|
||||||
t[#t+1] = {[0] = 'TODO', choice = n}
|
end
|
||||||
elseif id == radical_t then
|
if sub < 2 then
|
||||||
t[#t+1] = radical_to_table(n, sub)
|
t.displaystyle, t.scriptlevel = true, 0
|
||||||
elseif id == fraction_t then
|
|
||||||
t[#t+1] = fraction_to_table(n, sub)
|
|
||||||
elseif id == fence_t then
|
|
||||||
print(n)
|
|
||||||
t[#t+1] = {[0] = 'TODO', fence = n}
|
|
||||||
else
|
else
|
||||||
print(n)
|
t.displaystyle, t.scriptlevel = false, sub//2 - 1
|
||||||
t[#t+1] = n
|
end
|
||||||
|
cur_style = sub
|
||||||
|
elseif id == choice_t then
|
||||||
|
local size = cur_style//2
|
||||||
|
t[#t+1] = nodes_to_table(n[size == 0 and 'display' or size == 1 and 'text'
|
||||||
|
or size == 2 and 'script'
|
||||||
|
or size == 3 and 'scriptscript' or assert(false)], 2*size)
|
||||||
|
elseif id == radical_t then
|
||||||
|
t[#t+1] = radical_to_table(n, sub, cur_style)
|
||||||
|
elseif id == fraction_t then
|
||||||
|
t[#t+1] = fraction_to_table(n, sub, cur_style)
|
||||||
|
elseif id == fence_t then
|
||||||
|
t[#t+1] = fence_to_table(n, sub, cur_style)
|
||||||
|
else
|
||||||
|
t[#t+1] = {[0] = 'tex:TODO', other = n}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return t
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(head)
|
return function(head, style)
|
||||||
local result = nodes_to_table(head)
|
local result = nodes_to_table(head, style or 0)
|
||||||
result[0] = 'math'
|
result[0] = 'math'
|
||||||
result.xmlns = 'http://www.w3.org/1998/Math/MathML'
|
result.xmlns = 'http://www.w3.org/1998/Math/MathML'
|
||||||
result['xmlns:tex'] = 'http://typesetting.eu/2021/LuaMathML'
|
result['xmlns:tex'] = 'http://typesetting.eu/2021/LuaMathML'
|
||||||
|
if style == 2 then
|
||||||
|
result.display = 'block'
|
||||||
|
end
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
@ -4,10 +4,11 @@ local function show(t) return print(inspect(t)) end
|
|||||||
local mlist_to_table = require'mlist_to_mml'
|
local mlist_to_table = require'mlist_to_mml'
|
||||||
local write_xml = require'write_xml'
|
local write_xml = require'write_xml'
|
||||||
|
|
||||||
luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist)
|
luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
|
||||||
print'\n\n'
|
print'\n\n'
|
||||||
local xml = mlist_to_table(mlist)
|
local xml = mlist_to_table(mlist, style == 'display' and 2 or 0)
|
||||||
show(write_xml(xml))
|
print(write_xml(xml))
|
||||||
|
-- print(write_xml(xml, '\n'))
|
||||||
print'\n'
|
print'\n'
|
||||||
return true
|
return true
|
||||||
end, 'dump_list')
|
end, 'dump_list')
|
||||||
|
@ -9,6 +9,6 @@
|
|||||||
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
|
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
|
||||||
\]
|
\]
|
||||||
\[
|
\[
|
||||||
x = \longdivision{5}
|
\sum_a\underline c\dot bc'
|
||||||
\]
|
\]
|
||||||
\end{document}
|
\end{document}
|
||||||
|
@ -11,13 +11,14 @@ local escapes = {
|
|||||||
['&'] = "&",
|
['&'] = "&",
|
||||||
}
|
}
|
||||||
local function escape_text(text)
|
local function escape_text(text)
|
||||||
return text:gsub('("<>&)', escapes)
|
return string.gsub(tostring(text), '("<>&)', escapes)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function write_elem(tree)
|
local function write_elem(tree, indent)
|
||||||
if not tree[0] then print('ERR', require'inspect'(tree)) end
|
if not tree[0] then print('ERR', require'inspect'(tree)) end
|
||||||
local escaped_name = escape_name(assert(tree[0]))
|
local escaped_name = escape_name(assert(tree[0]))
|
||||||
local out = "<" .. escaped_name
|
local out = "<" .. escaped_name
|
||||||
|
if indent then out = indent .. out end
|
||||||
for attr, val in next, tree do if type(attr) == 'string' then
|
for attr, val in next, tree do if type(attr) == 'string' then
|
||||||
out = out .. ' ' .. escape_name(attr) .. '="' .. escape_text(val) .. '"'
|
out = out .. ' ' .. escape_name(attr) .. '="' .. escape_text(val) .. '"'
|
||||||
end end
|
end end
|
||||||
@ -25,13 +26,18 @@ local function write_elem(tree)
|
|||||||
return out .. '/>'
|
return out .. '/>'
|
||||||
end
|
end
|
||||||
out = out .. '>'
|
out = out .. '>'
|
||||||
|
local inner_indent = indent and indent .. ' '
|
||||||
for _, elem in ipairs(tree) do
|
for _, elem in ipairs(tree) do
|
||||||
if type(elem) == 'string' then
|
if type(elem) == 'string' then
|
||||||
|
if inner_indent then
|
||||||
|
out = out .. inner_indent
|
||||||
|
end
|
||||||
out = out .. escape_text(elem)
|
out = out .. escape_text(elem)
|
||||||
else
|
else
|
||||||
out = out .. write_elem(elem)
|
out = out .. write_elem(elem, inner_indent)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if indent then out = out .. indent end
|
||||||
return out .. '</' .. escaped_name .. '>'
|
return out .. '</' .. escaped_name .. '>'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user