0

In a document class for XeLaTeX, I invoke hyperref in \AtBeginDocument so that it gets loaded last, and I reset the link colours at the same time. I then use \hypersetup in \maketitle to set the PDF metadata.

In the MWE below, I don't get any PDF metadata in the output (pdfinfo returns no title or author). I have obviously misunderstood something about \hypersetup with metadata, but what?

test.cls =========================================================================================

\NeedsTeXFormat{LaTeX2e}[2017/04/15]
\ProvidesClass{test}[v0.1 test hypersetup]
%
\ProcessOptions\relax
\LoadClass[a4paper]{report}
%
\def\MY@customtitle{\relax}
\def\MY@customauthor{\relax}
%
\renewcommand{\title}[1]{\gdef\MY@customtitle{#1}}
\renewcommand{\author}[1]{\gdef\MY@customauthor{#1}}
%
\AtBeginDocument{%
  \RequirePackage[colorlinks]{hyperref}%
  \hypersetup{linkcolor=blue,
              urlcolor=purple,
              citecolor=magenta}%
}
%
\renewcommand{\maketitle}{%
  \begin{titlepage}
    \MY@customtitle
    \par\bigskip
    \MY@customauthor
    \par\vfill
  \end{titlepage}
  \pagenumbering{roman}
  \hypersetup{pdfauthor={\MY@customauthor},
              pdftitle={\MY@customtitle},
              pdfcreator={XeLaTeX}}%
}
\endinput

test.tex =================================================================================

\documentclass{test}
\begin{document}
\title{Test document}
\author{A.N. Author}
\maketitle
Here is a link on some \href{http://latex.silmaril.ie}{text}
\end{document}

(Also, very weirdly, it fails to honour the colour purple, despite the xcolor documentation sayin that it's available by default).

3
  • as you are not loading xcolor it isn't really relevant what the documentation says about purple. Commented May 31, 2020 at 22:28
  • I assumed hyperref would load xcolor like it normally does because I requested [colorlinks]. Most of the time hyperref does load xcolor, and barfs because if you need a palette, you have to force it in with \PassOptionsToPackage to avoid the clash. Commented Jun 1, 2020 at 14:03
  • hyperref never loads xcolor. Commented Jun 1, 2020 at 14:16

1 Answer 1

2

Currently hyperref will write the metadata at the end of the first page to the pdf. Your \hypersetup is after the titlepage environment and so on the second page. This is too late.

1
  • Ooh, thank you. I had missed that. Commented Jun 1, 2020 at 14:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .