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.

I have 4 sets/groups of exam questions. I want to enumerate them from 1 to a number of persons. Because a number of students exceed 4 I must repeat the sets. If I had 40 students therefore I would write (where i is a number of repetitions)

for (i in 1 to 10) 
{
Print(Group(4*i -3)))
Print(Group(4*i -2 ))
Print(Group(4*i -1))
Print(Group(4*i))
}

How to do this in LaTeX? In the last resort I could repeat (CTRL-C, CTRL-V) code below 10 times changing consecutive numbers. I would also appreciate if you figure out how to get the same visual effect on each page i.e. items in the first page are spaced out what I don’t want to.

\documentclass[a4paper,11pt]{article}
\usepackage[cm]{fullpage}
\usepackage [utf8]{inputenc}
\usepackage{lscape}
\usepackage{multicol}
\pagestyle{empty}


\begin{document}


\begin{landscape}
\begin{multicols}{2}[\columnsep 1.5cm]


\begin{center}
\textsc{Group $4i-3$}
\end{center}

\begin{enumerate}
 \item Task  A
\item Task  B
\item Task  C
\item Task D
\end{enumerate}    
\columnbreak

\begin{center}
\textsc{Group $4i-2$}
\end{center}

\begin{enumerate}
 \item Task  E
\item Task  F
\item Task  G
\item Task H
\end{enumerate}
\pagebreak

\begin{center}
\textsc{Group $4i-1$}
\end{center}

\begin{enumerate}
 \item Task  I
\item Task  J
\item Task  K
\item Task L
\end{enumerate}


\begin{center}
\textsc{Group $4*i$}
\end{center}

\begin{enumerate}
 \item Task  M
\item Task  N
\item Task  O
\item Task P
\end{enumerate}


\end{multicols}
\end{landscape}

\end{document}
share|improve this question
1  
Try to put the repeating text into separate file. Insert it every time by \input. To change text in header you can write a simple script on bash or awk, or you can do it with TeX iterators. –  Eddy_Em Jun 7 at 6:56

4 Answers 4

up vote 2 down vote accepted

You need something like the following where the individual group questions are saved in files named like \jobname1.tex.

\documentclass{article}

\usepackage{forloop}
\usepackage{intcalc}

\begin{document}

\newcounter{stno} 
\newcounter{groupno}
\forloop{stno}{1}{\value{stno} < 41}
{
  \setcounter{groupno}{\intcalcMod{\arabic{stno}}{4}}
  \stepcounter{groupno}
  Student Number: \arabic{stno}, Set: \arabic{groupno}
  \input {\jobname\arabic{groupno}.tex}
  \clearpage
}

\end{document}
share|improve this answer

The generation of the groups can be done easily with the \forloop command from the equally named package, also to numbering of the groups.

I believe, that Task A... etc has to replaced by some other text later on, but that is out of reach to me, because I have no idea, what that tasks might be.

The individual group questions should be placed in separate files and included in the loop, perhaps with randomization.

\documentclass[a4paper,11pt]{article}
\usepackage[cm]{fullpage}
\usepackage [utf8]{inputenc}
\usepackage{lscape}
\usepackage{multicol}
\usepackage{etoolbox}
\usepackage{calc}%
\usepackage{forloop}
\usepackage{enumerate}
\pagestyle{empty}

\newcounter{taskcounter}
\newcounter{tempcounter}
\newrobustcmd{\taskcommand}{%
\refstepcounter{taskcounter}%
Task \Alph{taskcounter}%
}%


\newrobustcmd{\PrintGroup}[1]{%
\begin{center}
\setcounter{tempcounter}{4*\number\value{#1}}
\addtocounter{tempcounter}{-\number\value{groupcounter}}
\textsc{Group \number\value{tempcounter}}
\end{center}
\begin{enumerate}
\item \taskcommand
\item \taskcommand
\item \taskcommand
\item \taskcommand
\end{enumerate}
\addtocounter{groupcounter}{-1}%
}%


\newcounter{myloopcounter}
\newcounter{groupcounter}
\newcounter{maxpersons}
\setcounter{maxpersons}{11}
\begin{document}


\begin{landscape}

\begin{multicols}{2}[\columnsep 1.5cm]

\forloop{myloopcounter}{1}{\number\value{myloopcounter} < \number\value{maxpersons}}{%
\setcounter{groupcounter}{3}%
\setcounter{taskcounter}{0}%
\PrintGroup{myloopcounter}
\PrintGroup{myloopcounter}
\PrintGroup{myloopcounter}
\PrintGroup{myloopcounter}
\columnbreak%
}%


\end{multicols}
\end{landscape}

\end{document}
share|improve this answer

Here is another solution with lualatex:

\documentclass[a4paper,11pt]{article}
\usepackage{luacode}
\usepackage[cm]{fullpage}
\usepackage [utf8]{luainputenc}
\usepackage{lscape}
\usepackage{multicol}
\pagestyle{empty}
\usepackage{enumitem}


\begin{document}

\begin{luacode}

s = 9 -- Number of Students

task = {
    "Content of task A.", --A
    "Content of task B.", --B
    "Content of task C.", --C
    "Content of task D.", --D
    "Content of task E.", --E
    "Content of task F.", --F
    "Content of task G.", --G
    "Content of task H.", --H
    "Content of task I.", --I
    "Content of task J.", --J
    "Content of task K.", --K
    "Content of task L.", --L
    "Content of task M.", --M
    "Content of task N.", --N
    "Content of task O.", --O
    "Content of task P.", --P
    }

function item(n,p)
 if n == 1 then
 tex.print('\\begin{multicols}{2}[\\columnsep 1.5cm]')
 end
 z = (math.floor(n/4)) % 4 + 1
 tex.print('\\begin{center}')
 tex.print('\\textsc{Group '.. z ..'}')
 tex.print('\\end{center}')
 tex.print('\\begin{enumerate}')
 for i=n,n+3,1 do
 t = (i-1) % 16 + 1
 tex.print('\\item ' .. task[t])
 end
 tex.print('\\end{enumerate}')
 if math.floor(n/4)+1 <= p-2 then
  if (math.floor(n/4)+1) % 2 == 1 then
  print('\\columnbreak')
  else
  tex.print('\\end{multicols}')
  tex.print('\\pagebreak')
  tex.print('\\begin{multicols}{2}[\\columnsep 1.5cm]')
  end
 elseif math.floor(n/4)+1 == p-1 and p % 2 == 1 then
 tex.print('\\end{multicols}')
 tex.print('\\pagebreak')
 tex.print('\\begin{multicols}{2}[\\columnsep 1.5cm]')
 elseif math.floor(n/4)+1 == p-1 and p % 2 < 1 then
 tex.print('\\columnbreak')
 elseif math.floor(n/4)+1 == p then
  tex.print('\\end{multicols}')
 end
end     

function group(y)
 for x=1,y*4,4 do
  item(x,y)
 end
end

tex.print('\\begin{landscape}')
group(s)
tex.print('\\end{landscape}')

\end{luacode}

\end{document}

The tasks are saved in a lua table and you can simply change the number of students. There is a problem with an odd number of students, because of the multicolumn-environment.

share|improve this answer

Here is another solution (more common).

\documentclass[a4paper,12pt]{article}
\usepackage[english]{babel}

\makeatletter
\tracingmacros=1
\newcount\@grp
\newcount\@g
\newcount\@pp
\def\GrpNum{\number\@g}
\def\PersNum{\number\@pp}
\def\@p@#1{\csname @persIn\romannumeral#1\endcsname}
\def\PersInGrp#1{\global\advance\@grp by 1%
    \edef\@p@@{\csname @persIn\romannumeral\@grp\endcsname}
    \expandafter\newcount\@p@@%
    \expandafter\global\@p@@#1\relax
}
\def\GrpHas#1{\edef\@tmp@rg{\@p@{#1}}\number\@tmp@rg\relax}
\long\def\r@peatGrp#1{\ifnum\@grp>\@g\relax\global\advance\@g
    by1\relax#1\r@peatGrp{#1}\fi}
\long\def\forAllG#1{\global\@g0\relax\r@peatGrp{#1}}
\long\def\r@peatPinG#1#2{\ifnum\@p@{#1}>\@pp\relax\global\advance\@pp
    by1\relax#2\r@peatPinG{#1}{#2}\fi}
\long\def\forAllPinG#1#2{\global\@pp0\relax\global\@g#1\relax\r@peatPinG{#1}{#2}}
\long\def\forAll#1{\forAllG{\global\@pp0\relax\r@peatPinG{\GrpNum}{#1}}}
\makeatother
\begin{document}
\PersInGrp{2}\PersInGrp{3}\PersInGrp{4}\PersInGrp{5}
1: \GrpHas{1}; 2: \GrpHas{2}; 3: \GrpHas{3}; 4: \GrpHas{4}.

\forAllG{\GrpNum: hello, }

\forAllPinG{2}{\GrpNum: people --- \PersNum;}

\forAll{\textbf{Group: \GrpNum, Person: \PersNum}\par\input{b.tex}\par}
\end{document}

Macro \PersInGrp{arg} intitialize next group with arg persons; macro \GrpHas{arg} show how many persons are in group arg; macro \forAllG{arg} repeats its arg for all initialized groups; macro \forAllPinG{grp}{arg} repeats arg for all persons in group grp; macro \forAll{arg} repeats its arg for all persons in all groups.

To have access to number of person in group and number of group use macros PersNum and \GrpNum inside of arg.

share|improve this answer

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.