TransWikia.com

Changed hyperxmp or hyperref causing error with pdfdate={today}

TeX - LaTeX Asked on January 1, 2021

The following used to be OK. With the most recent release of hyperxmp, it no longer does, giving error:

./hypersetup-bug.tex:9: Argument of hyxmp@pdf@to@xmp@date has an extra }.
<inserted text> 
                par 
l.9 }

How can this be fixed or worked around?

documentclass{article}

usepackage{hyperxmp} % to add metadata info into pdf
usepackage[pdfa]{hyperref}
hypersetup{
  pdfapart=2, 
  pdfaconformance=u,
  pdfdate={today},
}

usepackage{kantlipsum}

begin{document}
kant[1]
end{document}

I tried changing the preamble so as to include the following:

usepackage[main=english]{babel}
usepackage{datetime2}

That avoids the error. However, I still want to be able to include in the text of the document a date of a form such as "December 1, 2020". Unfortunately, timedate2 has redefined today, and I cannot figure out from that package’s documentation to have both 2020-112-01 as the value of today in the argument to hypersetup, on the one hand, and somehow nanipulate the date so as to have the wordy form "December 1, 2020" within the body of the document.

One Answer

The error stems from the requirement that pdfdate needs to be in a specific format, not <monthname> <day>, <year>. The hyperxmp documentation mentions:

XMP metadata can include a number of dates (in fact, timestamps, as they include both date and time components). pdfdate specifies the document date. It is analogous to the LaTeX date command, and, like date, defaults to the date the document was built. It must be specified in either XMP format or PDF format.

Your date format doesn't match either of these. As you found, including datetime2 fixes this as it suddenly conforms to the PDF date format. However, in order to get your desired in-document date display, you need to redefine the date format. Here's how:

documentclass{article}

usepackage{datetime2}
DTMusemodule{english}{en-US}

usepackage{hyperxmp} % to add metadata info into pdf
usepackage[pdfa]{hyperref}

hypersetup{
  pdftitle = {A title},
  pdfauthor = {An author},
  pdfapart = 2,
  pdfaconformance = U,
  pdfdate = {today}
}

usepackage{lipsum}

% Set a new date style/representation
DTMnewdatestyle{usdate}{%
  % DTMdisplaydate{<year>}{<month>}{<day>}{<day of week>}
  renewcommand{DTMdisplaydate}[4]{%
    DTMenglishmonthname{##2} number##3, number##1 }%
   renewcommand{DTMDisplaydate}{DTMdisplaydate}% Capitalization of DTMdisplaydate
}
DTMsetdatestyle{usdate}% Use the above-defined date for date representation within the document

begin{document}

today

lipsum[1]

end{document}

Correct answer by Werner on January 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP