3

I'm using datatool to load a csv table. Students names are in that table (first column first name, second column last name) and I like to print them on the exam. In a related question, I asked how to print a student id number on each exam. In a similar way I like to print the names taken from the table on each exam. My first approach (I just like to print an arbitrary value) looks like this and unfortunately doesn't work:

\documentclass[
  paper=A4,
  fontsize=10pt
]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{multido}
\usepackage{datatool}

\pagestyle{empty}

\newcounter{studentidcounter}
\setcounter{studentidcounter}{1}
\newcommand{\studentid}{%
  \ifnum\thestudentidcounter<10\relax%
  0\thestudentidcounter\else%
  \thestudentidcounter\fi%
}

\DTLsetdelimiter{,}
\DTLloaddb[noheader=true]{members}{members.csv}

\DTLgetvalue{\studentsurname}{members}{1}{2}
\DTLgetvalue{\studentlastname}{members}{1}{1}

\newcommand{\studentname}[2]{#1 #2}

\begin{document}

\show\studentsurname

\multido{\nx = 1+1}{3}{  
  \input{examMain.tex}
  \clearpage
  %----------------------------------------------------------------------
  % Uncomment next lines if exam has an odd number of pages.
%   \newpage
%   \mbox{}
%   \newpage
  %----------------------------------------------------------------------
  \stepcounter{studentidcounter}%
  \setcounter{equation}{0}
}

\end{document}

So how can I achieve that the table is iterated within multido? And I need some kind of macro that I can use in examMain.tex to access the students full name?

A possible example of members.cvs could look like this

Name1, FirstName1
Name2, FirstName2
Name3, FirstName3
2
  • 1
    Could you please add a small example of how the members.csv file is organized?
    – egreg
    Commented Feb 12, 2013 at 11:57
  • I added an example. But I think that doesn't really matter. I suggest a situation where I already had been able to seperate my file with the help of datatool into 2 columns, one for the family name and one for the first name.
    – DaPhil
    Commented Feb 13, 2013 at 11:32

1 Answer 1

3

Use \DTLforeach:

\begin{filecontents*}{students.csv}
firstname,lastname
FirstName1,LastName1
FirstName2,LastName2
FirstName3,LastName3
\end{filecontents*}

\begin{filecontents*}{\jobname-exam.tex}
\noindent Student ID = \fbox{\studentid}\quad
\studentfirstname\ \studentlastname

\bigskip

Solve the equation $x-1=0$.
\end{filecontents*}

\documentclass{article}
\usepackage{datatool}

\pagestyle{empty}

\newcounter{studentidcounter}
\newcommand{\studentid}{%
  \ifnum\thestudentidcounter<10 0\fi
  \thestudentidcounter}

\DTLsetdelimiter{,}
\DTLloaddb{students}{students.csv}

\begin{document}

\DTLforeach{students}
  {\studentfirstname=firstname,\studentlastname=lastname}
  {\stepcounter{studentidcounter}
   \input{\jobname-exam.tex}
   %\clearpage
   \par\bigskip\hrule\bigskip % just not to produce many pages
  }

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .