Here's a version with LaTeX3 macros:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\authorsfromfile} { O{,~} m }
{
\IfFileExists{#2}
{ \bargen_authors:nn { #1 } { #2 } }
{ \author{\texttt{https://github.com/HSR-Stud/}} }
}
\ior_new:N \l_bargen_file_ior
\seq_new:N \bargen_authors_seq
\cs_new_protected:Npn \bargen_authors:nn #1 #2
{
\seq_clear:N \l_bargen_authors_seq
\ior_open:Nn \l_bargen_file_ior { #2 }
\ior_map_inline:Nn \l_bargen_file_ior
{
\seq_put_right:Nx \l_bargen_authors_seq { \tl_trim_spaces:n { ##1 } }
}
\author { \seq_use:Nnnn \l_bargen_authors_seq { #1 } { #1 } { #1 } }
}
\ExplSyntaxOff
\begin{document}
\authorsfromfile{CONTRIBUTORS.txt}
\title{Document}
\maketitle
\end{document}
You can also do
\authorsfromfile[\and]{CONTRIBUTORS.txt}
that would use the traditional \and separator between authors.
Basically we read the file line by line and deliver the sequence thus obtained to the \author macro, with items separated by the optional argument to \authorsfromfile (default is "comma and space").
The advantage of this approach is that the line
\seq_put_right:Nx \l_bargen_authors_seq { \tl_trim_spaces:n { ##1 } }
can be modified in various ways, for example to process the input line for changing the appearance of the nickname.
A "classical" implementation, where we use the catchfile package to read the file; each line is delimited by ^^J, a character that won't appear in any reasonable text file. Also the nickname will be stripped off; the names are inserted in a \mbox in order not to split them across lines in the title page.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{catchfile}
\makeatletter
\newcommand{\authorsfromfile}[2][, ]{%
\IfFileExists{#2}
{\CatchFileDef\authors@list{#2}{\endlinechar=`^^J }\authors@do{#1}}
{\author{\texttt{https://github.com/HSR-Stud/}}}%
}
\def\authors@final@list{}
\def\authors@do#1{%
\def\authors@sep{#1}%
\expandafter\authors@do@aux\authors@list\@nil
}
\def\authors@do@aux#1^^J#2\@nil{%
\authors@strip@parens{#1}%
\expandafter\g@addto@macro\expandafter\authors@final@list\expandafter{\authors@current}%
\if\relax\detokenize{#2}\relax
\author{\authors@final@list}%
\expandafter\@gobble
\else
\expandafter\g@addto@macro\expandafter\authors@final@list\expandafter{\authors@sep}%
\expandafter\@firstofone
\fi
{\authors@do@aux#2\@nil}%
}
\def\authors@strip@parens#1{\authors@strip@aux#1 (\@nil}
\def\authors@strip@aux#1 (#2\@nil{\def\authors@current{\mbox{#1}}}
\makeatother
\begin{document}
\authorsfromfile{CONTRIBUTORS.txt}
\title{Document}
\maketitle
\end{document}
Again, one can also call this as
\authorsfromfile[\and]{CONTRIBUTORS.txt}
to get the standard separation between different authors. If the file is missing, a standard "author" will appear.
As it is it won't work if the file exists but is empty; one might add a check for it.
In order to make a long list of authors be well typeset by the article class you need to change \maketitle or, more precisely, \@maketitle:
\makeatletter
\def\@maketitle{%
\newpage
\null
\vskip 2em%
\begin{center}%
\let \footnote \thanks
{\LARGE \@title \par}%
\vskip 1.5em%
\begin{minipage}{.6\textwidth}
\large\centering\@author
\end{minipage}
\vskip 1em%
{\large \@date}%
\end{center}%
\par
\vskip 1.5em}
\makeatother
Here's what's printed if the file contains
John Doe (jdoe)
Jane Roe (jroe)
Christian Fässler
Jonas Furrer
Danilo Bargen

CONTRIBUTORS.txtwith a script (inpythonorawkor ...) before inclusion in yourLaTeXdocument. Since amakefileanswers another of your questions here that's likely. Others on this site may provide aTeXonly solution. – Ethan Bolker Jan 13 at 2:17