6

I started a document like this to avoid having to write the title and author twice:

\title{The Document's Title}
\author{My Name}

\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=blue,
    urlcolor=black,
    pdftitle={\@title},
    pdfauthor={\@author},
    bookmarks=true
}

I read about using \@title to insert the document's title. However, it doesn't work. Instead, my PDF's title (the text in the window bar of the PDF viewer) is now "title".

If you want a complete document which exhibits the problem for testing, you can use this:

\documentclass{report}
\usepackage{hyperref}

\title{The Document's Title}
\author{My Name}

\hypersetup{
    colorlinks,
    citecolor=black,
    filecolor=black,
    linkcolor=blue,
    urlcolor=black,
    pdftitle={\@title},
    pdfauthor={\@author},
    bookmarks=true
}

\begin{document}
Some text.
\end{document}
Heiko Oberdiek
  • 271,626
UTF-8
  • 411
  • You should make (small) but complete examples. Snippets can not be tested easily. – Ulrike Fischer Oct 30 '16 at 16:45
  • @UlrikeFischer I assumed it's so basic that that's not necessary. I added it. – UTF-8 Oct 30 '16 at 16:51
  • \@title is the \@ command followed by title in a document unless you use \makeatletter which makes @ a letter – David Carlisle Oct 30 '16 at 16:57
  • You need to add \makeatletter and \makeatother, as suggested in http://tex.stackexchange.com/a/17254/4012. But it’s easier to use the option pdfusetitle. Essentially, this question seems to be a duplicate of http://tex.stackexchange.com/q/17218/4012, so I’d propose closing it as that? Edit: Why doesn’t tex.sx show me new comments until I submitted mine ... ? – doncherry Oct 30 '16 at 17:04
  • 1
    @UTF-8: get the habit to provide a complete example. May it be necessary or not it makes testing more easier http://meta.tex.stackexchange.com/a/6258/2388 – Ulrike Fischer Oct 30 '16 at 18:07

1 Answers1

8

\@title and \@author have @ in their names, therefore \makeatletter is needed:

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

An alternative is option pdfusetitle, which tries to automatically catch \@title and \@author:

\usepackage[pdfusetitle]{hyperref}
Heiko Oberdiek
  • 271,626
  • I tried using the pdfusetitle option but it didn't work. It didn't put the title nor the author into the PDF. Since the title was then empty, PDF viewers didn't show a title as meta information and put the file name into the window bar. However, using \makeatletter worked and put both the author and the title information into to PDF's meta data. Thank you! – UTF-8 Oct 30 '16 at 18:26
  • @UTF-8 The option pdfusetitle hooks into \maketitle, which is missing here. – Heiko Oberdiek Oct 30 '16 at 19:05
  • In my document, \maketitle is the very first command after \begin{document}. – UTF-8 Oct 30 '16 at 19:30
  • @UTF-8 Without further details, MWE, it's guessing in the dark. Anyway, pdfusetitle is just a convenience option. Either it works or not, there are other ways of setting the title and author in the PDF document. – Heiko Oberdiek Oct 30 '16 at 20:06