Parent Directory
|
Revision Log
Work around IE bug for ordered lists. Maybe someday this can be undone.
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) . " <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' || $main::displayMode eq 'HTML_asciimath' 441 || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') { 442 my $i=1; my $quest; 443 foreach $quest (@questions) { 444 $out.= "\n<p>" . " $quest" . pop_up_list(@list); 445 $i++; 446 } 447 $out .= "<br>\n"; 448 } elsif ($main::displayMode eq 'Latex2HTML') { 449 my $i=1; my $quest; 450 foreach $quest (@questions) { 451 $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; 452 $i++; 453 } 454 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 455 } elsif ($main::displayMode eq 'TeX') { 456 $out = "\n\\par\\begin{enumerate}\n"; 457 my $i=1; my $quest; 458 foreach $quest (@questions) { 459 $out .= "\\item[" . pop_up_list(@list) . "$i.] $quest\n"; 460 $i++; 461 } 462 $out .= "\\end{enumerate}\n"; 463 } else { 464 $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n"; 465 } 466 $out; 467 468 } 469 # To put pop-up-list in the middle of a question. 470 # contributed by Mark Schmitt 3-6-03 471 472 sub ans_in_middle_pop_up_list_print_q { 473 my $self = shift; 474 my (@questions) = @_; 475 my $length = $self->{ans_rule_len}; 476 my @list = @{$self->{ra_pop_up_list} }; 477 my $out = ""; 478 479 if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth' 480 || $main::displayMode eq 'HTML_jsMath' || $main::displayMode eq 'HTML_asciimath' 481 || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') { 482 my $i=1; my $quest; 483 foreach $quest (@questions) { 484 $out.= "" . " $quest" . pop_up_list(@list); 485 $i++; 486 } 487 $out .= ""; 488 } elsif ($main::displayMode eq 'Latex2HTML') { 489 my $i=1; my $quest; 490 foreach $quest (@questions) { 491 $out.= " \\begin{rawhtml}<p><B>\\end{rawhtml}" . pop_up_list(@list) . " $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; 492 $i++; 493 } 494 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 495 } elsif ($main::displayMode eq 'TeX') { 496 $out = "\n\\par\\begin{enumerate}\n"; 497 my $i=1; my $quest; 498 foreach $quest (@questions) { 499 $out .= "\\item[" . pop_up_list(@list) . "$i.] $quest\n"; 500 $i++; 501 } 502 $out .= "\\end{enumerate}\n"; 503 } else { 504 $out = "Error: PGchoicemacros: pop_up_list_print_q: Unknown displayMode: $main::displayMode.\n"; 505 } 506 $out; 507 508 } 509 510 511 # Units for physics class 512 # contributed by Mark Schmitt 3-6-03 513 514 sub units_list_print_q { 515 my $self = shift; 516 my (@questions) = @_; 517 my $length = $self->{ans_rule_len}; 518 my @list = @{$self->{ra_pop_up_list} }; 519 my $out = ''; 520 521 $out.= pop_up_list(@list); 522 523 $out; 524 } 525 526 #Standard method of printing answers in a matching list 527 sub std_print_a { 528 my $self = shift; 529 my(@array) = @_; 530 my $i = 0; 531 my @alpha = ("A".."Z"); 532 my $letter; 533 my $out= &main::M3( 534 "\\begin{enumerate}\n", 535 " \\begin{rawhtml} <OL TYPE=\"A\" VALUE=\"1\"> \\end{rawhtml} ", 536 # kludge to fix IE/CSS problem 537 #"<OL COMPACT TYPE=\"A\" START=\"1\">\n" 538 "<BLOCKQUOTE>\n" 539 ) ; 540 my $elem; 541 foreach $elem (@array) { 542 $letter = shift @alpha; 543 $out .= &main::M3( 544 "\\item[$main::ALPHABET[$i].] $elem\n", 545 " \\begin{rawhtml} <LI> \\end{rawhtml} $elem ", 546 #"<LI> $elem</LI>\n" 547 "<br /> <b>$letter.</b> $elem\n" 548 ) ; 549 $i++; 550 } 551 $out .= &main::M3( 552 "\\end{enumerate}\n", 553 " \\begin{rawhtml} </OL>\n \\end{rawhtml} ", 554 #"</OL>\n" 555 "</BLOCKQUOTE>\n" 556 ) ; 557 $out; 558 559 } 560 561 562 563 564 #Alternate method of printing answers as a list of radio buttons for multiple choice 565 sub radio_print_a { 566 my $self = shift; 567 my (@answers) = @_; 568 my $out = ""; 569 my $i =0; 570 my @in = (); 571 #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') { 572 if ($main::displayMode =~ /^HTML/) { 573 foreach my $ans (@answers) { 574 push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans")); 575 $i++; 576 } 577 my @radio_buttons = ans_radio_buttons(@in); 578 $out = "\n<BR>" . join "\n<BR>", @radio_buttons; 579 $out .= "<BR>\n"; 580 } elsif ($main::displayMode eq 'Latex2HTML') { 581 foreach my $ans (@answers) { 582 push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans")); 583 $i++; 584 } 585 my @radio_buttons = ans_radio_buttons(@in); 586 $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @radio_buttons; 587 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 588 } elsif ($main::displayMode eq 'TeX') { 589 foreach my $ans (@answers) { 590 push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans")); 591 $i++; 592 } 593 my @radio_buttons = ans_radio_buttons(@in); 594 #$out = "\n\\par\\begin{itemize}\n"; 595 $out .= join '', @radio_buttons; 596 #$out .= "\\end{itemize}\n"; 597 } else { 598 $out = "Error: PGchoicemacros: radio_print_a: Unknown displayMode: $main::displayMode.\n"; 599 } 600 $out; 601 602 } 603 604 #Second alternate method of printing answers as a list of radio buttons for multiple choice 605 #Method for naming radio buttons is no longer round about and hackish 606 sub checkbox_print_a { 607 my $self = shift; 608 my (@answers) = @_; 609 my $out = ""; 610 my $i =0; 611 my @in = (); 612 # if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') { 613 if ($main::displayMode =~ /^HTML/) { 614 foreach my $ans (@answers) { 615 push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans")); 616 $i++; 617 } 618 my @checkboxes = ans_checkbox(@in); 619 $out = "\n<BR>" . join "\n<BR>", @checkboxes; 620 $out .= "<BR>\n"; 621 } elsif ($main::displayMode eq 'Latex2HTML') { 622 foreach my $ans (@answers) { 623 push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans")); 624 $i++; 625 } 626 my @checkboxes = ans_checkbox(@in); 627 $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @checkboxes; 628 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 629 } elsif ($main::displayMode eq 'TeX') { 630 foreach my $ans (@answers) { 631 push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans")); 632 $i++; 633 } 634 my @radio_buttons = ans_checkbox(@in); 635 #$out = "\n\\par\\begin{itemize}\n"; 636 $out .= join '', @radio_buttons ; 637 #$out .= "\\end{itemize}\n"; 638 } else { 639 $out = "Error: PGchoicemacros: checkbox_print_a: Unknown displayMode: $main::displayMode.\n"; 640 } 641 $out; 642 643 } 644 645 646 #Standard method of printing questions in a matching or select list 647 sub std_print_q { 648 my $self = shift; 649 my (@questions) = @_; 650 my $length = $self->{ans_rule_len}; 651 my $out = ""; 652 #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') { 653 if ($main::displayMode =~ /^HTML/) { 654 my $i=1; my $quest; $out = "\n<P>\n"; 655 foreach $quest (@questions) { 656 $out.= ans_rule($length) . " <B>$i.</B> $quest<BR>"; 657 $i++; 658 } 659 } elsif ($main::displayMode eq 'Latex2HTML') { 660 my $i=1; my $quest; $out = "\\par\n"; 661 foreach $quest (@questions) { 662 $out.= ans_rule($length) . "\\begin{rawhtml}<B>$i. </B>\\end{rawhtml} $quest\\begin{rawhtml}<BR>\\end{rawhtml}\n"; 663 $i++; 664 } 665 } elsif ($main::displayMode eq 'TeX') { 666 $out = "\n\\par\\begin{enumerate}\n"; 667 my $i=1; my $quest; 668 foreach $quest (@questions) { 669 $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n"; 670 $i++; 671 } 672 $out .= "\\end{enumerate}\n"; 673 } else { 674 $out = "Error: PGchoicemacros: std_print_q: Unknown displayMode: $main::displayMode.\n"; 675 } 676 $out; 677 678 } 679 680 681 682 =head3 legacy macros 683 684 These are maintained for backward compatibility. 685 They can still be useful in constructing non-standard lists that don't fit 686 the various list objects. In general the using the list objects is likely 687 to give better results and is preferred. 688 689 =cut 690 691 =head4 qa 692 693 =cut 694 695 sub qa { 696 my($questionsRef,$answersRef,@questANDanswer) = @_; 697 while (@questANDanswer) { 698 push(@$questionsRef,shift(@questANDanswer)); 699 push(@$answersRef,shift(@questANDanswer)); 700 701 } 702 } 703 704 =head4 invert 705 706 =cut 707 708 sub invert { 709 my @array = @_; 710 my @out = (); 711 my $i; 712 for ($i=0;$i<=$#array;$i++) { 713 $out[$array[$i]]=$i; 714 } 715 @out; 716 } 717 718 =head4 NchooseK 719 720 =cut 721 722 sub NchooseK { 723 my($n,$k)=@_;; 724 my @array = 0..($n-1); 725 my @out = (); 726 while (@out<$k) { 727 push(@out, splice(@array, random(0,$#array,1) , 1) ); 728 } 729 @out; 730 } 731 732 =head4 shuffle 733 734 =cut 735 736 sub shuffle { 737 my ($i) = @_; 738 my @out = &NchooseK($i,$i); 739 @out; 740 } 741 742 =head4 match_questions_list 743 744 =cut 745 746 sub match_questions_list { 747 my (@questions) = @_; 748 my $out = ""; 749 #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') { 750 if ($main::displayMode =~ /^HTML/) { 751 my $i=1; my $quest; 752 foreach $quest (@questions) { 753 $out.= "\n<BR>" . ans_rule(4) . "<B>$i.</B> $quest"; 754 $i++; 755 } 756 $out .= "<br>\n"; 757 } elsif ($main::displayMode eq 'Latex2HTML') { 758 my $i=1; my $quest; 759 foreach $quest (@questions) { 760 $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule(4) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest"; 761 $i++; 762 } 763 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 764 } elsif ($main::displayMode eq 'TeX') { 765 $out = "\n\\par\\begin{enumerate}\n"; 766 my $i=1; my $quest; 767 foreach $quest (@questions) { 768 $out .= "\\item[" . ans_rule(3) . "$i.] $quest\n"; 769 $i++; 770 } 771 $out .= "\\end{enumerate}\n"; 772 } else { 773 $out = "Error: PGchoicemacros: match_questions_list: Unknown displayMode: $main::displayMode.\n"; 774 } 775 $out; 776 } 777 778 779 780 sub match_questions_list_varbox { 781 my ($length, @questions) = @_; 782 my $out = ""; 783 #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') { 784 if ($main::displayMode =~ /^HTML/) { 785 my $i=1; my $quest; 786 foreach $quest (@questions) { 787 $out.= "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest"; 788 $i++; 789 } 790 $out .= "<br>\n"; 791 } elsif ($main::displayMode eq 'Latex2HTML') { 792 my $i=1; my $quest; 793 foreach $quest (@questions) { 794 $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest"; 795 $i++; 796 } 797 $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} "; 798 } elsif ($main::displayMode eq 'TeX') { 799 $out = "\n\\par\\begin{enumerate}\n"; 800 my $i=1; my $quest; 801 foreach $quest (@questions) { 802 $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n"; 803 $i++; 804 } 805 $out .= "\\end{enumerate}\n"; 806 } else { 807 $out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n"; 808 } 809 $out; 810 } 811 812 813 814 1;
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |