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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2267 - (view) (download) (as text)

1 : apizer 1080
2 : sh002i 1050 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 : apizer 1080 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 : sh002i 1050 and the use of objects based on these classes. The list sub-classes are:
21 : apizer 1080 "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 : sh002i 1050 (e.g. true/false questions) from a larger question set, and
25 : apizer 1080 "Multiple.pm" which aids in setting up a
26 :     standard style, one question, many answers type multiple
27 : sh002i 1050 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 : apizer 1080 $ml->qa( "What color is a rose?",
38 : sh002i 1050 "Red",
39 :     "What color is the sky?",
40 :     "Blue",
41 :     "What color is the sea?",
42 :     "Green"
43 :     );
44 : apizer 1080 # choose two of these questions, ordered at random,
45 : sh002i 1050 # which will be printed in the problem.
46 : apizer 1080 $ml->choose(2);
47 : sh002i 1050 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 : apizer 1080
54 : sh002i 1050 ANS( $ml->ra_correct_ans() );
55 : apizer 1080
56 : sh002i 1050 =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 : apizer 1080 Either call will create a matching list object in the variable $ml.
77 : sh002i 1050 (I< Note: $ml cannot be a my variable if it is to be used within a BEGIN_TEXT/END_TEXT block.>)
78 :    
79 : apizer 1080 The first argument is the seed for the match list (choosen at random between 1 and 2000 in
80 : sh002i 1050 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 : apizer 1080 example of how to do this is demonstrated with
84 : sh002i 1050 "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 : apizer 1080 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 : sh002i 1050 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 : apizer 1080 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 : sh002i 1050 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 : apizer 1080 The answer formatting method has the same interface as the question formatting
124 : sh002i 1050 method.
125 :    
126 : apizer 1080
127 : sh002i 1050 =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 : gage 1068
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 : dpvc 2267 || $main::displayMode eq 'HTML_jsMath' || $main::displayMode eq 'HTML_asciimath'
441 : gage 1068 || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') {
442 :     my $i=1; my $quest;
443 :     foreach $quest (@questions) {
444 :     $out.= "\n<p>" . "&nbsp; $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 : dpvc 2267 || $main::displayMode eq 'HTML_jsMath' || $main::displayMode eq 'HTML_asciimath'
481 : gage 1068 || $main::displayMode eq 'HTML_dpng'|| $main::displayMode eq 'HTML_img') {
482 :     my $i=1; my $quest;
483 :     foreach $quest (@questions) {
484 :     $out.= "" . "&nbsp; $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 : sh002i 1050 #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 $out= &main::M3(
532 :     "\\begin{enumerate}\n",
533 :     " \\begin{rawhtml} <OL TYPE=\"A\" VALUE=\"1\"> \\end{rawhtml} ",
534 :     "<OL COMPACT TYPE=\"A\" START=\"1\">\n"
535 :     ) ;
536 :     my $elem;
537 :     foreach $elem (@array) {
538 :     $out .= &main::M3(
539 :     "\\item[$main::ALPHABET[$i].] $elem\n",
540 :     " \\begin{rawhtml} <LI> \\end{rawhtml} $elem ",
541 :     "<LI> $elem\n"
542 :     ) ;
543 :     $i++;
544 :     }
545 :     $out .= &main::M3(
546 :     "\\end{enumerate}\n",
547 :     " \\begin{rawhtml} </OL>\n \\end{rawhtml} ",
548 :     "</OL>\n"
549 :     ) ;
550 :     $out;
551 :    
552 :     }
553 :    
554 :    
555 :    
556 :    
557 :     #Alternate method of printing answers as a list of radio buttons for multiple choice
558 :     sub radio_print_a {
559 :     my $self = shift;
560 :     my (@answers) = @_;
561 :     my $out = "";
562 :     my $i =0;
563 :     my @in = ();
564 :     #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
565 :     if ($main::displayMode =~ /^HTML/) {
566 :     foreach my $ans (@answers) {
567 :     push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
568 :     $i++;
569 :     }
570 :     my @radio_buttons = ans_radio_buttons(@in);
571 :     $out = "\n<BR>" . join "\n<BR>", @radio_buttons;
572 :     $out .= "<BR>\n";
573 :     } elsif ($main::displayMode eq 'Latex2HTML') {
574 :     foreach my $ans (@answers) {
575 :     push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
576 :     $i++;
577 :     }
578 :     my @radio_buttons = ans_radio_buttons(@in);
579 :     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @radio_buttons;
580 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
581 :     } elsif ($main::displayMode eq 'TeX') {
582 :     foreach my $ans (@answers) {
583 :     push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
584 :     $i++;
585 :     }
586 :     my @radio_buttons = ans_radio_buttons(@in);
587 :     #$out = "\n\\par\\begin{itemize}\n";
588 :     $out .= join '', @radio_buttons;
589 :     #$out .= "\\end{itemize}\n";
590 :     } else {
591 :     $out = "Error: PGchoicemacros: radio_print_a: Unknown displayMode: $main::displayMode.\n";
592 :     }
593 :     $out;
594 :    
595 :     }
596 :    
597 :     #Second alternate method of printing answers as a list of radio buttons for multiple choice
598 :     #Method for naming radio buttons is no longer round about and hackish
599 :     sub checkbox_print_a {
600 :     my $self = shift;
601 :     my (@answers) = @_;
602 :     my $out = "";
603 :     my $i =0;
604 :     my @in = ();
605 :     # if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
606 :     if ($main::displayMode =~ /^HTML/) {
607 :     foreach my $ans (@answers) {
608 :     push (@in, ($main::ALPHABET[$i], "<B> $main::ALPHABET[$i]. </B> $ans"));
609 :     $i++;
610 :     }
611 :     my @checkboxes = ans_checkbox(@in);
612 :     $out = "\n<BR>" . join "\n<BR>", @checkboxes;
613 :     $out .= "<BR>\n";
614 :     } elsif ($main::displayMode eq 'Latex2HTML') {
615 :     foreach my $ans (@answers) {
616 :     push (@in, ($main::ALPHABET[$i], "\\begin{rawhtml}<B> $main::ALPHABET[$i]. </B> \\end{rawhtml} $ans"));
617 :     $i++;
618 :     }
619 :     my @checkboxes = ans_checkbox(@in);
620 :     $out = "\\begin{rawhtml}<BR>\\end{rawhtml}" . join "\\begin{rawhtml}<BR>\\end{rawhtml}", @checkboxes;
621 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
622 :     } elsif ($main::displayMode eq 'TeX') {
623 :     foreach my $ans (@answers) {
624 :     push (@in, ($main::ALPHABET[$i], "$main::ALPHABET[$i]. $ans"));
625 :     $i++;
626 :     }
627 :     my @radio_buttons = ans_checkbox(@in);
628 :     #$out = "\n\\par\\begin{itemize}\n";
629 :     $out .= join '', @radio_buttons ;
630 :     #$out .= "\\end{itemize}\n";
631 :     } else {
632 :     $out = "Error: PGchoicemacros: checkbox_print_a: Unknown displayMode: $main::displayMode.\n";
633 :     }
634 :     $out;
635 :    
636 :     }
637 :    
638 :    
639 :     #Standard method of printing questions in a matching or select list
640 :     sub std_print_q {
641 :     my $self = shift;
642 :     my (@questions) = @_;
643 :     my $length = $self->{ans_rule_len};
644 :     my $out = "";
645 :     #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
646 :     if ($main::displayMode =~ /^HTML/) {
647 :     my $i=1; my $quest;
648 :     foreach $quest (@questions) {
649 :     $out.= "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest";
650 :     $i++;
651 :     }
652 :     $out .= "<br>\n";
653 :     } elsif ($main::displayMode eq 'Latex2HTML') {
654 :     my $i=1; my $quest;
655 :     foreach $quest (@questions) {
656 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
657 :     $i++;
658 :     }
659 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
660 :     } elsif ($main::displayMode eq 'TeX') {
661 :     $out = "\n\\par\\begin{enumerate}\n";
662 :     my $i=1; my $quest;
663 :     foreach $quest (@questions) {
664 :     $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
665 :     $i++;
666 :     }
667 :     $out .= "\\end{enumerate}\n";
668 :     } else {
669 :     $out = "Error: PGchoicemacros: std_print_q: Unknown displayMode: $main::displayMode.\n";
670 :     }
671 :     $out;
672 :    
673 :     }
674 :    
675 :    
676 :    
677 :     =head3 legacy macros
678 :    
679 :     These are maintained for backward compatibility.
680 :     They can still be useful in constructing non-standard lists that don't fit
681 :     the various list objects. In general the using the list objects is likely
682 :     to give better results and is preferred.
683 :    
684 :     =cut
685 :    
686 :     =head4 qa
687 :    
688 :     =cut
689 :    
690 :     sub qa {
691 :     my($questionsRef,$answersRef,@questANDanswer) = @_;
692 :     while (@questANDanswer) {
693 :     push(@$questionsRef,shift(@questANDanswer));
694 :     push(@$answersRef,shift(@questANDanswer));
695 :    
696 :     }
697 :     }
698 :    
699 :     =head4 invert
700 :    
701 :     =cut
702 :    
703 :     sub invert {
704 :     my @array = @_;
705 :     my @out = ();
706 :     my $i;
707 :     for ($i=0;$i<=$#array;$i++) {
708 :     $out[$array[$i]]=$i;
709 :     }
710 :     @out;
711 :     }
712 :    
713 :     =head4 NchooseK
714 :    
715 :     =cut
716 :    
717 :     sub NchooseK {
718 :     my($n,$k)=@_;;
719 :     my @array = 0..($n-1);
720 :     my @out = ();
721 :     while (@out<$k) {
722 :     push(@out, splice(@array, random(0,$#array,1) , 1) );
723 :     }
724 :     @out;
725 :     }
726 :    
727 :     =head4 shuffle
728 :    
729 :     =cut
730 :    
731 :     sub shuffle {
732 :     my ($i) = @_;
733 :     my @out = &NchooseK($i,$i);
734 :     @out;
735 :     }
736 :    
737 :     =head4 match_questions_list
738 :    
739 :     =cut
740 :    
741 :     sub match_questions_list {
742 :     my (@questions) = @_;
743 :     my $out = "";
744 :     #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
745 :     if ($main::displayMode =~ /^HTML/) {
746 :     my $i=1; my $quest;
747 :     foreach $quest (@questions) {
748 :     $out.= "\n<BR>" . ans_rule(4) . "<B>$i.</B> $quest";
749 :     $i++;
750 :     }
751 :     $out .= "<br>\n";
752 :     } elsif ($main::displayMode eq 'Latex2HTML') {
753 :     my $i=1; my $quest;
754 :     foreach $quest (@questions) {
755 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule(4) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
756 :     $i++;
757 :     }
758 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
759 :     } elsif ($main::displayMode eq 'TeX') {
760 :     $out = "\n\\par\\begin{enumerate}\n";
761 :     my $i=1; my $quest;
762 :     foreach $quest (@questions) {
763 :     $out .= "\\item[" . ans_rule(3) . "$i.] $quest\n";
764 :     $i++;
765 :     }
766 :     $out .= "\\end{enumerate}\n";
767 :     } else {
768 :     $out = "Error: PGchoicemacros: match_questions_list: Unknown displayMode: $main::displayMode.\n";
769 :     }
770 :     $out;
771 :     }
772 :    
773 :    
774 :    
775 :     sub match_questions_list_varbox {
776 :     my ($length, @questions) = @_;
777 :     my $out = "";
778 :     #if ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
779 :     if ($main::displayMode =~ /^HTML/) {
780 :     my $i=1; my $quest;
781 :     foreach $quest (@questions) {
782 :     $out.= "\n<BR>" . ans_rule($length) . "<B>$i.</B> $quest";
783 :     $i++;
784 :     }
785 :     $out .= "<br>\n";
786 :     } elsif ($main::displayMode eq 'Latex2HTML') {
787 :     my $i=1; my $quest;
788 :     foreach $quest (@questions) {
789 :     $out.= " \\begin{rawhtml}<BR>\\end{rawhtml} " . ans_rule($length) . "\\begin{rawhtml}<B>\\end{rawhtml} $i. \\begin{rawhtml}</B>\\end{rawhtml} $quest"; #"$i. $quest";
790 :     $i++;
791 :     }
792 :     $out .= " \\begin{rawhtml}<BR>\\end{rawhtml} ";
793 :     } elsif ($main::displayMode eq 'TeX') {
794 :     $out = "\n\\par\\begin{enumerate}\n";
795 :     my $i=1; my $quest;
796 :     foreach $quest (@questions) {
797 :     $out .= "\\item[" . ans_rule($length) . "$i.] $quest\n";
798 :     $i++;
799 :     }
800 :     $out .= "\\end{enumerate}\n";
801 :     } else {
802 :     $out = "Error: PGchoicemacros: match_questions_list_varbox: Unknown displayMode: $main::displayMode.\n";
803 :     }
804 :     $out;
805 :     }
806 :    
807 :    
808 :    
809 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9