More reliable pdfTeX annotations
This commit is contained in:
parent
d63bed65a1
commit
e1b8debcf6
29
luamml.dtx
29
luamml.dtx
@ -313,14 +313,17 @@
|
|||||||
\cs_new_protected:Npn \luamml_annotate:nen #1#2#3 {
|
\cs_new_protected:Npn \luamml_annotate:nen #1#2#3 {
|
||||||
\int_gincr:N \g__luamml_annotation_id_int
|
\int_gincr:N \g__luamml_annotation_id_int
|
||||||
\iow_shipout_x:Nx \l__luamml_pdf_stream {
|
\iow_shipout_x:Nx \l__luamml_pdf_stream {
|
||||||
\tl_to_str:e {
|
LUAMML_MARK_REF:
|
||||||
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
|
:
|
||||||
|
}
|
||||||
|
\iow_now:Nx \l__luamml_pdf_stream {
|
||||||
LUAMML_MARK:
|
LUAMML_MARK:
|
||||||
\int_use:N \g__luamml_annotation_id_int
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
:
|
:
|
||||||
count = \int_eval:n {#1},
|
count = \int_eval:n {#1},
|
||||||
#2
|
#2
|
||||||
}
|
\iow_newline:
|
||||||
\exp_not:N \iow_newline:
|
|
||||||
LUAMML_MARK_END
|
LUAMML_MARK_END
|
||||||
}
|
}
|
||||||
#3
|
#3
|
||||||
@ -328,27 +331,33 @@
|
|||||||
\cs_new_protected:Npn \luamml_annotate:en #1#2 {
|
\cs_new_protected:Npn \luamml_annotate:en #1#2 {
|
||||||
\int_gincr:N \g__luamml_annotation_id_int
|
\int_gincr:N \g__luamml_annotation_id_int
|
||||||
\iow_shipout_x:Nx \l__luamml_pdf_stream {
|
\iow_shipout_x:Nx \l__luamml_pdf_stream {
|
||||||
\tl_to_str:e {
|
LUAMML_MARK_REF:
|
||||||
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
|
:
|
||||||
|
}
|
||||||
|
\iow_now:Nx \l__luamml_pdf_stream {
|
||||||
LUAMML_MARK:
|
LUAMML_MARK:
|
||||||
\int_use:N \g__luamml_annotation_id_int
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
:
|
:
|
||||||
count = data.count[\int_use:N \g__luamml_annotation_id_int],
|
count = data.count[\int_use:N \g__luamml_annotation_id_int],
|
||||||
#1
|
#1
|
||||||
}
|
\iow_newline:
|
||||||
\exp_not:N \iow_newline:
|
|
||||||
LUAMML_MARK_END
|
LUAMML_MARK_END
|
||||||
}
|
}
|
||||||
\iow_now:Nx \l__luamml_pdf_stream {
|
\use:x {
|
||||||
|
\iow_now:Nn \l__luamml_pdf_stream {
|
||||||
LUAMML_COUNT:
|
LUAMML_COUNT:
|
||||||
\int_use:N \g__luamml_annotation_id_int
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
}
|
}
|
||||||
\__luamml_pdf_showlists:
|
\__luamml_pdf_showlists:
|
||||||
#2
|
\exp_not:n {#2}
|
||||||
\iow_now:Nx \l__luamml_pdf_stream {
|
\iow_now:Nn \l__luamml_pdf_stream {
|
||||||
LUAMML_COUNT_END
|
LUAMML_COUNT_END:
|
||||||
|
\int_use:N \g__luamml_annotation_id_int
|
||||||
}
|
}
|
||||||
\__luamml_pdf_showlists:
|
\__luamml_pdf_showlists:
|
||||||
}
|
}
|
||||||
|
}
|
||||||
% \end{macrocode}
|
% \end{macrocode}
|
||||||
% \end{macro}
|
% \end{macro}
|
||||||
%
|
%
|
||||||
|
@ -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 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 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
|
local luamml_precount = l.Cg('LUAMML_COUNT:' * id * l.P'\n'^1
|
||||||
* count_block
|
* count_block * l.Cc'precount')
|
||||||
* (line-'LUAMML_COUNT_END\n')^0
|
|
||||||
* 'LUAMML_COUNT_END' * l.P'\n'^1
|
local luamml_postcount = l.Cg('LUAMML_COUNT_END:' * id * l.P'\n'^1
|
||||||
* count_block / function(id, first, second)
|
* count_block * l.Cc'postcount')
|
||||||
return id, second - first
|
|
||||||
end * l.Cc'count')
|
|
||||||
|
|
||||||
local luamml_instruction = l.Cg('LUAMML_INSTRUCTION:' * l.Cc(nil) * l.C((1 - l.P'\n')^0) * '\n' * l.Cc'instructions')
|
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
|
return t
|
||||||
end
|
end
|
||||||
local log_file = l.Cf(l.Ct(l.Cg(l.Ct'', 'groups')
|
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'', 'marks')
|
||||||
* l.Cg(l.Ct'', 'instructions'))
|
* 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)
|
multi_table_set)
|
||||||
|
|
||||||
return function(filename)
|
return function(filename)
|
||||||
@ -50,5 +49,13 @@ return function(filename)
|
|||||||
if f then f:close() end
|
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.
|
-- 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.
|
-- 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
|
end
|
||||||
|
@ -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 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 parse_list
|
||||||
local function parse_kernel(lines, i, prefix, parsed)
|
local function parse_kernel(lines, i, prefix, parsed)
|
||||||
|
Loading…
Reference in New Issue
Block a user