Reenable amsmath

This commit is contained in:
Marcel Fabian Krüger 2021-04-25 18:09:13 +02:00
parent 3dbf44a542
commit aa98c70f82
5 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,6 @@
local write_xml = require'luamml-xmlwriter' local write_xml = require'luamml-xmlwriter'
local make_root = require'luamml-convert'.make_root local make_root = require'luamml-convert'.make_root
local save_result = require'luamml-tex'.save_result
local properties = node.get_properties_table() local properties = node.get_properties_table()
@ -14,7 +15,6 @@ lua.get_functions_table()[funcid] = function()
local props = assert(properties[startmath]) local props = assert(properties[startmath])
local mml = assert(props.saved_mathml_table) local mml = assert(props.saved_mathml_table)
props.saved_mathml_table = nil props.saved_mathml_table = nil
table.insert(mml, 1, {[0] = 'maligngroup'})
if mml[0] == 'mstyle' and mml.displaystyle == true then if mml[0] == 'mstyle' and mml.displaystyle == true then
mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil mml[0], mml.displaystyle, mml.scriptlevel = 'mtd', nil, nil
else else
@ -68,7 +68,10 @@ lua.get_functions_table()[funcid] = function()
local mml_table = props.mathml_table_node_table local mml_table = props.mathml_table_node_table
props.mathml_table_node_table = nil props.mathml_table_node_table = nil
if not mml_table then return end 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 end
funcid = luatexbase.new_luafunction'luamml_last_math_alignmark:' funcid = luatexbase.new_luafunction'luamml_last_math_alignmark:'

View File

@ -17,12 +17,14 @@
\ifmeasuring@ \ifmeasuring@
\luamml_flag_ignore: \luamml_flag_ignore:
\else \else
\luamml_flag_alignment_left: \luamml_flag_save:
\fi \fi
$ $
} }
\ifmeasuring@ \ifmeasuring@
\savefieldlength@ \savefieldlength@
\else
\luamml_amsmath_add_box_to_row:
\fi \fi
\set@field \set@field
\tabskip\z@skip \tabskip\z@skip
@ -34,13 +36,12 @@
\displaystyle \displaystyle
{ {
{} {}
\luamml_last_math_alignmark:
## ##
} }
\ifmeasuring@ \ifmeasuring@
\luamml_flag_ignore: \luamml_flag_ignore:
\else \else
\luamml_flag_alignment_right: \luamml_flag_save:
\fi \fi
$ $
} }

View File

@ -38,6 +38,10 @@ end
local mlist_buffer local mlist_buffer
local mlist_result 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) luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
local flag = tex.count.l__luamml_flag_int local flag = tex.count.l__luamml_flag_int
if flag & 3 == 3 then if flag & 3 == 3 then
@ -57,7 +61,7 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
end end
local xml = process_mlist(new_mlist, style == 'display' and 0 or 2) local xml = process_mlist(new_mlist, style == 'display' and 0 or 2)
if flag & 2 == 0 then 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 else
assert(style == 'text') assert(style == 'text')
local startmath = tex.nest.top.tail 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)))) tex.sprint(-2, tostring(pdf.immediateobj('stream', mlist_result, '/Subtype /application#2Fmathml+xml\n' .. token.scan_argument(true))))
mlist_result = nil mlist_result = nil
end end
return {
save_result = save_result,
}

View File

@ -4,6 +4,9 @@
\int_new:N \l__luamml_flag_int \int_new:N \l__luamml_flag_int
\lua_now:n { require'luamml-tex' } \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: { \cs_new:Nn \luamml_flag_ignore: {
\int_set:Nn \l__luamml_flag_int { 3 } \int_set:Nn \l__luamml_flag_int { 3 }
} }
@ -14,4 +17,4 @@
\int_set:Nn \l__luamml_flag_int { 6 } \int_set:Nn \l__luamml_flag_int { 6 }
} }
% \RequirePackage { luamml-patches-amsmath } \RequirePackage { luamml-patches-amsmath }

View File

@ -27,6 +27,7 @@
1+2&=3\\ 1+2&=3\\
5 5
\end{align} \end{align}
\ShowMathMLObj
Es gilt $\sin(x)-\sin(x+2\pi)=0$. Es gilt $\sin(x)-\sin(x+2\pi)=0$.
\end{document} \end{document}