summaryrefslogtreecommitdiff
path: root/Master
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2025-02-15 21:24:12 +0000
committerKarl Berry <karl@freefriends.org>2025-02-15 21:24:12 +0000
commitab1ede6089420f3d462f8053f78acf6b51f1a933 (patch)
tree9f7d87075c3d73aa5b01d597a61371e3cda79b31 /Master
parent28224addd410e91001a20438346b754380b1bb20 (diff)
luatbls (15feb25)
git-svn-id: svn://tug.org/texlive/trunk@73999 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master')
-rw-r--r--Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdfbin76652 -> 85700 bytes
-rw-r--r--Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex30
-rw-r--r--Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua12
-rw-r--r--Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty26
4 files changed, 47 insertions, 21 deletions
diff --git a/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf b/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf
index c9c25d8c4aa..e3d7d890429 100644
--- a/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf
+++ b/Master/texmf-dist/doc/lualatex/luatbls/luatbls.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex b/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex
index ff807d013b7..391e1111c8f 100644
--- a/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex
+++ b/Master/texmf-dist/doc/lualatex/luatbls/luatbls.tex
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2025-01-05
+% 2025-02-14
% Copyright (C) 2025 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -23,7 +23,9 @@
% OR OTHER DEALINGS IN THE SOFTWARE.
+
\documentclass[11pt,parskip=half]{scrartcl}
+\usepackage[default]{lato}
\usepackage[left=0.75in,right=0.75in,top=1in,bottom=1in]{geometry}
\setlength{\parindent}{0ex}
\newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}}}}
@@ -97,7 +99,7 @@ In this documentation, arguments are represented as follows:\\
\llcmd{opts }: options for \cmd{luakeys.parse()}.\\
\llcmd{cstemp }: a template for command-sequences, lengths, or toggles. By default is \cmd{ltbl<t><k>}.\\
-There are a few ways to use the index (placeholder \cmd{i}.\\
+There are a few ways to use the index (placeholder \cmd{i}).\\
\cmd{t.k} where \cmd{t} is the table name and \cmd{k} is a string key (i.e. uses \cmd{luatbls.t.k}),\\
\cmd{t/n} where \cmd{n} is an integer index (i.e. uses \cmd{t.k[n]}); note that negative indexes are allowed where -1 is the last element.
Alternatively, \cmd{t} and the symbol can be omitted, and simply pass the element without the table name as a prefix,
@@ -140,13 +142,16 @@ which will not expand the \cmd{v}, \cmd{keyval}, or \cmd{csv} args.
\cmd{\tblchg{t}} changes the 'recent' table\\
\\
\cmd{\tblfrkv{t}{keyval}[opts]} new table from key-vals using \cmd{luakeys} \\
-\cmd{\tblfrkvN{t}{keyval}[opts]} does not expand key-val string \cmd{luakeys} \\
-
-\cmd{\tblkvundefcheck} 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}.\\
+\cmd{\tblfrkvN{t}{keyval}[opts]} does not expand key-val string \cmd{luakeys}. Note:
+\cmd{opts} are parsed using luakeys with the \cmd{naked_as_value=true}, so booleans must be explicitly set.\\
\\
\cmd{\tblfrcsv{t}{csv}[opts]} a shorthand \cmd{\tblfrkv{t}{csv}[naked_as_value=true,opts]}, a good way to convert a comma-separated list to an array\\
\cmd{\tblfrcsvN{t}{csv}[opts]} same as above, but the csv is not expanded.\\
+\\
+\cmd{\tblkvundefcheck} 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}.\\
+\\
+\cmd{\tblenforcechoices{i}{csv}} will throw an error if the value of item \cmd{i} is not in the provided \cmd{csv}
\subsection*{Setting, getting, and modifying}
@@ -204,16 +209,23 @@ The validity of table names and keys are not checked.\\
\cmd{\tblif{i}{tr}[fa]} runs code \cmd{tr} if the item is true else \cmd{fa}\\
\cmd{\tblifv{i}{tr}[fa]} runs code \cmd{tr} if the item is truth-y (using \cmd{pl.hasval}) else \cmd{fa}\\
-\cmd{\tblifeq{i}{v}{tr}[fa]} checks the equivalency of to a user-specified value. Quotes must be used to indicate strings.
+\cmd{\tblifeq{i}{v}{tr}[fa]} checks the equivalency of to a user-specified value.
+The value is fully expanded. Quotes must be used to indicate strings.\\
+\cmd{\tblifeqstr{i}{v}{tr}[fa]} checks the equivalency of to a user-specified value to a string (uses luastring).
\begin{LTXexample}
+ \def\JJ{1}
\tblfrcsv{x}{n=false,y=true,
- k0="",kv=val,k2=6}
+ k0="",kv=val,k2=6,
+ k1=1,k11="1",
+}
\tblif{n}{tr}[FA]\\
\tblif{k0}{TR}[fa]\\
\tblifv{k0}{tr}[FA]\\
\tblifeq{kv}{'val'}{TR}[fa]\\
\tblifeq{k2}{6}{TR}[fa]\\
+\tblifeq{k1}{\JJ}{Tr}
+\tblifeqstr{k11}{\JJ}{Tr}
\end{LTXexample}
@@ -294,7 +306,7 @@ plain numbers are found, \cmd{sp} units are used (in case the \cmd{convert_dimen
\begin{LTXexample}
- \tblfrkv{ex}{alen=1cm,blen=2cm,clen=10mm*2+2cm}[convert_dimensions]
+ \tblfrkv{ex}{alen=1cm,blen=2cm,clen=10mm*2+2cm}[convert_dimensions=true]
\tblmakelengths{}[<k>]
I\hspace{\alen}I\\
I\hspace{\blen}I\\
diff --git a/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua b/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua
index 5cb1e29ab31..1904b814d32 100644
--- a/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua
+++ b/Master/texmf-dist/tex/lualatex/luatbls/luatbls.lua
@@ -1,5 +1,5 @@
--% Kale Ewasiuk (kalekje@gmail.com)
---% 2025-01-05
+--% 2025-02-14
--% Copyright (C) 2025 Kale Ewasiuk
--%
--% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -150,6 +150,16 @@ function luatbls._check_recent_tbl_undefault()
end
end
+function luatbls._check_choices(k, csv)
+ local csv = penlight.List(luatbls._luakeys.parse(csv,{naked_as_value=true}))
+ local v = luatbls._get_tbl_item(k)
+ if not csv:contains(v) then
+ penlight.tex.pkgerror('luatbls', 'Invalid choice "'..v..'" given to tbl.key "'..k..'". Allowed choices are: '..
+ (', '):join(csv))
+ end
+end
+
+
function luatbls._make_alpha_key(k)
if tonumber(k) ~= nil then
k = penlight.Char(tonumber(k))
diff --git a/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty b/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty
index f52facd7df6..c11c47118ba 100644
--- a/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty
+++ b/Master/texmf-dist/tex/lualatex/luatbls/luatbls.sty
@@ -1,5 +1,5 @@
% Kale Ewasiuk (kalekje@gmail.com)
-% 2025-01-05
+% 2025-02-14
% Copyright (C) 2025 Kale Ewasiuk
%
% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -41,13 +41,13 @@
}}
\NewDocumentCommand{\tblfrkv}{m +m O{}}{\luadirect{% parse a tbl from key-vals, naked are set to boolean
- luatbls._rec_tbl_opts = luatbls._luakeys.parse(\luastring{#3})
+ luatbls._rec_tbl_opts = luatbls._luakeys.parse(\luastring{#3}, {naked_as_value=true})
luatbls[\luastring{#1}] = luatbls._luakeys.parse(string.subpar(\luastring{#2}), luatbls._rec_tbl_opts)
luatbls._rec_tbl = \luastring{#1}
}}
\NewDocumentCommand{\tblfrkvN}{m +m O{}}{\luadirect{%
- luatbls._rec_tbl_opts = luatbls._luakeys.parse(\luastring{#3})
+ luatbls._rec_tbl_opts = luatbls._luakeys.parse(\luastring{#3}, {naked_as_value=true})
luatbls[\luastring{#1}] = luatbls._luakeys.parse(string.subpar(\luastringN{#2}), luatbls._rec_tbl_opts)
luatbls._rec_tbl = \luastring{#1}
}}
@@ -58,6 +58,9 @@
\NewDocumentCommand{\tblkvundefcheck}{}{\luadirect{luatbls._check_recent_tbl_undefault()}}% check defaults list and throw error if foreign keys were used
+\NewDocumentCommand{\tblenforcechoices}{m m}{\luadirect{luatbls._check_choices(\luastring{#1},\luastring{#2})}}
+
+
\NewDocumentCommand{\tblapp}{m m}{\luadirect{% append to a table (ie using integer index) with a value (second arg)
@@ -134,18 +137,20 @@
\NewDocumentCommand{\tblsetE}{m m}{\luadirect{luatbls.#1 = #2}}% set item with {value}
-\NewDocumentCommand{\tblif}{ m m O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
+\NewDocumentCommand{\tblif}{ m +m +O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
-\NewDocumentCommand{\tblifv}{m m O{}}{\ifluaxv{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
+\NewDocumentCommand{\tblifv}{m +m +O{}}{\ifluaxv{luatbls._get_tbl_item(\luastring{#1})}{#2}[#3]}
-\NewDocumentCommand{\tblifeq}{m m m O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1}) == #2}{#3}[#4]}
+\NewDocumentCommand{\tblifeq}{m m +m +O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1}) == \expanded{#2}}{#3}[#4]}
+\NewDocumentCommand{\tblifeqstr}{m m +m +O{}}{\ifluax{luatbls._get_tbl_item(\luastring{#1}) == \luastring{#2}}{#3}[#4]}
-\NewDocumentCommand{\tblfor}{ m m }{\luadirect{luatbls._for_tbl(\luastring{#1}, \luastring{#2})}}
-\NewDocumentCommand{\tblforN}{ m m }{\luadirect{luatbls._for_tbl(\luastring{#1}, \luastringN{#2})}}
-\NewDocumentCommand{\tblforE}{ m m }{\luadirect{luatbls._for_tbl_e(luatbls.#1, \luastring{#2})}}
-\NewDocumentCommand{\tblforEN}{ m m }{\luadirect{luatbls._for_tbl_e(luatbls.#1, \luastringN{#2})}}
+\NewDocumentCommand{\tblfor}{ m +m }{\luadirect{luatbls._for_tbl(\luastring{#1}, \luastring{#2})}}
+\NewDocumentCommand{\tblforN}{ m +m }{\luadirect{luatbls._for_tbl(\luastring{#1}, \luastringN{#2})}}
+
+\NewDocumentCommand{\tblforE}{ m +m }{\luadirect{luatbls._for_tbl_e(luatbls.#1, \luastring{#2})}}
+\NewDocumentCommand{\tblforEN}{ m +m }{\luadirect{luatbls._for_tbl_e(luatbls.#1, \luastringN{#2})}}
\NewDocumentCommand{\tbldef}{ m o }{\luadirect{luatbls._def_tbl(\luastring{#1}, \luastring{#2})}}
@@ -158,7 +163,6 @@
\ProvideDocumentCommand{\providenewlength}{ m }{\ifdeflength{#1}{}{\newlength{#1}}}
-
\NewDocumentCommand{\tblmaketoggle}{ m o }{\luadirect{luatbls._make_toggle_tbl(\luastring{#1}, \luastring{#2})}}
\NewDocumentCommand{\tblmakegtoggle}{ m o }{\luadirect{luatbls._make_toggle_tbl(\luastring{#1}, \luastring{#2}, '\\global')}}