Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm typesetting a document based on the Elsevier document class.

I want to use hyperref's \hypersetup to set title, author, and keywords of the generated PDF file to the corresponding values.

The problem is that I want \hypersetup values to be generated automatically; i.e. it takes the title of the paper and sets it as the title of the PDF file, and does the same for the author and keywords fields.

Here's what I came up with until now:

\documentclass{elsarticle}

\usepackage{hyperref}

\begin{document}

\title{A Test Title}

\author{John Doe}
\author{Jane Doe}
\author{John Smith}

\begin{abstract}
...
\end{abstract}

\begin{keyword}
    key1, key2, key3, key4.
\end{keyword}

\maketitle

\makeatletter
\hypersetup{
    pdfinfo={
        Title={\@title},
        Author={},
        Keywords={}
    }
}
\makeatother

\end{document}

As shown above, I used \@title (which is defined internally by elsarticle document class). I just don't know how to automatically include author names and keyword list (both of them in the comma-separated format).

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

Unfortunately elsarticle doesn't simply store the list of authors in a control sequence, nor the list of keywords, so you have to create your own:

\documentclass{elsarticle}

\usepackage{etoolbox,environ}
\makeatletter
\def\auto@authors{\@gobbletwo}
\pretocmd{\@author}{\g@addto@macro\auto@authors{,\space #1}}{}{}
\pretocmd{\@@author}{\g@addto@macro\auto@authors{,\space #2}}{}{}
\let\kept@keyword\keyword
\let\kept@endkeyword\endkeyword

\let\keyword\relax\let\endkeyword\relax
\NewEnviron{keyword}{%
  \expandafter\gdef\expandafter\auto@keywords\expandafter{\BODY}%
  \kept@keyword\BODY\kept@endkeyword}
\makeatother

\usepackage{hyperref}

\begin{document}

\title{A Test Title}

\author{John Doe}
\author{Jane Doe}
\author{John Smith}

\begin{abstract}
...
\end{abstract}

\begin{keyword}
    key1, key2, key3, key4.
\end{keyword}

\maketitle

\makeatletter
\hypersetup{
    pdfinfo={
        Title={\@title},
        Author={\auto@authors},
        Keywords={\auto@keywords}
    }
}
\makeatother

\end{document}

Here's the (relevant) output of pdfinfo:

Title:          A Test Title
Subject:        
Keywords:       key1, key2, key3, key4.
Author:         John Doe, Jane Doe, John Smith
Creator:        LaTeX with hyperref package
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.