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).



I could have done this like that


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 ]{

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.

  • Welcome to TeX.SE. It would be helpful to know exactly what you want to accomplish. There is the arrayjobx pacakge, but I tend to just use comma separated lists, and use pgf's \foreach to process them. newcommand{\fooArray}{foo,bar} should suffice. – Peter Grill Sep 15 '12 at 0:12
  • I have told exactly what I want to do now :) – Benoît Legat Jul 16 '13 at 19:32

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

enter image description here

\usepackage{hyperref}% http://ctan.org/pkg/hyperref
  {\renewcommand{\and}{\unskip, }\hypersetup{pdfauthor={#1}}}
\title{My title}
\authors{John Doe \and Dark Vador \and Yoda}

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


For the special case, there is also a cheap solution. \and can be redfined for hyperref's pdfauthor:


\pdfstringdefDisableCommands{\def\and{, }} 

\title{Test document}
\authors{John Doe\and Dark Vador\and Yoda}% without space before \and


And pdfinfo reports:

Author:         John Doe, Dark Vador, Yoda

The real application is almost trivial with xparse and expl3.


  \legat_authors:nn { #1 } { #2 }
\seq_new:N \g_legat_authors_seq

\cs_new_protected:Npn \legat_authors:nn #1 #2
  \seq_gset_split:Nnn \g_legat_authors_seq { #1 } { #2 }
    \exp_not:N \hypersetup {pdfauthor={ \seq_use:Nn \g_legat_authors_seq { , } } }
  \author{ \seq_use:Nn \g_legat_authors_seq { \and } }

\authors{John Doe, Dark Vador, Yoda}
\title{Star Wears}



The only subtle point is passing the list of authors expanded to \hypersetup, which is obtained by \use:x.

The command \authors has an optional argument; if a different delimiter than a comma is needed one can set it in the optional argument:

\authors[;]{Dean Martin; Sammy Davis, Jr; Jerry Lewis}

Note that this requires an up-to-date TeX distribution.

enter image description here

How does it work? The \seq_gset_split:Nnn function (globally) stores the third argument as elements of the sequence, using the second argument as delimiter between items. This sequence can then be used as many times as one wants. Here we use it first for passing the comma separated list of authors to \hypersetup, then as the argument to \author.

  • Your solution is great, sadly, I'm looking for a simple solution that works through many LaTeX version :) – Benoît Legat Jul 17 '13 at 11:07

Since I couldn't get yours to give any output, I changed some definitions around to produce parsed output of the form you requested.



  \convertword[e]{#1}{~and~}{, }%
  \convertchar[e]{\thestring}{,}{ \and}%
\authors{John Doe, Dark Vador and Yoda}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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