59

I once read about an option for hyperref that automatically takes the info provided via the standard \author and \title, and puts it into the pdfinfo. Now I want to implement it in my template and can't find it anywhere in the hyperref manual nor anywhere else.

Did I dream about this or can someone help me out here?

(A similar, but more general question: Is hyperref really the best way to add metadata to a TeX file?)

doncherry
  • 54,637

2 Answers2

67

The option is pdfusetitle. It is described in the hyperref README file.

Lev Bishop
  • 45,462
  • 10
    Ah, that's where I saw it, thanks! For some reason it only seems to work as \usepackage[pdfusetitle]{hyperref} and not as \hypersetup{pdfusetitle} though. – doncherry May 02 '11 at 22:11
  • @doncherry: Yeah, a few options are like that. I suppose they require special arrangements to be made at load time... – SamB May 03 '11 at 03:58
  • 7
    As of April 2012, this option is not described in the hyperref manual. Any reason for that? – Olivier Jul 07 '12 at 10:13
  • 1
    This doesn't work (anymore?). It gives the following warning: Package hyperref Warning: Option \pdfusetitle' has already been used, setting the option has no effect on input line 44.` and has no effect (in that the PDF has no title or author set automatically). – Najib Idrissi Jul 15 '15 at 12:48
  • @NajibIdrissi The warning only says, that pdfusetitle was set too late. It needs to be set at package loading time (\usepackage). – Heiko Oberdiek Oct 30 '16 at 17:00
26

You could also use

 \makeatletter
 \hypersetup{pdftitle={\@title},pdfauthor={\@author}}
 \makeatother

(edit: makeat* pointed out by Joseph Wright)

Jaap Eldering
  • 1,760
  • 15
  • 20
  • 5
    This needs \makeatletter, of course. – Joseph Wright May 03 '11 at 11:27
  • This might be a nice alternative if pdfusetitle fails -- the readme says it "tries to derive the values", so a failure for whatever reason apparently can't be excluded. – doncherry May 03 '11 at 15:18
  • @Joseph: Would \makeatletter be called before (and \makeatother after) \hypersetup{...} or separately for each argument? Considering that I have up to nine or ten arguments for \hypersetup and considering how mighty and thus dangerous hyperref is, it might cause conflicts if placed around the entire command? – doncherry May 03 '11 at 15:23
  • @doncherry: \makeatletter before \hypersetup and \makeatother after it. – Joseph Wright May 03 '11 at 15:37
  • @doncherry the readme is right, pdfusetitle will fail if you have any non ASCII character in your title or author name, with the error ** WARNING ** Failed to convert input string to UTF16... That's why this method, with your addendum is the best. – Andrei Oct 08 '15 at 07:52
  • This works only before \begin{document}, doesn't it? – koppor Mar 14 '18 at 07:55
  • There's also the authoraftertitle package but I somehow can't get it to work. – khatchad Jun 28 '18 at 20:01