TeX interface to retrieve handle for MML

This commit is contained in:
Marcel Fabian Krüger 2021-04-25 17:11:36 +02:00
parent 8843b99ece
commit 26e1ffad33
4 changed files with 22 additions and 4 deletions

View File

@ -24,7 +24,6 @@ lua.get_functions_table()[funcid] = function()
mml = {[0] = 'mtd', mml}
end
local row_temp = tex.nest[tex.nest.ptr-1]
print(row_temp)
props = properties[row_temp]
if not props then
props = {}
@ -42,7 +41,6 @@ token.set_lua('luamml_amsmath_finalize_row:', funcid, 'protected')
lua.get_functions_table()[funcid] = function()
-- TODO: Error handling etc
local row_temp = tex.nest[tex.nest.ptr-1]
print("final", row_temp)
local props = properties[row_temp]
if not props then return end
if not props.mathml_row then return end

View File

@ -36,6 +36,7 @@ end
-- Bit 2: Integrate with table mechanism
local mlist_buffer
local mlist_result
luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
local flag = tex.count.l__luamml_flag_int
@ -56,7 +57,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
print(write_xml(make_root(xml, (style == 'display' or flag & 1 == 1) and 0 or 2)) .. '\n')
mlist_result = write_xml(make_root(xml, (style == 'display' or flag & 1 == 1) and 0 or 2))
else
assert(style == 'text')
local startmath = tex.nest.top.tail
@ -73,3 +74,15 @@ luatexbase.add_to_callback('pre_mlist_to_hlist_filter', function(mlist, style)
end
return true
end, 'dump_list')
funcid = luatexbase.new_luafunction'luamml_get_last_mathml_stream:e'
token.set_lua('luamml_get_last_mathml_stream:e', funcid)
lua.get_functions_table()[funcid] = function()
if not mlist_result then
tex.error('No current MathML data', {
"I was asked to provide MathML code for the last formula, but there weren't any new formulas since you last asked."
})
end
tex.sprint(-2, tostring(pdf.immediateobj('stream', mlist_result, '/Subtype /application#2Fmathml+xml\n' .. token.scan_argument(true))))
mlist_result = nil
end

View File

@ -14,4 +14,4 @@
\int_set:Nn \l__luamml_flag_int { 6 }
}
\RequirePackage { luamml-patches-amsmath }
% \RequirePackage { luamml-patches-amsmath }

View File

@ -4,10 +4,17 @@
\usepackage{luamml}
\RegisterFamilyMapping\symsymbols{oms}
\RegisterFamilyMapping\symletters{oml}
\ExplSyntaxOn
\pdfvariable compresslevel0
\cs_new_protected:Npn \ShowMathMLObj {
\message { \luamml_get_last_mathml_stream:e{}~0~R }
}
\ExplSyntaxOff
\begin{document}
\[
ax^2+bx+c=0
\]
\ShowMathMLObj
\[
x = \frac{-b \pm \sqrt{b^2-4ac}}{2a}.
\]