diff options
Diffstat (limited to 'macros/luatex')
-rw-r--r-- | macros/luatex/generic/penlight/penlight.pdf | bin | 38311 -> 38589 bytes | |||
-rw-r--r-- | macros/luatex/generic/penlight/penlight.sty | 21 | ||||
-rw-r--r-- | macros/luatex/generic/penlight/penlight.tex | 2 | ||||
-rw-r--r-- | macros/luatex/generic/penlight/penlightextras.lua | 79 | ||||
-rw-r--r-- | macros/luatex/latex/yamlvars/yamlvars.lua | 264 | ||||
-rw-r--r-- | macros/luatex/latex/yamlvars/yamlvars.pdf | bin | 69460 -> 71526 bytes | |||
-rw-r--r-- | macros/luatex/latex/yamlvars/yamlvars.sty | 21 | ||||
-rw-r--r-- | macros/luatex/latex/yamlvars/yamlvars.tex | 23 |
8 files changed, 342 insertions, 68 deletions
diff --git a/macros/luatex/generic/penlight/penlight.pdf b/macros/luatex/generic/penlight/penlight.pdf Binary files differindex 33f3457df2..3fcd22c54e 100644 --- a/macros/luatex/generic/penlight/penlight.pdf +++ b/macros/luatex/generic/penlight/penlight.pdf diff --git a/macros/luatex/generic/penlight/penlight.sty b/macros/luatex/generic/penlight/penlight.sty index 936cb6dce7..a73948af29 100644 --- a/macros/luatex/generic/penlight/penlight.sty +++ b/macros/luatex/generic/penlight/penlight.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-03-03 +% 2022-03-15 % Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -22,7 +22,7 @@ % OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE % OR OTHER DEALINGS IN THE SOFTWARE. -\ProvidesPackage{penlight}[2022-03-03] +\ProvidesPackage{penlight}[2022-03-15] \RequirePackage{luacode} @@ -52,3 +52,20 @@ if __PENLIGHT__ == nil then tex.print('\\PackageError{penlight}{penlight or pl option must be passed to penlight as the first option}{}') end } + + + +\newcommand{\writePDFmetadata}{\luadirect{writePDFmetadata()}} + +\NewDocumentCommand{\writePDFmetadatakv}{ s m }{ +\IfBooleanTF{#1}{% if *, overwrite everything + \luadirect{ + __PDFmetadata__ = luakeys.parse(\luastring{#2}) + writePDFmetadata() + }}{ + \luadirect{ + __PDFmetadata__ = __PDFmetadata__ or {} + table.update(__PDFmetadata__, luakeys.parse(\luastring{#2}) + writePDFmetadata() + }} +} diff --git a/macros/luatex/generic/penlight/penlight.tex b/macros/luatex/generic/penlight/penlight.tex index 2096c10b68..d70fc258f3 100644 --- a/macros/luatex/generic/penlight/penlight.tex +++ b/macros/luatex/generic/penlight/penlight.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-03-03 +% 2022-03-15 % Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/macros/luatex/generic/penlight/penlightextras.lua b/macros/luatex/generic/penlight/penlightextras.lua index 192c86c923..e021567c13 100644 --- a/macros/luatex/generic/penlight/penlightextras.lua +++ b/macros/luatex/generic/penlight/penlightextras.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2022-03-03 +--% 2022-03-15 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -171,11 +171,25 @@ end --definition helpers -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -function pl.tex.defcmd(cs, val) -- simple definitions - val = val or '' +function pl.tex.defmacro(cs, val) -- , will not work if val contains undefined tokens (so pre-define them if using..) + val = val or '' -- however this works for arbitrary command names (\@hello-123 etc allowed) token.set_macro(cs, val, 'global') end + +function pl.tex.defcmd(cs, val) -- fixes above issue, but only chars allowed in cs (and no @) + val = val or '' + tex.sprint('\\gdef\\'..cs..'{'..val..'}') +end + +function pl.tex.defcmdAT(cs, val) -- allows @ in cs, + --however should only be used in preamble. I avoid \makeatother because I've ran into issues with cls and sty files using it. + val = val or '' + tex.sprint('\\makeatletter\\gdef\\'..cs..'{'..val..'}') +end + + + function pl.tex.prvcmd(cs, val) -- provide command via lua if token.is_defined(cs) then -- do nothing if token is defined already --pkgwarn('penlight', 'Definition '..cs..' is being overwritten') @@ -360,6 +374,9 @@ function str_mt.__index.totable(str) end +function str_mt.__index.upfirst(str) + return str:gsub('%a', function(x) return x:upper() end, 1) +end @@ -608,6 +625,62 @@ end +__PDFmetadata__ = {} +pl.tex.add_xspace_intext = true + + +function pl.tex.updatePDFtable(k, v, o) + k = k:upfirst() + if not pl.hasval(o) and __PDFmetadata__[k] ~= nil then + return + end + __PDFmetadata__[k] = v +end + +pl.tex.writePDFmetadata = function(t) -- write PDF metadata to xmpdata file + t = t or __PDFmetadata__ + local str = '' + for k, v in pairs(t) do + k = k:upfirst() + str = str..'\\'..k..'{'..v..'}'..'\n' + end + pl.utils.writefile(tex.jobname..'.xmpdata', str) +end + + + +function pl.tex.clear_cmds_str(s) + return s:gsub('%s+', ' '):gsub('\\\\',' '):gsub('\\%a+',''):gsub('{',' '):gsub('}',' '):gsub('%s+',' '):strip() +end + +function pl.tex.makePDFvarstr(s) + s = s:gsub('%s*\\sep%s+','\0'):gsub('%s*\\and%s+','\0') -- turn \and into \sep + s = pl.tex.clear_cmds_str(s) + s = s:gsub('\0','\\sep ') + pl.tex.help_wrt(s,'PDF var string') + return s +end + +function pl.tex.makeInTextstr(s) + local s, c_and = s:gsub('%s*\\and%s+','\0') + s = pl.tex.clear_cmds_str(s) + if pl.tex.add_xspace_intext then + s = s..'\\xspace' + end + if c_and == 1 then + s = s:gsub('\0',' and ') + elseif c_and > 1 then + s = s:gsub('\0',', ', c_and - 1) + s = s:gsub('\0',', and ') + end + pl.tex.help_wrt(s,'in text var string') + return s +end + + + + + if not __PL_NO_GLOBALS__ then __PL_EXTRAS__ = 2 diff --git a/macros/luatex/latex/yamlvars/yamlvars.lua b/macros/luatex/latex/yamlvars/yamlvars.lua index f32627a21a..b485236d10 100644 --- a/macros/luatex/latex/yamlvars/yamlvars.lua +++ b/macros/luatex/latex/yamlvars/yamlvars.lua @@ -1,5 +1,5 @@ --% Kale Ewasiuk (kalekje@gmail.com) ---% 2022-03-03 +--% 2022-03-15 --% Copyright (C) 2021-2022 Kale Ewasiuk --% --% Permission is hereby granted, free of charge, to any person obtaining a copy @@ -61,6 +61,7 @@ YAMLvars.dec = {} -- table of declare function YAMLvars.varsvals = {} YAMLvars.varspecs = {} +YAMLvars.varslowcase = pl.List() YAMLvars.xfmDefault = {} YAMLvars.prcDefault = 'gdef' @@ -68,6 +69,7 @@ YAMLvars.dftDefault = nil YAMLvars.allowUndeclared = false YAMLvars.overwritedefs = false +YAMLvars.lowvasevarall = false YAMLvars.valTemp = '' YAMLvars.varTemp = '' @@ -85,6 +87,10 @@ function YAMLvars.debugtalk(s, ss) end end +function YAMLvars.pkgerr(m) + pl.tex.pkgerror('yamlvars', m, '', true) +end + -- xfm functions (transforms) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function YAMLvars.xfm.addxspace(var, val) @@ -133,11 +139,22 @@ function YAMLvars.xfm.arrsortlastnameAZ(var, val) val = pl.List(val):sort(complastname) return val end + -- todo need distinction beyyween table and penlight list ??? function YAMLvars.xfm.list2nl(var, val) + if type(val) == 'string' then + return val + end return pl.List(val):join('\\\\ ') end +function YAMLvars.xfm.list2and(var, val) -- for doc vars like author, publisher + if type(val) == 'string' then + return val + end + return pl.List(val):join('\\and ') +end + --val = pl.array2d.map_slice1(_1..'\\\\', val, 1,-2) --return val:join('') --return pl.tablex.reduce(_1.._2, val, '') @@ -188,12 +205,14 @@ end -- prc functions (processing) -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- function YAMLvars.prc.gdef(var, val) - token.set_macro(var, val, 'global') + --token.set_macro(var, val, 'global') -- old way, don't do as it will cause issues if val contains undef'd macros + pl.tex.defcmd(var, val) YAMLvars.debugtalk(var..' = '..val, 'prc gdef') end function YAMLvars.prc.yvdef(var, val) - token.set_macro('yv--'..var, val, 'global') + --token.set_macro('yv--'..var, val, 'global') -- todo fix with csname hack? + pl.tex.defmacro('yv--'..var, val) YAMLvars.debugtalk('yv--'..var..' = '..val, 'prc yvdef') end @@ -215,83 +234,81 @@ function YAMLvars.prc.length(t, v) YAMLvars.debugtalk(s, 'prc length') end -function YAMLvars.prc.PDFtitle(var, val) - tex.print('\\hypersetup{pdftitle={'..val..'}}') - --tex.print('\\setPDFtitle{'..val..'}') -end -function YAMLvars.prc.PDFauthor(var, val) - tex.print('\\hypersetup{pdfauthor={'..val..'}}') - --tex.print('\\setPDFauthor{'..val..'}') + + +function YAMLvars.prc.setATvar(var, val) -- set a @var directly: eg \gdef\@title{val} + pl.tex.defcmdAT('@'..var, val) end -function YAMLvars.prc.setheader(val, rl) - local _, count = string.gsub(val, '\\\\', '') - if count == 0 then - val = '{\\ }\\\\'..val + +function YAMLvars.prc.setdocvar(var, val) -- call a document var \var{val} = \title{val} + -- YAML syntax options + -- k: v -> \k{v} + -- k: + -- v1: v2 -> \k[v2]{v1} + -- k: [v1, v2] -> \k[v2]{v1} + -- k: [v1] -> \k{v1} + if type(val) ~= 'table' then + tex.sprint('\\'..var..'{'..val..'}') + elseif #val == 0 then -- assume single k,v passed + for k,v in pairs(val) do + tex.sprint('\\'..var..'['..v..']{'..k..'}') + end + elseif #val == 1 then + tex.sprint('\\'..var..'{'..val[1]..'}') + else + tex.sprint('\\'..var..'['..val[2]..']{'..val[1]..'}') end - val = '\\setstretch{0.8}'..val - tex.print('\\'..rl..'ohead{'..val..'}') end -function YAMLvars.prc.rhead(var, val) - YAMLvars.prc.setheader(val, 'r') -end -function YAMLvars.prc.lhead(var, val) - YAMLvars.prc.setheader(val, 'l') -end -function YAMLvars.prc.title(var, val) - token.set_macro('@title', val, 'global') +function YAMLvars.prc.setPDFdata(var, val) + --update pdf metat data table + -- requires a table + for k, v in pairs(val) do + if type(v) == 'table' then + v = pl.List(v):join('\\sep ') + end + pl.tex.updatePDFtable(k, v, true) + end end -function YAMLvars.prc.author(var, val) - token.set_macro('@author', val, 'global') -end -function YAMLvars.prc.date(var, val) - token.set_macro('@date', val, 'global') -end --- do this with author, title, company -function YAMLvars.prc.setdocvar(var, val) - tex.print('\\'..var..'{'..val..'}') -end -function YAMLvars.prc.setdocvarOpts(var, val) - local s = '\\'..var..'{'..tostring(val[1])..'}' - for k, v in pairs(val) do - if k > 1 then - s = s..'['..tostring(v)..']' - end - end - tex.print(s) +-- with hyperref package +function YAMLvars.prc.PDFtitle(var, val) + tex.print('\\hypersetup{pdftitle={'..val..'}}') end +function YAMLvars.prc.PDFauthor(var, val) + tex.print('\\hypersetup{pdfauthor={'..val..'}}') +end -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - - -function YAMLvars.prvcmd(cs, val) -- provide command via lua +function YAMLvars.makecmd(cs, val) -- provide command via lua if token.is_defined(cs) and (not YAMLvars.overwritedefs) then - tex.print('\\PackageError{YAMLvars}{Variable '..cs..' already defined, could not declare}{}') + YAMLvars.pkgerr('Variable '..cs..' already defined, could not declare') else - token.set_macro(cs, val, 'global') + pl.tex.defcmd(cs, val) + --token.set_macro(cs, val, 'global') -- issues if val contains undefined macro end end function YAMLvars.deccmd(cs, def) if def == nil then - YAMLvars.prvcmd(cs, '\\PackageError{YAMLvars}{Variable "'..cs..'" was declared and used but, not set}{}') + YAMLvars.makecmd(cs, '\\PackageError{YAMLvars}{Variable "'..cs..'" was declared and used but, not set}{}') else - YAMLvars.prvcmd(cs, def) + YAMLvars.makecmd(cs, def) end end +-- -- -- -- -- -- local function getYAMLfile(y) local f = io.open(y,"r") @@ -300,16 +317,19 @@ local function getYAMLfile(y) io.close(f) return y else - tex.print('\\PackageError{YAMLvars}{YAML file "'..y..'" not found}{}') + YAMLvars.pkgerr('YAML file "'..y..'" not found') return 'YAMLvars: FileNotFound' end end - function YAMLvars.declareYAMLvarsStr(y) local t = YAMLvars.yaml.parse(y) for var, specs in pairs(t) do + if pl.hasval(specs['lowcasevar']) or YAMLvars.lowvasevarall then + var = var:lower() + YAMLvars.varslowcase:append(var) + end YAMLvars.varspecs[var] = {xfm=YAMLvars.xfmDefault,prc=YAMLvars.prcDefault,dft=YAMLvars.dftDefault} if type(specs) == 'string' then specs = {xfm={specs}} @@ -339,11 +359,14 @@ local function check_def(var, val) if YAMLvars.allowUndeclared then if YAMLvars.prcDefault == 'yvdef' then YAMLvars.prc.yvdef(var, val) + YAMLvars.debugtalk(var..' = '..val,'yvdef made (undeclared)') else - YAMLvars.prvcmd(var, val) + YAMLvars.makecmd(var, val) + YAMLvars.debugtalk(var..' = '..val,'gdef made (undeclared)') end else - tex.print('\\PackageError{YAMLvars}{Variable "'..var..'" set but not declared}{}') + --tex.print('\\PackageError{YAMLvars}{Variable "'..var..'" set but not declared}{}') + YAMLvars.pkgerr('Variable "'..var..'" set but not declared') end end @@ -355,7 +378,8 @@ local _YV_invalid_expression = '\1 invalid expression' local _YV_no_return = '\2 no return val' local function expr_err(var, val) - tex.print('\\PackageError{YAMLvars}{xfm with "= or /" error on var "'..var..'"}{}') -- todo make program stop + --tex.print('\\PackageError{YAMLvars}{xfm with "= or /" error on var "'..var..'"}{}') -- todo make program stop + YAMLvars.pkgerr('xfm with "= or /" error on var "'..var..'"}{}') -- todo make program stop end local function eval_expr(func, var, val) @@ -374,7 +398,8 @@ local function eval_expr(func, var, val) --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..'"}{}') -- + --tex.print('\\PackageError{YAMLvars}{xfm with "= or /" error on var "'..var..'"}{}') -- + YAMLvars.pkgerr('xfm with "= or /" error on var "'..var) -- end if c > 0 then expr_err(var) @@ -390,7 +415,8 @@ local function transform_and_prc(var, val) if f == nil then local val2 = eval_expr(func, var, val) if val2 == _YV_invalid_expression then - tex.print('\\PackageError{YAMLvars}{xfm function "'..func..'" not defined or invalid expression passed on var "'..var..'"}{}') + --tex.print('\\PackageError{YAMLvars}{xfm function "'..func..'" not defined or invalid expression passed on var "'..var..'"}{}') + YAMLvars.pkgerr('xfm function "'..func..'" not defined or invalid expression passed on var "'..var) elseif val == _YV_no_return then else val = val2 @@ -401,7 +427,8 @@ local function transform_and_prc(var, val) end f = YAMLvars.prc[YAMLvars.varspecs[var]['prc']] if f == nil then - tex.print('\\PackageError{YAMLvars}{prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined}{}') + --tex.print('\\PackageError{YAMLvars}{prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined}{}') + YAMLvars.pkgerr('prc function "'..YAMLvars.varspecs[var]['prc']..'" on var "'..var..'" not defined') end f(var, val) -- prc the value of the variable end @@ -409,6 +436,9 @@ end function YAMLvars.parseYAMLvarsStr(y) YAMLvars.varsvals = YAMLvars.yaml.parse(y) for var, val in pairs(YAMLvars.varsvals) do + if YAMLvars.varslowcase:contains(var:lower()) then + var = var:lower() + end if YAMLvars.varspecs[var] == nil then check_def(var, val) -- if not declared -- todo consider free form parse declaring @@ -464,10 +494,127 @@ function YAMLvars.getYAMLcli() end + +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 t = {} + for k,v in pairs(pdfmetadata_yaml) do -- ensure first character is capital letter + t[k:upfirst()] = v + end + __PDFmetadata__ = table.update(__PDFmetadata__, t) + end + end + + + + + + + +-- graveyard + + +function YAMLvars.prc.setheader(val, rl) + local _, count = string.gsub(val, '\\\\', '') + if count == 0 then + val = '{\\ }\\\\'..val + end + val = '\\setstretch{0.8}'..val + tex.print('\\'..rl..'ohead{'..val..'}') +end + + +function YAMLvars.prc.setheader(val, rl) + local _, count = string.gsub(val, '\\\\', '') + if count == 0 then + val = '{\\ }\\\\'..val + end + val = '\\setstretch{0.8}'..val + tex.print('\\'..rl..'ohead{'..val..'}') +end + +function YAMLvars.prc.rhead(var, val) + YAMLvars.prc.setheader(val, 'r') +end + +function YAMLvars.prc.lhead(var, val) + YAMLvars.prc.setheader(val, 'l') +end + + + +function YAMLvars.prc.memoTo(var, val) + for k, v in pairs(v) do + pl.tex.defcmd('@memoTo', val) + v = YAMLvars.xfm.list2nl(var, v) + pl.tex.defcmd('@memoTo', val) + end +end +function YAMLvars.prc.memoFr(var, val) + for k, v in pairs(v) do + pl.tex.defcmd('@memoFr', val) + v = YAMLvars.xfm.list2nl(var, v) + pl.tex.defcmd('@memoFrAddr', val) + + end +end +-- produce \Var[val[2]\\val[3].....\val[n]]{val[1]} +--function YAMLvars.prc.setdocvarOpt(var, val) +-- if type(val) ~= 'table' then +-- val = {val} +-- end +-- local s = '\\'..var..'{'..tostring(val[1])..'}' +-- s = s..'['..pl.List(v):map_slice1():join()..']' -- what does this do? +-- tex.print(s) +--end +-- +-- +--function YAMLvars.prc.setdocvarOpts(var, val) +-- if type(val) ~= 'table' then +-- val = {val} +-- end +-- local s = '\\'..var..'{'..tostring(val[1])..'}' +-- for k, v in pairs(val) do +-- if k > 1 then +-- s = s..'['..tostring(v)..']' +-- end +-- end +-- tex.print(s) +--end + return YAMLvars + + + + + + + --token.set_macro('@memoFr', k, 'global') + --token.set_macro('@memoFrAddr', v, 'global') + --token.set_macro('@memoTo', k, 'global') + --token.set_macro('@memoToAddr', v, 'global') + --help_wrt(var,val) + -- token.set_macro('@'..var, val, 'global') + +--function YAMLvars.prc.title(var, val) +-- YAMLvars.prc.setdocvar('title', val) +--end +-- +-- +--function YAMLvars.prc.author(var, val) +-- YAMLvars.prc.setdocvar('author', val) +--end +-- +--function YAMLvars.prc.date(var, val) +-- YAMLvars.prc.setdocvar('date', val) +--end + + --clean = clean or true --if clean then -- clean first part of yaml string -- y = clean_tex_spaces(y) @@ -479,4 +626,5 @@ return YAMLvars -- end -- s, _ = s:gsub('\\par ','\n\n') -- return s ---end
\ No newline at end of file +--end + diff --git a/macros/luatex/latex/yamlvars/yamlvars.pdf b/macros/luatex/latex/yamlvars/yamlvars.pdf Binary files differindex 864a0842d4..6fc0c5ce7e 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 1c4b8fcf32..852b0de8cc 100644 --- a/macros/luatex/latex/yamlvars/yamlvars.sty +++ b/macros/luatex/latex/yamlvars/yamlvars.sty @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-03-03 +% 2022-03-15 % Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -25,7 +25,7 @@ \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{YAMLvars}[2022-03-03] +\ProvidesPackage{YAMLvars}[2022-03-15] \IfFileExists{markdown-tinyyaml.lua}{}{\PackageError{YAMLvars}{This package requires installation of the 'markdown' package, please install it and try again}{}} @@ -69,8 +69,23 @@ } \newenvironment{parseYAMLvars}{\luadirect{pl.tex.startrecording()}}{\luadirect{pl.tex.stoprecording()} - \luadirect{YAMLvars.parseYAMLvarsStr(pl.tex.recordedbuf)} } +\AfterEndEnvironment{parseYAMLvars}{\luadirect{YAMLvars.parseYAMLvarsStr(pl.tex.recordedbuf)}} +% 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 \newcommand{\resetYAMLvarsspec}{\luadirect{YAMLvars.varspec = {}}} + +\newcommand{\lowercasevarYVon}{\luadirect{YAMLvars.lowvasevarall = true}} +\newcommand{\lowercasevarYVoff}{\luadirect{YAMLvars.lowvasevarall = false}} + + + +\newenvironment{parseYAMLpdfdata}{\luadirect{pl.tex.startrecording()}}{ + \luadirect{pl.tex.stoprecording() + YAMLvars.yaml2PDFmetadata(pl.tex.recordedbuf) + pl.tex.writePDFmetadata() + } +} + diff --git a/macros/luatex/latex/yamlvars/yamlvars.tex b/macros/luatex/latex/yamlvars/yamlvars.tex index 1c412c2f6d..344185dd5f 100644 --- a/macros/luatex/latex/yamlvars/yamlvars.tex +++ b/macros/luatex/latex/yamlvars/yamlvars.tex @@ -1,5 +1,5 @@ % Kale Ewasiuk (kalekje@gmail.com) -% 2022-03-03 +% 2022-03-15 % Copyright (C) 2021-2022 Kale Ewasiuk % % Permission is hereby granted, free of charge, to any person obtaining a copy @@ -147,6 +147,16 @@ If the token is available, it is set to a package error, so that if the variable tell the user they forgot to set it. This will be overwritten when you parse the variables and assign a value to it. +\paragraph{If you want a case-insensitive variable} In the declaration YAML document, +add a \cmd{lowcasevar: true} under the variable name. +This will make the variable name lowercase before any transforms or processing is done. +For example, if you have \cmd{title} as a YAML variable to set +the \cmd{prc} function \cmd{setdocvar}, a user could write +\cmd{Title} in the parsing file and still have it work. +You can toggle this behaviour globally with +the commands \cmd{\lowercasevarYVon} and \cmd{\lowercasevarYVoff} +See the last example below. + You can change the default \texttt{xfm}, \texttt{prc}, or \texttt{dft} by changing the value (in Lua): \texttt{YAMLvars.xfmDefault = ''} etc. @@ -164,6 +174,17 @@ Revisions: xfm: [sortZA, list2tab] Rhead: prc: setRightHead + + +author: + xfm: list2and # (joins a list with \and (or lets a single string be passed) + prc: setdocvar # calls \author{val} + lowcasevar: true # allows user to use Title: or TITLE: + +title: + xfm: lb2nl # (make line-breaks \\) + prc: setdocvar # calls \title{val} + lowcasevar: true # allows user to use Title: or TITLE: \end{declareYAMLvars} \end{verbatim} |