# Printing a sheet multiple times with list of names

How to print the same exam (can be multiple pages long) multiple times with a different student name on it?

Something similar has been covered here. However, I want the name list to be separated only with line break (like copy pasted from Google Drive or Excel):

Sam Student
John Doe
Bat Man

-
Have you looked at the datatool package? –  John Kormylo Sep 4 at 17:04

Here's a way using only one file, besides the list of students. In the example I used the filecontents* environment to make it self-contained.

\begin{filecontents*}{students.lst}
Sam Student
John Doe
Bat Man
\end{filecontents*}

\documentclass{article}
\usepackage{xparse,environ}

\ExplSyntaxOn
\NewDocumentCommand{\printexamtext}{m}
{
\ior_open:Nn \g_mappi_student_list_stream { #1 }
\ior_map_inline:Nn \g_mappi_student_list_stream
{
\tl_set:Nn \studentname {##1}
\mappi_print_exam:
}
}
\ior_new:N \g_mappi_student_list_stream
\cs_new_protected:Npn \mappi_print_exam:
{
\clearpage
\setcounter{page}{1}
\BODY
\ExamFooter
}
\ExplSyntaxOff

\NewEnviron{ExamText}[1]{%
\printexamtext{#1}%
}

\begin{center}
\LARGE Linear Algebra -- 2014 -- Fall Session \\[2ex]
\large \studentname
\end{center}
\vspace{2cm}
}

\newcommand{\ExamFooter}{%
\vfill
\hrule
\vspace{2ex}
}

\begin{document}

\begin{ExamText}{students.lst}
\noindent\textbf{Exercise 1}

Compute the rank of a matrix of your choice.

\bigskip

\noindent\textbf{Exercise 2}

What are the eigenvalues of the identity matrix?

\bigskip

\noindent\textbf{Exercise 3}

Prove that the zero matrix is not invertible.
\end{ExamText}

\end{document}


The ExamText environment contains the questions, type it as if it were a normal document. I split up the header and footer to have them in a separate place (for code reusing).

xparse is not really necessary, it just makes it easier to loop through an external file.

-
Works like a glove! And, aww, how sweet of you to provide questions as well :) –  Mappi Sep 5 at 4:46

Shamelessly based on the code in egreg's answer.

I would use textmerg. In combination with titling and fancyhdr, you don't need to do anything special to get the examination title etc. customised for each student's paper. The use of enumitem makes it easy to customise the format of the questions if this is desired.

\begin{filecontents*}{students.lst}
Sam Student
John Doe
Bat Man
\end{filecontents*}

\documentclass{article}
\usepackage{textmerg,titling,fancyhdr,enumitem,kantlipsum}
\newlist{examqns}{enumerate}{1}
\setlist[examqns]{label=Question \arabic*, font=\bfseries, wide, ref=\arabic*}

\begin{document}
\title{Introduction to Philosophy --- Autumn 2014}
\date{Date of Examination}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\thetitle}
\fancyhf[cf]{\theauthor}
\fancyhf[rh]{\thepage}

\Fields{\studentname}
\Merge{students.lst}{%
\clearpage% use \cleardoublepage if printing double-sided
\author{\studentname}
\maketitle
\setcounter{page}{1}
\begin{center}
\fbox{\parbox{.5\linewidth}{%
\centering\bfseries
\normalsize There are \ref{lastone} questions.\\
}}
\end{center}
\bigskip

\begin{examqns}
\item Could this examination have been a surprise?
\item Prove God's existence. (Maximum 250 words)
\item Why does Russell's barber present a problem?
\item \label{lastone}Critically evaluate the following passage from Kant:
\begin{quote}
\kant[1-3]
\end{quote}
\end{examqns}
}

\end{document}


-
My questions are more difficult. :P –  egreg Sep 4 at 19:56
@egreg Yes, but the answers to mine are harder :). –  cfr Sep 4 at 19:57