From 6b9d0f71edf988e01edf2bdf90915c9fa8bfd662 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 3 Mar 2022 21:08:22 +0000 Subject: yamlvars (3mar22) git-svn-id: svn://tug.org/texlive/trunk@62375 c570f23f-e606-0410-a88d-b1316a301751 --- .../texmf-dist/tex/lualatex/yamlvars/yamlvars.lua | 54 ++++++++-------------- 1 file changed, 19 insertions(+), 35 deletions(-) (limited to 'Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua') diff --git a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua index 1f95a50f250..f32627a21a4 100644 --- a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua +++ b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2022-02-25 +--% 2022-03-03 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -46,9 +46,15 @@ --OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --SOFTWARE. +YAMLvars = {} -- self table +YAMLvars.yaml = require'markdown-tinyyaml' -- note: YAMLvars.sty will have checked existence of this already + +local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl +if (__PL_EXTRAS__ == nil) or (__PENLIGHT__ == nil) then + tex.sprint('\\PackageError{yamlvars}{penlight package with extras (or extrasnoglobals) option must be loaded before this package}{}') +end -YAMLvars = {} -- self table YAMLvars.xfm = {} YAMLvars.prc = {} YAMLvars.dec = {} -- table of declare function @@ -70,13 +76,12 @@ YAMLvars.tabmidrule = 'hline' YAMLvars.debug = false -YAMLvars.yaml = require'markdown-tinyyaml' -- note: YAMLvars.sty will have checked existence of this already -local pl = _G['penlight'] or _G['pl'] -- penlight for this namespace is pl + function YAMLvars.debugtalk(s, ss) if YAMLvars.debug then - help_wrt(s, ss) + pl.tex.help_wrt(s, ss) end end @@ -130,7 +135,7 @@ function YAMLvars.xfm.arrsortlastnameAZ(var, val) end -- todo need distinction beyyween table and penlight list ??? function YAMLvars.xfm.list2nl(var, val) - return pl.tablex.join(val,'\\\\ ') + return pl.List(val):join('\\\\ ') end --val = pl.array2d.map_slice1(_1..'\\\\', val, 1,-2) @@ -150,7 +155,7 @@ end function YAMLvars.xfm.markdown(var, val) --return '\\begin{markdown} '..val..'\n \\end{markdown}' - help_wrt(val, md) + pl.tex.help_wrt(val, md) return [[begin markdown ..val.. par end markdown]] @@ -194,7 +199,7 @@ end function YAMLvars.prc.toggle(t, v) -- requires penlight extras local s = '' - if hasval(v) then + if pl.hasval(v) then s = '\\global\\toggletrue{'..t..'}' else s = '\\global\\togglefalse{'..t..'}' @@ -358,15 +363,15 @@ local function eval_expr(func, var, val) if c == 0 then return _YV_invalid_expression else - --help_wrt(s, var) - --help_wrt(val, var) + --pl.tex.help_wrt(s, var) + --pl.tex.help_wrt(val, var) YAMLvars.valTemp = val YAMLvars.varTemp = var - --help_wrt(s, var) + --pl.tex.help_wrt(s, var) s, c = s:gsub('\2', '') -- strip \2 that might have appeared if / was applied s = sub_lua_var(' '..s, 'x', 'YAMLvars.valTemp') s = sub_lua_var(s, 'v', 'YAMLvars.varTemp') - --help_wrt(s, var) + --pl.tex.help_wrt(s, var) local f, err = pcall(loadstring(s)) if not f then tex.print('\\PackageError{YAMLvars}{xfm with "= or /" error on var "'..var..'"}{}') -- @@ -431,27 +436,6 @@ end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --- https://tex.stackexchange.com/questions/38150/in-lualatex-how-do-i-pass-the-content-of-an-environment-to-lua-verbatim -recordedbuf = "" -function readbuf(buf) - i,j = string.find(buf, '\\end{%w+}') - if i==nil then -- if not ending an environment - recordedbuf = recordedbuf .. buf .. "\n" - return "" - else - return nil - end -end - -function startrecording() - recordedbuf = "" - luatexbase.add_to_callback('process_input_buffer', readbuf, 'readbuf') -end - -function stoprecording() - luatexbase.remove_from_callback('process_input_buffer', 'readbuf') - recordedbuf = recordedbuf:gsub("\\end{%w+}\n","") -end @@ -475,7 +459,7 @@ function YAMLvars.getYAMLcli() end end end - --help_wrt(t) + --pl.tex.help_wrt(t) return t end @@ -489,7 +473,7 @@ return YAMLvars -- y = clean_tex_spaces(y) --end --local function clean_tex_spaces(s) --- help_wrt(s) +-- pl.tex.help_wrt(s) -- if s:sub(1,2) == '%s' then -- s, _ = s:gsub('%s+','',1) -- end -- cgit v1.2.3