diff options
author | Norbert Preining <norbert@preining.info> | 2021-12-16 03:01:13 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2021-12-16 03:01:13 +0000 |
commit | 16b22a983bc0f05cbbb201a6e0f5cbbfc3c8fffb (patch) | |
tree | 09f27480427360daa44bee043154b5d9580efa33 /macros/luatex/latex | |
parent | 0efaa39c6d0b17b58df9a68ae1319ea20aaabc28 (diff) |
CTAN sync 202112160301
Diffstat (limited to 'macros/luatex/latex')
-rw-r--r-- | macros/luatex/latex/yamlvars/YAMLvars.lua | 75 | ||||
-rw-r--r-- | macros/luatex/latex/yamlvars/YAMLvars.pdf | bin | 46334 -> 46890 bytes | |||
-rw-r--r-- | macros/luatex/latex/yamlvars/YAMLvars.sty | 10 | ||||
-rw-r--r-- | macros/luatex/latex/yamlvars/YAMLvars.tex | 8 |
4 files changed, 73 insertions, 20 deletions
diff --git a/macros/luatex/latex/yamlvars/YAMLvars.lua b/macros/luatex/latex/yamlvars/YAMLvars.lua index e7baaf26f7..72e4d6ad1a 100644 --- a/macros/luatex/latex/yamlvars/YAMLvars.lua +++ b/macros/luatex/latex/yamlvars/YAMLvars.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2021-11-07 +--% 2021-12-15 --% Copyright (C) 2021 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -51,6 +51,7 @@ YAMLvars = {} -- self table YAMLvars.xfm = {} YAMLvars.prc = {} +YAMLvars.dec = {} -- table of declare function YAMLvars.varsvals = {} YAMLvars.varspecs = {} @@ -66,8 +67,15 @@ YAMLvars.varTemp = '' YAMLvars.tabmidrule = 'hline' +YAMLvars.debug = false + YAMLvars.yaml = require('tinyyaml') +function YAMLvars.debugtalk(s, ss) + if YAMLvars.debug then + help_wrt(s, ss) + end +end -- xfm functions (transforms) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function YAMLvars.xfm.addxspace(var, val) @@ -143,17 +151,56 @@ end --- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +-- dec laration functions, -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- + +function YAMLvars.dec.gdef(var, dft) + YAMLvars.deccmd(var, dft) +end + +function YAMLvars.dec.yvdef(var, dft) + YAMLvars.deccmd('yv--'..var, dft) +end + +function YAMLvars.dec.toggle(var, dft) + tex.print('\\global\\newtoggle{'..var..'}') + YAMLvars.prc.toggle(var, dft) +end + +function YAMLvars.dec.length(var, dft) + tex.print('\\global\\newlength{\\'..var..'}') + YAMLvars.prc.length(var, dft) +end + -- prc functions (processing) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function YAMLvars.prc.gdef(var, val) token.set_macro(var, val, 'global') + YAMLvars.debugtalk(var..' = '..val, 'prc gdef') end function YAMLvars.prc.yvdef(var, val) token.set_macro('yv--'..var, val, 'global') + YAMLvars.debugtalk('yv--'..var..' = '..val, 'prc yvdef') +end + +function YAMLvars.prc.toggle(t, v) -- requires penlight extras + local s = '' + if hasval(v) then + s = '\\global\\toggletrue{'..t..'}' + else + s = '\\global\\togglefalse{'..t..'}' + end + tex.print(s) + YAMLvars.debugtalk(s, 'prc toggle') +end + +function YAMLvars.prc.length(t, v) + v = v or '0pt' + local s = '\\global\\setlength{\\global\\'..t..'}{'..v..'}' + tex.print(s) + YAMLvars.debugtalk(s, 'prc length') end function YAMLvars.prc.PDFtitle(var, val) @@ -211,13 +258,7 @@ function YAMLvars.prc.setdocvarOpts(var, val) tex.print(s) end -function YAMLvars.prc.toggle(t, v) -- requires penlight extras - if hasval(v) then - tex.print('\\global\\toggletrue{'..t..'}') - else - tex.print('\\global\\togglefalse{'..t..'}') - end -end + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- @@ -257,7 +298,7 @@ end function YAMLvars.declareYAMLvarsStr(y) local t = YAMLvars.yaml.parse(y) for var, specs in pairs(t) do - YAMLvars.varspecs[var] = {xfm=YAMLvars.xfrmDefault,prc=YAMLvars.prcDefault,dft=YAMLvars.dftDefault} + YAMLvars.varspecs[var] = {xfm=YAMLvars.xfmDefault,prc=YAMLvars.prcDefault,dft=YAMLvars.dftDefault} if type(specs) == 'string' then specs = {xfm={specs}} end @@ -266,17 +307,17 @@ function YAMLvars.declareYAMLvarsStr(y) if s == 'xfm' and type(p) ~= 'table' then p = {p} end YAMLvars.varspecs[var][s] = p -- set property of var end - if YAMLvars.varspecs[var]['prc'] == 'gdef' then - YAMLvars.deccmd(var, YAMLvars.varspecs[var]['dft']) - elseif YAMLvars.varspecs[var]['prc'] == 'yvdef' then - YAMLvars.deccmd('yv--'..var, YAMLvars.varspecs[var]['dft']) - elseif YAMLvars.varspecs[var]['prc'] == 'toggle' then - tex.print('\\global\\newtoggle{'..var..'}') - YAMLvars.prc.toggle(var, YAMLvars.varspecs[var]['dft']) + if YAMLvars.dec[YAMLvars.varspecs[var].prc] ~= nil then + YAMLvars.dec[YAMLvars.varspecs[var].prc](var, YAMLvars.varspecs[var].dft) + --else -- actually don't a dec function for all + -- -- -- -- tex.print('\\PackageError{YAMLvars}{Declaration function for '..YAMLvarspecs[var].prc..'not found}{}') end end + YAMLvars.debugtalk(YAMLvars.varspecs, 'declared YAML vars, varspecs') end + + function YAMLvars.declareYAMLvarsFile(y) YAMLvars.declareYAMLvarsStr(getYAMLfile(y)) end diff --git a/macros/luatex/latex/yamlvars/YAMLvars.pdf b/macros/luatex/latex/yamlvars/YAMLvars.pdf Binary files differindex 18fa3a43e3..eeeab7ea6c 100644 --- a/macros/luatex/latex/yamlvars/YAMLvars.pdf +++ b/macros/luatex/latex/yamlvars/YAMLvars.pdf diff --git a/macros/luatex/latex/yamlvars/YAMLvars.sty b/macros/luatex/latex/yamlvars/YAMLvars.sty index f7154389d7..2392800651 100644 --- a/macros/luatex/latex/yamlvars/YAMLvars.sty +++ b/macros/luatex/latex/yamlvars/YAMLvars.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2021-11-07 +% 2021-12-15 % Copyright (C) 2021 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -24,9 +24,13 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{YAMLvars}[2021] +\ProvidesPackage{YAMLvars}[2021-12-15] \RequirePackage{luacode} +\RequirePackage{xspace} +\RequirePackage{etoolbox} +\RequirePackage[pl,extras]{penlight} + \luadirect{YAMLvars = require('YAMLvars')} @@ -39,6 +43,8 @@ } \DeclareOption{allowundeclared}{ \luadirect{YAMLvars.allowUndeclared = true} +}\DeclareOption{debug}{ + \luadirect{YAMLvars.debug = true} } \DeclareOption*{\PackageWarning{YAMLvars}{Unknown option: '\CurrentOption'}{}} diff --git a/macros/luatex/latex/yamlvars/YAMLvars.tex b/macros/luatex/latex/yamlvars/YAMLvars.tex index 38cc59dc48..5e32058dab 100644 --- a/macros/luatex/latex/yamlvars/YAMLvars.tex +++ b/macros/luatex/latex/yamlvars/YAMLvars.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2021-11-07 +% 2021-12-15 % Copyright (C) 2021 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -145,6 +145,12 @@ Rhead: \end{verbatim} +To change how a variable is declared (initialize), you can modify or add functions in +\texttt{YAMLvars.dec} table, where the index is the same as the \texttt{prc} name. +This function accepts two variables, the var name, and the default value set by dft. +For lengths and toggles (from etoolbox), these functions are used to initialize lengths +with newlength and newtoggle. + \section{Parsing variables} A YAML file to be parsed will contain the variables as the top level keys, similar to declaring. |