3

Background

I want to create a document with the user data of our network at school, which should be handed out to the user. This should be done class by class.

Approach

The user data are given in a csv-file. I use csvsimple to process them as follows. I know that there are better ways to structure the data as \newline, but I want to keep it simple.

\documentclass{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{filecontents}
\usepackage{csvsimple}

\begin{filecontents*}{user.csv}
Adam Apfel;5a
Alexander Arthur;5a
Arndt Albrecht;5a
Barbara Boll;5b
Bert Brüller;5b
Brian Blaumann;5b
Charles Chaume;5c
Claude Claudette;5c
\end{filecontents*}

\newcommand{\csvfilename}{user.csv}


\begin{document}

  \csvreader[
    separator=semicolon,
    after line=\newline
  ]
  {\csvfilename}
  {1=\name, 2=\class}
  {
    \name, \class
  }

\end{document}

Problem

I want to print the user class by class. So there should be a pagebreak after the class changes, and I have one (or more) pages for class 5a, one for 5b and so on.

I tried many different things, but nothing worked. My idea (which I deleted after frustration ...) was to create a temporary macro, which saves the current class and compares it with the current class at the next row. But I didn't get it work.

3

You can store the actual class from the csv list in a command \lastclass and check if the next one is still the same, or then do \clearpage.

Be sure to use \edef to update the value of \lastclass so it's updated in this very moment.

\documentclass{scrartcl}

\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{filecontents}
\usepackage{csvsimple}
\usepackage{ifthen}

\begin{filecontents*}{user.csv}
Adam Apfel;5a
Alexander Arthur;5a
Arndt Albrecht;5a
Barbara Boll;5b
Bert Brüller;5b
Brian Blaumann;5b
Charles Chaume;5c
Claude Claudette;5c
\end{filecontents*}

\newcommand{\csvfilename}{user.csv}


\begin{document}
  \def\lastclass{}%
  \csvreader[
    separator=semicolon,
    after line=\newline
  ]
  {\csvfilename}
  {1=\myname, 2=\myclass}
  {%
    \ifthenelse{\equal{\lastclass}{\myclass}}{}{%
        \clearpage
        \edef\lastclass{\myclass}%
        }
    \myname, \myclass
  }

\end{document}
  • That's exactly what I was looking for! Thank you very much! As my knowledge about plain TeX is very limited, I don't know much about expandation and \edef is new to me. – dawu Oct 11 '15 at 19:08

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.