From 75ede91b5db6e7a9cd4221ae3ffdb3aa8f59cec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Fabian=20Kr=C3=BCger?= Date: Wed, 23 Jun 2021 15:48:56 +0200 Subject: [PATCH] Smaller improvements --- luamml-convert.lua | 4 ++-- luamml-demo.sty | 12 ++++++++++-- luamml-structelemwriter.lua | 15 +++++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/luamml-convert.lua b/luamml-convert.lua index 1cbcd6b..b7ca08b 100644 --- a/luamml-convert.lua +++ b/luamml-convert.lua @@ -139,7 +139,7 @@ local function delim_to_table(delim) else local fam = delim.small_fam char = remap_lookup[fam << 21 | char] - local result = {[0] = 'mo', char, ['tex:family'] = fam ~= 0 and fam or nil, stretchy = not stretchy[char] or nil, lspace = 0, rspace = 0, [':nodes'] = {delim} } + local result = {[0] = 'mo', char, ['tex:family'] = fam ~= 0 and fam or nil, stretchy = not stretchy[char] or nil, lspace = 0, rspace = 0, [':nodes'] = {delim}, [':actual'] = char} if mathml_filter then return mathml_filter(result, result) else @@ -166,7 +166,7 @@ local function acc_to_table(acc, cur_style, stretch) if stretch ~= not stretchy[char] then -- Handle nil gracefully in stretchy stretch = nil end - local result = {[0] = 'mo', char, ['tex:family'] = fam ~= 0 and fam or nil, stretchy = stretch, [':nodes'] = {acc}} + local result = {[0] = 'mo', char, ['tex:family'] = fam ~= 0 and fam or nil, stretchy = stretch, [':nodes'] = {acc}, [':actual'] = stretch and char or nil} if mathml_filter then return mathml_filter(result) else diff --git a/luamml-demo.sty b/luamml-demo.sty index 3667e60..08748d3 100644 --- a/luamml-demo.sty +++ b/luamml-demo.sty @@ -13,10 +13,14 @@ } \ExplSyntaxOn + +\bool_new:N \l__luamml_demo_structelem_bool + \DeclareOption{tracing}{ \tracingmathml=2 } \DeclareOption{structelem}{ + \bool_set_true:N \l__luamml_demo_structelem_bool \luamml_flag_structelem: } \DeclareOption{files}{ @@ -36,7 +40,9 @@ \int_gincr:N \g__luamml_demo_af_int \exp_args:Ne \pdf_object_new:nn{__luamml_demo_\int_use:N \g__luamml_demo_af_int}{dict} \exp_args:Ne \tagstructbegin{tag=Formula,AF=__luamml_demo_\int_use:N \g__luamml_demo_af_int,#1} - \tagmcbegin{tag=Formula} + \bool_if:NF \l__luamml_demo_structelem_bool { + \tagmcbegin{tag=Formula} + } #2 \group_begin: \pdfdict_put:nnn {l_pdffile/Filespec} {AFRelationship}{/Supplement} @@ -45,7 +51,9 @@ { test.xml } { \luamml_get_last_mathml_stream:e{}\c_space_tl 0~R} \group_end: - \tagmcend + \bool_if:NF \l__luamml_demo_structelem_bool { + \tagmcend + } \tagstructend } diff --git a/luamml-structelemwriter.lua b/luamml-structelemwriter.lua index 8b766bd..bd0a59f 100644 --- a/luamml-structelemwriter.lua +++ b/luamml-structelemwriter.lua @@ -61,15 +61,18 @@ local function write_elem(tree, stash) stash = '__luamml_stashed_' .. stash_cnt tree[':struct'] = stash stash = ', stash, label = ' .. stash - else - stash = '' end - if i == 0 then - tex.sprint(struct_begin, '{tag=' .. tree[0] .. '/mathml' .. stash .. '}') - else - tex.sprint(struct_begin, '{tag=' .. tree[0] .. '/mathml, attribute=' .. attributes[table.concat(attrs)] .. stash .. '}') + local attr_flag = i ~= 0 and ', attribute=' .. attributes[table.concat(attrs)] + tex.sprint(struct_begin, '{tag=' .. tree[0] .. '/mathml') + if stash then tex.sprint(stash) end + if attr_flag then tex.sprint(attr_flag) end + if tree[':actual'] then + tex.sprint(', actualtext = {') + tex.cprint(12, tree[':actual']) + tex.sprint'}' end + tex.sprint'}' for j = 1, i do attrs[j] = nil end if tree[':nodes'] then