| 1 |
% Kale Ewasiuk ([email protected]) |
| 2 |
% 2025-02-14 |
| 3 |
% Copyright (C) 2021-2025 Kale Ewasiuk |
| 4 |
% |
| 5 |
% Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 |
% of this software and associated documentation files (the "Software"), to deal |
| 7 |
% in the Software without restriction, including without limitation the rights |
| 8 |
% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 |
% copies of the Software, and to permit persons to whom the Software is |
| 10 |
% furnished to do so, subject to the following conditions: |
| 11 |
% |
| 12 |
% The above copyright notice and this permission notice shall be included in |
| 13 |
% all copies or substantial portions of the Software. |
| 14 |
% |
| 15 |
% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF |
| 16 |
% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED |
| 17 |
% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 18 |
% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT |
| 19 |
% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR |
| 20 |
% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 |
% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 |
% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE |
| 23 |
% OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
\ProvidesPackage{penlightplus}[2025-02-14] |
| 26 |
|
| 27 |
\RequirePackage{luacode} |
| 28 |
\RequirePackage{luakeys} |
| 29 |
\RequirePackage[import]{penlight} |
| 30 |
\RequirePackage{etoolbox} |
| 31 |
\RequirePackage{tokcycle} |
| 32 |
|
| 33 |
|
| 34 |
\DeclareOption{globals}{\luadirect{__PL_GLOBALS__ = true}} |
| 35 |
\DeclareOption{pl}{\directlua{pl = penlight}} |
| 36 |
\ProcessOptions*\relax |
| 37 |
|
| 38 |
\luadirect{require'penlightplus'} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
\global\newcommand{\writePDFmetadata}{\luadirect{penlight.tex.writePDFmetadata()}} |
| 44 |
|
| 45 |
\NewDocumentCommand{\writePDFmetadatakv}{ s O{f} m }{% |
| 46 |
\MakeluastringCommands[f]{#2}% |
| 47 |
\IfBooleanTF{#1}{% if *, delete existing data |
| 48 |
\luadirect{ |
| 49 |
__PDFmetadata__ = penlight.tex.makePDFtablekv(\plluastringA{#3}) |
| 50 |
}}{ % if no star, update |
| 51 |
\luadirect{ |
| 52 |
__PDFmetadata__ = __PDFmetadata__ or {} |
| 53 |
penlight.tablex.update(__PDFmetadata__, penlight.tex.makePDFtablekv(\plluastringA{#3})) |
| 54 |
}}% |
| 55 |
\writePDFmetadata{}% |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
\gdef\luastringT#1{\luastring{\unexpanded\expandafter\expandafter\expandafter{#1}}} % expand luastring twice |
| 61 |
\global\let\luastringF\luastring % fully expanded luastring |
| 62 |
|
| 63 |
% |
| 64 |
%\xtokcycleenvironment\luastringeenv |
| 65 |
% {\addcytoks{##1}} |
| 66 |
% {\processtoks{##1}} |
| 67 |
% {\addcytoks[1]{##1}} |
| 68 |
% {\addcytoks{##1}} |
| 69 |
% {} |
| 70 |
% {\cytoks\expandafter{\expandafter\luastringO\expandafter{\the\cytoks}}} |
| 71 |
% |
| 72 |
%\def\luastringE#1{\luastringeenv#1\endluastringeenv} |
| 73 |
%\gdef\luastringE#1{\begin{luastringeenv#1\endluastringeenv} |
| 74 |
|
| 75 |
|
| 76 |
% allow control over expansion of arguments to a latex function |
| 77 |
\NewDocumentCommand{\MakeluastringCommands}{O{} m }{% #1 the desired commands #2 defaults |
| 78 |
\luadirect{penlight.tex.aliasluastring(\luastring{#2},\luastring{#1})}% |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
%%%% |
| 87 |
|
| 88 |
\newtoggle{luaexpr}\togglefalse{luaexpr} |
| 89 |
|
| 90 |
\NewDocumentCommand{\ifluax}{m +m +O{}}{% if lua expression is true do {m} if not [o] |
| 91 |
\luadirect{penlight.toggle_luaexpr(\expanded{#1})}% |
| 92 |
\iftoggle{luaexpr}{#2}{#3}% |
| 93 |
\togglefalse{luaexpr}% safety set to false |
| 94 |
} |
| 95 |
|
| 96 |
\NewDocumentCommand{\ifluaxv}{m +m +O{}}{\ifluax{penlight.hasval(#1)}{#2}[#3]}% if lua expression is truthy do {m} else [o] |
| 97 |
|
| 98 |
|
| 99 |
\NewDocumentCommand{\caseswitch}{s m +m}{\ignorespaces\luadirect{penlight.caseswitch(\luastring{#1},\luastring{#2},\luastringN{#3})}\unskip} |
| 100 |
% argument 1 is star option, which throws an error if case is not found |
| 101 |
% argument 2 is the case, fully expanded |
| 102 |
% argument 3 is a luakeys table of options, not expanded |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|