diff --git a/config-lua.lua b/config-lua.lua index 119e608..22e287b 100644 --- a/config-lua.lua +++ b/config-lua.lua @@ -2,3 +2,16 @@ testfiledir = "testfiles-lua" checkengines = {"luatex"} stdengine = "luatex" checkruns = 3 + +test_types = test_types or {} +test_types.mml = { + test = '.mlt', + generated = '.mml', + reference = '.mlr', + expectation = '.mle', + rewrite = function(source, result, engine, errlevels) + return os.execute(string.format('tidy -xml -indent -wrap -quiet --output-file "%s" "%s"', result, source)) + end, +} + +test_order = {'log', 'pdf', 'mml'} diff --git a/luamml-demo.sty b/luamml-demo.sty index c68620c..eb4ee9c 100644 --- a/luamml-demo.sty +++ b/luamml-demo.sty @@ -36,6 +36,12 @@ \jobname -formula- \int_use:N \g__luamml_demo_mathml_int .xml } } +\DeclareOption{l3build}{ + \luamml_set_filename:n { + \jobname .mml + } + \luamml_begin_single_file: +} \ProcessOptions\relax \cs_new_eq:NN \LuaMMLSetFilename \luamml_set_filename:n diff --git a/luamml-tex.lua b/luamml-tex.lua index 49f645a..c391a0a 100644 --- a/luamml-tex.lua +++ b/luamml-tex.lua @@ -66,6 +66,8 @@ end -- Bit 1: Save MathML as a fully converted formula -- Bit 0: Save MathML for later usage in startmath node. Ignored for display math. +local out_file + local mlist_result local undefined_cmd = token.command_id'undefined_cs' @@ -75,14 +77,18 @@ local labelled_mathml = {} local function save_result(xml, display, structelem) mlist_result = make_root(xml, display and 0 or 2) - token.put_next(filename_token) - local filename = token.scan_argument() - local tracing = tex.count.tracingmathml > 1 - if filename ~= '' then - assert(io.open(filename, 'w')) - :write(write_xml(mlist_result, true):sub(2) .. '\n') - :close() + if out_file then + out_file:write(write_xml(mlist_result, true):sub(2) .. '\n') + else + token.put_next(filename_token) + local filename = token.scan_argument() + if filename ~= '' then + assert(io.open(filename, 'w')) + :write(write_xml(mlist_result, true):sub(2) .. '\n') + :close() + end end + local tracing = tex.count.tracingmathml > 1 if tracing then texio.write_nl(write_xml(mlist_result) .. '\n') end @@ -159,6 +165,25 @@ lua.get_functions_table()[funcid] = function() mlist_result = nil end +funcid = luatexbase.new_luafunction'luamml_begin_single_file:' +token.set_lua('luamml_begin_single_file:', funcid, protected) +lua.get_functions_table()[funcid] = function() + token.put_next(filename_token) + local filename = token.scan_argument() + if filename ~= '' then + out_file = assert(io.open(filename, 'w')) + end +end + +funcid = luatexbase.new_luafunction'luamml_end_single_file:' +token.set_lua('luamml_end_single_file:', funcid, protected) +lua.get_functions_table()[funcid] = function() + if out_file then + out_file:close() + out_file = nil + end +end + local annotate_context = require'luamml-tex-annotate' annotate_context.data.mathml = labelled_mathml diff --git a/luamml.dtx b/luamml.dtx index e577199..4d6f84e 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -227,6 +227,12 @@ } % % \end{macrocode} +% +% \begin{macro}{\luamml_begin_single_file:, \luamml_end_single_file:} +% Everything between these two commands gets written into the same XML file. +% The filename is expanded when \cs{luamml_begin_single_file:} gets executed. +% +% (Implemented in Lua) % \end{macro} % % By default, the flag is set to assume complete formulas.