summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2022-10-15 20:18:37 +0000
committerKarl Berry <karl@freefriends.org>2022-10-15 20:18:37 +0000
commitebe59a3d758c0d9f851743e256ead7c4db07d3bc (patch)
tree209b7ff0b764ead2fc1fa686ded7766bbb167897 /Master/texmf-dist/tex/luatex
parent76d32cb25b03db5d9b4b5ac6bc53e618e3bc0f10 (diff)
penlight (15oct22)
git-svn-id: svn://tug.org/texlive/trunk@64709 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/penlight/penlight.sty26
-rw-r--r--Master/texmf-dist/tex/luatex/penlight/penlightextras.lua75
2 files changed, 95 insertions, 6 deletions
diff --git a/Master/texmf-dist/tex/luatex/penlight/penlight.sty b/Master/texmf-dist/tex/luatex/penlight/penlight.sty
index 04cb66a482c..d796f1e1c88 100644
--- a/Master/texmf-dist/tex/luatex/penlight/penlight.sty
+++ b/Master/texmf-dist/tex/luatex/penlight/penlight.sty
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2022-04-16
+% 2022-10-15
% Copyright (C) 2021-2022 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,10 +22,13 @@
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
% OR OTHER DEALINGS IN THE SOFTWARE.
-\ProvidesPackage{penlight}[2022-04-16]
+\ProvidesPackage{penlight}[2022-10-15]
\RequirePackage{luacode}
+\IfFileExists{luakeys.lua}{}{\PackageError{penlight}{This package requires that luakeys be installed}{help text}}
+
+
\DeclareOption{pl}{\luadirect{
pl = require('penlight')
__PENLIGHT__ = 'pl'
@@ -69,3 +72,22 @@ end
writePDFmetadata()
}}
}
+
+
+\def\luastringT#1{\luastring{\unexpanded\expandafter\expandafter\expandafter{#1}}}
+\let\luastringF\luastring % fully expanded luastring
+
+% allow control over expansion of arguments to a latex function
+\NewDocumentCommand{\MakeluastringCommands}{O{} m }{% #1 the desired commands #2 defaults
+ \luadirect{_G[__PENLIGHT__].tex.aliasluastring(\luastring{#2},\luastring{#1})}%
+}
+
+\NewDocumentCommand{\splitToComma}{ O{nn} m m }{%
+ \MakeluastringCommands[nn]{#1}%
+ \luadirect{_G[__PENLIGHT__].tex.split2comma(\plluastringA{#2},\plluastringB{#3})}%
+}
+
+\NewDocumentCommand{\splitToItems}{ O{NN} m m }{%
+ \MakeluastringCommands[nn]{#1}%
+ \luadirect{_G[__PENLIGHT__].tex.split2items(\plluastringA{#2},\plluastringB{#3})}%
+} \ No newline at end of file
diff --git a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua b/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
index 253527cc52b..9ce0903f1c6 100644
--- a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
+++ b/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2022-04-16
+--% 2022-10-15
--% Copyright (C) 2021-2022 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -24,13 +24,16 @@
__SKIP_TEX__ = __SKIP_TEX__ or false --if declared true before here, it will use regular print functions
-- (for troubleshooting with texlua instead of actual use in lua latex)
+__SKIP_LUAKEYS__ = __SKIP_LUAKEYS__ or false
__PL_NO_GLOBALS__ = __PL_NO_GLOBALS__ or false
__PL_EXTRAS__ = 1
-- requires penlight
local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl
-luakeys = require'luakeys'
+if not __SKIP_LUAKEYS__ then
+ luakeys = require'luakeys'
+end
-- some bonus string operations, % text operator, and functional programming
pl.stringx.import()
@@ -278,6 +281,25 @@ end
+function pl.tex.aliasluastring(s, d)
+ s = s:delspace():upper():tolist()
+ d = d:delspace():upper():tolist()
+ for i, S in pl.seq.enum(d:slice_assign(1,#s,s)) do
+ if (S == 'E') or (S == 'F') then S = '' end -- E or F is fully expanded
+ pl.tex.prtn('\\let\\plluastring'..pl.Char(i)..'\\luastring'..S)
+ end
+end
+
+
+
+function pl.tex.get_ref_info(l)
+ local r = token.get_macro('r@'..l)
+ if r == nil then
+ return 0, 0
+ end
+ local sec, page = r:match("{([^}]*)}{([^}]*)}")
+ return sec, page
+end
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
@@ -314,6 +336,17 @@ local number = P{"number",
}
+
+
+function pl.char(num)
+ return string.char(string.byte("a")+num-1)
+end
+
+function pl.Char(num)
+ return string.char(string.byte("A")+num-1)
+end
+
+
local str_mt = getmetatable("") -- register functions with str
function str_mt.__index.gnum(s)
@@ -374,11 +407,19 @@ function str_mt.__index.totable(str)
return t
end
+function str_mt.__index.tolist(str)
+ return pl.List(str)
+end
+
function str_mt.__index.upfirst(str)
return str:gsub('%a', function(x) return x:upper() end, 1)
end
+function str_mt.__index.delspace(str)
+ return str:gsub('%s','')
+end
+
-- -- -- -- function stuff
@@ -658,7 +699,7 @@ function pl.tex.makePDFvarstr(s)
s = s:gsub('%s*\\sep%s+','\0'):gsub('%s*\\and%s+','\0') -- turn \and into \sep
s = pl.tex.clear_cmds_str(s)
s = s:gsub('\0','\\sep ')
- pl.tex.help_wrt(s,'PDF var string')
+ --pl.tex.help_wrt(s,'PDF var string')
return s
end
@@ -674,10 +715,36 @@ function pl.tex.makeInTextstr(s)
s = s:gsub('\0',', ', c_and - 1)
s = s:gsub('\0',', and ')
end
- pl.tex.help_wrt(s,'in text var string')
+ --pl.tex.help_wrt(s,'in text var string')
+ return s
+end
+
+--todo decide on above or below
+
+function pl.tex.list2comma(t)
+ local s = ''
+ if #t == 1 then
+ s = t[1]
+ elseif #t == 2 then
+ s = t:join(' and ')
+ elseif #t >= 3 then
+ s = t:slice(1,#t-1):join(', ')..', and '..t[#t]
+ end
return s
end
+function pl.tex.split2comma(s, d)
+ local t = pl.List(s:split(d)):map(string.strip)
+ pl.tex.prt(pl.tex.list2comma(t))
+end
+
+function pl.tex.split2items(s, d)
+ local t = pl.List(s:split(d)):map(string.strip)
+ for n, v in ipairs(t) do
+ pl.tex.prtn('\\item '..v)
+ end
+end
+