diff --git a/luamml-pdf.sty b/luamml-pdf.sty index 67bcd15..d4ee290 100644 --- a/luamml-pdf.sty +++ b/luamml-pdf.sty @@ -1,26 +1,42 @@ \ProvidesExplPackage {luamml-pdf} {2021-05-31} {0.0.1-alpha} {MathML generation for L̶u̶a̶pdfLaTeX} -\cs_new:Npn \__luamml_pdf_showlists: { - \group_begin: - \int_set:Nn \l_tmpa_int { \tex_interactionmode:D } - \int_set:Nn \tex_interactionmode:D { 0 } - \int_set:Nn \tex_showboxdepth:D { \c_max_int } - \int_set:Nn \tex_showboxbreadth:D { \c_max_int } - \tex_showlists:D - \int_set:Nn \tex_interactionmode:D { \l_tmpa_int } - \group_end: +\cs_if_exist:NTF \showstream { + \iow_new:N \l__luamml_pdf_stream + \iow_open:Nn \l__luamml_pdf_stream { \jobname .tml } + \cs_new_protected:Npn \__luamml_pdf_showlists: { + \group_begin: + \int_set:Nn \tex_showboxdepth:D { \c_max_int } + \int_set:Nn \tex_showboxbreadth:D { \c_max_int } + \showstream = \l__luamml_pdf_stream + \tex_showlists:D + \iow_now:Nx \l__luamml_pdf_stream {} + \group_end: + } +} { + \cs_set_eq:NN \l__luamml_pdf_stream \c_log_iow + \cs_set_eq:NN \__luamml_pdf_set_showstream: \scan_stop: + \cs_new_protected:Npn \__luamml_pdf_showlists: { + \group_begin: + \int_set:Nn \l_tmpa_int { \tex_interactionmode:D } + \int_set:Nn \tex_interactionmode:D { 0 } + \int_set:Nn \tex_showboxdepth:D { \c_max_int } + \int_set:Nn \tex_showboxbreadth:D { \c_max_int } + \tex_showlists:D + \int_set:Nn \tex_interactionmode:D { \l_tmpa_int } + \group_end: + } } \int_new:N \g__luamml_formula_id_int \cs_new_protected:Npn \luamml_pdf_write: { \int_gincr:N \g__luamml_formula_id_int - \iow_log:x { + \iow_now:Nx \l__luamml_pdf_stream { LUAMML_FORMULA_BEGIN: \int_use:N \g__luamml_formula_id_int } \__luamml_pdf_showlists: - \iow_log:x { + \iow_now:Nx \l__luamml_pdf_stream { LUAMML_FORMULA_END } } @@ -38,7 +54,7 @@ \int_new:N \g__luamml_annotation_id_int \cs_new_protected:Npn \luamml_pdf_annotate:nnn #1#2#3 { \int_gincr:N \g__luamml_annotation_id_int - \iow_shipout_x:Nx \c_log_iow { + \iow_shipout_x:Nx \l__luamml_pdf_stream { \tl_to_str:e { LUAMML_MARK: \int_use:N \g__luamml_annotation_id_int @@ -58,7 +74,7 @@ % THIS VERSION IS SIGNIFICANTLY SLOWER \cs_new_protected:Npn \luamml_pdf_annotate:nn #1#2 { \int_gincr:N \g__luamml_annotation_id_int - \iow_shipout_x:Nx \c_log_iow { + \iow_shipout_x:Nx \l__luamml_pdf_stream { \tl_to_str:e { LUAMML_MARK: \int_use:N \g__luamml_annotation_id_int @@ -69,20 +85,20 @@ \exp_not:N \iow_newline: LUAMML_MARK_END } - \iow_now:Nx \c_log_iow { + \iow_now:Nx \l__luamml_pdf_stream { LUAMML_COUNT: \int_use:N \g__luamml_annotation_id_int } \__luamml_pdf_showlists: #2 - \iow_now:Nn \c_log_iow { + \iow_now:Nx \l__luamml_pdf_stream { LUAMML_COUNT_END } \__luamml_pdf_showlists: } \NewDocumentCommand \RegisterFamilyMapping {m m} { - \iow_log:x { + \iow_now:Nx \l__luamml_pdf_stream { LUAMML_INSTRUCTION:REGISTER_MAPPING: \int_use:N #1 : #2 } } diff --git a/pdfmml-logreader.lua b/pdfmml-logreader.lua index 4fb7c75..8aa7bdd 100644 --- a/pdfmml-logreader.lua +++ b/pdfmml-logreader.lua @@ -3,7 +3,7 @@ local l = lpeg or require'lpeg' local line = (1-l.P'\n')^0 * '\n' local id = l.R'09'/tonumber -local non_final_list_block = (l.C((1-l.P'\n')^0) * '\n' - '### ')^0 +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' * non_final_list_block)^1 local generic_list_block = '### ' * (line - 'current page:') * non_final_list_block diff --git a/pdfmml-showlists.lua b/pdfmml-showlists.lua index b271955..ddaab6a 100644 --- a/pdfmml-showlists.lua +++ b/pdfmml-showlists.lua @@ -64,7 +64,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-{LUAMML_MARK:' * (l.R'09'^1/tonumber) * ':' +local mark_whatsit = '\\write' * ('-' + l.R'09'^1) * '{LUAMML_MARK:' * (l.R'09'^1/tonumber) * ':' local parse_list local function parse_kernel(lines, i, prefix, parsed)