[Tex/LaTex] Make ar­ray data struc­tures in LaTeX

data structuresmacros

Is there a way to make an array in LaTeX.
I want to write a function that does this (here the array has only 2 elements but I want to be able to have many as I want).

\foo{\MakeArray{foo,bar}}

foo|bar-foo&bar

I could have done this like that

\newcommand\foo[2]{\1-\2}
\foo{foo|bar}{foo&bar}

But I need to enter the elements twice which is not very neat…

EDIT:
Sadly, even if your answer solve my question, it doesn't work with my exact case so I'll tell it exactly.
I currently have

\newcommand{\authors}[2][e ]{
  \usepackage[pdfauthor={#1}]{hyperref}
  \author{#2}
}

that I use that way

\authors{John Doe, Dark Vador and Yoda}{John Doe \and Dark Vador \and Yoda}

and I would like to have the same result without specifying it twice.
However, the \and doesn't work with the proposed solution.

Best Answer

Load the hyperref package first, and then set the PDF document properties using \hypersetup:

enter image description here

\documentclass{article}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\newcommand{\authors}[1]{
  {\renewcommand{\and}{\unskip, }\hypersetup{pdfauthor={#1}}}
  \author{#1}
}
\title{My title}
\authors{John Doe \and Dark Vador \and Yoda}
\begin{document}
\maketitle
\end{document}

Inside \authors, the definition of \and is momentarily updated to insert commas.

Related Question