diff options
Diffstat (limited to 'Master/texmf-dist/tex/luatex/penlight/penlightextras.lua')
-rw-r--r-- | Master/texmf-dist/tex/luatex/penlight/penlightextras.lua | 79 |
1 files changed, 76 insertions, 3 deletions
diff --git a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua b/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua index 192c86c9231..e021567c139 100644 --- a/Master/texmf-dist/tex/luatex/penlight/penlightextras.lua +++ b/Master/texmf-dist/tex/luatex/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 |