l3build for Lua testing

This commit is contained in:
Marcel Fabian Krüger 2021-10-31 17:18:23 +01:00
parent cfae79975e
commit 8ddc9aeebc
4 changed files with 57 additions and 7 deletions

View File

@ -2,3 +2,16 @@ testfiledir = "testfiles-lua"
checkengines = {"luatex"} checkengines = {"luatex"}
stdengine = "luatex" stdengine = "luatex"
checkruns = 3 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'}

View File

@ -36,6 +36,12 @@
\jobname -formula- \int_use:N \g__luamml_demo_mathml_int .xml \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 \ProcessOptions\relax
\cs_new_eq:NN \LuaMMLSetFilename \luamml_set_filename:n \cs_new_eq:NN \LuaMMLSetFilename \luamml_set_filename:n

View File

@ -66,6 +66,8 @@ end
-- Bit 1: Save MathML as a fully converted formula -- Bit 1: Save MathML as a fully converted formula
-- Bit 0: Save MathML for later usage in startmath node. Ignored for display math. -- Bit 0: Save MathML for later usage in startmath node. Ignored for display math.
local out_file
local mlist_result local mlist_result
local undefined_cmd = token.command_id'undefined_cs' local undefined_cmd = token.command_id'undefined_cs'
@ -75,14 +77,18 @@ local labelled_mathml = {}
local function save_result(xml, display, structelem) local function save_result(xml, display, structelem)
mlist_result = make_root(xml, display and 0 or 2) mlist_result = make_root(xml, display and 0 or 2)
token.put_next(filename_token) if out_file then
local filename = token.scan_argument() out_file:write(write_xml(mlist_result, true):sub(2) .. '\n')
local tracing = tex.count.tracingmathml > 1 else
if filename ~= '' then token.put_next(filename_token)
assert(io.open(filename, 'w')) local filename = token.scan_argument()
:write(write_xml(mlist_result, true):sub(2) .. '\n') if filename ~= '' then
:close() assert(io.open(filename, 'w'))
:write(write_xml(mlist_result, true):sub(2) .. '\n')
:close()
end
end end
local tracing = tex.count.tracingmathml > 1
if tracing then if tracing then
texio.write_nl(write_xml(mlist_result) .. '\n') texio.write_nl(write_xml(mlist_result) .. '\n')
end end
@ -159,6 +165,25 @@ lua.get_functions_table()[funcid] = function()
mlist_result = nil mlist_result = nil
end 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' local annotate_context = require'luamml-tex-annotate'
annotate_context.data.mathml = labelled_mathml annotate_context.data.mathml = labelled_mathml

View File

@ -227,6 +227,12 @@
} }
%</luatex> %</luatex>
% \end{macrocode} % \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} % \end{macro}
% %
% By default, the flag is set to assume complete formulas. % By default, the flag is set to assume complete formulas.