summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/penlight
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/penlight')
-rw-r--r--macros/luatex/generic/penlight/penlight.pdfbin59499 -> 60005 bytes
-rw-r--r--macros/luatex/generic/penlight/penlight.sty70
-rw-r--r--macros/luatex/generic/penlight/penlight.tex56
-rw-r--r--macros/luatex/generic/penlight/penlightextras.lua17
4 files changed, 109 insertions, 34 deletions
diff --git a/macros/luatex/generic/penlight/penlight.pdf b/macros/luatex/generic/penlight/penlight.pdf
index d8a0ac2f15..a063e8922a 100644
--- a/macros/luatex/generic/penlight/penlight.pdf
+++ b/macros/luatex/generic/penlight/penlight.pdf
Binary files differ
diff --git a/macros/luatex/generic/penlight/penlight.sty b/macros/luatex/generic/penlight/penlight.sty
index 8180a839ac..4f5900e3b8 100644
--- a/macros/luatex/generic/penlight/penlight.sty
+++ b/macros/luatex/generic/penlight/penlight.sty
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2022-10-24
+% 2023-07-18
% Copyright (C) 2021-2022 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -22,7 +22,7 @@
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
% OR OTHER DEALINGS IN THE SOFTWARE.
-\ProvidesPackage{penlight}[2022-10-24]
+\ProvidesPackage{penlight}[2023-07-18]
\RequirePackage{luacode}
@@ -42,11 +42,15 @@
\DeclareOption{stringx}{\luadirect{_G[__PENLIGHT__].stringx.import()}}
\DeclareOption{format}{\luadirect{_G[__PENLIGHT__].stringx.format_operator()}}
\DeclareOption{func}{\luadirect{_G[__PENLIGHT__].utils.import(__PENLIGHT__..'.func')}}
-\DeclareOption{extras}{\luadirect{require'penlightextras'}}
+\DeclareOption{extras}{\luadirect{require'penlightextras'}
+ \gdef\penlight@loadextras{}
+}
\DeclareOption{extrasglobals}{\luadirect{
__PL_GLOBALS__ = true
require'penlightextras'
-}}
+ }
+ \gdef\penlight@loadextras{}
+}
\ProcessOptions*\relax
@@ -56,9 +60,9 @@ if __PENLIGHT__ == nil then
end
}
+\ifdefined\penlight@loadextras
-
-\newcommand{\writePDFmetadata}{\luadirect{_G[__PENLIGHT__].tex.writePDFmetadata()}}
+\global\newcommand{\writePDFmetadata}{\luadirect{_G[__PENLIGHT__].tex.writePDFmetadata()}}
\NewDocumentCommand{\writePDFmetadatakv}{ s m }{
\IfBooleanTF{#1}{% if *, overwrite everything
@@ -74,8 +78,8 @@ end
}
-\def\luastringT#1{\luastring{\unexpanded\expandafter\expandafter\expandafter{#1}}} % expand luastring twice
-\let\luastringF\luastring % fully expanded luastring
+\gdef\luastringT#1{\luastring{\unexpanded\expandafter\expandafter\expandafter{#1}}} % expand luastring twice
+\global\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
@@ -90,4 +94,52 @@ end
\NewDocumentCommand{\splitToItems}{ O{NN} m m }{%
\MakeluastringCommands[nn]{#1}%
\luadirect{_G[__PENLIGHT__].tex.split2items(\plluastringA{#2},\plluastringB{#3})}%
-} \ No newline at end of file
+}
+
+
+%
+%
+%\NewDocumentCommand{\tblnew}{m}{\luadirect{
+% _G[\luastring{#1}] = {}
+%}}
+%
+%\NewDocumentCommand{\tblfrkv}{m m O{} }{\luadirect{
+% _G[\luastring{#1}] = luakeys.parse(\luastring{#2}, luakeys.parse(\luastring{#3}))
+%}}
+%
+%\NewDocumentCommand{\tblset}{m m m}{\luadirect{
+% _G[\luastring{#1}][\luastring{#2}] = \luastring{#3}
+%}}
+%
+%\NewDocumentCommand{\tblget}{m m}{\luadirect{
+% tex.sprint(tostring(_G[\luastring{#1}][\luastring{#2}]))
+%}}
+%
+%\NewDocumentCommand{\tblidx}{m m}{\luadirect{
+% tex.sprint(tostring(_G[\luastring{#1}][#2]))
+%}}
+%
+%
+%\NewDocumentCommand{\tblupd}{ m m}{\luadirect{
+% _G[__PENLIGHT__].tablex.update(_G[\luastring{#1}], _G[\luastring{#2}])
+%}}
+%
+%\NewDocumentCommand{\tblupdkv}{ m m }{\luadirect{
+% _G[__PENLIGHT__].tablex.update(_G[\luastring{#1}], luakeys.parse(\luastring{#2}))
+%}}
+%
+%% todo need a get table function. If blank is passed, the last table referenced is used.
+%\NewDocumentCommand{\tblfrkvII}{ m m m }{\luadirect{
+% _G[\luastring{#1}] = _G[__PENLIGHT__].tablex.update(luakeys.parse(\luastring{#2}), luakeys.parse(\luastring{#3}))
+%}}
+
+
+%\NewDocumentCommand{\tbldo}{m m O{} }{\luadirect{
+% % tex.sprint(tostring(_G[\luastring{#1}][#2]))
+% % todo allow one to use pl tablex function here,
+% % {tbl}{update}[arg1][arg2]
+% _G[__PENLIGHT__].tablex[\luastring[#1]](_G[\luastring{}], _G[\luastring{}])
+%}}
+
+
+\else\fi \ No newline at end of file
diff --git a/macros/luatex/generic/penlight/penlight.tex b/macros/luatex/generic/penlight/penlight.tex
index dad50c7be2..edba4933e8 100644
--- a/macros/luatex/generic/penlight/penlight.tex
+++ b/macros/luatex/generic/penlight/penlight.tex
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2022-10-24
+% 2023-07-18
% Copyright (C) 2021-2022 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -58,7 +58,6 @@
\subtitle{Lua libraries for use in LuaLaTeX}
\begin{document}
-
%{\Huge todo add split to text example with ltxexample\\reference the exact version of penlight used in this library. consider no globals by default\\ COVERT existing examples to extras globals, document hyperref}
\maketitle
@@ -113,33 +112,32 @@ require'penlightextras'
\subsection*{Extras}
+Note: this option is considered experimental.
+The following global variables are defined:
-If \cmd{extras} is used, the following Lua globals will be defined:\\
-
-\subsubsection*{Misc stuff}
-\llcmd{__SKIP_TEX__} If using package with \cmd{texlua}, set this global before loading \cmd{penlight}\\
+\llcmd{__SKIP_TEX__} If using the \cmd{penlight} package with \cmd{texlua} (good for troubleshooting), set this global before loading \cmd{penlight}\\
The gloals flags below are taken care of in the package options:\\
\llcmd{__PL_}\cmd{GLOBALS__} If using package with \cmd{texlua} and you don't want to set some globals (described in next sections), set this global before to \cmd{true} loading \cmd{penlight}\\
\cmd{__SKIP_LUAKEYS__}\\
\cmd{__PL_NO_HYPERREF__}\\
\cmd{__PL_EXTRAS__} false, 1 or 2\\
-\llcmd{hasval(x)} Python-like boolean testing\\
+\subsubsection*{penlight additions}
+
+Some functionality is added to penlight/lua.
+
+\llcmd{pl.hasval(x)} Python-like boolean testing\\
\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\\
-\subsubsection*{\cmd{pl.tex.} module is added}
+\subsubsection*{A \cmd{pl.tex.} module is added}
\llcmd{add_bkt}\cmd{_cnt(n), }\cmd{close_bkt_cnt(n), reset_bkt_cnt} functions to keep track of adding curly brackets as strings. \cmd{add} will return \cmd{n} (default 1) \{'s and increment a counter. \cmd{close} will return \cmd{n} \}'s (default will close all brackets) and decrement.\\
\llcmd{_NumBkts} internal integer for tracking the number of brackets\\
\llcmd{opencmd(cs)} prints \cmd{\cs}\{ and adds to the bracket counters.\\
@@ -166,6 +164,12 @@ is true, it will overwrite an existing command (using \cmd{defcmd}), otherwise,
+\subsubsection*{global extras}
+If \cmd{extrasglobals} is used and NOT \cmd{extras}, many additional globals are set for shortcuts\\
+All \cmd{pl.tex} modules are made global.\\
+\cmd{pl.hasval}, \cmd{pl.COMP}, \cmd{pl.utils.kpairs}, \cmd{pl.utils.npairs} become globals with the function name.\\
+
+
\subsection*{Macro helpers}
\cmd{\MakeluastringCommands[def]{spec}} will let \cmd{\plluastring(A|B|C..)} be \cmd{\luastring(N|O|T|F)}
@@ -221,10 +225,8 @@ spliToItems:
\end{LTXexample}
-\subsubsection*{global extras}
-If \cmd{extrasglobals} is used and NOT \cmd{extras}, many globals are set.\\
-All \cmd{pl.tex} modules are made global.\\
-\cmd{hasval}, \cmd{COMP}, \cmd{kpairs}, \cmd{npairs} are globals.\\
+
+
\section*{}
Disclaimer: I am not the author of the Lua Penlight library.
@@ -233,5 +235,25 @@ All \cmd{pl.tex} modules are made global.\\
\url{https://github.com/lunarmodules/penlight}\\
The author of this library has merged all Lua sub-modules into one file for this package.
-
+% \tblfrkv{tbl_def}{kale=cool,paul=gay,craig=fun}
+% \tblfrkv{tbl}{kale,paul=gay} %[naked_as_value=true]
+%
+% \tblget{tbl}{kale}%
+% \tblget{tbl}{paul}%
+% \tblget{tbl}{craig}%
+%
+% \tblupd{tbl_def}{tbl}%
+%
+% \tblfrkvII{tbl}{kale=cool,paul=gay,craig=fun}{kale=weak,paul=sad}
+% \tblget{tbl}{craig}%
+% \tblget{tbl}{paul}%
+% \tblget{tbl}{kale}%
+%
+% \NewDocumentCommand{\THINg}{ O{} m}{%
+% \tblfrkvII{setti}{color=red,size=small}{#1} % make settings and update based on [arg=]
+% {\color{\tblget{setti}{color}}\tblget{setti}{size} #2}
+% }
+%
+% \THINg[color=blue,size=tiny]{Kale}
+
\end{document} \ No newline at end of file
diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua
index 7d0a7eb6b5..5f5f76aefb 100644
--- a/macros/luatex/generic/penlight/penlightextras.lua
+++ b/macros/luatex/generic/penlight/penlightextras.lua
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2022-10-24
+--% 2023-07-18
--% Copyright (C) 2021-2022 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -28,14 +28,16 @@ __PL_SKIP_LUAKEYS__ = __PL_SKIP_LUAKEYS__ or false
__PL_GLOBALS__ = __PL_GLOBALS__ or false
__PL_EXTRAS__ = 1
__PL_NO_HYPERREF__ = __PL_NO_HYPERREF__ or false
+-- __PENLIGHT__ = 'penlight' or 'pl'
-- requires penlight
local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl
if not __PL_SKIP_LUAKEYS__ then
- luakeys = require'luakeys'
+ luakeys = require'luakeys'()
end
+
-- some bonus string operations, % text operator, and functional programming
pl.stringx.import()
pl.stringx.format_operator()
@@ -311,7 +313,7 @@ function pl.tex.get_ref_info(l)
t = pl.tablex.map(string.trimfl, t)
end
t[#t+1] = r -- add the og return of label
- pl.help_wrt(t, 'ref info')
+ --pl.help_wrt(t, 'ref info')
return t
end
@@ -511,7 +513,7 @@ pl.array2d.map_slice1 = pl.tablex.map_slice
-- todo option for multiple filters with AND logic, like the filter files??
function pl.tablex.filterstr(t, exp, case)
-- case = case sensitive
- case = hasval(case)
+ case = pl.hasval(case)
-- apply lua patterns to a table to filter iter
-- str or table of str's can be passed, OR logic is used if table is passed
if case then
@@ -699,12 +701,11 @@ __PDFmetadata__ = {}
pl.tex.add_xspace_intext = true
-function pl.tex.updatePDFtable(k, v, o)
+function pl.tex.updatePDFtable(k, v, o) -- key val overwrite
k = k:upfirst()
- if not pl.hasval(o) and __PDFmetadata__[k] ~= nil then
- return
+ if pl.hasval(o) or (__PDFmetadata__[k] == nil) then
+ __PDFmetadata__[k] = v
end
- __PDFmetadata__[k] = v
end
pl.tex.writePDFmetadata = function(t) -- write PDF metadata to xmpdata file