From d63bed65a1468105c18d1a4b7aa782e627291f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Sun, 27 Jun 2021 04:30:49 +0200 Subject: [PATCH] More pdfTeX work --- luamml.dtx | 23 +++++++++++++++++++++-- pdfmml-logreader.lua | 2 +- pdfmml-showlists.lua | 11 +++++++++++ pdfmml.lua | 2 +- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/luamml.dtx b/luamml.dtx index 99038fc..7f02bbc 100644 --- a/luamml.dtx +++ b/luamml.dtx @@ -130,6 +130,25 @@ } % \end{macro} % +% \begin{macro}{\__luamml_style_to_num:N} +% \begin{macrocode} +\cs_new:Npn \__luamml_style_to_num:N #1 { +% 32 * #1 +%<*pdftex> + \token_case_meaning:NnF #1 { + \displaystyle {0} + \textstyle {32} + \scriptstyle {64} + \scriptscriptstyle {96} + } { + \Invalid_mathstyle + } +% +} +% \end{macrocode} +% \end{macro} +% +% % \begin{macro}{\luamml_flag_save:n, % \luamml_flag_save:nN, % \luamml_flag_save:nn, @@ -151,7 +170,7 @@ } \cs_new_protected:Npn \luamml_flag_save:nN #1#2 { \tl_set:Nn \l__luamml_label_tl {#1} - \int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 17 + 32 * #2 } + \int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 17 + \__luamml_style_to_num:N #2 } } \cs_new_protected:Npn \luamml_flag_save:nn #1 { \tl_set:Nn \l__luamml_label_tl {#1} @@ -160,7 +179,7 @@ } \cs_new_protected:Npn \luamml_flag_save:nNn #1#2 { \tl_set:Nn \l__luamml_label_tl {#1} - \int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 21 + 32 * #2 } + \int_set:Nn \l__luamml_flag_int { \__luamml_maybe_structelem: 21 + \__luamml_style_to_num:N #2 } \tl_set:Nn \l__luamml_root_tl } % \end{macrocode} diff --git a/pdfmml-logreader.lua b/pdfmml-logreader.lua index 19d410e..a9f0e9e 100644 --- a/pdfmml-logreader.lua +++ b/pdfmml-logreader.lua @@ -2,7 +2,7 @@ local l = lpeg or require'lpeg' local line = (1-l.P'\n')^0 * '\n' -local id = l.R'09'/tonumber +local id = l.R'09'^1/tonumber 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 diff --git a/pdfmml-showlists.lua b/pdfmml-showlists.lua index ddaab6a..20d11d1 100644 --- a/pdfmml-showlists.lua +++ b/pdfmml-showlists.lua @@ -56,6 +56,8 @@ local simple_noad = l.Ct( + '\\kern' * l.Cg(' ' * l.Cc(1) + l.Cc(0), 'subtype') * l.Cg(scaled, 'kern') * (' (for ' * (l.R'az' + l.S'/\\') * ')')^-1 * l.Cg(l.Cc'kern', 'id') ) * -1 +local box_node = '\\' * l.S'hv' * 'box(' + local fraction_noad = l.Ct('\\fraction, thickness ' * l.Cg('= default' * l.Cc(0x40000000) + scaled, 'width') * l.Cg(', left-delimiter ' * delimiter_code, 'left')^-1 * l.Cg(', right-delimiter ' * delimiter_code, 'right')^-1 @@ -72,9 +74,18 @@ local function parse_kernel(lines, i, prefix, parsed) if not line or line:sub(1, #prefix) ~= prefix then return nil, i end local result = math_char:match(lines[i], #prefix + 1) if result then return result, i+1 end + if box_node:match(lines[i], #prefix + 1) then return skip_list(lines, i+1, prefix .. '.') end result, i = parse_list(lines, i, prefix, parsed) return {list = result, id = 'sub_mlist'}, i end +function skip_list(lines, i, prefix) + i = i or 1 + local count = #lines + while i <= count and lines[i]:sub(1, #prefix) == prefix do + i = i + 1 + end + return {id = 'sub_box', list = {}}, i +end function parse_list(lines, i, prefix, parsed) i = i or 1 prefix = prefix or '' diff --git a/pdfmml.lua b/pdfmml.lua index 05d16da..457dda2 100755 --- a/pdfmml.lua +++ b/pdfmml.lua @@ -84,7 +84,7 @@ for i, block in ipairs(parsed.groups) do xml = {[0] = tag, xml} end end - if style == 2 and flag & 1 == 1 and label ~= '' then + if style == 2 and flag & 1 == 1 and label then if parsed.mathml[label] then error'Invalid label reuse' end