diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/semantex/stripsemantex.lua')
-rw-r--r-- | Master/texmf-dist/tex/latex/semantex/stripsemantex.lua | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/Master/texmf-dist/tex/latex/semantex/stripsemantex.lua b/Master/texmf-dist/tex/latex/semantex/stripsemantex.lua index 769d5b05516..ba3eb9f2dac 100644 --- a/Master/texmf-dist/tex/latex/semantex/stripsemantex.lua +++ b/Master/texmf-dist/tex/latex/semantex/stripsemantex.lua @@ -55,7 +55,12 @@ end addIDsToRegisters = function(str) str = removeStricttexFormatting(str) - content = content:gsub('\\' .. str .. '%f[^%a]' ,'\\SemantexIDcommand{}\\' .. str) + content = content:gsub('\\' .. str .. '([^%a])' ,'\\SemantexIDcommand{}\\' .. str .. '%1') + -- '%f[^%a]' does not work here, as it will not react if the last character of str is a number, + -- which stricttex allows. + -- Because of this choice, there will be an issue if you use stricttex and let + -- \<command> by a SemanTeX command and \<command>' be a non-SemanTeX command. + -- So simply *don't do that*. end removeSuperfluousIDs = function() @@ -106,7 +111,7 @@ semantexIDluacommand = function(id, source, output) content = content:sub(1 , p-1) .. content:sub(p+1, -1) i = i + 1 elseif s:match('%s') then - content = content:sub(1, p-1) .. content:sub (p+1, -1) + content = content:sub(1, p-1) .. content:sub(p+1, -1) elseif s == '%' then content = content:sub(1 , p-1) .. content:sub(p,-1):gsub('%%.-\n','',1) elseif s == '{' then @@ -123,9 +128,38 @@ semantexIDluacommand = function(id, source, output) netto = netto + 1 elseif e == '\\' then q = q + 1 + elseif e == '%' then + content = content:sub(1, p+q-1) .. content:sub(p+q,-1):gsub('%%.-\n','',1) + q = q - 1 end end content = content:sub(1,p-1) .. content:sub(p+1,p+q-1) .. content:sub(p+q+1,-1) + elseif s == '<' and content:sub(p+1,p+2) == '[>' then + content = content:sub(1,p-1) .. content:sub(p+3,-1) + i = i + 1 + elseif s == '<' and content:sub(p+1,p+2) == ']>' then + content = content:sub(1,p-1) .. content:sub(p+3,-1) + i = i + 1 + elseif source:sub(i,i) == '{' then + -- In this case, we remove the corresponding right brace, + -- once we find it + local netto = 1 -- The current brace group level + local q = 0 -- The position we have moved forward so far + while netto > 0 do + q = q + 1 + local e = source:sub(i+q,i+q) + if e == '}' then + netto = netto - 1 + elseif e == '{' then + netto = netto + 1 + elseif e == '\\' then + q = q + 1 + -- there is no chance that the source contains a %, so we do not + -- check for this + end + end + source = source:sub(1,i-1) .. source:sub(i+1,i+q-1) .. source:sub(i+q+1,-1) + length = source:len() else tex.sprint( [[\begingroup\ExplSyntaxOn \msg_fatal:nnnn { stripsemantex } { source_not_expected } { ]] .. source:sub(i,i) .. [[ } { ]] .. s .. [[ } |