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.lua16
1 files changed, 10 insertions, 6 deletions
diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua
index f612bd3370..13d0ab5817 100644
--- a/macros/luatex/generic/penlight/penlightextras.lua
+++ b/macros/luatex/generic/penlight/penlightextras.lua
@@ -2,17 +2,22 @@
local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl
local bind = bind or pl.func.bind
+-- some bonus string operations, % text operator, and functional programmng
+pl.stringx.import()
+pl.text.format_operator()
+pl.utils.import('pl.func')
+
function help_wrt(s1, s2) -- helpful printing, makes it easy to debug, s1 is object, s2 is note
local wrt = wrt or texio.write_nl
local wrt = wrt or print
s2 = s2 or ''
- wrt('\nvvvvv '..s2)
+ wrt('\nvvvvv '..s2..'\n')
if type(s1) == 'table' then
wrt(pl.pretty.write(s1))
else
wrt(tostring(s1))
end
- wrt('^^^^^\n')
+ wrt('\n^^^^^\n')
end
@@ -129,7 +134,7 @@ local function like(M1, v)
return pl.array2d.new(r,c,v)
end
-function from_table(t) -- turns a labelled table to a 2d, label-free array
+local function from_table(t) -- turns a labelled table to a 2d, label-free array
t_new = {}
for k, v in pairs(t) do
if type(v) == 'table' then
@@ -145,7 +150,7 @@ function from_table(t) -- turns a labelled table to a 2d, label-free array
return t_new
end
-function toTeX(M, EL) --puts & between columns, can choose to end line with \\ if EL is true (end-line)
+local function toTeX(M, EL) --puts & between columns, can choose to end line with \\ if EL is true (end-line)
EL = EL or false
if EL then EL = '\\\\' else EL = '' end
return pl.array2d.reduce2(_1..EL.._2, _1..'&'.._2, M)..EL
@@ -221,10 +226,9 @@ function mod2(a) -- math modulo 2
end
function hasval(x) -- if something has value
- -- todo check for Lists, other penlight objects
if (x == nil) or (x == false) or (x == 0) or (x == '') then
return false
- elseif type(x) == 'table' then
+ elseif (type(x) ~= 'number') or (type(x) ~= 'string') then
if #x == 0 then
return false
else