diff --git a/luamml.dtx b/luamml.dtx index 7f02bbc..493e7a7 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -313,14 +313,17 @@ \cs_new_protected:Npn \luamml_annotate:nen #1#2#3 { \int_gincr:N \g__luamml_annotation_id_int \iow_shipout_x:Nx \l__luamml_pdf_stream { - \tl_to_str:e { - LUAMML_MARK: - \int_use:N \g__luamml_annotation_id_int - : - count = \int_eval:n {#1}, - #2 - } - \exp_not:N \iow_newline: + LUAMML_MARK_REF: + \int_use:N \g__luamml_annotation_id_int + : + } + \iow_now:Nx \l__luamml_pdf_stream { + LUAMML_MARK: + \int_use:N \g__luamml_annotation_id_int + : + count = \int_eval:n {#1}, + #2 + \iow_newline: LUAMML_MARK_END } #3 @@ -328,26 +331,32 @@ \cs_new_protected:Npn \luamml_annotate:en #1#2 { \int_gincr:N \g__luamml_annotation_id_int \iow_shipout_x:Nx \l__luamml_pdf_stream { - \tl_to_str:e { - LUAMML_MARK: - \int_use:N \g__luamml_annotation_id_int - : - count = data.count[\int_use:N \g__luamml_annotation_id_int], - #1 - } - \exp_not:N \iow_newline: + LUAMML_MARK_REF: + \int_use:N \g__luamml_annotation_id_int + : + } + \iow_now:Nx \l__luamml_pdf_stream { + LUAMML_MARK: + \int_use:N \g__luamml_annotation_id_int + : + count = data.count[\int_use:N \g__luamml_annotation_id_int], + #1 + \iow_newline: LUAMML_MARK_END } - \iow_now:Nx \l__luamml_pdf_stream { - LUAMML_COUNT: - \int_use:N \g__luamml_annotation_id_int + \use:x { + \iow_now:Nn \l__luamml_pdf_stream { + LUAMML_COUNT: + \int_use:N \g__luamml_annotation_id_int + } + \__luamml_pdf_showlists: + \exp_not:n {#2} + \iow_now:Nn \l__luamml_pdf_stream { + LUAMML_COUNT_END: + \int_use:N \g__luamml_annotation_id_int + } + \__luamml_pdf_showlists: } - \__luamml_pdf_showlists: - #2 - \iow_now:Nx \l__luamml_pdf_stream { - LUAMML_COUNT_END - } - \__luamml_pdf_showlists: } % \end{macrocode} % \end{macro} diff --git a/pdfmml-logreader.lua b/pdfmml-logreader.lua index a9f0e9e..2b66e8b 100644 --- a/pdfmml-logreader.lua +++ b/pdfmml-logreader.lua @@ -18,13 +18,11 @@ local luamml_mark = l.Cg('LUAMML_MARK:' * id * ':' * l.Cs((1 - l.P'\n' + l.Cg('\ local function add(a, b) return a + b end local count_block = '### ' * line * l.Cf(l.Cc(0) * (('\\' * l.Cc(1))^-1 * line - '### ')^0, add) -local luamml_count = l.Cg('LUAMML_COUNT:' * id * l.P'\n'^1 - * count_block - * (line-'LUAMML_COUNT_END\n')^0 - * 'LUAMML_COUNT_END' * l.P'\n'^1 - * count_block / function(id, first, second) - return id, second - first - end * l.Cc'count') +local luamml_precount = l.Cg('LUAMML_COUNT:' * id * l.P'\n'^1 + * count_block * l.Cc'precount') + +local luamml_postcount = l.Cg('LUAMML_COUNT_END:' * id * l.P'\n'^1 + * count_block * l.Cc'postcount') local luamml_instruction = l.Cg('LUAMML_INSTRUCTION:' * l.Cc(nil) * l.C((1 - l.P'\n')^0) * '\n' * l.Cc'instructions') @@ -34,10 +32,11 @@ local function multi_table_set(t, key, value, table) return t end local log_file = l.Cf(l.Ct(l.Cg(l.Ct'', 'groups') - * l.Cg(l.Ct'', 'count') + * l.Cg(l.Ct'', 'precount') + * l.Cg(l.Ct'', 'postcount') * l.Cg(l.Ct'', 'marks') * l.Cg(l.Ct'', 'instructions')) - * (luamml_block + luamml_mark + luamml_instruction + luamml_count + line)^0, + * (luamml_block + luamml_mark + luamml_instruction + luamml_precount + luamml_postcount + line)^0, multi_table_set) return function(filename) @@ -50,5 +49,13 @@ return function(filename) if f then f:close() end -- The following does *not* end with * -1 since we want to allow the last line to not end with \n. -- In that case we ignore the last line, but that's safe since the last line never contains our markers. - return assert(log_file:match(content)) + local parsed = assert(log_file:match(content)) + local precount, postcount, count = parsed.precount, parsed.postcount, {} + for id, pre in next, precount do + local post = assert(postcount[id], 'Unbalanced count') + count[id], postcount[id] = post-pre, nil + end + assert(not next(postcount), 'Unbalanced count') + parsed.precount, parsed.postcount, parsed.count = nil, nil, count + return parsed end diff --git a/pdfmml-showlists.lua b/pdfmml-showlists.lua index 20d11d1..8d0a9dc 100644 --- a/pdfmml-showlists.lua +++ b/pdfmml-showlists.lua @@ -66,7 +66,7 @@ local fraction_noad = l.Ct('\\fraction, thickness ' local mathchoice_noad = l.Ct('\\mathchoice' * l.Cg(l.Cc'choice', 'id') * -1) -local mark_whatsit = '\\write' * ('-' + l.R'09'^1) * '{LUAMML_MARK:' * (l.R'09'^1/tonumber) * ':' +local mark_whatsit = '\\write' * ('-' + l.R'09'^1) * '{LUAMML_MARK_REF:' * (l.R'09'^1/tonumber) * ':' local parse_list local function parse_kernel(lines, i, prefix, parsed)