Add \l__luamml_pretty_int to control prettyprinting

This commit is contained in:
Marcel Fabian Krüger 2024-08-14 00:30:56 +02:00
parent 62bab63177
commit 1a19e3947a
2 changed files with 8 additions and 5 deletions

View File

@ -100,23 +100,23 @@ 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)
if out_file then if out_file then
out_file:write(write_xml(mlist_result, true):sub(2) .. '\n') out_file:write(write_xml(mlist_result, tex.count.l__luamml_pretty_int & 1 == 1):sub(2) .. '\n')
else else
token.put_next(filename_token) token.put_next(filename_token)
local filename = token.scan_argument() local filename = token.scan_argument()
if filename ~= '' then if filename ~= '' then
assert(io.open(filename, 'w')) assert(io.open(filename, 'w'))
:write(write_xml(mlist_result, true):sub(2) .. '\n') :write(write_xml(mlist_result, tex.count.l__luamml_pretty_int & 1 == 1):sub(2) .. '\n')
:close() :close()
end end
end end
local tracing = tex.count.tracingmathml > 1 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, tex.count.l__luamml_pretty_int & 2 == 2) .. '\n')
end end
if output_hook_token then if output_hook_token then
tex.runtoks(function() tex.runtoks(function()
tex.sprint(-2, output_hook_token, left_brace, write_xml(mlist_result), right_brace) tex.sprint(-2, output_hook_token, left_brace, write_xml(mlist_result, tex.count.l__luamml_pretty_int & 4 == 4), right_brace)
end) end)
end end
if tex.count.l__luamml_flag_int & 8 == 8 then if tex.count.l__luamml_flag_int & 8 == 8 then
@ -184,7 +184,7 @@ lua.get_functions_table()[funcid] = function()
"I was asked to provide MathML code for the last formula, but there weren't any new formulas since you last asked." "I was asked to provide MathML code for the last formula, but there weren't any new formulas since you last asked."
}) })
end end
local mml = write_xml(mlist_result) local mml = write_xml(mlist_result, tex.count.l__luamml_pretty_int & 8 == 8)
if tex.count.tracingmathml == 1 then if tex.count.tracingmathml == 1 then
texio.write_nl(mml .. '\n') texio.write_nl(mml .. '\n')
end end

View File

@ -85,12 +85,15 @@
% them later. % them later.
% \begin{macrocode} % \begin{macrocode}
\int_new:N \l__luamml_flag_int \int_new:N \l__luamml_flag_int
\int_new:N \l__luamml_pretty_int
%<luatex>\tl_new:N \l__luamml_filename_tl %<luatex>\tl_new:N \l__luamml_filename_tl
\tl_new:N \l__luamml_root_tl \tl_new:N \l__luamml_root_tl
\tl_set:Nn \l__luamml_root_tl { mrow } \tl_set:Nn \l__luamml_root_tl { mrow }
\tl_new:N \l__luamml_label_tl \tl_new:N \l__luamml_label_tl
%<pdftex>\int_new:N \g__luamml_formula_id_int %<pdftex>\int_new:N \g__luamml_formula_id_int
%<luatex>\int_new:N \tracingmathml %<luatex>\int_new:N \tracingmathml
\int_set:Nn \l__luamml_pretty_int { 1 }
% \end{macrocode} % \end{macrocode}
% %
% Now we can load the Lua module which defines the callback. % Now we can load the Lua module which defines the callback.