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 two datasets, each containing problems dealing with a specific topic. These problems are stored in external files (again, one file per topic) and loaded into the datasets in a random order. I need to generate a document that has this basic format:

Quiz 1

  • Question 1: Display the first question listed in topic1 dataset
  • Question 2: Display the first question listed in topic2 dataset

Quiz 2

  • Question 1: Display the second question listed in topic1 dataset
  • Question 2: Display the second question listed in topic2 dataset

Continue...

I've poured over the documentation, and I suspect I don't understand it fully. The only examples seem to focus on displaying all the questions in one dataset at a time. The only other option seems to be to know ahead of time what the labels are for each question, but that doesn't help since the questions were loaded in a random order.

Any help you can give would be greatly appreciated. And if this question has already been addressed, a gentle nudge to the right place would be wonderful.

share|improve this question
1  
Could you post the code you already have (tried)? It doesn't need to solve your problem, just provide a starting point for experiments by people who want to produce an answer. –  Stephan Lehmke Sep 17 '12 at 12:12

1 Answer 1

up vote 5 down vote accepted
+100

Since you do not provide any code snippets it is not exactly clear how you want this to work, but here is how I would do this.

Topic Directories:

I would create directories for each topic. For instance AlgebraQuestions/, and TrigQuestions/ to contain all the files which are all the possible questions from these topics. This would be defined as follows:

\newcommand*{\ListOfTopics}{%
    AlgebraQuestions,%  MUST have trailing % here
    TrigQuestions%
}%

This list of topics determines how many questions will be in the quiz since it appears that you want one question per topic in a quiz. If you organized all your topic directories to be sub-directories then this \ListOfTopics could be auto generated based on the names of the sub-directories.

List of Questions for each Topic:

For each topic directory I would define a pgfmathdeclarerandomlist. So, for instance if the topic AlgebraQuestions/ had three files named file, file2, and file3, I would define:

\pgfmathdeclarerandomlist{AlgebraQuestions}{{file1}{file2}{file3}}

In the MWE below I have hard coded this list, but it certainly could be auto generated on the fly based on the existing files in a directory.

Number of Quizzes:

The only variable that would need to be manually set (or specified on the command line), would be the number of quizzes you desire to generate:

\newcommand*{\NumberOfQuizes}{4}%

Output:

So assuming that directory AlgebraQuestions/ contains files named AlgebraQ1,...,AlgebraQ6, and the TrigQuestions/ directory contains files named TrigQ1,...,TrigQ9 we get:

enter image description here

But instead of printing the files names as I have done below with \item, you would import the file name defined in \RandomQuestion.

Notes:

  • Since questions are selected at random there is a possibility that some quizzes will have the same question (as is the case with Quiz 3 and 4 below). However this probability reduces as the number of questions grow. If this is not desired this could be prevented with additional coding to ensure that a previously picked random number for each list is not reused.

  • If the questions for each topic are in one file, one could adapt the solution from Automating quoting across LaTeX documents, which picks out specific named environment from a file. The usage of this will depend on exactly how the problems are defined, and require that each problem be given a name with which to address it by.

    However, I would highly recommend that each question be in a separate file, (perhaps using the standalone package) as this

    1. greatly simplifies the management of this process (especially as the number of questions grows),
    2. allows one to easily add new problems without worrying about providing a unique name for it, as the file system will take ensure that the names of each problem are unique,
    3. allows each file to be compiled and proofed by itself, and
    4. if desired, one can easily create a document with all the problems. See the References section for some options on this.

References:

Code:

\documentclass{article}
%\usepackage[paperheight=3.0cm, paperwidth=12.0cm, margin=0.1cm]{geometry}% Simplify image capture

\usepackage{enumitem}
\usepackage{tikz}% Easy way to get all the pgf functions

% The list of topics determines how many questions will be in the quiz
% since it appears that you want one question per topic in a quiz.
% This could be auto generated.
\newcommand*{\ListOfTopics}{%
    AlgebraQuestions,%  MUST have trailing % here
    TrigQuestions%
}%


% These list of files names from each question can be auto generated
% but for example purposes I am just using the file names as the
% content in the file. The number of questions in each topic do not
% need to be the same.  I would create directories with the topic 
% names and auto generate this based on the directory and file names.

\pgfmathdeclarerandomlist{AlgebraQuestions}{%
    {AlgebraQ1}%
    {AlgebraQ1}%
    {AlgebraQ3}%
    {AlgebraQ4}%
    {AlgebraQ5}%
    {AlgebraQ6}%    
}%
\pgfmathdeclarerandomlist{TrigQuestions}{%
    {TrigQ1}%
    {TrigQ2}%
    {TrigQ3}%
    {TrigQ4}%
    {TrigQ5}%
    {TrigQ6}%
    {TrigQ7}%
    {TrigQ8}%
    {TrigQ9}%
}%




\newcommand*{\NumberOfQuizes}{4}%

\begin{document}
\foreach \QuizNumber in {1,...,\NumberOfQuizes} {%
    \clearpage% Start each quiz on a new page
   \noindent\textbf{\Large Quiz Number \QuizNumber}%
    \begin{enumerate}
    \foreach \Topic in \ListOfTopics {%
        % Determine random question to use form list
        \pgfmathrandomitem{\RandomQuestion}{\Topic} 
        % The following should import the file named in \RandomQuestion
        \item Random Question from Topic='\Topic': 
            \textbf{\Large\RandomQuestion}%
    }%
    \end{enumerate}
}%

\end{document}
share|improve this answer
    
Wow. I mean...wow. Thank you! I also apologize for not providing a code snippet (work responsibilities engulfed my existence suddenly and without warning). I'm going to try implementing this tonight! –  HTG Sep 20 '12 at 20:11
    
Trying to parse your code and accompanying instructions...In the AlgebraQuestions/ subdirectory, I see that each question is in its own file. Currently, I have a single file for each topic, and it contains 10+ questions for that topic. So, in the file QuadFormula.tex I have ten questions defined (using the \newproblem command from the probsoln package). Is there a way to preserve the functionality of your solution while keeping these questions in a single file? –  HTG Sep 20 '12 at 20:32
    
@HTG: Have added a section to the Notes for this. For future reference, instead of describing your situation, you should provide as much code that shows exactly what you have and how you want it to work, to avoid this confusion. The way you are defining the questions will affect how you extract the particular question from the file. –  Peter Grill Sep 20 '12 at 21:35
    
Thanks, and I will keep that in mind going forward. I really appreciate the help. –  HTG Sep 21 '12 at 2:06
    
I'm getting errors when I compile the code. The console window complains "Use of \\enumerate doesn't match its definition." I'm digging through the code, but I don't speak the language well enough yet. Anyway you can help? –  HTG Sep 21 '12 at 17:18

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.