diff options
Diffstat (limited to 'macros/luatex/generic/penlight/penlightextras.lua')
-rw-r--r-- | macros/luatex/generic/penlight/penlightextras.lua | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua index 9ce0903f1c..a6a5c1ff0a 100644 --- a/macros/luatex/generic/penlight/penlightextras.lua +++ b/macros/luatex/generic/penlight/penlightextras.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2022-10-15 +--% 2022-10-22 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -22,16 +22,17 @@ --% 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 +__PL_SKIP_TEX__ = __PL_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) -__SKIP_LUAKEYS__ = __SKIP_LUAKEYS__ or false -__PL_NO_GLOBALS__ = __PL_NO_GLOBALS__ or false +__PL_SKIP_LUAKEYS__ = __PL_SKIP_LUAKEYS__ or false +__PL_GLOBALS__ = __PL_GLOBALS__ or false __PL_EXTRAS__ = 1 +__PL_NO_HYPERREF__ = __PL_NO_HYPERREF__ or false -- requires penlight local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl -if not __SKIP_LUAKEYS__ then +if not __PL_SKIP_LUAKEYS__ then luakeys = require'luakeys' end @@ -74,7 +75,7 @@ pl.tex._xNoValue = '-NoValue-' --Generic LuaLaTeX utilities for print commands or environments -if not __SKIP_TEX__ then +if not __PL_SKIP_TEX__ then local function check_special_chars(s) -- todo extend to toher special chars? if type(s) == 'string' then if string.find(s, '[\n\r\t\0]') then @@ -142,6 +143,7 @@ function pl.tex.help_wrt(s1, s2) -- helpful printing, makes it easy to debug, s1 end wrt2('\n^^^^^\n') end +pl.help_wrt = pl.tex.help_wrt function pl.tex.prt_array2d(t) for _, r in ipairs(t) do @@ -292,15 +294,37 @@ end + + function pl.tex.get_ref_info(l) + local n = 5 + if __PL_NO_HYPERREF__ then + local n = 2 + end local r = token.get_macro('r@'..l) + local t = {} if r == nil then - return 0, 0 + t = pl.tablex.new(n, 0) -- make all 0s + r = '-not found-' + else + t = {r:match(("(%b{})"):rep(n))} + t = pl.tablex.map(string.trimfl, t) end - local sec, page = r:match("{([^}]*)}{([^}]*)}") - return sec, page + t[#t+1] = r -- add the og return of label + pl.help_wrt(t, 'ref info') + return t end +-- todo add regex pattern for cref info +--function pl.tex.get_ref_info_all_cref(l) +-- local r = token.get_macro('r@'..l..'@cref') +-- if r == nil then +-- return r, 0, 0 +-- end +-- local sec, page = r:match("{([^}]*)}{([^}]*)}") +-- return r, sec, page +--end + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- @@ -420,6 +444,10 @@ function str_mt.__index.delspace(str) return str:gsub('%s','') end +function str_mt.__index.trimfl(str) + return str:sub(2,-2) +end + -- -- -- -- function stuff @@ -750,7 +778,7 @@ end -if not __PL_NO_GLOBALS__ then +if _PL_GLOBALS__ then __PL_EXTRAS__ = 2 -- iterators kpairs = pl.utils.kpairs @@ -767,6 +795,13 @@ if not __PL_NO_GLOBALS__ then end end table.join = table.concat -- alias + -- todo should tablex have all table functions + + pl.tablex.concat = table.concat + pl.tablex.insert = table.insert + pl.tablex.maxn = table.maxn + pl.tablex.remove = table.remove + pl.tablex.sort = table.sort hasval = pl.hasval COMP = pl.COMP |