texlive[68974] Master/texmf-dist: yamlvars (26nov23)

commits+karl at tug.org commits+karl at tug.org
Sun Nov 26 22:05:23 CET 2023


Revision: 68974
          https://tug.org/svn/texlive?view=revision&revision=68974
Author:   karl
Date:     2023-11-26 22:05:23 +0100 (Sun, 26 Nov 2023)
Log Message:
-----------
yamlvars (26nov23)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf
    trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex
    trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua
    trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex	2023-11-26 21:05:12 UTC (rev 68973)
+++ trunk/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex	2023-11-26 21:05:23 UTC (rev 68974)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-07-22
+% 2023-11-25
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -54,6 +54,7 @@
 
 
 \usepackage[overwritedefs]{yamlvars}
+\yamlvarsdebugon
 \title{YAMLvars}
 \subtitle{a YAML variable parser for LuaLaTeX}
 
@@ -80,13 +81,6 @@
 standard title, author, etc. commands.
 
 \section{Package Options}
-\leavevmode\llap{\texttt{useyv}\ \ \ }By default, when you specify a YAML variable, it will be defined using \texttt{gdef}
-(only if it wasn't defined previously).
-If you use this setting, unless otherwise specified, YAML variables will be accessible under
-the \texttt{\textbackslash yv\{<var>\}} command.
-This also allows numbers and symbols in the variable names.
-Note that internally, the variables are stored in the command sequence
-\texttt{yv--<var>}.
 
 \leavevmode\llap{\texttt{parseCLI}\ \ \ }If this option is enabled, any arguments passed to your lualatex compile
 command that end in ``.yaml'' will be used, separated by a space.
@@ -105,6 +99,14 @@
 
 \llcmd{overwritedefs}Danger! This will allow you to \cmd{gdef} commands with YAML. Caution should be taken to not set definitions like \cmd{begin}, \cmd{section}, etc.
 
+\leavevmode\llap{\texttt{useyv}\ \ \ }By default, when you specify a YAML variable, it will be defined using \texttt{gdef}
+(only if it wasn't defined previously).
+If you use this setting, unless otherwise specified, YAML variables will be accessible under
+the \texttt{\textbackslash yv\{<var>\}} command.
+This also allows numbers and symbols in the variable names.
+Note that internally, the variables are stored in the command sequence
+\texttt{yv--<var>}. This option is currently under repair and will not work properly in this version.
+
 \section{Dependencies}
 \llcmd{Note:}This package requires the \cmd{tinyyaml} package, available on CTAN.
 
@@ -119,6 +121,23 @@
 \cmd{luacode}, \cmd{luakeys}, and
 \cmd{etoolbox}.
 
+\section{Settings}
+\cmd{\setdefYAMLvars{kv}} changes the default settings of key-vals.\\
+\cmd{\setYAMLvars*{kv}} changes the current settings from key-vals. Use \cmd{*} if you want to first restore to defaults.
+  
+  The \cmd{YAMLvars.setts} lua table contains the settings, which are:\\
+\cmd{parseopts} table passed to YAML parser options  (default is \cmd{{timestamps=false}})       \\
+\cmd{decstr}   in the declaration YAML text, if a value is a string, how should it be treated (\cmd{xfm, dft, or prc})       \\
+\cmd{undeclared} boolean  for allowing parsing of undeclared vars        \\
+\cmd{overwrite}  boolean for allowing overwriting of previous definitions     \\
+\cmd{lowercase}  boolean for auto-changing vars to lowercase       \\
+\cmd{prcstring}  boolean for auto-converting final value before processing (sometimes) numbers can have odd effects       \\
+%\cmd{tabmidrule} type of rule for tabu          \\
+\cmd{xfm}    default xfm function(s) if none passed to declared key, separated by space     \\
+\cmd{prc}    default prc function if none passed to declared key     \\
+\cmd{dft}    default dft function if none passed to declared key     \\
+
+
 \section{Declaring variables}
 A declaration file can either be parsed with the command \texttt{declareYAMLvarsFile} command,
 or, if you want to do it \LaTeX, you can put the YAML code in the \texttt{declareYAMLvars} environment.

Modified: trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua	2023-11-26 21:05:12 UTC (rev 68973)
+++ trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua	2023-11-26 21:05:23 UTC (rev 68974)
@@ -1,5 +1,5 @@
 --% Kale Ewasiuk (kalekje at gmail.com)
---% 2023-07-22
+--% 2023-11-25
 --% Copyright (C) 2021-2023 Kale Ewasiuk
 --%
 --% Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -48,11 +48,15 @@
 
 YAMLvars.debug = false
 
+
 YAMLvars.setts = {}
+YAMLvars.setts.parseopts = {timestamps=false}
+YAMLvars.setts.decstr = 'xfm' -- if in declaration key, value is a string, how should it be treated
 YAMLvars.setts.undeclared = false
 YAMLvars.setts.overwrite = false
 YAMLvars.setts.lowercase = false
 YAMLvars.setts.tabmidrule = 'midrule'
+YAMLvars.setts.prcstring = true
 YAMLvars.setts.xfm = {}
 YAMLvars.setts.prc = 'gdef'
 YAMLvars.setts.dft = ''
@@ -325,7 +329,7 @@
 end
 
 function YAMLvars.declareYAMLvarsStr(y)
-    local t = YAMLvars.yaml.parse(y)
+    local t = YAMLvars.yaml.parse(y, YAMLvars.setts.parseopts)
     for var, specs in pairs(t) do
         if pl.hasval(specs['lowcasevar']) or YAMLvars.setts.lowercase then
             var = var:lower()
@@ -333,9 +337,11 @@
         end
         YAMLvars.varspecs[var] = default_stuff()
         if type(specs) == 'string' then
-            specs = {xfm={specs}}
+            if YAMLvars.setts.decstr == 'xfm' then specs = {xfm={specs}} end
+            if YAMLvars.setts.decstr == 'dft' then specs = {dft=specs} end
+            if YAMLvars.setts.decstr == 'prc' then specs = {prc=specs} end
         end
-        if specs['xfm'] == nil then specs['xfm'] = {} end
+        if specs['xfm'] == nil then specs['xfm'] = YAMLvars.setts.xfm end
         for s, p in pairs(specs) do
             if s == 'xfm' and type(p) ~= 'table' then p = {p} end
             YAMLvars.varspecs[var][s] = p -- set property of var
@@ -402,6 +408,8 @@
                 val = val2
             end
         else
+            YAMLvars.debugtalk('function: '..func..'\nvariable: '.. var .. '\n' ..
+        'value: '.. tostring(val) .. '\nval type: ' ..type(val), "Applying transforming (xfm) function")
             val = f(var, val)
         end
     end
@@ -409,6 +417,12 @@
     if f == nil then
         YAMLvars.pkgerr('prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined')
     end
+    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
+        val = tostring(val)
+    end
     f(var, val) -- prc the value of the variable
 end
 
@@ -415,7 +429,8 @@
 
 
 function YAMLvars.parseYAMLvarsStr(y)
-    YAMLvars.varsvals = YAMLvars.yaml.parse(y)
+    YAMLvars.debugtalk(YAMLvars.varsvals, 'Parsing YAML vars with table')
+    YAMLvars.varsvals = YAMLvars.yaml.parse(y, YAMLvars.setts.parseopts)
     for var, val in pairs(YAMLvars.varsvals) do
         if YAMLvars.varslowcase:contains(var:lower()) then
             var = var:lower()
@@ -477,7 +492,7 @@
 YAMLvars.yaml2PDFmetadata = function(ytext) -- parse a YAML file and update the pdfmetadata table
       __PDFmetadata__ = __PDFmetadata__ or {} -- existing metadata
       if ytext ~= nil then
-        local pdfmetadata_yaml = YAMLvars.yaml.parse(ytext) -- new metadata
+        local pdfmetadata_yaml = YAMLvars.yaml.parse(ytext, {timestamps = false}) -- new metadata
         local t = {}
         for k,v in pairs(pdfmetadata_yaml) do  -- ensure first character is capital letter
             t[k:upfirst()] = v

Modified: trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty	2023-11-26 21:05:12 UTC (rev 68973)
+++ trunk/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty	2023-11-26 21:05:23 UTC (rev 68974)
@@ -1,5 +1,5 @@
 % Kale Ewasiuk (kalekje at gmail.com)
-% 2023-07-22
+% 2023-11-25
 % Copyright (C) 2021-2023 Kale Ewasiuk
 %
 % Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -25,7 +25,7 @@
 
 
 \NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{yamlvars}[2023-07-22]
+\ProvidesPackage{yamlvars}[2023-11-25]
 
 \RequirePackage{luacode}
 \RequirePackage{etoolbox}
@@ -38,7 +38,9 @@
 \luadirect{YAMLvars = require('YAMLvars')}
 
 \DeclareOption{useyv}{
-        \gdef\yv#1{\csname yv--#1\endcsname}
+    \newcommand\yv{}
+    \gdef\yv#1{\csname yv--#1\endcsname}  % todo not working... why??
+%      \NewDocumentCommand{\yv}{m}{\luadirect{tex.sprint(tostring(token.get_macro('yv--'..\luastring{#1})))}}
         \luadirect{YAMLvars.setts.prc = 'yvdef'}
         \luadirect{YAMLvars.settsdefault.prc = 'yvdef'}
 }
@@ -58,7 +60,8 @@
 
 
 
-%% todo delete below
+\newcommand{\yamlvarsdebugon}{\luadirect{YAMLvars.debug = true}}
+\newcommand{\yamlvarsdebugoff}{\luadirect{YAMLvars.debug = false}}
 \newcommand{\lowercasevarYVon}{\luadirect{YAMLvars.lowvasevarall = true}}
 \newcommand{\lowercasevarYVoff}{\luadirect{YAMLvars.lowvasevarall = false}}
 \newcommand{\AllowUndeclaredYV}{\luadirect{YAMLvars.setts.undeclared = true}}
@@ -130,8 +133,8 @@
 }}
 
 \NewDocumentCommand{\setdefYAMLvars}{ m }{\luadirect{
-  YAMLvars.updatesettskv(pl.tex._xFalse, \luastring{#1}, true)
-}}
+  YAMLvars.updatesettskv(\luastring{#1}, pl.tex._xFalse, true)
+}} % set the default settings
 
 %  \IfBooleanTF{#1}{\luadirect{YAMLvars.setts = pl.tablex.deepcopy(YAMLvars.settsdefault)}}{} % if * return to default first
 %  \luadirect{pl.tablex.update(YAMLvars.setts, luakeys.parse(\luastring{#2}))}



More information about the tex-live-commits mailing list.