texlive[64709] Master/texmf-dist: penlight (15oct22)
commits+karl at tug.org
commits+karl at tug.org
Sat Oct 15 22:18:37 CEST 2022
Revision: 64709
http://tug.org/svn/texlive?view=revision&revision=64709
Author: karl
Date: 2022-10-15 22:18:37 +0200 (Sat, 15 Oct 2022)
Log Message:
-----------
penlight (15oct22)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/luatex/penlight/penlight.pdf
trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex
trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty
trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
Modified: trunk/Master/texmf-dist/doc/luatex/penlight/penlight.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex
===================================================================
--- trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex 2022-10-15 20:18:13 UTC (rev 64708)
+++ trunk/Master/texmf-dist/doc/luatex/penlight/penlight.tex 2022-10-15 20:18:37 UTC (rev 64709)
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje at 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
@@ -76,12 +76,13 @@
you can access it by setting \cmd{__SKIP_TEX__ = true} and adding the package to path. For example:
\begin{verbatim}
package.path = package.path .. ';'..'path/to/texmf/tex/latex/penlight/?.lua'
-penlight = require('penlight')
+penlight = require'penlight'
-- below is optional
__SKIP_TEX__ = true --only required if you want to use
--penlightextras without a LaTeX run
-- __PL_NO_GLOBALS__ = true -- optional, skip global definitions
-require('penlightextras')
+__SKIP_LUAKEYS__ = true -- luakeys is laoded in penlightextras be default, you may skip it with this
+require'penlightextras'
\end{verbatim}
\pagebreak
@@ -118,8 +119,13 @@
\llcmd{COMP'xyz'()} Python-like comprehensions:\\\url{https://lunarmodules.github.io/Penlight/libraries/pl.comprehension.html}\\
\llcmd{math.mod(n,d)}, \cmd{math.mod2(n)} math modulous\\
\llcmd{string.}\cmd{totable(s)} string a table of characters\\
+\llcmd{string.}\cmd{delspace(s)} clear spaces from string\\
+\llcmd{pl.}\cmd{char(n)} return letter corresponding to 1=a, 2=b, etc.\\
+\llcmd{pl.}\cmd{Char(n)} return letter corresponding to 1=A, 2=B, etc.\\
\llcmd{kpairs(t), }\cmd{npairs(t)} iterate over keys only, or include nil value from table ipairs\\
+{\Large todo document all string helper functions}
+
\llcmd{pl.utils.}\cmd{filterfiles}\cmd{(dir,filt,rec)} Get files from dir and apply glob-like filters. Set rec to \cmd{true} to include sub directories\\
\pagebreak
@@ -148,8 +154,48 @@
to a package warning saying \cmd{'cs' was declared and used in document, but never set}. If \cmd{overwrite}
is true, it will overwrite an existing command (using \cmd{defcmd}), otherwise, it will throw error like \cmd{newcmd}.\\
+\subsection{Split stuff}
+splitToComma:
+-\splitToComma{ j doe }{\and}-\\
+-\splitToComma{ j doe \and s else }{\and}-\\
+-\splitToComma{ j doe \and s else \and a per }{\and}-\\
+-\splitToComma{ j doe \and s else \and a per \and f guy}{\and}-
+\def\authors{j doe \and s else \and a per \and f guy}
+\splitToComma[o]{\authors}{\and}
+
+spliToItems:
+\begin{itemize}
+ \splitToItems{kale\and john}{\and}
+ \splitToItems{kale -john -someone else}{-}
+\end{itemize}
+
+\subsection{Macro helpers}
+\cmd{\MakeluastringCommands[def]{spec}} will let \cmd{\plluastring(A|B|C..)} be \cmd{\luastring(N|O|T|F)}
+based on the letters that \cmd{spec} is set to (or \cmd{def} if nothing is provided)
+This is useful if you want to write a command with flexibility on argument expansion.
+The user can specify \cmd{n}, \cmd{o}, \cmd{t}, and \cmd{f} (case insensitve) if they want
+no, once, twice, or full expansion.
+
+
+\def\NOTexp{\ONEexp}
+\def\ONEexp{\TWOexp}
+\def\TWOexp{\TREexp}
+\def\TREexp{Fully expanded}
+
+\NewDocumentCommand{\luastringExpTest}{m m}{
+ \MakeluastringCommands{#1}
+ \luadirect{texio.write_nl('VVVVVVVVVVVVVVVVVVVVVVVVVVVVV')}
+ \luadirect{texio.write_nl(\plluastringA{#2}..' | Not')}
+ \luadirect{texio.write_nl(\plluastringB{#2}..' | Once')}
+ \luadirect{texio.write_nl(\plluastringC{#2}..' | Twice')}
+ \luadirect{texio.write_nl(\plluastringD{#2}..' | Full')}
+ \luadirect{texio.write_nl('VVVVVVVVVVVVVVVVVVVVVVVVVVVVV')}
+}
+
+\luastringExpTest{ n o t f }{\NOTexp}
+
\subsubsection*{global extras}
If \cmd{extras} is used and NOT \cmd{extrasnoglobals}, then some globals are set.\\
All \cmd{pl.tex} modules are added.\\
Modified: trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty 2022-10-15 20:18:13 UTC (rev 64708)
+++ trunk/Master/texmf-dist/tex/luatex/penlight/penlight.sty 2022-10-15 20:18:37 UTC (rev 64709)
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje at 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 @@
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
Modified: trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua
===================================================================
--- trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua 2022-10-15 20:18:13 UTC (rev 64708)
+++ trunk/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua 2022-10-15 20:18:37 UTC (rev 64709)
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje at 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,6 +24,7 @@
__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
@@ -30,7 +31,9 @@
-- 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,8 +281,27 @@
+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 @@
}
+
+
+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,13 +407,21 @@
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
function pl.clone_function(fn)
@@ -658,7 +699,7 @@
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,15 +715,41 @@
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
+
+
+
+
if not __PL_NO_GLOBALS__ then
__PL_EXTRAS__ = 2
-- iterators
More information about the tex-live-commits
mailing list.