diff options
author | Karl Berry <karl@freefriends.org> | 2020-08-29 20:17:19 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2020-08-29 20:17:19 +0000 |
commit | bcef2848e43c83b6e9eac3afa81f6dd99fea6bd3 (patch) | |
tree | ede3418e2dbe0cec66c63a69161b773fc42cb43d /Master/texmf-dist/tex | |
parent | 7a73a52bad53a24322a5524cb9beb70afd4442c5 (diff) |
stricttex (29aug20)
git-svn-id: svn://tug.org/texlive/trunk@56210 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/stricttex/stricttex.lua | 162 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/stricttex/stricttex.sty | 48 |
2 files changed, 210 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/lualatex/stricttex/stricttex.lua b/Master/texmf-dist/tex/lualatex/stricttex/stricttex.lua new file mode 100644 index 00000000000..d8dd9621410 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/stricttex/stricttex.lua @@ -0,0 +1,162 @@ +-- Functions for making brackets strict: + +stricttexAddBracesToBrackets = function(str) + p = str:find('[%[%]]') + if p then + while true do + if str:sub(p-1,p-1) == '\\' then + q = str:sub(p+1,-1):find('[%[%]]') + if q then + p = p + q + else + break + end + elseif str:sub(p-1,p+1) == '<[>' or str:sub(p-1,p+1) == '<]>' then + str = str:sub(1,p-2) .. str:sub(p,p) .. str:sub(p+2,-1) + q = str:sub(p,-1):find('[%[%]]') + if q then + p = p + q - 1 + else + break + end + elseif str:sub(p,p) == '[' then + str = str:sub(1,p) .. '{' .. str:sub(p+1,-1) + q = str:sub(p+2,-1):find('[%[%]]') + if q then + p = p + q + 1 + else + break + end + else -- i.e. if str:sub(p,p) == ']' + str = str:sub(1,p-1) .. '}' .. str:sub(p,-1) + q = str:sub(p+2,-1):find('[%[%]]') + if q then + p = p + q + 1 + else + break + end + end + end + end + return str +end + +stricttexStrictBracketsOn = function() + luatexbase.add_to_callback( + "process_input_buffer", stricttexAddBracesToBrackets , "stricttexStrictBrackets" + ) + ifStricttexStrictBracketsOn = true +end + +stricttexStrictBracketsOff = function() + if ifStricttexStrictBracketsOn then + luatexbase.remove_from_callback( + "process_input_buffer", "stricttexStrictBrackets" + ) + ifStricttexStrictBracketsOn = false + else + tex.sprint('\\begingroup\\ExplSyntaxOn\\msg_error:nnnn { stricttex } { callback_not_registered } { \\StrictBracketsOn } { \\StrictBracketsOff }\\endgroup') + end +end + +-- Functions for numbers (and possibly primes) in command names + +stricttexReplaceNumbersByLetters = function(str) + str = str:gsub('0','numberZERO') + str = str:gsub('1','numberONE') + str = str:gsub('2','numberTWO') + str = str:gsub('3','numberTHREE') + str = str:gsub('4','numberFOUR') + str = str:gsub('5','numberFIVE') + str = str:gsub('6','numberSIX') + str = str:gsub('7','numberSEVEN') + str = str:gsub('8','numberEIGHT') + str = str:gsub('9','numberNINE') + return str +end + +stricttexFormatNumbers = function(str) + local p, q = str:find('\\%a+%d') + if p then + while true do + local r,s = str:sub(q,-1):find('%w+') -- ^ in the beginning did not work + local newstring = stricttexReplaceNumbersByLetters( str:sub(q,q+s-1) ) + local l = string.len(newstring) + str = str:sub(1, q-1) .. newstring .. str:sub(q+s,-1) + local t = str:sub(q+l,-1):find('\\%a+%d') + if t then + q = q + l + t - 1 + else + break + end + end + end + return str +end + +stricttexReplacePrimes = function(str) + str = str:gsub("'",'symbolPRIME') + return str +end + +stricttexFormatNumbersAndPrimes = function(str) + local p, q = str:find("\\%a+[%d']") + if p then + while true do + local r,s = str:sub(q,-1):find("[%w']+") -- ^ in the beginning did not work + local newstring = stricttexReplaceNumbersByLetters( str:sub(q,q+s-1) ) + mewstring = stricttexReplacePrimes( newstring ) + local l = string.len(newstring) + str = str:sub(1, q-1) .. newstring .. str:sub(q+s,-1) + local t = str:sub(q+l,-1):find("\\%a+[%d']") + if t then + q = q + l + t - 1 + else + break + end + end + end + return str +end + +stricttexNumbersInCommandsOn = function() + if ifStricttexNumbersAndPrimesInCommands then + stricttexNumbersAndPrimesInCommandsOff() + end + luatexbase.add_to_callback( + "process_input_buffer", stricttexFormatNumbers , "stricttexNumbersInCommands" + ) + ifStricttexNumbersInCommands = true +end + +stricttexNumbersInCommandsOff = function() + if ifStricttexNumbersInCommands then + luatexbase.remove_from_callback( + "process_input_buffer", "stricttexNumbersInCommands" + ) + ifStricttexNumbersInCommands = false + else + tex.sprint('\\begingroup\\ExplSyntaxOn\\msg_error:nnnn { stricttex } { callback_not_registered } { \\NumbersInCommandsOn } { \\NumbersInCommandsOff }\\endgroup') + end +end + +stricttexNumbersAndPrimesInCommandsOn = function() + if ifStricttexNumbersInCommands then + stricttexNumbersInCommandsOff() + end + luatexbase.add_to_callback( + "process_input_buffer", stricttexFormatNumbersAndPrimes , "stricttexNumbersAndPrimesInCommands" + ) + ifStricttexNumbersAndPrimesInCommandsOn = true +end + +stricttexNumbersAndPrimesInCommandsOff = function() + if ifStricttexNumbersAndPrimesInCommandsOn then + luatexbase.remove_from_callback( + "process_input_buffer", "stricttexNumbersAndPrimesInCommands" + ) + ifStricttexNumbersAndPrimesInCommandsOn = false + else + tex.sprint('\\begingroup\\ExplSyntaxOn\\msg_error:nnnn { stricttex } { callback_not_registered } { \\NumbersAndPrimesInCommandsOn } { \\NumbersAndPrimesInCommandsOff }\\endgroup') + end +end
\ No newline at end of file diff --git a/Master/texmf-dist/tex/lualatex/stricttex/stricttex.sty b/Master/texmf-dist/tex/lualatex/stricttex/stricttex.sty new file mode 100644 index 00000000000..8a3e9874dd1 --- /dev/null +++ b/Master/texmf-dist/tex/lualatex/stricttex/stricttex.sty @@ -0,0 +1,48 @@ +\ProvidesExplPackage{stricttex}{2020/07/28}{0.1beta}{} + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% stricttex -- strictly paired brackets and numbers in command names % +% https://ctan.org/pkg/semantex % +% (C) 2020 Sebastian Ørsted % +% sorsted@gmail.com % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +\msg_new:nnn { stricttex } { not_luatex } { This~package~only~works~with~LuaTeX;~the~current~TeX~run~has~been~terminated. } + +\msg_new:nnn { stricttex } { callback_not_registered } { Found~#2 with~no~preceding~#1 } + +\sys_if_engine_luatex:F { \msg_fatal:nn { stricttex } { not_luatex } } + +\lua_now:e { require('stricttex.lua') } + +\cs_new_protected:Npn\StrictBracketsOn +{ + \lua_now:e { stricttexStrictBracketsOn() } +} + +\cs_new_protected:Npn\StrictBracketsOff +{ + \lua_now:e { stricttexStrictBracketsOff() } +} + +\cs_new_protected:Npn\NumbersInCommandsOn +{ + \lua_now:e { stricttexNumbersInCommandsOn() } +} + +\cs_new_protected:Npn\NumbersInCommandsOff +{ + \lua_now:e { stricttexNumbersInCommandsOff() } +} + +\cs_new_protected:Npn\NumbersAndPrimesInCommandsOn +{ + \lua_now:e { stricttexNumbersAndPrimesInCommandsOn() } +} + +\cs_new_protected:Npn\NumbersAndPrimesInCommandsOff +{ + \lua_now:e { stricttexNumbersAndPrimesInCommandsOff() } +}
\ No newline at end of file |