summaryrefslogtreecommitdiff
path: root/macros/luatex/generic/penlight/penlightextras.lua
diff options
context:
space:
mode:
Diffstat (limited to 'macros/luatex/generic/penlight/penlightextras.lua')
-rw-r--r--macros/luatex/generic/penlight/penlightextras.lua75
1 files changed, 66 insertions, 9 deletions
diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua
index 0cdec03763..192c86c923 100644
--- a/macros/luatex/generic/penlight/penlightextras.lua
+++ b/macros/luatex/generic/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