From 11206aecdeba87079c3e61c265beb243dca21dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 2 May 2021 02:58:20 +0200 Subject: [PATCH 1/3] Simplify internal interface --- luamml-amsmath.lua | 2 +- luamml-tex.lua | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/luamml-amsmath.lua b/luamml-amsmath.lua index 453b543..eacb91f 100644 --- a/luamml-amsmath.lua +++ b/luamml-amsmath.lua @@ -33,7 +33,7 @@ lua.get_functions_table()[funcid] = function() spacing[#spacing+1] = n.width == 0 and '0' or '.8em' end mml_table.columnspacing = table.concat(spacing, ' ', 2, #spacing-2) - save_result(mml_table, 0) + save_result(mml_table, true) end local last_tag diff --git a/luamml-tex.lua b/luamml-tex.lua index c76d1f7..b0ededa 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -38,8 +38,8 @@ end local mlist_buffer local mlist_result -local function save_result(xml, style) - mlist_result = write_xml(make_root(xml, style)) +local function save_result(xml, display) + mlist_result = write_xml(make_root(xml, display and 0 or 2)) if tex.count.tracingmathml > 1 then texio.write_nl(mlist_result .. '\n') end @@ -64,7 +64,7 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style) end local xml = process_mlist(new_mlist, style == 'display' and 0 or 2) if flag & 2 == 0 then - save_result(xml, (style == 'display' or flag & 1 == 1) and 0 or 2) + save_result(xml, style == 'display' or flag & 1 == 1) else assert(style == 'text') local startmath = tex.nest.top.tail From c0f7e707a999c459d905eab153dc306a2acad937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Mon, 3 May 2021 20:07:29 +0200 Subject: [PATCH 2/3] Delay more work until MathML is requested --- luamml-tex.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/luamml-tex.lua b/luamml-tex.lua index b0ededa..bbfeaa2 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -36,12 +36,13 @@ end -- Bit 2: Integrate with table mechanism local mlist_buffer -local mlist_result +local mlist_result, mlist_display local function save_result(xml, display) - mlist_result = write_xml(make_root(xml, display and 0 or 2)) + mlist_result, mlist_display = xml, display if tex.count.tracingmathml > 1 then - texio.write_nl(mlist_result .. '\n') + -- Here xml gets wrapped in an mrow to avoid modifying it. + texio.write_nl(write_xml(make_root({[0] = 'mrow', xml}, display and 0 or 2)) .. '\n') end end @@ -90,10 +91,11 @@ lua.get_functions_table()[funcid] = function() "I was asked to provide MathML code for the last formula, but there weren't any new formulas since you last asked." }) end + local mml = write_xml(make_root(mlist_result, mlist_display and 0 or 2)) if tex.count.tracingmathml == 1 then - texio.write_nl(mlist_result .. '\n') + texio.write_nl(mml .. '\n') end - tex.sprint(-2, tostring(pdf.immediateobj('stream', mlist_result, '/Subtype/application#2Fmathml+xml' .. token.scan_argument(true)))) + tex.sprint(-2, tostring(pdf.immediateobj('stream', mml, '/Subtype/application#2Fmathml+xml' .. token.scan_argument(true)))) mlist_result = nil end From 246ae13e4e26eb828f9242d42e8a8dc7b6ce8310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Mon, 3 May 2021 20:07:57 +0200 Subject: [PATCH 3/3] Always store MathML table --- luamml-tex.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/luamml-tex.lua b/luamml-tex.lua index bbfeaa2..36edff8 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -66,8 +66,8 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style) local xml = process_mlist(new_mlist, style == 'display' and 0 or 2) if flag & 2 == 0 then save_result(xml, style == 'display' or flag & 1 == 1) - else - assert(style == 'text') + end + if style == 'text' then local startmath = tex.nest.top.tail local props = properties[startmath] if not props then