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)
mlist_result = make_root(xml, display and 0 or 2)
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
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')
:write(write_xml(mlist_result, tex.count.l__luamml_pretty_int & 1 == 1):sub(2) .. '\n')
:close()
end
end
local tracing = tex.count.tracingmathml > 1
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
if output_hook_token then
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
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."
})
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
texio.write_nl(mml .. '\n')
end

View File

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