Making Quizzes From A Template

Josh Deutsch, March 2006

Introduction

The days of small intro classes are long gone and we all have to deal with how to administer fair exams in large crowded classrooms. In such an environment, it's useful to have many versions of the same exam, which differ in the numerical values that are used. If multiple choice questions are given, then randomizing the order of choices would seem desirable. Randomizing the order of some of the problems may not be a bad idea either.

But creating multiple versions and their solutions, is a time consuming and painful proposition. Especially as a typo or calculational error in the solution can have major repercussions. That's where this piece of software comes in handy. Starting with a template, which expresses formulas symbolically, it produces as many versions as you'd like, and is therefore much less prone to errors. It'll also provide answer keys and solutions for each version, assuming of course that you've provided the solution template.

Templates

To produce a template, I've settled on what seems to me to be the simplest method for user. Well who is the user? I'm assuming physics faculty and grad students, but mathematicians should be able to use as easily also.

For formulas, the choice is easy. tex (or latex). That's pretty ubiquitous, and is even used when communicating over email. It's much more efficient than trying some GUI way of building formulas.

For symbolic mathematical manipulation, I'm using perl syntax, which is awfully similar to fortran, or C. For example mv2/r would be $m*$v**2/$r. The dollar signs make it possible to easily separate out this stuff from normal text. The values of m,v and r can be set to constants, like $m = 3.1, or they can be set to random numbers, like $m = 1 + ran_int(19) will choose a random integer uniformly for $m between 1 and 20.

For ordering problems and choices, I've done two things. The first and most important, is to let you, the user not have to worry about this if you don't want to. If you have no multiple choice questions, and you don't want to randomize the order of questions, then there is nothing else to worry about, but the above issues. For me, that normally suffices because for weekly quizzes, I'll seldom have more than one problem and it won't be multiple choise. If however, you want to use this for preparing a final exam, then you do have to worry about how to randomize problems and choices. In that case you need some structure to tell you what is a problem and what is a choice. For that I use "XML". This is nothing that terribly difficult, and quite similar to html. So you have things like

 
		  <problem>

		  Two masses blah blah ...
		   
		  </problem>

		  <problem>

		  An object moving in the blah blah ...
		   
		  </problem>
		  
to describe the beginning and end of problems. But I find the best way to learn is through examples, so I'll give a couple. The first which shows you have to use you how to generate quiz templates and the second which also includes randomized problems and choices.

Example 1

Here is an example of a template file without most of the XML stuff:



\def\half{{1\over 2}} 

\centerline{{\bf Quiz 4}}
\centerline{{\bf Physics 5D}}
\centerline{{\bf 11/22/05}}

\vskip .25in
{\em Please read the question carefully before attempting it. You will not
be given any credit if you only write down the final answers. You must
show your work.}

\vskip .25in

<def>
   $pi = 3.14159265;
   $d = (1+ran_int(8))*1e-6;
   $T = 50*(1+ran_int(3));



   $rho = 1.0;
   $cal = 4.186;
   $k_B = 1.38e-23;

   $r = $d/2;

</def>

Very small solid particles, called grains, exist in interstellar space. They
are continually bombarded by hydrogen atoms of the surrounding interstellar
gas. As a result of these collisions, the grains execute Brownian movement in
both translation and rotation. Assume the grains are uniform spheres of diameter
@$d cm@ and density @$rho g/cm^3@, and the temperature of the gas is @$T \degrees{K}@.
Find the root mean square speed of the grains between collisions.


\paragraph*{Useful information:} 

@k_B = $k_B J /molecule\cdot \degrees{K}@.


\newpage

@d = $d, T = $T@

\vskip 0.2in

<def>
   $rho1 = $rho* 1e3;
   $r1 = $r * .01;
   $V = (4/3.0)*$pi*$r1**3;
   $m = $rho1*$V;
</def>

The equipartition theorem says 
@\langle Translational Kinetic Energy\rangle@  = (number of degrees of freedom ) @ * k_B T/2 @

\vskip 0.2in
The number of degrees of freedom are 3 per particle.
So @\langle \half m v^2 \rangle = {3\over 2} k_B T@ which gives
@m = \rho V@ with @V = (4 \pi/3) r^3@ with @ r = $d/2 = <eval> $r1</eval> m@.
Therefore @m = $m kg@. 

\vskip 0.2in
So @\langle v^2\rangle = 3 k_B T/m@. 

\vskip 0.2in
So @v_{rms} = \sqrt{\langle v^2\rangle} =  \sqrt{3*$k_B*$T/($m)} = <eval>sqrt(3*$k_B*$T/$m)</eval> m/s@.


		  

You can see that this is largely regular old latex. The differences mostly come from the stuff inside <def> and <eval> tags. The <def> tag is where you put definitions of variables. Pretty much any valid perl construct will work, but I've also defined some special functions for making our lives simpler.

  • ran_int($n), produces a random integer from 0 to, but not including, $n.
  • ran_round($n), produces a random number from 0 to, but not including, $n, but only to two decimal places. This is important in not making the numerical values ridiculously long.
  • ran_word("Jonny","Beth","Mary","Xerxes"), assigns one of these names randomly (with equal probability). I find this quite useful when making up multiple versions of an exam.

Another important difference is that formulae in tex, that is math mode, normally begin and end with $ signs. Because variables here use $ already, this needed to be changed. So in this modified form of tex, you use @ instead, for example @m = $m kg@. would print out m = 5.19 kg, assuming that $m = 5.59.

There is another tag that is used called <eval>. The stuff inside is evaluated and the result also rounded to three decimal places. If you look at the example: "Therefore @m = $m kg@." produces a very long decimal number for m, which we don't really want. So it's better to change this to If you look at the example: "Therefore @m = <eval> $m </eval > kg@." which produces a rounded number. You can put any mathematical expression inside an eval tag, e.g. <eval> $r*cos(log($m)**2) </eval > kg@.

Another thing that you'll need to modify is the use of "<" and ">". Because these are used in xml tags, their use would be ambiguous, so I've replaced "<" with "\lt" and ">" with "\gt". Similarly "&" is replaced with "\ampersand" because this is also a special escape character in xml.

Let's see the output this produces.

Example 2

Now let's move on to situations where you have multiple problems and multiple choice questions. Here's a silly example:

<?xml version="1.0" encoding="ISO-8859-1"?>

<quiz>
   <header>
      \begin{center}
      QUIZ TEST
      \end{center}
      \vskip .1in
   </header>
   <problem>

      <def>
	 $pi = 3.14159265;
	 $R1 = 0.5 + ran_round(0.25);
      </def>

      <question>
	 1.	 A wheel is of radius @$R1@. It's diameter is
      </question>

      <choice>
	 <text>
	    @<eval>2*$pi</eval>@.
	 </text>
      </choice>

      <choice>
	 <text>
	    @<eval>3*$pi</eval>@.
	 </text>
      </choice>

      <choice>
	 <text>
	    @-2@.
	 </text>
      </choice>

      <choice type="right"> 
	 <text>
	    @<eval>2*$R1</eval>@.
	 </text>
      </choice>

      <choice fix="here" > 
	 <text>
	    None of the above.
	 </text>
      </choice>

      <solution>
	 \begin{center}
	 Solution
	 \end{center}

	 Hmm... Something to do with rockets?
      </solution>
   </problem>

   <keep>
      <problem>

	 <def>
	    $R2 = 0.5 + ran_round(0.25);
	 </def>

	 <question>
	    A circle is of radius @$R2@. Its circumference is
	 </question>

	 <choice type="right">
	    <text>
	       @<eval>2*$pi*$R2</eval>@.
	    </text>
	 </choice>

	 <choice>
	    <text>
	       @<eval>2*$pi</eval>@.
	    </text>
	 </choice>

	 <choice>
	    <text>
	       @2@.
	    </text>
	 </choice>

	 <choice> 
	    <text>
	       @<eval>3*$R2</eval>@.
	    </text>
	 </choice>

	 <choice fix="here" > 
	    <text>
	       None of the above.
	    </text>
	 </choice>


	 <solution>
	    \begin{center}
	    Solution
	    \end{center}

	    Hmm... beats me.
	 </solution>
      </problem>

      <problem>

	 <def>
	    $R3 = 0.5 + ran_round(0.25);
	 </def>

	 <question>
	    Take the circle of the last problem. Its area is
	 </question>

	 <choice>
	    <text>
	       @<eval>2*$pi</eval>@.
	    </text>
	 </choice>

	 <choice type="right">
	    <text>
	       @<eval>$pi*$R2**2</eval>@.
	    </text>
	 </choice>

	 <choice>
	    <text>
	       @<eval>2*$R2</eval>@.
	    </text>
	 </choice>

	 <choice>
	    <text>
	       @0@.
	    </text>
	 </choice>

	 <choice> 
	    <text>
	       @<eval>2*$pi*$R2</eval>@.
	    </text>
	 </choice>

	 <choice fix="here" > 
	    <text>
	       None of the above.
	    </text>
	 </choice>


	 <solution>
	    \begin{center}
	    Solution
	    \end{center}

	    Hmm... Depends on what state you're in.
	 </solution>
      </problem>


   </keep>

   <footer>

      Well, that was a fun little exam!
   </footer>



</quiz>

		  

The new thing here are the XML tags inside the angled brackets. These elements group text hierarchicaly. The figure above shows the relation of the tags to each other. At the top level there's the quiz. At the next level there's an optional header section for displaying info like the title of the exam. Then there are any number of problems. Then there's an optional footer section.

Another feature is that the you can choose to keep the ordering of some problems the same, even when you shuffle. So problems between <keep> and </keep> have their order preserved. This is useful when having exams where the results of previous problems are used in the present one.

Further down the hierarchy, each problem is subdivided into a question, and an optional number of choices, and an optional solution. The choices have two options you can add to them.

  • <choice fix="here" > means that those choices are not shuffled. For example you'd want to put that in when you say "none of the above".
  • <choice type="right"> means that you've determined that this is the right answer. That's normally a prudent thing to do before giving a multiple choice exam to 200 students. Not only does this make a note of it in the template file, it also lets you split out an answer key. Remember the choices can be shuffled so its very convenient to be told which one is correct.

Running the program

Prerequisites

You'll need perl and latex to produce dvi files. dvipdf if you want to produce a pdf file, and latex2html if you want to produce an html version.

How to run the code

Once you've produced a templae file, like q.xml, you'll have to run the code to produce the final quizzes.

There are two ways to run the code. The macho/command line way and the wimpy GUI way. I spent a lot time trying to get the GUI looking good, and actually think that it might be preferable if you're only using this system occasionally.

Command Line

The command line looks something like this:
quizmaker -shuffle -answer_key_on -solutions on -num 4 -out qout -in q.xml -rand_seed 13463 -latex -all -html
  • -shuffle shuffles the problems and choices. Of course the keep tag and "fix" option in choices can selectively prevent shuffling.
  • -answer_key_on also produces an answer key to multiple choice problems.
  • -solutions can be "on" or "off". (Default if off). This will incorporate the solutions you've also created into the final pdf document.
  • -num 4. This is the number of randomized versions created.
  • -rand_seed 13463 is the random seed. If you don't like the random values chosen, which sometimes happens, use this to make a new set of exams.
  • -latex produces individual dvi files of the template. I don't find this all that useful.
  • -all This is the option I normally use. This produces a complete pdf of all the exams. If you also turn on -solutions, you can use \newpage in those to put them on new pages so that they're not included in what you hand out!
  • -html This requires the installation of latex2html. It produces web pages of your exams. But I hardly latex2html for exam solutions. I think pdf output on the web is fine.

GUI

Start up gui.pl. If it doesn't come up, maybe you're not running on linux. Horror of horrors. Well I'm currently working on porting to lesser operating systems.

Anyway, if you mouse-over each label, there should be help provided. You'll have to keep the mouse there for a good second or so to see the little help factoids, so be patient.

After you've read through the command line options, let me know if it's not self explanatory. I think that a good GUI should be.