From aa98c70f82a7f39ccc5662b985c078281165d10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 25 Apr 2021 18:09:13 +0200 Subject: [PATCH] Reenable amsmath --- luamml-amsmath.lua | 7 +++++-- luamml-patches-amsmath.sty | 7 ++++--- luamml-tex.lua | 10 +++++++++- luamml.sty | 5 ++++- test_tex.tex | 1 + 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/luamml-amsmath.lua b/luamml-amsmath.lua index f25ca05..1e961c4 100644 --- a/luamml-amsmath.lua +++ b/luamml-amsmath.lua @@ -1,5 +1,6 @@ local write_xml = require'luamml-xmlwriter' local make_root = require'luamml-convert'.make_root +local save_result = require'luamml-tex'.save_result local properties = node.get_properties_table() @@ -14,7 +15,6 @@ lua.get_functions_table()[funcid] = function() local props = assert(properties[startmath]) local mml = assert(props.saved_mathml_table) props.saved_mathml_table = nil - table.insert(mml, 1, {[0] = 'maligngroup'}) if mml[0] == 'mstyle' and mml.displaystyle == true then mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil else @@ -68,7 +68,10 @@ lua.get_functions_table()[funcid] = function() local mml_table = props.mathml_table_node_table props.mathml_table_node_table = nil if not mml_table then return end - print(write_xml(make_root(mml_table, 0))) + local columns = node.count(node.id'align_record', tex.lists.align_head)//2 + mml_table.columnalign = string.rep('right left', columns, ' ') + mml_table.columnalign = string.rep('0.3em', columns, '0.8em ') -- FIXME: 0.3em is a hack needed since MathML doesn't add spacing for our empty mrow + save_result(mml_table, 0) end funcid = luatexbase.new_luafunction'luamml_last_math_alignmark:' diff --git a/luamml-patches-amsmath.sty b/luamml-patches-amsmath.sty index 15565fe..ae74dc9 100644 --- a/luamml-patches-amsmath.sty +++ b/luamml-patches-amsmath.sty @@ -17,12 +17,14 @@ \ifmeasuring@ \luamml_flag_ignore: \else - \luamml_flag_alignment_left: + \luamml_flag_save: \fi $ } \ifmeasuring@ \savefieldlength@ + \else + \luamml_amsmath_add_box_to_row: \fi \set@field \tabskip\z@skip @@ -34,13 +36,12 @@ \displaystyle { {} - \luamml_last_math_alignmark: ## } \ifmeasuring@ \luamml_flag_ignore: \else - \luamml_flag_alignment_right: + \luamml_flag_save: \fi $ } diff --git a/luamml-tex.lua b/luamml-tex.lua index 28e0c3e..175ba78 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -38,6 +38,10 @@ end local mlist_buffer local mlist_result +local function save_result(xml, style) + mlist_result = write_xml(make_root(xml, style)) +end + luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style) local flag = tex.count.l__luamml_flag_int if flag & 3 == 3 then @@ -57,7 +61,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 - mlist_result = write_xml(make_root(xml, (style == 'display' or flag & 1 == 1) and 0 or 2)) + save_result(xml, (style == 'display' or flag & 1 == 1) and 0 or 2) else assert(style == 'text') local startmath = tex.nest.top.tail @@ -86,3 +90,7 @@ lua.get_functions_table()[funcid] = function() tex.sprint(-2, tostring(pdf.immediateobj('stream', mlist_result, '/Subtype /application#2Fmathml+xml\n' .. token.scan_argument(true)))) mlist_result = nil end + +return { + save_result = save_result, +} diff --git a/luamml.sty b/luamml.sty index 89dc1e5..d78d4a2 100644 --- a/luamml.sty +++ b/luamml.sty @@ -4,6 +4,9 @@ \int_new:N \l__luamml_flag_int \lua_now:n { require'luamml-tex' } +\cs_new:Nn \luamml_flag_save: { + \int_set:Nn \l__luamml_flag_int { 2 } +} \cs_new:Nn \luamml_flag_ignore: { \int_set:Nn \l__luamml_flag_int { 3 } } @@ -14,4 +17,4 @@ \int_set:Nn \l__luamml_flag_int { 6 } } -% \RequirePackage { luamml-patches-amsmath } +\RequirePackage { luamml-patches-amsmath } diff --git a/test_tex.tex b/test_tex.tex index fb1e967..a6adc1b 100644 --- a/test_tex.tex +++ b/test_tex.tex @@ -27,6 +27,7 @@ 1+2&=3\\ 5 \end{align} +\ShowMathMLObj Es gilt $\sin(x)-\sin(x+2\pi)=0$. \end{document}