# Problem with \and within \hypersetup{pdfauthor=…}

I use a custom macro to set the author of both my document and its metadata. It had worked fine until I started writing a document with a colleague.

This is the code:

%----------------------------------------------------------------------------------------
%    PDF INFO
%----------------------------------------------------------------------------------------
\newcommand*{\mytitle}{Equacions diferencials}
\newcommand*{\myauthor}{Alfredo Hernández \and John Smith}
\newcommand*{\myuni}{Universitat Autònoma de Barcelona, Departament de Física}
\newcommand*{\mydate}{\normalsize 2013-2014}

\usepackage{hyperxmp}
\hypersetup{pdfauthor={\myauthor}, pdftitle={\mytitle}}

%----------------------------------------------------------------------------------------
%    TITLE SECTION AND DOCUMENT BEGINNING
%----------------------------------------------------------------------------------------
\newcommand{\horrule}[1]{\rule{\linewidth}{#1}}
\title{
\normalfont
\small \scshape{\myuni} \\ [25pt]
\horrule{0.5pt} \\[0.4cm]
\huge \mytitle \\
\horrule{2pt} \\[0.5cm]
}
\author{\myauthor}
\date{\mydate}

\begin{document}


As I understand it, the command \and is the proper way to set more than one authors. The problem is that hypersetup crashes when trying to write the metadata (of course, if I delete \and, the document renders perfectly).

Do you know any workaround to keep using \myauthor command in the metadata and the title itself?

SOLUTIONS THAT MAY WORK:

1. I have tried using & between the authors, but ShareLatex tells me that \cr is better. However, I don't know what the \cr command does and I want to avoid using code I don't know, also I don't even know if that is a proper solution in terms of coding.
2. I think that using \author1 and \author2 could solve my problem, (\author{\author1 \and \author2}; \hypersetup{pdfauthor={\author1 , \author2}), but again, I don't think this is the best solution.
• Please make your code compilable, starting with \documentclass{...} and ending with \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to help you. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Sep 30 '13 at 11:06
• Okay, I'll have that in mind. – Alfredo Hernández Sep 30 '13 at 13:00

Two approaches:

1. Add \pdfstringdefDisableCommands{\def\and{and }} after loading hyperref

2. Define two different strings for TeX and for PDF

\newcommand*{\myauthor}{%
\texorpdfstring{Alfredo Hernández \and John Smith}
{Alfredo Hernández, John Smith}}


With the first solution, the authors in the metadata will be

Alfredo Hernández and John Smith

With the second one you'll get

Alfredo Hernández, John Smith

Of course, the second way is far more flexible.

• Somehow, when I use the second approach (or use a comma in the first one) I get: 'Alfredo Hernández, John Smith';John Smith in the author metadata. However, the first solution (using and) is exactly what I wanted. – Alfredo Hernández Oct 1 '13 at 6:34