summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/penlightplus/penlightplus.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2023-09-06 03:01:07 +0000
committerNorbert Preining <norbert@preining.info>2023-09-06 03:01:07 +0000
commit30e902c79d7838a9ec84133dec2415eb48968762 (patch)
tree98f80627e917fc91308cdd784a43e58ce7e187f4 /macros/luatex/generic/penlightplus/penlightplus.tex
parent42959ab19eab5531850a6067d53d13f777ec160b (diff)
CTAN sync 202309060301
Diffstat (limited to 'macros/luatex/generic/penlightplus/penlightplus.tex')
-rw-r--r--macros/luatex/generic/penlightplus/penlightplus.tex63
1 files changed, 42 insertions, 21 deletions
diff --git a/macros/luatex/generic/penlightplus/penlightplus.tex b/macros/luatex/generic/penlightplus/penlightplus.tex
index fec72b8dfd..fbc4ec32d5 100644
--- a/macros/luatex/generic/penlightplus/penlightplus.tex
+++ b/macros/luatex/generic/penlightplus/penlightplus.tex
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2023-08-27
+% 2023-09-04
% Copyright (C) 2021-2023 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -58,6 +58,8 @@
\title{penlightplus}
\subtitle{Additions to the Penlight Lua Libraries}
+
+
\begin{document}
%
@@ -72,15 +74,17 @@ If you want to use penlightplus.lua with the \texttt{texlua} interpreter
(no document is made, but useful for testing your Lua code),
you can access it by setting \cmd{__SKIP_TEX__ = true} before loading. For example:
\begin{verbatim}
-package.path = package.path .. ';'..'path/to/texmf/tex/latex/penlightplus/?.lua'
-package.path = package.path .. ';'..'path/to/texmf/tex/latex/penlight/?.lua'
+package.path = package.path .. ';'..'path/to/texmf/tex/lualatex/penlightplus/?.lua'
+package.path = package.path .. ';'..'path/to/texmf/tex/lualatex/penlight/?.lua'
penlight = require'penlight'
__SKIP_TEX__ = true --only required if you want to use
--penlightplus without a LaTeX run
__PL_GLOBALS__ = true -- optional, include global definitions
+
require'penlightplus'
-\end{verbatim}
+
+ \end{verbatim}
@@ -182,7 +186,7 @@ no, once, twice, or full expansion. For example, we can control the expansion of
\cmd{\ifluax{<Lua expr>}{<do if true>}[<do if false>]} and\\ \cmd{\ifluax{<Lua expr>}{<do if true>}[<do if false>]} for truthy (uses \cmd{penlight.hasval})
-\begin{LTXexample}
+\begin{LTXexample}[width=0.3\linewidth]
\ifluax{3^3 == 27}{3*3*3 is 27}[WRONG]\\
\ifluax{abc123 == nil}{Var is nil}[WRONG]\\
\ifluax{not true}{tRuE}[fAlSe]\\
@@ -197,38 +201,55 @@ no, once, twice, or full expansion. For example, we can control the expansion of
\cmd{\newtbl{t}} declares a new table with name \cmd{t}\\
\cmd{\chgtbl{t}} changes the 'recent' table\\
-\cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals, used \cmd{luakeys} \\
+\cmd{\tblfrkv{t}{key-val string}[luakeys opts]} new table from key-vals using \cmd{luakeys} \\
+ \cmd{\tblfrcsv} a shorthand \cmd{\tblfrkv{t}{csv}[naked_as_value=true,opts]}, a good way to convert a comma-separated list to an array\\
\cmd{\settbl{i}{v}} sets a value of the table/index \cmd{i} to \cmd{v}\\
\cmd{\gettbl{i}} gets the value and \cmd{tex.sprint()}'s it\\
\cmd{\deftbl{i}{d}} pushes the value to a \cmd{cs} named \cmd{d}\\
\cmd{\gdeftbl{i}{d}} pushes the value to a global\\
-\cmd{\iftbl{i}{t}[f]} runs code \cmd{t} if the item is true else \cmd{f}\\
-\cmd{\iftblv{i}{t}[f]} runs code \cmd{t} if the item is truthy else \cmd{f}\\
+\cmd{\iftbl{i}{tr}[fa]} runs code \cmd{ta} if the item is true else \cmd{fr}\\
+\cmd{\iftblv{i}{tr}[fa]} runs code \cmd{ta} if the item is truthy else \cmd{fr}\\
+\cmd{\kvtblundefcheck} will throw an error if you use define a table from key-values
+and use a key that was not specified in the luakeys parse options via \cmd{opts.defaults} or \cmd{opts.defs}.
There are 3 ways to use the index (placeholder \cmd{{i}} above).
\cmd{t.key} where \cmd{t} is the table name and \cmd{key} is a string key,
-\cmd{t/int} where \cmd{int} is a numeric indexer (ie uses \cmd{t[int]}),
-or simply \cmd{ind} without the table name, where the assumed table is the last one that was created or changed to, (pure-numbers are not treated as strings in this case).
-
-\begin{LTXexample}
-\tblfrkv{my}{a,b,c,first=john,last=smith}[defaults={x=0,1=one,n=false,y=yes}, naked_as_value=true]
-
-\settbl{my/4}{d}\gettbl{my/4}\\
-\settbl{5}{e}\gettbl{5}\\
+\cmd{t/int} where \cmd{int} is an integer index (ie. uses \cmd{t[int]}, note that negative indexes are allowered where -1 is the last element),
+or simply use \cmd{ind} without the table name, where the assumed table is the last one that was created or changed to, (passing a number will used as an integer index).
+\enlargethispage{2em}
+\begin{LTXexample}[width=0.3\linewidth]
+\tblfrkv{my}{a,b,c,first=john,last=smith}%
+ [defaults={x=0,1=one,n=false,y=yes}]
+\gettbl{my.a}\\
\gettbl{my.x}\\
-\iftbl{n}{t}[f]\\
-\iftblv{n}{t}[f]\\
-\iftbl{my.y}{t}[f]\\
-\iftblv{y}{t}[f]\\
+\iftbl{n}{tr}[fa]\\
+\iftblv{n}{TR}[FA]\\
+\iftbl{my.y}{Tr}[Fa]\\
+\iftblv{y}{tR}[fA]\\
+%% \kvtblundefcheck % would throw error
+\deftbl{my.first}{mydef} \mydef\\
+{\deftbl{last}{mydef} \mydef} \mydef\\
+{\gdeftbl{last}{mydef}} \mydef\\
+
+\tblfrcsv{me}{a,b,"c,see",d,e}
+\gettbl{me/1},\gettbl{2}\\
+\gettbl{3}\\
+\settbl{me/4}{D}\gettbl{me/4}\\
+\settbl{5}{E}\gettbl{5}\\
+\gettbl{-2},\gettbl{me/-1}\\
+%% \gettbl{k} % would throw error
\end{LTXexample}
+
+
+
\subsection*{Splitting strings}
Splitting text (or a cmd) into oxford comma format via:
\cmd{\splitToComma[expansion level]{text}{text to split on}}:
-\begin{LTXexample}
+\begin{LTXexample}[width=0.3\linewidth]
-\splitToComma{ j doe }{\and}-\\
-\splitToComma{ j doe \and s else }{\and}-\\
-\splitToComma{ j doe \and s else \and a per }{\and}-\\