diff options
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r-- | Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf | bin | 82984 -> 83795 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex | 35 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua | 27 | ||||
-rw-r--r-- | Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty | 15 |
4 files changed, 57 insertions, 20 deletions
diff --git a/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf b/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf Binary files differindex 4719837d3c8..013335b3ad1 100644 --- a/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf +++ b/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.pdf diff --git a/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex b/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex index 552fc21988d..93e690d896d 100644 --- a/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex +++ b/Master/texmf-dist/doc/lualatex/yamlvars/yamlvars.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@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 @@ or just find it easier to read document metadata from a YAML file compared to th 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 @@ will br thrown if the name exists. Alternatively, you can use the commands \cmd{ \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 @@ like \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. diff --git a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.lua index 479880a3e82..d6d2f7ca4f3 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) ---% 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.varTemp = '' 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 @@ local function default_stuff() 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 @@ function YAMLvars.declareYAMLvarsStr(y) 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 @@ local function transform_and_prc(var, val) 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,13 +417,20 @@ local function transform_and_prc(var, val) 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 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 @@ function YAMLvars.getYAMLcli() 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 diff --git a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty index 733ee80b69d..bd0643ec573 100644 --- a/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty +++ b/Master/texmf-dist/tex/lualatex/yamlvars/yamlvars.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@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 @@ YAMLvars.xfmDefault = {'lb2nl','addxspace'} }} \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}))} |