diff options
author | Karl Berry <karl@freefriends.org> | 2025-02-12 21:05:29 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2025-02-12 21:05:29 +0000 |
commit | 4b6b8ff522c0798d64a126ed43b87912ba93112b (patch) | |
tree | 1c2a018f7ebac5fbc402c9f37bc0ad2aa8fb840a /Master/texmf-dist/tex | |
parent | 6c5c88f14947976890a162b1caea3066c8f1b496 (diff) |
yamlvars (12feb25)
git-svn-id: svn://tug.org/texlive/trunk@73922 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua | 32 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty | 16 |
2 files changed, 40 insertions, 8 deletions
diff --git a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua index b63dabeccbb..ca3fcac0587 100644 --- a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua +++ b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua @@ -1,6 +1,6 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2024-08-17 ---% Copyright (C) 2021-2023 Kale Ewasiuk +--% 2025-02-11 +--% Copyright (C) 2021-2025 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 @@ -28,6 +28,7 @@ YAMLvars = {} -- self table YAMLvars.yaml = require'tinyyaml' -- note: YAMLvars.sty will have checked existence of this already + YAMLvars.luakeys = require'luakeys'() -- note: YAMLvars.sty will have checked existence of this already local pl = penlight @@ -57,7 +58,7 @@ YAMLvars.setts.overwrite = false YAMLvars.setts.lowercase = false YAMLvars.setts.stripvars = true -- todo add this as an option accessible in latex YAMLvars.setts.tabmidrule = 'midrule' -YAMLvars.setts.prcstring = true +YAMLvars.setts.prcstring = 'number' YAMLvars.setts.xfm = {} YAMLvars.setts.prc = 'gdef' YAMLvars.setts.dft = '' @@ -296,6 +297,29 @@ end -- -- + +YAMLvars.curr_keyvals = {} +function YAMLvars.prc.keyvals(var, val) + YAMLvars.curr_keyvals[var] = val +end +function YAMLvars.callkeyvals() + for var, tbl in pairs(YAMLvars.curr_keyvals) do + local cmd = '\\'..var..'{' + for key, val in pairs(tbl) do + if tonumber(key) ~= nil then + cmd = cmd .. val + else + cmd = cmd .. key .. '=' .. val + end + cmd = cmd .. ',' + end + tex.sprint(cmd..'}') + end + YAMLvars.curr_keyvals = {} +end + + + -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function YAMLvars.makecmd(cs, val) -- provide command via lua @@ -427,7 +451,7 @@ local function transform_and_prc(var, val) YAMLvars.debugtalk('function: '..YAMLvars.varspecs[var]['prc']..'\nvariable: '.. var .. '\n' .. 'value: '.. tostring(val) .. '\nval type: ' ..type(val), "Applying processing (prc) function") - if YAMLvars.setts.prcstring then + if YAMLvars.setts.prcstring:find(type(val)) then val = tostring(val) end f(pl.stringx.strip(var), val) -- prc the value of the variable diff --git a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty index 8bc387a0f5a..4d7203c0180 100644 --- a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty +++ b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty @@ -1,6 +1,6 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2024-08-17 -% Copyright (C) 2021-2023 Kale Ewasiuk +% 2025-02-11 +% Copyright (C) 2021-2025 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 @@ -25,7 +25,7 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{yamlvars}[2024-08-17] +\ProvidesPackage{yamlvars}[2025-02-11] \RequirePackage{luacode} \RequirePackage{etoolbox} @@ -37,6 +37,11 @@ \luadirect{YAMLvars = require('YAMLvars')} +\luadirect{ + if YAMLvars.yaml == nil then + tex.sprint('\\PackageError{yamlvars}{"tinyyaml.lua" not found. Install the "lua-tinyyaml" package from CTAN or include "tinyyaml.lua" in your project}{}') + end +} @@ -92,6 +97,9 @@ YAMLvars.xfmDefault = {'lb2nl','addxspace'} \luadirect{YAMLvars.setts2default()} +\NewDocumentCommand{\YAMLvarsSetKeyVals}{}{\luadirect{YAMLvars.callkeyvals()}} + + \newcommand{\declareYAMLvarsFile}[1]{\luadirect{YAMLvars.declareYAMLvarsFile(\luastring{#1})}} \NewDocumentCommand{\parseYAMLvarsFile}{m}{\luadirect{ YAMLvars.parseYAMLvarsFile(\luastring{#1}) @@ -110,7 +118,7 @@ YAMLvars.xfmDefault = {'lb2nl','addxspace'} {\luadirect{ penlight.tex.stoprecording() }} -\AfterEndEnvironment{parseYAMLvars}{\luadirect{YAMLvars.parseYAMLvarsStr(penlight.tex.recordedbuf)}} +\AfterEndEnvironment{parseYAMLvars}{\luadirect{YAMLvars.parseYAMLvarsStr(penlight.tex.recordedbuf)}\YAMLvarsSetKeyVals} % necessary hack to get rohead and lohead to work.. % .. https://tex.stackexchange.com/questions/637018/setting-koma-heading-within-lua/637021?noredirect=1#comment1587387_637021 |