diff --git a/luamml-tex.lua b/luamml-tex.lua index 852c93a..6f08ec5 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -7,6 +7,8 @@ local mappings = require'luamml-legacy-mappings' local write_xml = require'luamml-xmlwriter' local write_struct = require'luamml-structelemwriter' +local filename_token = token.create'l__luamml_filename_tl' + local properties = node.get_properties_table() local funcid = luatexbase.new_luafunction'RegisterFamilyMapping' @@ -39,8 +41,18 @@ end local mlist_buffer local mlist_result, mlist_display +local undefined_cmd = token.command_id'undefined_cs' +local call_cmd = token.command_id'call' + local function save_result(xml, display) mlist_result, mlist_display = xml, display + if filename_token.command ~= undefined_cmd then + assert(filename_token.command == call_cmd) + token.put_next(filename_token) + assert(io.open(token.scan_string(), 'w')) + :write(write_xml(make_root({[0] = 'mrow', xml}, display and 0 or 2)) .. '\n') + :close() + end if tex.count.tracingmathml > 1 then -- 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') diff --git a/luamml.sty b/luamml.sty index 10e07ec..c14f68e 100644 --- a/luamml.sty +++ b/luamml.sty @@ -2,24 +2,28 @@ {Feel free to add a description here} \int_new:N \l__luamml_flag_int +\tl_new:N \l__luamml_filename_tl \int_new:N \tracingmathml \lua_now:n { require'luamml-tex' } -\cs_new:Nn \luamml_flag_save: { +\cs_new:Npn \luamml_flag_save: { \int_set:Nn \l__luamml_flag_int { 2 } } -\cs_new:Nn \luamml_flag_ignore: { +\cs_new:Npn \luamml_flag_ignore: { \int_set:Nn \l__luamml_flag_int { 3 } } -\cs_new:Nn \luamml_flag_alignment_left: { +\cs_new:Npn \luamml_flag_alignment_left: { \int_set:Nn \l__luamml_flag_int { 7 } } -\cs_new:Nn \luamml_flag_alignment_right: { +\cs_new:Npn \luamml_flag_alignment_right: { \int_set:Nn \l__luamml_flag_int { 6 } } -\cs_new:Nn \luamml_flag_structelem: { +\cs_new:Npn \luamml_flag_structelem: { \int_set:Nn \l__luamml_flag_int { 8 } } +\cs_new:Npn \luamml_set_filename:n { + \tl_set:Nn \l__luamml_filename_tl +} \cs_new:Npn \__luamml_patch_package:nn #1 #2 { \@ifpackageloaded {#1} {#2} { diff --git a/test_structelem.tex b/test_structelem.tex new file mode 100644 index 0000000..5fd6e33 --- /dev/null +++ b/test_structelem.tex @@ -0,0 +1,34 @@ +% !Mode:: "TeX:DE:UTF-8:Main" +\PassOptionsToPackage{enable-debug,check-declarations}{expl3} +\RequirePackage{pdfmanagement-testphase} +\DeclareDocumentMetadata{uncompress,pdfversion=2.0} +\RequirePackage{expl3} +\documentclass{article} +\usepackage{unicode-math} +\usepackage{tagpdf} +\tagpdfsetup{activate-all,interwordspace=true,} +\usepackage{amsmath} +\usepackage{luamml} +% \RegisterFamilyMapping\symsymbols{oms} +% \RegisterFamilyMapping\symletters{oml} +% \RegisterFamilyMapping\symlargesymbols{omx} +\ExplSyntaxOn + +\luamml_flag_structelem: +\int_new:N \g__my_mathml_int +\luamml_set_filename:n { + \immediateassignment \int_gincr:N \g__my_mathml_int + \jobname -formula- \int_use:N \g__my_mathml_int .xml +} +\ExplSyntaxOff +\begin{document} +\tagstructbegin{tag=Document} +\tagstructbegin{tag=Formula} +\[ + ax^2+bx+c=0,\quad + \int_1^n f(x) = \sum_{i=1}^m x^4 dx +\] +\tagstructend +\tagstructend + +\end{document}