From 26e1ffad33bca455ed76473bb91a6d2e57f0e0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 25 Apr 2021 17:11:36 +0200 Subject: [PATCH] TeX interface to retrieve handle for MML --- luamml-amsmath.lua | 2 -- luamml-tex.lua | 15 ++++++++++++++- luamml.sty | 2 +- test_tex.tex | 7 +++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/luamml-amsmath.lua b/luamml-amsmath.lua index 0ca5d02..f25ca05 100644 --- a/luamml-amsmath.lua +++ b/luamml-amsmath.lua @@ -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 diff --git a/luamml-tex.lua b/luamml-tex.lua index ad9c176..28e0c3e 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -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 diff --git a/luamml.sty b/luamml.sty index f95c505..89dc1e5 100644 --- a/luamml.sty +++ b/luamml.sty @@ -14,4 +14,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 6fd13bb..fb1e967 100644 --- a/test_tex.tex +++ b/test_tex.tex @@ -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}. \]