diff options
author | Norbert Preining <norbert@preining.info> | 2022-10-16 03:02:53 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-10-16 03:02:53 +0000 |
commit | 84ccc4dcda9db6735202d4ed21610de28392e708 (patch) | |
tree | 5572dd71e0688f59f52d89e22864ae162c88d365 /macros/luatex | |
parent | 716f66d13d38e113c2d0491804fae5879de67bb3 (diff) |
CTAN sync 202210160302
Diffstat (limited to 'macros/luatex')
-rw-r--r-- | macros/luatex/generic/penlight/penlight.pdf | bin | 38483 -> 42045 bytes | |||
-rw-r--r-- | macros/luatex/generic/penlight/penlight.sty | 26 | ||||
-rw-r--r-- | macros/luatex/generic/penlight/penlight.tex | 52 | ||||
-rw-r--r-- | macros/luatex/generic/penlight/penlightextras.lua | 75 |
4 files changed, 144 insertions, 9 deletions
diff --git a/macros/luatex/generic/penlight/penlight.pdf b/macros/luatex/generic/penlight/penlight.pdf Binary files differindex 55eda4b6fe..b0b89352b2 100644 --- a/macros/luatex/generic/penlight/penlight.pdf +++ b/macros/luatex/generic/penlight/penlight.pdf diff --git a/macros/luatex/generic/penlight/penlight.sty b/macros/luatex/generic/penlight/penlight.sty index 04cb66a482..d796f1e1c8 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-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/macros/luatex/generic/penlight/penlight.tex b/macros/luatex/generic/penlight/penlight.tex index f1c07a00cb..869fda37ed 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-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 @@ If you want to use Penlight (and extras) with the \texttt{texlua} intrepreter (n 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 @@ If \cmd{extras} is used, the following Lua globals will be defined:\\ \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,7 +154,47 @@ If \cmd{extras} is used, the following Lua globals will be defined:\\ 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.\\ diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua index 253527cc52..9ce0903f1c 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-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 + |