# Is there a poisonous interaction between memoir, hyperref, and hyperxmp?

In another, now rather confused, question, I'm struggling to get copyright information into a PDF produced by memoir.

The investigations so far have led to this problematical MWE:

% !TEX TS-program = XeLaTeX
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{hyperxmp}
\hypersetup{
pdfauthor={Brent Longborough},
pdftitle={O Hai},
}
\begin{document}
\lipsum[1]
\end{document}


which produces a PDF with the copyright notice successfully included in the metadata, and with the "PDF Producer" set to "XeTeX 0.9997"

However, if I change the document class to:

\documentclass{memoir}


then I get no copyright notice, and the PDF Producer is now set to "xdvipdfmx (0.7.8)".

After an hour or so ploughing through memoir.sty and memhfixc.sty, I'm flummoxed. Does anyone have any idea where to look next?

-
Is there a missing left brace in the pdfcopyright line? –  Seamus Feb 28 '12 at 12:46
@Seamus: Well spotted, actually, I think it's missing both left and right (as the right one you can see actually closes \hypersetup{) –  Brent.Longborough Feb 28 '12 at 15:54

This is actually a timing problem: The metadata has to be inserted before the final \clearpage command, otherwise, it isn't written to the PDF document any more. However, memoir issues a \clearpage with

\AtBeginDocument{\AtEndDocument{\clearpage\dol@stsheet\dol@stpage}}


so the code used by hyperxmp

\AtBeginDocument{%
% [...]
\AtEndDocument{%
\hyxmp@embed@packet
}%
% [...]
}


is too late as \hyxmp@find@metadata and \hyxmp@embed@packet are executed after \clearpage.

To solve this, you can manually issue

\makeatletter
\makeatother


### Minimal test code:

% !TEX TS-program = XeLaTeX
% !TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{hyperxmp}
\makeatletter
\makeatother
\hypersetup{
pdfauthor={Brent Longborough},
pdftitle={O Hai},

@Seamus: I'll talk to Lars. I think the right place for this is in memhfixc.sty, but I have no idea where. –  Brent.Longborough Feb 28 '12 at 16:28