diff --git a/luametalatex-back-pdf.lua b/luametalatex-back-pdf.lua index e1265a4..253f566 100644 --- a/luametalatex-back-pdf.lua +++ b/luametalatex-back-pdf.lua @@ -25,6 +25,27 @@ token.luacmd("shipout", function() token.put_next(token.create'immediateassignment', token.create'global', token.create'deadcycles', token.create(0x30), token.create'relax') token.scan_token() end, 'protected') +local infodir = "" +local creationdate = os.date("D:%Y%m%d%H%M%S%z"):gsub("+0000$", "Z"):gsub("%d%d$", "'%0") +local function write_infodir(p) + local additional = "" + if not string.find(infodir, "/CreationDate", 1, false) then + additional = string.format("/CreationDate(%s)", creationdate) + end + if not string.find(infodir, "/ModDate", 1, false) then + additional = string.format("%s/ModDate(%s)", additional, creationdate) + end + if not string.find(infodir, "/Producer", 1, false) then + additional = string.format("%s/Producer(LuaMetaLaTeX)", additional) + end + if not string.find(infodir, "/Creator", 1, false) then + additional = string.format("%s/Creator(TeX)", additional) + end + if not string.find(infodir, "/PTEX.Fullbanner", 1, false) then + additional = string.format("%s/PTEX.Fullbanner(%s)", additional, status.banner) + end + return p:indirect(nil, string.format("<<%s%s>>", infodir, additional)) +end callback.register("stop_run", function() for fid, id in pairs(fontdirs) do local f = font.getfont(fid) @@ -38,6 +59,7 @@ callback.register("stop_run", function() end pfile.root = pfile:getobj() pfile:indirect(pfile.root, string.format([[<>]], pfile:writepages())) + pfile.info = write_infodir(pfile) pfile:close() end, "Finish PDF file") token.luacmd("pdfvariable", function() @@ -49,7 +71,11 @@ token.luacmd("pdfvariable", function() end -- The following error message gobbles the next word as a side effect. -- This is intentional to make error-recovery easier. + --[[ error(string.format("Unknown PDF variable %s", token.scan_word())) + ]] -- Delay the error to ensure luatex85.sty compatibility + texio.write_nl(string.format("Unknown PDF variable %s", token.scan_word())) + tex.sprint"\\unexpanded{\\undefinedpdfvariable}" end) local whatsit_id = node.id'whatsit' local whatsits = node.whatsits() @@ -129,6 +155,8 @@ token.luacmd("pdffeedback", function() local mode = scan_literal_mode() local default = token.scan_string() tex.sprint(tostring(pdf.newcolorstack(default, mode, page))) + elseif token.scan_keyword"creationdate" then + tex.sprint(creationdate) else -- The following error message gobbles the next word as a side effect. -- This is intentional to make error-recovery easier. @@ -148,6 +176,8 @@ token.luacmd("pdfextension", function() data = literal, }) node.write(whatsit) + elseif token.scan_keyword"info" then + infodir = infodir .. token.scan_string() else -- The following error message gobbles the next word as a side effect. -- This is intentional to make error-recovery easier. diff --git a/luametalatex-baseregisters.tex b/luametalatex-baseregisters.tex index f19bd05..ad51020 100644 --- a/luametalatex-baseregisters.tex +++ b/luametalatex-baseregisters.tex @@ -71,8 +71,10 @@ \def\pdfAlloc{% \internalAlloc{pdf}% } -\texAlloc{dimen}{pageheight}{11in} -\texAlloc{dimen}{pagewidth}{8.5in} +\texAlloc{count}{outputmode}{1} % The "traditional" default would be 0, + % but we do not actually support that. +\texAlloc{dimen}{pageheight}{210mm} +\texAlloc{dimen}{pagewidth}{297mm} \pdfAlloc{dimen}{horigin}{1in} \pdfAlloc{dimen}{vorigin}{1in} \directlua{ diff --git a/luametalatex-pdf.lua b/luametalatex-pdf.lua index 695813e..fed0016 100644 --- a/luametalatex-pdf.lua +++ b/luametalatex-pdf.lua @@ -52,7 +52,8 @@ local function trailer(pdf) offsets[linked+1] = '\0\0\0\0\255' pdf[nextid] = assigned -- TODO: Add an /ID according to 14.4 - stream(pdf, nextid, format([[/Type/XRef/Size %i/W[1 3 1]/Root %i 0 R]], nextid+1, pdf.root), table.concat(offsets)) + local info = pdf.info and string.format("/Info %i 0 R", pdf.info) or "" + stream(pdf, nextid, format([[/Type/XRef/Size %i/W[1 3 1]/Root %i 0 R%s]], nextid+1, pdf.root, info), table.concat(offsets)) pdf.file:write('startxref\n', myoff, '\n%%EOF') end local function close(pdf)