From a5ae362f44affd15330a416887b5ba01f5aa1860 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 3 Mar 2022 21:07:49 +0000 Subject: penlight (3mar22) git-svn-id: svn://tug.org/texlive/trunk@62373 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/doc/luatex/penlight/README.md | 4 +- Master/texmf-dist/doc/luatex/penlight/penlight.pdf | Bin 38237 -> 38311 bytes Master/texmf-dist/doc/luatex/penlight/penlight.tex | 4 +- Master/texmf-dist/tex/luatex/penlight/penlight.sty | 22 +++--- .../tex/luatex/penlight/penlightextras.lua | 75 ++++++++++++++++++--- 5 files changed, 84 insertions(+), 21 deletions(-) (limited to 'Master/texmf-dist') diff --git a/Master/texmf-dist/doc/luatex/penlight/README.md b/Master/texmf-dist/doc/luatex/penlight/README.md index 818fb7d4ea3..ca66c41b745 100644 --- a/Master/texmf-dist/doc/luatex/penlight/README.md +++ b/Master/texmf-dist/doc/luatex/penlight/README.md @@ -1,11 +1,11 @@ # penlight -- Lua libraries for use in LuaLaTeX -This LuaLaTeX package provides a thin-wrapper to use the [penlight](https://github.com/lunarmodules/Penlight) Lua libraries with LuaLaTeX. +This LuaLaTeX package provides a wrapper to use the [penlight](https://github.com/lunarmodules/Penlight) Lua libraries with LuaLaTeX, with some extra functionality added. # License -Copyright (C) 2021 Kale Ewasiuk +Copyright (C) 2021-2022 Kale Ewasiuk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/doc/luatex/penlight/penlight.pdf b/Master/texmf-dist/doc/luatex/penlight/penlight.pdf index a8e166a1ae4..33f3457df2a 100644 Binary files a/Master/texmf-dist/doc/luatex/penlight/penlight.pdf and b/Master/texmf-dist/doc/luatex/penlight/penlight.pdf differ diff --git a/Master/texmf-dist/doc/luatex/penlight/penlight.tex b/Master/texmf-dist/doc/luatex/penlight/penlight.tex index 176dc4e5572..2096c10b682 100644 --- a/Master/texmf-dist/doc/luatex/penlight/penlight.tex +++ b/Master/texmf-dist/doc/luatex/penlight/penlight.tex @@ -1,6 +1,6 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-02-27 -% Copyright (C) 2021 Kale Ewasiuk +% 2022-03-03 +% Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal diff --git a/Master/texmf-dist/tex/luatex/penlight/penlight.sty b/Master/texmf-dist/tex/luatex/penlight/penlight.sty index b9f5a9490a9..936cb6dce72 100644 --- a/Master/texmf-dist/tex/luatex/penlight/penlight.sty +++ b/Master/texmf-dist/tex/luatex/penlight/penlight.sty @@ -1,6 +1,6 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-02-27 -% Copyright (C) 2021 Kale Ewasiuk +% 2022-03-03 +% Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal @@ -22,7 +22,7 @@ % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE % OR OTHER DEALINGS IN THE SOFTWARE. -\ProvidesPackage{penlight}[2022-02-27] +\ProvidesPackage{penlight}[2022-03-03] \RequirePackage{luacode} @@ -32,17 +32,23 @@ }} \DeclareOption{penlight}{\luadirect{ penlight = require('penlight') - __PENLIGHT__ = 'penlight' + __PENLIGHT__ = 'penlight' }} \DeclareOption{stringx}{\luadirect{_G[__PENLIGHT__].stringx.import()}} \DeclareOption{format}{\luadirect{_G[__PENLIGHT__].stringx.format_operator()}} \DeclareOption{func}{\luadirect{_G[__PENLIGHT__].utils.import(__PENLIGHT__..'.func')}} -\DeclareOption{extras}{\luadirect{require('penlightextras')}} -\DeclareOption{extrasnoglobals}{ +\DeclareOption{extras}{\luadirect{require'penlightextras'}} +\DeclareOption{extrasnoglobals}{\luadirect{ __PL_NO_GLOBALS__ = true - \luadirect{require('penlightextras') - }} + require'penlightextras' +}} \ProcessOptions*\relax + +\luadirect{ +if __PENLIGHT__ == nil then + tex.print('\\PackageError{penlight}{penlight or pl option must be passed to penlight as the first option}{}') +end +} diff --git a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua b/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua index 0cdec037631..192c86c9231 100644 --- a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua +++ b/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua @@ -1,8 +1,31 @@ +--% Kale Ewasiuk (kalekje@gmail.com) +--% 2022-03-03 +--% Copyright (C) 2021-2022 Kale Ewasiuk +--% +--% Permission is hereby granted, free of charge, to any person obtaining a copy +--% of this software and associated documentation files (the "Software"), to deal +--% in the Software without restriction, including without limitation the rights +--% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +--% copies of the Software, and to permit persons to whom the Software is +--% furnished to do so, subject to the following conditions: +--% +--% The above copyright notice and this permission notice shall be included in +--% all copies or substantial portions of the Software. +--% +--% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +--% ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +--% TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +--% PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +--% SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR +--% ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +--% ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +--% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE +--% OR OTHER DEALINGS IN THE SOFTWARE. __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) - __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 @@ -10,8 +33,8 @@ local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl -- some bonus string operations, % text operator, and functional programming pl.stringx.import() -pl.text.format_operator() -pl.utils.import('pl.func') -- allow placeholder expressions _1 +1 etc. +pl.stringx.format_operator() +pl.utils.import'pl.func' -- allow placeholder expressions _1 +1 etc. pl.COMP = require'pl.comprehension'.new() -- for comprehensions @@ -561,15 +584,48 @@ end +-- https://tex.stackexchange.com/questions/38150/in-lualatex-how-do-i-pass-the-content-of-an-environment-to-lua-verbatim +pl.tex.recordedbuf = "" +function pl.tex.readbuf(buf) + i,j = string.find(buf, '\\end{%w+}') + if i==nil then -- if not ending an environment + pl.tex.recordedbuf = pl.tex.recordedbuf .. buf .. "\n" + return "" + else + return nil + end +end + +function pl.tex.startrecording() + pl.tex.recordedbuf = "" + luatexbase.add_to_callback('process_input_buffer', pl.tex.readbuf, 'readbuf') +end + +function pl.tex.stoprecording() + luatexbase.remove_from_callback('process_input_buffer', 'readbuf') + pl.tex.recordedbuf = pl.tex.recordedbuf:gsub("\\end{%w+}\n","") +end + + + + if not __PL_NO_GLOBALS__ then + __PL_EXTRAS__ = 2 -- iterators kpairs = pl.utils.kpairs npairs = pl.utils.npairs --enum = utils.enum for k,v in pairs(pl.tablex) do -- extend the table table to contain tablex functions - _G['table'][k] = v + if k == 'sort' then + table.sortk = v + elseif k == 'move' then + table.xmove = v + else + _G['table'][k] = v + end end + table.join = table.concat -- alias hasval = pl.hasval COMP = pl.COMP @@ -589,6 +645,12 @@ if not __PL_NO_GLOBALS__ then _G[k] = v end +end + + + + + --_xTrue = pl.tex._xTrue --_xFalse = pl.tex._xFalse --_xNoValue = pl.tex._xNoValue @@ -619,11 +681,6 @@ if not __PL_NO_GLOBALS__ then --add_bkt_cnt = pl.tex.add_bkt_cnt --close_bkt_cnt = pl.tex.close_bkt_cnt -end - - - - -- graveyard -- cgit v1.2.3