Prepare for better pdfTeX support

This commit is contained in:
Marcel Fabian Krüger 2021-06-26 19:49:28 +02:00
parent f5acbf0ab4
commit 903480a3f9
5 changed files with 46 additions and 13 deletions

View File

@ -33,6 +33,7 @@
\iow_now:Nx \l__luamml_pdf_stream { \iow_now:Nx \l__luamml_pdf_stream {
LUAMML_FORMULA_BEGIN: LUAMML_FORMULA_BEGIN:
\int_use:N \g__luamml_formula_id_int \int_use:N \g__luamml_formula_id_int
:3:mrow
} }
\__luamml_pdf_showlists: \__luamml_pdf_showlists:
\iow_now:Nx \l__luamml_pdf_stream { \iow_now:Nx \l__luamml_pdf_stream {

View File

@ -32,5 +32,8 @@ node = {
traverse = function(head) traverse = function(head)
return traverse_iter, head, nil return traverse_iter, head, nil
end, end,
direct = {
todirect = function(n) return n end,
},
} }
tex.nulldelimiterspace = tex.nulldelimiterspace or 78643 -- 1.2pt tex.nulldelimiterspace = tex.nulldelimiterspace or 78643 -- 1.2pt

View File

@ -7,8 +7,10 @@ local non_final_list_block = (l.C((1-l.P'\n')^1) * '\n' - '### ' + '\n')^0
local math_lists_block = l.Ct('### ' * l.Cg(l.C'display' * ' ', 'display')^-1 * 'math mode entered at line ' * l.Cg(l.R'09'^1 / tonumber, 'line') * '\n' local math_lists_block = l.Ct('### ' * l.Cg(l.C'display' * ' ', 'display')^-1 * 'math mode entered at line ' * l.Cg(l.R'09'^1 / tonumber, 'line') * '\n'
* non_final_list_block)^1 * non_final_list_block)^1
local generic_list_block = '### ' * (line - 'current page:') * non_final_list_block local generic_list_block = '### ' * (line - 'current page:') * non_final_list_block
local luamml_block = l.Cg('LUAMML_FORMULA_BEGIN:' * id * l.P'\n'^1 * l.Ct( local luamml_block = l.Cg('LUAMML_FORMULA_BEGIN:' * id * ':' * l.Ct(
(math_lists_block + generic_list_block/0)^0 l.Cg(id, 'flag') * ':' * l.Cg((1-l.P'\n')^0, 'tag') * l.P'\n'^1
* (math_lists_block + generic_list_block/0)^0
* (line - 'LUAMML_FORMULA_END\n')^0 * (line - 'LUAMML_FORMULA_END\n')^0
* 'LUAMML_FORMULA_END\n') * l.Cc'groups') * 'LUAMML_FORMULA_END\n') * l.Cc'groups')

View File

@ -52,13 +52,40 @@ else
out_stream = assert(io.open(arg[2], 'w')) out_stream = assert(io.open(arg[2], 'w'))
end end
end end
for i, block in ipairs(parsed.groups) do parsed.mathml = {}
local stream = out_stream or assert(io.open(out_prefix .. tostring(i) .. out_suffix, 'w'))
block = block[1] local function shallow_copy(t)
local parsed = parse_showlists(block, nil, nil, parsed) local new = {}
local style = block.display and 0 or 2 for k, v in next, t do
stream:write( new[k] = v
to_xml(convert.make_root(convert.process(parsed, style), style)), '\n' end
) return new
if not out_stream then stream:close() end end
-- Currently only 3 flag values are supported:
-- 0: Ignore (Doesn't make a lot of sense here)
-- 1: Only save
-- 3: Generate normally
for i, block in ipairs(parsed.groups) do
local flag, tag = block.flag, block.tag
block = block[1]
if flag & 3 ~= 0 then
local style = block.display and 0 or 2
local xml = convert.process(parse_showlists(block, nil, nil, parsed), style)
if flag & 2 == 2 then
local stream = out_stream or assert(io.open(out_prefix .. tostring(i) .. out_suffix, 'w'))
stream:write(to_xml(convert.make_root(shallow_copy(xml), style)), '\n')
if not out_stream then stream:close() end
end
if tag ~= 'mrow' then
if xml[0] == 'mrow' then
xml[0] = tag
else
xml = {[0] = tag, xml}
end
end
if style == 2 and flag & 1 == 1 then
parsed.mathml[i] = xml
end
end
end end

View File

@ -9,9 +9,9 @@
\cs_set_eq:NN \WriteoutFormula \luamml_pdf_write: \cs_set_eq:NN \WriteoutFormula \luamml_pdf_write:
\NewDocumentCommand\AnnotateFormula{ o m m }{% \NewDocumentCommand\AnnotateFormula{ o m m }{%
\IfValueTF{#1}{% \IfValueTF{#1}{%
\luamml_annotate:nnn{#1}% \luamml_annotate:nen{#1}%
}{ }{
\luamml_annotate:nn \luamml_annotate:en
}{#2}{#3} }{#2}{#3}
} }
\ExplSyntaxOff \ExplSyntaxOff