diff options
Diffstat (limited to 'macros/luatex')
-rw-r--r-- | macros/luatex/generic/penlightplus/penlightplus.lua | 2 | ||||
-rw-r--r-- | macros/luatex/generic/penlightplus/penlightplus.pdf | bin | 78922 -> 87755 bytes | |||
-rw-r--r-- | macros/luatex/generic/penlightplus/penlightplus.sty | 24 | ||||
-rw-r--r-- | macros/luatex/generic/penlightplus/penlightplus.tex | 9 | ||||
-rw-r--r-- | macros/luatex/latex/luatbls/luatbls.lua | 12 | ||||
-rw-r--r-- | macros/luatex/latex/luatbls/luatbls.pdf | bin | 76652 -> 85700 bytes | |||
-rw-r--r-- | macros/luatex/latex/luatbls/luatbls.sty | 26 | ||||
-rw-r--r-- | macros/luatex/latex/luatbls/luatbls.tex | 30 |
8 files changed, 61 insertions, 42 deletions
diff --git a/macros/luatex/generic/penlightplus/penlightplus.lua b/macros/luatex/generic/penlightplus/penlightplus.lua index b982d45a0a..21596fac07 100644 --- a/macros/luatex/generic/penlightplus/penlightplus.lua +++ b/macros/luatex/generic/penlightplus/penlightplus.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2025-02-11 +--% 2025-02-14 --% Copyright (C) 2021-2025 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/macros/luatex/generic/penlightplus/penlightplus.pdf b/macros/luatex/generic/penlightplus/penlightplus.pdf Binary files differindex 0b5b2744dd..7544f0d5cf 100644 --- a/macros/luatex/generic/penlightplus/penlightplus.pdf +++ b/macros/luatex/generic/penlightplus/penlightplus.pdf diff --git a/macros/luatex/generic/penlightplus/penlightplus.sty b/macros/luatex/generic/penlightplus/penlightplus.sty index f50ac14faf..7e33fbce93 100644 --- a/macros/luatex/generic/penlightplus/penlightplus.sty +++ b/macros/luatex/generic/penlightplus/penlightplus.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2025-02-11 +% 2025-02-14 % Copyright (C) 2021-2025 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{penlightplus}[2025-02-11] +\ProvidesPackage{penlightplus}[2025-02-14] \RequirePackage{luacode} \RequirePackage{luakeys} @@ -44,10 +44,10 @@ \NewDocumentCommand{\writePDFmetadatakv}{ s O{f} m }{% \MakeluastringCommands[f]{#2}% -\IfBooleanTF{#1}{% if *, overwrite everything +\IfBooleanTF{#1}{% if *, delete existing data \luadirect{ __PDFmetadata__ = penlight.tex.makePDFtablekv(\plluastringA{#3}) - }}{ + }}{ % if no star, update \luadirect{ __PDFmetadata__ = __PDFmetadata__ or {} penlight.tablex.update(__PDFmetadata__, penlight.tex.makePDFtablekv(\plluastringA{#3})) @@ -73,8 +73,6 @@ %\gdef\luastringE#1{\begin{luastringeenv#1\endluastringeenv} - - % allow control over expansion of arguments to a latex function \NewDocumentCommand{\MakeluastringCommands}{O{} m }{% #1 the desired commands #2 defaults \luadirect{penlight.tex.aliasluastring(\luastring{#2},\luastring{#1})}% @@ -85,25 +83,17 @@ - - %%%% \newtoggle{luaexpr}\togglefalse{luaexpr} - - -\NewDocumentCommand{\ifluax}{m m O{}}{% if lua expression is true do {m} if not [o] - \luadirect{penlight.toggle_luaexpr(#1)}% +\NewDocumentCommand{\ifluax}{m +m +O{}}{% if lua expression is true do {m} if not [o] + \luadirect{penlight.toggle_luaexpr(\expanded{#1})}% \iftoggle{luaexpr}{#2}{#3}% \togglefalse{luaexpr}% safety set to false } -\NewDocumentCommand{\ifluaxv}{m m O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}% if lua expression is truthy do {m} else [o] - - - - +\NewDocumentCommand{\ifluaxv}{m +m +O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}% if lua expression is truthy do {m} else [o] \NewDocumentCommand{\caseswitch}{s m +m}{\ignorespaces\luadirect{penlight.caseswitch(\luastring{#1},\luastring{#2},\luastringN{#3})}\unskip} diff --git a/macros/luatex/generic/penlightplus/penlightplus.tex b/macros/luatex/generic/penlightplus/penlightplus.tex index 09d63fbca5..78b5ee846a 100644 --- a/macros/luatex/generic/penlightplus/penlightplus.tex +++ b/macros/luatex/generic/penlightplus/penlightplus.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2025-02-11 +% 2025-02-14 % Copyright (C) 2021-2025 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,6 +24,7 @@ \documentclass[11pt,parskip=half]{scrartcl} +\usepackage[default]{lato} \setlength{\parindent}{0ex} \newcommand{\llcmd}[1]{\leavevmode\llap{\texttt{\detokenize{#1}}}} \newcommand{\cmd}[1]{\texttt{\detokenize{#1}}} @@ -133,7 +134,7 @@ Some functionality is added to penlight and Lua. \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\\ -\llcmd{pl.}{trysplitcomma(s)} will try to split a string on comma (and strip), but if is a table, leave it +\llcmd{pl.}\cmd{trysplitcomma(s)} will try to split a string on comma (and strip), but if is a table, leave it \llcmd{pl.}\cmd{findfiles{}} or \cmd{findfiles'kv'} is an updated version of \cmd{filterfiles}. Pass a table or a luakeys kv string as the only argument. Valid table options are: \cmd{fn, dir, ext, sub}. @@ -379,7 +380,9 @@ Use \_\_ as a placeholder for a case that isn't matched. The case is fully expan \subsection*{PDF meta data (for pdfx package)} -\cmd{\writePDFmetadatakv*[x]{kv}} Take a key-value string (eg. \cmd{title=whatever, author=me}) and then writes to the \cmd{jobname.xmpdata} file, which is used by pdfx. \cmd{*} will first clear \cmd{__PDFmetadata__} which contains the metadata. The un-starred version updates that table. +\cmd{\writePDFmetadatakv*[x]{kv}} Take a key-value string (eg. \cmd{title=whatever, author=me}) and then writes to the \cmd{jobname.xmpdata} file, which is used by pdfx. +\cmd{*} will first clear \cmd{__PDFmetadata__} which is the table variable that stores the metadata. +The un-starred version updates that table. You can control the expansion of the key-val argument with \cmd{[x]}, which is fully expanded by default. Command sequences are ultimately stripped from the values, except for \cmd{\and} is converted to \cmd{\sep} for pdfx usage (\url{https://texdoc.org/serve/pdfx/0}). \\ diff --git a/macros/luatex/latex/luatbls/luatbls.lua b/macros/luatex/latex/luatbls/luatbls.lua index 5cb1e29ab3..1904b814d3 100644 --- a/macros/luatex/latex/luatbls/luatbls.lua +++ b/macros/luatex/latex/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/macros/luatex/latex/luatbls/luatbls.pdf b/macros/luatex/latex/luatbls/luatbls.pdf Binary files differindex c9c25d8c4a..e3d7d89042 100644 --- a/macros/luatex/latex/luatbls/luatbls.pdf +++ b/macros/luatex/latex/luatbls/luatbls.pdf diff --git a/macros/luatex/latex/luatbls/luatbls.sty b/macros/luatex/latex/luatbls/luatbls.sty index f52facd7df..c11c47118b 100644 --- a/macros/luatex/latex/luatbls/luatbls.sty +++ b/macros/luatex/latex/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')}} diff --git a/macros/luatex/latex/luatbls/luatbls.tex b/macros/luatex/latex/luatbls/luatbls.tex index ff807d013b..391e1111c8 100644 --- a/macros/luatex/latex/luatbls/luatbls.tex +++ b/macros/luatex/latex/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\\ |