Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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
share|improve this question
    
Have you looked at the datatool package? –  John Kormylo Sep 4 at 17:04

2 Answers 2

up vote 6 down vote accepted

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}
  \ExamHeader
  \BODY
  \ExamFooter
 }
\ExplSyntaxOff  

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

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

\newcommand{\ExamFooter}{%
  \vfill
  \hrule
  \vspace{2ex}
  \noindent Please, answer all questions\par
}

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

enter image description here

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

share|improve this answer
    
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}
  \renewcommand{\footrulewidth}{\headrulewidth}

  \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
          \large Answer ALL questions.\\
          \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}

examination

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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