[system] / trunk / pg / macros / PGchoicemacros.pl Repository:
ViewVC logotype

View of /trunk/pg/macros/PGchoicemacros.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4386 - (download) (as text) (annotate)
Thu Aug 17 23:55:17 2006 UTC (13 years, 6 months ago) by dpvc
File size: 22132 byte(s)
Added LaTeXMathML mode.

    1 
    2 BEGIN{
    3   be_strict;
    4 }
    5 
    6 package main;
    7 
    8 
    9 =head1 NAME
   10 
   11 PGchoicemacros.pl --- located in the courseScripts directory
   12 
   13 
   14 =head1 SYNPOSIS
   15 
   16 =pod
   17 
   18 There are two types of choice macros. The older versions are simply scripts.
   19 The newer versions involve the "List.pm" class and its sub-classes
   20 and the use of objects based on these classes. The list sub-classes are:
   21 "Match.pm" which aids in setting up matching question
   22  and answer lists, "Select.pm" which aids in selecting
   23  and presenting a subset of questions with short answers
   24 (e.g. true/false questions) from a larger question set, and
   25 "Multiple.pm" which aids in setting up a
   26 standard style, one question, many answers type multiple
   27 choice question.
   28 
   29 
   30 =head1 DESCRIPTION
   31 
   32 Sample usage:
   33 
   34 
   35   $ml = new_match_list();
   36   # enter three questions and their answers
   37   $ml->qa(   "What color is a rose?",
   38        "Red",
   39        "What color is the sky?",
   40        "Blue",
   41        "What color is the sea?",
   42        "Green"
   43   );
   44   # choose two of these questions, ordered at random,
   45   # which will be printed in the problem.
   46   $ml->choose(2);
   47   BEGIN_TEXT
   48     Match the answers below with these questions:$BR
   49     \\{$ml->print_q\\} $BR
   50     Answers:
   51     \\{$ml->print_a\\}
   52   END_TEXT
   53 
   54   ANS( $ml->ra_correct_ans()    );
   55 
   56 =cut
   57 
   58 
   59 =head2 Matching List macros
   60 
   61 
   62 =head3 new_match_list
   63 
   64 Matching list object creation macro
   65 
   66 Usage:
   67 
   68 
   69   $ml = new_match_list();
   70 
   71 Which is short hand for the following direct call to Match
   72 
   73   $ml = new Match(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);
   74 
   75 
   76 Either call will create a matching list object in the variable $ml.
   77 (I< Note: $ml cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.>)
   78 
   79 The first argument is the seed for the match list (choosen at random between 1 and 2000 in
   80 the example above.).  The next two arguments are references to the print subroutines
   81 used to print the questions and the answers.
   82 Other printing methods can be used instead of the standard ones.  An
   83 example of how to do this is demonstrated with
   84 "pop_up_list_print_q"  below.
   85 
   86 =head4 std_print_q
   87 
   88 Standard method for formatting a list of questions with answer blanks.
   89 
   90 This  formatting routine is the default method for formatting the
   91 way questions are printed
   92 for each of the three sub-classes of "List.pm". It lists the questions vertically, numbering
   93 them sequentially and providing an answer blank before each question.
   94 C<std_print_q> checks which mode the user is trying to print the
   95 questions from and returns the appropriately formatted string.
   96 
   97 The length of the answer blank can be set with C<$ml->
   98 
   99 To replace the standard question formatting method with your own, use:
  100 
  101   $ml->rf_print_q(~~&my_question_format_method)
  102 
  103 Your method should be a subroutine of the form C<my_question_format_method($self, @questions)>
  104 and should return a string to be printed.  The @questions array contains the
  105 questions to be listed, while $self  can be used to obtain extra information from
  106 the object for formatting purposes. The variable C<$main::displayMode> contains the
  107 current display mode.  (See "MODES" for more details on display modes and
  108 see "writing print methods for lists" for details on constructing formatting subroutines.)
  109 
  110 
  111 =head4 std_print_a
  112 
  113 Standard method for formatting a list of answers.
  114 
  115 This simple formatting routine is the default method for formatting
  116 the answers for matching lists.  It lists the answers vertically
  117 lettered sequentially.
  118 
  119 To replace the standard answer formatting method with your own subroutine use:
  120 
  121   $ml->rf_print_q(~~&my_answer_format_method)
  122 
  123 The answer formatting method has the same interface as the question formatting
  124 method.
  125 
  126 
  127 =head2 Select List macros
  128 
  129 
  130 =head3 new_select_list
  131 
  132 Select list object creation macro
  133 
  134 Usage:
  135 
  136   $sl = new_select_list;
  137 
  138 Which is equivalent to this direct call to Select
  139 
  140   $sl = new Select(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);
  141 
  142 
  143 Either call will create a select list object in the variable $sl. ( Note that
  144 $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
  145 block.)  The printing methods are the same as those defined for C<new_match_list>
  146 above.
  147 See the documentation for "Select.pm" to see how to use this
  148 object to create a true/false question.
  149 
  150 std_print_a is only intended to be used for debugging with select lists, as there is rarely a reason to
  151 print out the answers to a select list.
  152 
  153 
  154 =head3 new_pop_up_select_list
  155 
  156 
  157 
  158 Usage:
  159 
  160   $sl = new_pop_up_select_list;</I></PRE>
  161 
  162 Which is equivalent to this direct call to Select
  163 
  164   $sl = new Select(random(1,2000,1), ~~&pop_up_list_print_q, ~~&std_print_a);
  165 
  166 
  167 Either call will create a select list object in the variable $sl. ( Note that
  168 $sl cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
  169 block.)  The printing methods are passed as references (~~ in PG equals \ in
  170 perl) to subroutines so that no matter what printing subroutines are used,
  171 those subroutines can be used by saying $sl->print_q and $sl->print_a.  This
  172 also means that other subroutines can be used instead of the default ones.
  173 
  174 See the documentation for <a href='Select'>Select.pm</a> to see how to use this
  175   object to create a true/false question.
  176 
  177 
  178 =head4 std_print_q
  179 
  180 Standard method for printing questions with answer boxes
  181 
  182 See std_print_q under Matching Lists above.
  183 
  184 
  185 =head4 pop_up_list_print_q
  186 
  187 Alternate method for print questions with pop up lists.
  188 
  189 Usage:
  190 
  191 This printing routine is used to print the questions for a true/false or other
  192 select list with a preceding pop up list of possible answers.  A list of values
  193 and labels need to be given to the pop_up_list so that the intended answer is
  194 returned when a student selects an answer form the list.  Notethe use of => to
  195 associate the values on the left with the labels on the right, this means that,
  196 for instance, the student will see the word True in the pop_up_list but the
  197 answer that is returned to the grader is T, so that it corresponds with what
  198 the professor typed in as the answer when using $sl->qa('blah blah', 'T');
  199 
  200 =for html
  201   <PRE>
  202   <I>$sl->ra_pop_up_list([</I>value<I> => </I>label<I>,
  203               T => 'True',
  204               F => 'False']);</I></PRE>
  205 
  206 
  207 =head4 std_print_a
  208 
  209 This is only intended to be used for debugging as there is rarely a reason to
  210 print out the answers to a select list.
  211 
  212 See std_print_a under Matching Lists above.
  213 
  214 
  215 =head2 Multiple Choice macros
  216 
  217 
  218 =head3 new_multiple_choice
  219 
  220 Multiple choice object creation macro
  221 
  222 Usage:
  223 
  224 =for html
  225   <PRE>
  226   <I>$mc = new_multiple_choice;</I></PRE>
  227 
  228 Which is equivalent to this direct call to Multiple
  229 
  230 =for html
  231   <PRE>
  232   <I>$mc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&std_print_a);</I></PRE>
  233 
  234 Either call will create a multiple choice object in the variable $mc. Note that
  235 $mc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
  236 block.
  237 
  238 =for html
  239   <P>See the documentation for <a href='Multiple'>Multiple.pm</a> to see how to use
  240   this object to create a multiple choice question.
  241 
  242 
  243 =head4 std_print_q
  244 
  245 Standard method for printing questions
  246 
  247 See std_print_q under Matching Lists above.
  248 
  249 
  250 =head4 radio_print_a
  251 
  252 Method for printing answers with radio buttons
  253 
  254 This simple printing routine is used to print the answers to multiple choice
  255 questions in a bulleted style with radio buttons preceding each possible answer.
  256 When a multiple choice object is created, a reference to radio_print_a is passed
  257 to that object so that it can be used from within the object later.
  258 
  259 radio_print_a checks which mode the user is trying to print the answers from and
  260 returns the appropriately formatted string.
  261 
  262 
  263 =head3 new_checkbox_multiple_choice
  264 
  265 Checkbox multiple choice object creation macro
  266 
  267 Usage:
  268 
  269 =for html
  270   <PRE>
  271   <I>$cmc = new_checkbox_multiple_choice;</I></PRE>
  272 
  273 Which is equivalent to this direct call to Multiple
  274 
  275 =for html
  276   <PRE>
  277   <I>$cmc = new Multiple(random(1,2000,1), ~~&std_print_q, ~~&checkbox_print_a);</I></PRE>
  278 
  279 Either call will create a checkbox multiple choice object in the variable $cmc. Note that
  280 $cmc cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT
  281 block.
  282 
  283 =for html
  284   <P>See the documentation for <a href='Multiple'>Multiple.pm</a> to see how to use
  285   this object to create a multiple choice question.
  286 
  287 
  288 =head4 std_print_q
  289 
  290 Standard method for printing questions
  291 
  292 See std_print_q under Matching Lists above.
  293 
  294 
  295 =head4 checkbox_print_a
  296 
  297 Method for printing answers with radio buttons
  298 
  299 This simple printing routine is used to print the answers to multiple choice
  300 questions in a bulleted style with checkboxes preceding each possible answer.
  301 When a multiple choice object is created, a reference to checkbox_print_a is passed
  302 to that object so that it can be used from within the object later.
  303 
  304 checkbox_print_a checks which mode the user is trying to print the answers from and
  305 returns the appropriately formatted string.
  306 
  307 
  308 
  309 =cut
  310 BEGIN {
  311   be_strict();
  312 }
  313 sub _PGchoicemacros_init{
  314 }
  315 
  316 =head4 new_match_list
  317 
  318   Usage: $ml = new_match_list();
  319 
  320 
  321 Note that $ml cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block
  322 
  323 =cut
  324 
  325 sub new_match_list {
  326   new Match(random(1,2000,1), \&std_print_q, \&std_print_a);
  327 }
  328 
  329 =head4 new_select_list
  330   sage: $sl = new_select_list();
  331 
  332 Note that $sl cannot be a my variable if used within a BEGIN_TEXT/END_TEXT block
  333 
  334 =cut
  335 
  336 sub new_select_list {
  337   new Select(random(1,2000,1), \&std_print_q, \&std_print_a);
  338 }
  339 
  340 =head4 new_pop_up_select_list;
  341 
  342   Usage: $pusl = new_pop_up_select_list();
  343 
  344 =cut
  345 
  346 sub new_pop_up_select_list {
  347   new Select(random(1,2000,1), \&pop_up_list_print_q, \&std_print_a);
  348 }
  349 
  350 =head4 new_multiple_choice
  351 
  352   Usage: $mc = new_multiple_choice();
  353 
  354 =cut
  355 
  356 
  357 sub new_multiple_choice {
  358   new Multiple(random(1,2000,1), \&std_print_q, \&radio_print_a);
  359 }
  360 
  361 =head4 new_checkbox_multiple_choice
  362 
  363   Usage: $mcc = new_checkbox_multiple_choice();
  364 
  365 =cut
  366 
  367 sub new_checkbox_multiple_choice {
  368   new Multiple(random(1,2000,1), \&std_print_q, \&checkbox_print_a);
  369 }
  370 
  371 =head4 initializing a pop_up_list
  372 
  373   Usage:  $sl->rf_print_a(~~&pop_up_list_print_q);
  374       $sl->ra_pop_up_list([</I>value<I> => </I>label<I>, T => 'True', F => 'False']);
  375 
  376 =cut
  377 
  378 sub pop_up_list_print_q {
  379     my $self = shift;
  380     my (@questions) = @_;
  381     my $length = $self->{ans_rule_len};
  382     my @list = @{$self->{ra_pop_up_list} };
  383     my $out = "";
  384 
  385   #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  386   if ($main::displayMode =~ /^HTML/) {
  387     my $i=1; my $quest;
  388     foreach $quest (@questions) {
  389        $out.= "\n<p>" . pop_up_list(@list) . "&nbsp;<B>$i.</B> $quest";
  390        $i++;
  391     }
  392     $out .= "<br>\n";
  393   } elsif ($main::displayMode eq 'Latex2HTML') {
  394     my $i=1; my $quest;
  395     foreach $quest (@questions) {
  396        $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml}   $quest";
  397        $i++;
  398     }
  399     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  400   }  elsif ($main::displayMode eq 'TeX') {
  401       $out = "\n\\par\\begin{enumerate}\n";
  402       my $i=1; my $quest;
  403     foreach $quest (@questions) {
  404       $out .= "\\item[" .  pop_up_list(@list) . "$i.] $quest\n";
  405       $i++;
  406     }
  407     $out .= "\\end{enumerate}\n";
  408   } else {
  409     $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n";
  410   }
  411   $out;
  412 
  413 }
  414 
  415 
  416 # For graphs in a matching question.
  417 
  418 #sub format_graphs {
  419 # my $self = shift;
  420 # my @in = @_;
  421 # my $out = "";
  422 # while (@in) {
  423 #   $out .= shift(@in). "#" ;
  424 # }
  425 # $out;
  426 #}
  427 
  428 
  429 # To put pop-up-list at the end of a question.
  430 # contributed by Mark Schmitt 3-6-03
  431 
  432 sub quest_first_pop_up_list_print_q {
  433     my $self = shift;
  434     my (@questions) = @_;
  435     my $length = $self->{ans_rule_len};
  436     my @list = @{$self->{ra_pop_up_list} };
  437     my $out = "";
  438 
  439   if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth'
  440         || $main::displayMode eq 'HTML_jsMath'
  441         || $main::displayMode eq 'HTML_asciimath' || $main::displayMode eq 'HTML_LaTeXMathML'
  442               || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') {
  443     my $i=1; my $quest;
  444     foreach $quest (@questions) {
  445        $out.= "\n<p>" .  "&nbsp; $quest" . pop_up_list(@list);
  446        $i++;
  447     }
  448     $out .= "<br>\n";
  449   } elsif ($main::displayMode eq 'Latex2HTML') {
  450     my $i=1; my $quest;
  451     foreach $quest (@questions) {
  452        $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml}   $quest";
  453        $i++;
  454     }
  455     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  456   }  elsif ($main::displayMode eq 'TeX') {
  457       $out = "\n\\par\\begin{enumerate}\n";
  458       my $i=1; my $quest;
  459     foreach $quest (@questions) {
  460       $out .= "\\item[" .  pop_up_list(@list) . "$i.] $quest\n";
  461       $i++;
  462     }
  463     $out .= "\\end{enumerate}\n";
  464   } else {
  465     $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n";
  466   }
  467   $out;
  468 
  469 }
  470 # To put pop-up-list in the middle of a question.
  471 # contributed by Mark Schmitt 3-6-03
  472 
  473 sub ans_in_middle_pop_up_list_print_q {
  474     my $self = shift;
  475     my (@questions) = @_;
  476     my $length = $self->{ans_rule_len};
  477     my @list = @{$self->{ra_pop_up_list} };
  478     my $out = "";
  479 
  480   if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth'
  481         || $main::displayMode eq 'HTML_jsMath'
  482         || $main::displayMode eq 'HTML_asciimath' || $main::displayMode eq 'HTML_LaTeXMathML'
  483               || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') {
  484     my $i=1; my $quest;
  485     foreach $quest (@questions) {
  486        $out.= "" .  "&nbsp; $quest" . pop_up_list(@list);
  487        $i++;
  488     }
  489     $out .= "";
  490   } elsif ($main::displayMode eq 'Latex2HTML') {
  491     my $i=1; my $quest;
  492     foreach $quest (@questions) {
  493        $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml}   $quest";
  494        $i++;
  495     }
  496     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  497   }  elsif ($main::displayMode eq 'TeX') {
  498       $out = "\n\\par\\begin{enumerate}\n";
  499       my $i=1; my $quest;
  500     foreach $quest (@questions) {
  501       $out .= "\\item[" .  pop_up_list(@list) . "$i.] $quest\n";
  502       $i++;
  503     }
  504     $out .= "\\end{enumerate}\n";
  505   } else {
  506     $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n";
  507   }
  508   $out;
  509 
  510 }
  511 
  512 
  513 # Units for physics class
  514 # contributed by Mark Schmitt 3-6-03
  515 
  516 sub units_list_print_q {
  517     my $self = shift;
  518     my (@questions) = @_;
  519     my $length = $self->{ans_rule_len};
  520     my @list = @{$self->{ra_pop_up_list} };
  521     my $out = '';
  522 
  523   $out.= pop_up_list(@list);
  524 
  525     $out;
  526 }
  527 
  528 #Standard method of printing answers in a matching list
  529 sub std_print_a {
  530   my $self = shift;
  531   my(@array) = @_;
  532   my $i = 0;
  533   my @alpha = ('A'..'Z', 'AA'..'ZZ');
  534   my $letter;
  535   my  $out=   &main::M3(
  536           "\\begin{enumerate}\n",
  537           " \\begin{rawhtml} <OL TYPE=\"A\" VALUE=\"1\"> \\end{rawhtml} ",
  538           # kludge to fix IE/CSS problem
  539           #"<OL COMPACT TYPE=\"A\" START=\"1\">\n"
  540           "<BLOCKQUOTE>\n"
  541   ) ;
  542   my $elem;
  543   foreach $elem (@array) {
  544     $letter = shift @alpha;
  545     $out .= &main::M3(
  546           "\\item[$main::ALPHABET[$i].] $elem\n",
  547           " \\begin{rawhtml} <LI> \\end{rawhtml} $elem  ",
  548           #"<LI> $elem</LI>\n"
  549           "<br /> <b>$letter.</b> $elem\n"
  550     ) ;
  551     $i++;
  552   }
  553   $out .= &main::M3(
  554         "\\end{enumerate}\n",
  555         " \\begin{rawhtml} </OL>\n \\end{rawhtml} ",
  556         #"</OL>\n"
  557         "</BLOCKQUOTE>\n"
  558   ) ;
  559   $out;
  560 
  561 }
  562 
  563 
  564 
  565 
  566 #Alternate method of printing answers as a list of radio buttons for multiple choice
  567 sub radio_print_a {
  568     my $self = shift;
  569     my (@answers) = @_;
  570     my $out = "";
  571   my $i =0;
  572     my @in = ();
  573   #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  574   if ($main::displayMode =~ /^HTML/) {
  575     foreach my $ans (@answers) {
  576       push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
  577       $i++;
  578     }
  579     my @radio_buttons = ans_radio_buttons(@in);
  580     $out = "\n<BR>" . join "\n<BR>", @radio_buttons;
  581     $out .= "<BR>\n";
  582   } elsif ($main::displayMode eq 'Latex2HTML') {
  583     foreach my $ans (@answers) {
  584       push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
  585       $i++;
  586     }
  587     my @radio_buttons = ans_radio_buttons(@in);
  588     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @radio_buttons;
  589     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  590   }  elsif ($main::displayMode eq 'TeX') {
  591     foreach my $ans (@answers) {
  592       push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
  593       $i++;
  594     }
  595     my @radio_buttons = ans_radio_buttons(@in);
  596     #$out = "\n\\par\\begin{itemize}\n";
  597     $out .= join '', @radio_buttons;
  598     #$out .= "\\end{itemize}\n";
  599   } else {
  600     $out = "Error: PGchoicemacros: radio_print_a: Unknown displayMode: $main::displayMode.\n";
  601   }
  602   $out;
  603 
  604 }
  605 
  606 #Second alternate method of printing answers as a list of radio buttons for multiple choice
  607 #Method for naming radio buttons is no longer round about and hackish
  608 sub checkbox_print_a {
  609     my $self = shift;
  610     my (@answers) = @_;
  611     my $out = "";
  612   my $i =0;
  613     my @in = ();
  614 #   if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  615   if ($main::displayMode =~ /^HTML/) {
  616     foreach my $ans (@answers) {
  617       push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
  618       $i++;
  619     }
  620     my @checkboxes = ans_checkbox(@in);
  621     $out = "\n<BR>" . join "\n<BR>", @checkboxes;
  622     $out .= "<BR>\n";
  623   } elsif ($main::displayMode eq 'Latex2HTML') {
  624     foreach my $ans (@answers) {
  625       push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
  626       $i++;
  627     }
  628     my @checkboxes = ans_checkbox(@in);
  629     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @checkboxes;
  630     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  631   }  elsif ($main::displayMode eq 'TeX') {
  632     foreach my $ans (@answers) {
  633       push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
  634       $i++;
  635     }
  636     my @radio_buttons = ans_checkbox(@in);
  637     #$out = "\n\\par\\begin{itemize}\n";
  638     $out .= join '', @radio_buttons ;
  639     #$out .= "\\end{itemize}\n";
  640   } else {
  641     $out = "Error: PGchoicemacros: checkbox_print_a: Unknown displayMode: $main::displayMode.\n";
  642   }
  643   $out;
  644 
  645 }
  646 
  647 
  648 #Standard method of printing questions in a matching or select list
  649 sub std_print_q {
  650     my $self = shift;
  651     my (@questions) = @_;
  652     my $length = $self->{ans_rule_len};
  653     my $out = "";
  654   #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  655   if ($main::displayMode =~ /^HTML/) {
  656           my $i=1; my $quest; $out = "\n<P>\n";
  657     foreach $quest (@questions) {
  658        $out.= ans_rule($length) . "&nbsp;<B>$i.</B> $quest<BR>";
  659        $i++;
  660     }
  661   } elsif ($main::displayMode eq 'Latex2HTML') {
  662           my $i=1; my $quest; $out = "\\par\n";
  663     foreach $quest (@questions) {
  664        $out.= ans_rule($length) . "\\begin{rawhtml}<B>$i. </B>\\end{rawhtml} $quest\\begin{rawhtml}<BR>\\end{rawhtml}\n";
  665        $i++;
  666     }
  667   }  elsif ($main::displayMode eq 'TeX') {
  668       $out = "\n\\par\\begin{enumerate}\n";
  669       my $i=1; my $quest;
  670     foreach $quest (@questions) {
  671       $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
  672       $i++;
  673     }
  674     $out .= "\\end{enumerate}\n";
  675   } else {
  676     $out = "Error: PGchoicemacros: std_print_q: Unknown displayMode: $main::displayMode.\n";
  677   }
  678   $out;
  679 
  680 }
  681 
  682 
  683 
  684 =head3 legacy macros
  685 
  686 These are maintained for backward compatibility.
  687 They can still be useful in constructing non-standard lists that don't fit
  688 the various list objects.  In general the using the list objects is likely
  689 to give better results and is preferred.
  690 
  691 =cut
  692 
  693 =head4 qa
  694 
  695 =cut
  696 
  697 sub qa {
  698   my($questionsRef,$answersRef,@questANDanswer) = @_;
  699   while (@questANDanswer) {
  700     push(@$questionsRef,shift(@questANDanswer));
  701     push(@$answersRef,shift(@questANDanswer));
  702 
  703   }
  704 }
  705 
  706 =head4 invert
  707 
  708 =cut
  709 
  710 sub invert {
  711   my @array = @_;
  712   my @out = ();
  713   my $i;
  714   for ($i=0;$i<=$#array;$i++) {
  715     $out[$array[$i]]=$i;
  716   }
  717   @out;
  718 }
  719 
  720 =head4 NchooseK
  721 
  722 =cut
  723 
  724 sub NchooseK {
  725   my($n,$k)=@_;;
  726   my @array = 0..($n-1);
  727   my @out = ();
  728   while (@out<$k) {
  729     push(@out, splice(@array,    random(0,$#array,1) ,         1) );
  730   }
  731   @out;
  732 }
  733 
  734 =head4 shuffle
  735 
  736 =cut
  737 
  738 sub shuffle {
  739   my ($i) = @_;
  740   my @out = &NchooseK($i,$i);
  741   @out;
  742 }
  743 
  744 =head4 match_questions_list
  745 
  746 =cut
  747 
  748 sub match_questions_list {
  749   my (@questions) = @_;
  750   my $out = "";
  751   #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  752   if ($main::displayMode =~ /^HTML/) {
  753     my $i=1; my $quest;
  754     foreach $quest (@questions) {
  755        $out.= "\n<BR>" . ans_rule(4) . "<B>$i.</B> $quest";
  756        $i++;
  757     }
  758     $out .= "<br>\n";
  759   } elsif ($main::displayMode eq 'Latex2HTML') {
  760     my $i=1; my $quest;
  761     foreach $quest (@questions) {
  762        $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule(4) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml}   $quest"; #"$i.   $quest";
  763        $i++;
  764     }
  765     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  766   } elsif ($main::displayMode eq 'TeX') {
  767       $out = "\n\\par\\begin{enumerate}\n";
  768       my $i=1; my $quest;
  769     foreach $quest (@questions) {
  770       $out .= "\\item[" . ans_rule(3) . "$i.] $quest\n";
  771       $i++;
  772       }
  773     $out .= "\\end{enumerate}\n";
  774   } else {
  775     $out = "Error: PGchoicemacros: match_questions_list: Unknown displayMode: $main::displayMode.\n";
  776   }
  777   $out;
  778 }
  779 
  780 
  781 
  782 sub match_questions_list_varbox {
  783   my ($length, @questions) = @_;
  784   my $out = "";
  785   #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
  786   if ($main::displayMode =~ /^HTML/) {
  787     my $i=1; my $quest;
  788     foreach $quest (@questions) {
  789       $out.=  "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest";
  790       $i++;
  791     }
  792     $out .= "<br>\n";
  793   } elsif ($main::displayMode eq 'Latex2HTML') {
  794     my $i=1; my $quest;
  795     foreach $quest (@questions) {
  796       $out.=  " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml}   $quest"; #"$i.   $quest";
  797       $i++;
  798     }
  799     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
  800   } elsif ($main::displayMode eq 'TeX') {
  801     $out = "\n\\par\\begin{enumerate}\n";
  802     my $i=1; my $quest;
  803     foreach $quest (@questions) {
  804       $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
  805       $i++;
  806     }
  807     $out .= "\\end{enumerate}\n";
  808   } else {
  809     $out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n";
  810   }
  811   $out;
  812 }
  813 
  814 
  815 
  816 1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9