[system] / trunk / webwork / system / courseScripts / PGbasicmacros.pl Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/courseScripts/PGbasicmacros.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 : sam 11 #!/usr/local/bin/webwork-perl
2 : sam 2
3 :     ####################################################################
4 :     # Copyright @ 1995-1998 University of Rochester
5 :     # All Rights Reserved
6 :     ####################################################################
7 :    
8 :     =head1 NAME
9 :    
10 :     PGbasicmacros.pl --- located in the courseScripts directory
11 :    
12 :     =head1 SYNPOSIS
13 :    
14 :    
15 :    
16 :     =head1 DESCRIPTION
17 :    
18 :    
19 :    
20 :     =cut
21 :    
22 :     # this is equivalent to use strict, but can be used within the Safe compartment.
23 :     BEGIN{
24 :     be_strict;
25 :     }
26 : gage 36
27 :    
28 : gage 27 my $displayMode=$main::displayMode;
29 : sam 2
30 : gage 27 my ($PAR,
31 :     $BR,
32 :     $LQ,
33 :     $RQ,
34 :     $BM,
35 :     $EM,
36 :     $BDM,
37 :     $EDM,
38 :     $LTS,
39 :     $GTS,
40 :     $LTE,
41 :     $GTE,
42 :     $BEGIN_ONE_COLUMN,
43 :     $END_ONE_COLUMN,
44 :     $SOL,
45 : apizer 37 $SOLUTION,
46 : gage 27 $HINT,
47 :     $US,
48 :     $SPACE,
49 :     $BBOLD,
50 : apizer 208 $EBOLD,
51 :     $BITALIC,
52 :     $EITALIC,
53 :     $BCENTER,
54 :     $ECENTER,
55 : gage 27 $HR,
56 :     $LBRACE,
57 :     $RBRACE,
58 :     $LB,
59 :     $RB,
60 :     $DOLLAR,
61 :     $PERCENT,
62 :     $CARET,
63 :     $PI,
64 :     $E,
65 :     @ALPHABET,
66 :     );
67 : gage 36
68 : gage 27 sub _PGbasicmacros_init {
69 : gage 36 $displayMode =$main::displayMode;
70 : gage 27 $main::PAR = PAR();
71 :     $main::BR = BR();
72 :     $main::LQ = LQ();
73 :     $main::RQ = RQ();
74 :     $main::BM = BM();
75 :     $main::EM = EM();
76 :     $main::BDM = BDM();
77 :     $main::EDM = EDM();
78 :     $main::LTS = LTS();
79 :     $main::GTS = GTS();
80 :     $main::LTE = LTE();
81 :     $main::GTE = GTE();
82 :     $main::BEGIN_ONE_COLUMN = BEGIN_ONE_COLUMN();
83 :     $main::END_ONE_COLUMN = END_ONE_COLUMN();
84 :     $main::SOL = SOLUTION_HEADING();
85 : apizer 37 $main::SOLUTION = SOLUTION_HEADING();
86 : gage 27 $main::HINT = HINT_HEADING();
87 :     $main::US = US();
88 :     $main::SPACE = SPACE();
89 :     $main::BBOLD = BBOLD();
90 : apizer 208 $main::EBOLD = EBOLD();
91 :     $main::BITALIC = BITALIC();
92 :     $main::EITALIC = EITALIC();
93 :     $main::BCENTER = BCENTER();
94 :     $main::ECENTER = ECENTER();
95 : gage 27 $main::HR = HR();
96 :     $main::LBRACE = LBRACE();
97 :     $main::RBRACE = RBRACE();
98 :     $main::LB = LB();
99 :     $main::RB = RB();
100 :     $main::DOLLAR = DOLLAR();
101 :     $main::PERCENT = PERCENT();
102 :     $main::CARET = CARET();
103 :     $main::PI = PI();
104 :     $main::E = E();
105 :     @main::ALPHABET = ('A'..'ZZ');
106 :    
107 :     $PAR = PAR();
108 :     $BR = BR();
109 :     $LQ = LQ();
110 :     $RQ = RQ();
111 :     $BM = BM();
112 :     $EM = EM();
113 :     $BDM = BDM();
114 :     $EDM = EDM();
115 :     $LTS = LTS();
116 :     $GTS = GTS();
117 :     $LTE = LTE();
118 :     $GTE = GTE();
119 :     $BEGIN_ONE_COLUMN = BEGIN_ONE_COLUMN();
120 :     $END_ONE_COLUMN = END_ONE_COLUMN();
121 :     $SOL = SOLUTION_HEADING();
122 : apizer 37 $SOLUTION = SOLUTION_HEADING();
123 : gage 27 $HINT = HINT_HEADING();
124 :     $US = US();
125 :     $SPACE = SPACE();
126 :     $BBOLD = BBOLD();
127 :     $EBOLD = EBOLD();
128 :     $HR = HR();
129 :     $LBRACE = LBRACE();
130 :     $RBRACE = RBRACE();
131 :     $LB = LB();
132 :     $RB = RB();
133 :     $DOLLAR = DOLLAR();
134 :     $PERCENT = PERCENT();
135 :     $CARET = CARET();
136 :     $PI = PI();
137 :     $E = E();
138 :     @ALPHABET = ('A'..'ZZ');
139 :    
140 : gage 36
141 : sam 2
142 : gage 27 }
143 :    
144 : sam 2 =head2 Answer blank macros:
145 :    
146 :     These produce answer blanks of various sizes or pop up lists or radio answer buttons.
147 :     The names for the answer blanks are
148 :     generated implicitly.
149 :    
150 :     ans_rule( width )
151 :     tex_ans_rule( width )
152 :     ans_radio_buttons(value1=>label1, value2,label2 => value3,label3=>...)
153 :     pop_up_list(@list) # list consists of (value => label, PR => "Product rule",...)
154 :    
155 :     To indicate the checked position of radio buttons put a '%' in front of the value: C<ans_radio_buttons(1, 'Yes','%2','No')>
156 :     will have 'No' checked. C<tex_ans_rule> works inside math equations in C<HTML_tth> mode. It does not work in C<Latex2HTML> mode
157 :     since this mode produces gif pictures.
158 :    
159 :    
160 :     The following method is defined in F<PG.pl> for entering the answer evaluators corresponding
161 :     to answer rules with automatically generated names. The answer evaluators are matched with the
162 :     answer rules in the order in which they appear on the page.
163 :    
164 :     ANS(ans_evaluator1, ans_evaluator2,...);
165 :    
166 :     These are more primitive macros which produce answer blanks for specialized cases when complete
167 :     control over the matching of answers blanks and answer evaluators is desired.
168 :     The names of the answer blanks must be generated manually, and it is best if they do NOT begin
169 :     with the default answer prefix (currently AnSwEr).
170 :    
171 :    
172 :     NAMED_ANS_RULE(name, width)
173 :     NAMED_ANS_BOX(name, rows, cols)
174 :     NAMED_ANS_RADIO(name, value,label,)
175 :     NAMED_ANS_RADIO_OPTION(name, value,label)
176 :     NAMED_ANS_RADIO_BUTTONS(name,value1,label1,value2,label2,...)
177 :     check_box('-name' =>answer5,'-value' =>'statement3','-label' =>'I loved this course!' )
178 :     NAMED_POP_UP_LIST($name, @list) # list consists of (value => tag, PR => "Product rule",...)
179 :    
180 :     (Name is the name of the variable, value is the value given to the variable when this option is selected,
181 :     and label is the text printed next to the button or check box. Check box variables can have multiple values.)
182 :    
183 :     NAMED_ANS_RADIO_BUTTONS creates a sequence of NAMED_ANS_RADIO and NAMED_ANS_RADIO_OPTION items which
184 :     are output either as an array or, in scalar context, as the array glued together with spaces. It is
185 :     usually easier to use this than to manually construct the radio buttons by hand. However, sometimes
186 :     extra flexibility is desiredin which case:
187 :    
188 :     When entering radio buttons using the "NAMED" format, you should use NAMED_ANS_RADIO button for the first button
189 :     and then use NAMED_ANS_RADIO_OPTION for the remaining buttons. NAMED_ANS_RADIO requires a matching answer evalutor,
190 :     while NAMED_ANS_RADIO_OPTION does not. The name used for NAMED_ANS_RADIO_OPTION should match the name
191 :     used for NAMED_ANS_RADIO (and the associated answer evaluator).
192 :    
193 :    
194 :    
195 :     The following method is defined in in F<PG.pl> for entering the answer evaluators corresponding
196 :     to answer rules with automatically generated names. The answer evaluators are matched with the
197 :     answer rules in the order in which they appear on the page.
198 :    
199 :     NAMED_ANS(name1 => ans_evaluator1, name2 => ans_evaluator2,...);
200 :    
201 :     These auxiliary macros are defined in PG.pl
202 :    
203 :    
204 :     NEW_ANS_NAME( number ); # produces a new answer blank name from a number by adding a prefix (AnSwEr)
205 :     # and registers this name as an implicitly labeled answer
206 :     # Its use is paired with each answer evaluator being entered using ANS()
207 :    
208 :     ANS_NUM_TO_NAME(number); # adds the prefix (AnSwEr) to the number, but does nothing else.
209 :    
210 :     RECORD_ANS_NAME( name ); # records the order in which the answer blank is rendered
211 :     # This is called by all of the constructs above, but must
212 :     # be called explicitly if an input blank is constructed explictly
213 :     # using HTML code.
214 :    
215 :     These are legacy macros:
216 :    
217 :     ANS_RULE( number, width ); # equivalent to NAMED_ANS_RULE( NEW_ANS_NAME(number), width)
218 :     ANS_BOX( question_number,height, width ); # equivalent to NAMED_ANS_BOX( NEW_ANS_NAME(number), height, width)
219 :     ANS_RADIO( question_number, value,tag ); # equivalent to NAMED_ANS_RADIO( NEW_ANS_NAME(number), value,tag)
220 :     ANS_RADIO_OPTION( question_number, value,tag ); # equivalent to NAMED_ANS_RADIO_OPTION( ANS_NUM_TO_NAME(number), value,tag)
221 :    
222 :    
223 :     =cut
224 :    
225 :    
226 :     sub NAMED_ANS_RULE {
227 :     my($name,$col) = @_;
228 :     my $len = 0.07*$col;
229 :     my $answer_value = '';
230 :     $answer_value = ${$main::inputs_ref}{$name} if defined(${$main::inputs_ref}{$name});
231 :     if ($answer_value =~ /\0/ ) {
232 :     my @answers = split("\0", $answer_value);
233 :     $answer_value = shift(@answers); # use up the first answer
234 :     $main::rh_sticky_answers{$name}=\@answers; # store the rest
235 :     $answer_value= '' unless defined($answer_value);
236 : gage 188 } elsif (ref($answer_value) eq 'ARRAY') {
237 :     my @answers = @{ $answer_value};
238 :     $answer_value = shift(@answers); # use up the first answer
239 :     $main::rh_sticky_answers{$name}=\@answers; # store the rest
240 :     $answer_value= '' unless defined($answer_value);
241 :     }
242 : sam 2 $name = RECORD_ANS_NAME($name);
243 :     MODES(
244 :     TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ",
245 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
246 :     HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n"
247 :     );
248 :     }
249 :    
250 :     sub NAMED_ANS_RULE_OPTION {
251 :     &NAMED_ANS_RULE_EXTENSION;
252 :     }
253 :    
254 :     sub NAMED_ANS_RULE_EXTENSION {
255 :     my($name,$col) = @_;
256 :     my $len = 0.07*$col;
257 :     my $answer_value = '';
258 :     $answer_value = ${$main::inputs_ref}{$name} if defined(${$main::inputs_ref}{$name});
259 :     if ( defined($main::rh_sticky_answers{$name}) ) {
260 :     $answer_value = shift( @{$main::rh_sticky_answers{$name}});
261 :     $answer_value = '' unless defined($answer_value);
262 :     }
263 :     MODES(
264 :     TeX => '\\hrulefill\\quad ',
265 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
266 :     HTML => qq!<INPUT TYPE=TEXT SIZE=$col NAME = "$name" VALUE = "$answer_value">\n!
267 :     );
268 :     }
269 :    
270 :     sub ANS_RULE {
271 :     my($number,$col) = @_;
272 :     my $name = NEW_ANS_NAME($number);
273 :     NAMED_ANS_RULE($name,$col);
274 :     }
275 :    
276 :    
277 :     sub NAMED_ANS_BOX {
278 :     my($name,$row,$col) = @_;
279 :     $row = 10 unless defined($row);
280 :     $col = 80 unless defined($col);
281 :     $name = RECORD_ANS_NAME($name);
282 :     my $len = 0.07*$col;
283 :     my $height = .07*$row;
284 :     my $answer_value = '';
285 :     $answer_value = $main::inputs_ref->{$name} if defined( $main::inputs_ref->{$name} );
286 :     my $out = M3(
287 :     qq!\\vskip $height in \\hrulefill\\quad !,
288 :     qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
289 :     WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!,
290 :     qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
291 :     WRAP="VIRTUAL">$answer_value</TEXTAREA>!
292 :     );
293 :     $out;
294 :     }
295 :    
296 :     sub ANS_BOX {
297 :     my($number,$row,$col) = @_;
298 :     my $name = NEW_ANS_NAME($number);
299 :     NAMED_ANS_BOX($name,$row,$col);
300 :     }
301 :    
302 :     sub NAMED_ANS_RADIO {
303 :     my $name = shift;
304 :     my $value = shift;
305 :     my $tag =shift;
306 :     $name = RECORD_ANS_NAME($name);
307 :     my $checked = '';
308 :     if ($value =~/^\%/) {
309 :     $value =~ s/^\%//;
310 :     $checked = 'CHECKED'
311 :     }
312 :     if (defined($main::inputs_ref->{$name}) ) {
313 :     if ($main::inputs_ref->{$name} eq $value) {
314 :     $checked = 'CHECKED'
315 :     } else {
316 :     $checked = '';
317 :     }
318 :    
319 :     }
320 :    
321 :     MODES(
322 :     TeX => qq!\\item{$tag}\n!,
323 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=RADIO NAME="$name" VALUE="$value" $checked>\\end{rawhtml}$tag!,
324 :     HTML => qq!<INPUT TYPE=RADIO NAME="$name" VALUE="$value" $checked>$tag!
325 :     );
326 :    
327 :     }
328 :    
329 :     sub NAMED_ANS_RADIO_OPTION {
330 :     my $name = shift;
331 :     my $value = shift;
332 :     my $tag =shift;
333 :    
334 :    
335 :     my $checked = '';
336 :     if ($value =~/^\%/) {
337 :     $value =~ s/^\%//;
338 :     $checked = 'CHECKED'
339 :     }
340 :     if (defined($main::inputs_ref->{$name}) ) {
341 :     if ($main::inputs_ref->{$name} eq $value) {
342 :     $checked = 'CHECKED'
343 :     } else {
344 :     $checked = '';
345 :     }
346 :    
347 :     }
348 :    
349 :     MODES(
350 :     TeX => qq!\\item{$tag}\n!,
351 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=RADIO NAME="$name" VALUE="$value" $checked>\\end{rawhtml}$tag!,
352 :     HTML => qq!<INPUT TYPE=RADIO NAME="$name" VALUE="$value" $checked>$tag!
353 :     );
354 :    
355 :     }
356 :    
357 :     sub NAMED_ANS_RADIO_BUTTONS {
358 :     my $name =shift;
359 :     my $value = shift;
360 :     my $tag = shift;
361 :    
362 :    
363 :     my @out = ();
364 :     push(@out, NAMED_ANS_RADIO($name, $value,$tag));
365 :     my @buttons = @_;
366 :     while (@buttons) {
367 :     $value = shift @buttons; $tag = shift @buttons;
368 :     push(@out, NAMED_ANS_RADIO_OPTION($name, $value,$tag));
369 :     }
370 :     (wantarray) ? @out : join(" ",@out);
371 :     }
372 :     sub ANS_RADIO {
373 :     my $number = shift;
374 :     my $value = shift;
375 :     my $tag =shift;
376 :     my $name = NEW_ANS_NAME($number);
377 :     NAMED_ANS_RADIO($name,$value,$tag);
378 :     }
379 :    
380 :     sub ANS_RADIO_OPTION {
381 :     my $number = shift;
382 :     my $value = shift;
383 :     my $tag =shift;
384 :    
385 :    
386 :     my $name = ANS_NUM_TO_NAME($number);
387 :     NAMED_ANS_RADIO_OPTION($name,$value,$tag);
388 :     }
389 :     sub ANS_RADIO_BUTTONS {
390 :     my $number =shift;
391 :     my $value = shift;
392 :     my $tag = shift;
393 :    
394 :    
395 :     my @out = ();
396 :     push(@out, ANS_RADIO($number, $value,$tag));
397 :     my @buttons = @_;
398 :     while (@buttons) {
399 :     $value = shift @buttons; $tag = shift @buttons;
400 :     push(@out, ANS_RADIO_OPTION($number, $value,$tag));
401 :     }
402 :     (wantarray) ? @out : join(" ",@out);
403 :     }
404 :    
405 :     sub NAMED_ANS_CHECKBOX {
406 :     my $name = shift;
407 :     my $value = shift;
408 :     my $tag =shift;
409 :     $name = RECORD_ANS_NAME($name);
410 :    
411 :     my $checked = '';
412 :     if ($value =~/^\%/) {
413 :     $value =~ s/^\%//;
414 :     $checked = 'CHECKED'
415 :     }
416 :    
417 :     if (defined($main::inputs_ref->{$name}) ) {
418 :     if ($main::inputs_ref->{$name} eq $value) {
419 :     $checked = 'CHECKED'
420 :     }
421 :     else {
422 :     $checked = '';
423 :     }
424 :    
425 :     }
426 :    
427 :     MODES(
428 :     TeX => qq!\\item{$tag}\n!,
429 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=CHECKBOX NAME="$name" VALUE="$value" $checked>\\end{rawhtml}$tag!,
430 :     HTML => qq!<INPUT TYPE=CHECKBOX NAME="$name" VALUE="$value" $checked>$tag!
431 :     );
432 :    
433 :     }
434 :    
435 :     sub NAMED_ANS_CHECKBOX_OPTION {
436 :     my $name = shift;
437 :     my $value = shift;
438 :     my $tag =shift;
439 :    
440 :     my $checked = '';
441 :     if ($value =~/^\%/) {
442 :     $value =~ s/^\%//;
443 :     $checked = 'CHECKED'
444 :     }
445 :    
446 :     if (defined($main::inputs_ref->{$name}) ) {
447 :     if ($main::inputs_ref->{$name} eq $value) {
448 :     $checked = 'CHECKED'
449 :     }
450 :     else {
451 :     $checked = '';
452 :     }
453 :    
454 :     }
455 :    
456 :     MODES(
457 :     TeX => qq!\\item{$tag}\n!,
458 :     Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=CHECKBOX NAME="$name" VALUE="$value" $checked>\\end{rawhtml}$tag!,
459 :     HTML => qq!<INPUT TYPE=CHECKBOX NAME="$name" VALUE="$value" $checked>$tag!
460 :     );
461 :    
462 :     }
463 :    
464 :     sub NAMED_ANS_CHECKBOX_BUTTONS {
465 :     my $name =shift;
466 :     my $value = shift;
467 :     my $tag = shift;
468 :    
469 :     my @out = ();
470 :     push(@out, NAMED_ANS_CHECKBOX($name, $value,$tag));
471 :    
472 :     my @buttons = @_;
473 :     while (@buttons) {
474 :     $value = shift @buttons; $tag = shift @buttons;
475 :     push(@out, NAMED_ANS_CHECKBOX_OPTION($name, $value,$tag));
476 :     }
477 :    
478 :     (wantarray) ? @out : join(" ",@out);
479 :     }
480 :    
481 :     sub ANS_CHECKBOX {
482 :     my $number = shift;
483 :     my $value = shift;
484 :     my $tag =shift;
485 :     my $name = NEW_ANS_NAME($number);
486 :    
487 :     NAMED_ANS_CHECKBOX($name,$value,$tag);
488 :     }
489 :    
490 :     sub ANS_CHECKBOX_OPTION {
491 :     my $number = shift;
492 :     my $value = shift;
493 :     my $tag =shift;
494 :     my $name = ANS_NUM_TO_NAME($number);
495 :    
496 :     NAMED_ANS_CHECKBOX_OPTION($name,$value,$tag);
497 :     }
498 :    
499 :     sub ANS_CHECKBOX_BUTTONS {
500 :     my $number =shift;
501 :     my $value = shift;
502 :     my $tag = shift;
503 :    
504 :     my @out = ();
505 :     push(@out, ANS_CHECKBOX($number, $value, $tag));
506 :    
507 :     my @buttons = @_;
508 :     while (@buttons) {
509 :     $value = shift @buttons; $tag = shift @buttons;
510 :     push(@out, ANS_CHECKBOX_OPTION($number, $value,$tag));
511 :     }
512 :    
513 :     (wantarray) ? @out : join(" ",@out);
514 :     }
515 :    
516 :     sub ans_rule {
517 :     my $len = shift; # gives the optional length of the answer blank
518 :     $len = 20 unless $len ;
519 :     my $name = NEW_ANS_NAME(++$main::ans_rule_count);
520 :     NAMED_ANS_RULE($name ,$len);
521 :     }
522 :     sub ans_rule_extension {
523 :     my $len = shift;
524 :     $len = 20 unless $len ;
525 :     my $name = NEW_ANS_NAME($main::ans_rule_count); # don't update the answer name
526 :     NAMED_ANS_RULE($name ,$len);
527 :     }
528 :     sub ans_radio_buttons {
529 :     my $name = NEW_ANS_NAME(++$main::ans_rule_count);
530 :     my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_);
531 :    
532 : gage 27 if ($displayMode eq 'TeX') {
533 : sam 2 $radio_buttons[0] = "\n\\begin{itemize}\n" . $radio_buttons[0];
534 :     $radio_buttons[$#radio_buttons] .= "\n\\end{itemize}\n";
535 :     }
536 :    
537 :     (wantarray) ? @radio_buttons: join(" ", @radio_buttons);
538 :     }
539 :    
540 :     #added 6/14/2000 by David Etlinger
541 :     sub ans_checkbox {
542 :     my $name = NEW_ANS_NAME( ++$main::ans_rule_count );
543 :     my @checkboxes = NAMED_ANS_CHECKBOX_BUTTONS( $name, @_ );
544 :    
545 : gage 30 if ($displayMode eq 'TeX') {
546 : sam 2 $checkboxes[0] = "\n\\begin{itemize}\n" . $checkboxes[0];
547 :     $checkboxes[$#checkboxes] .= "\n\\end{itemize}\n";
548 :     }
549 :    
550 :     (wantarray) ? @checkboxes: join(" ", @checkboxes);
551 :     }
552 :    
553 :    
554 :     ## define a version of ans_rule which will work inside TeX math mode or display math mode -- at least for tth mode.
555 :     ## This is great for displayed fractions.
556 :     ## This will not work with latex2HTML mode since it creates gif equations.
557 :    
558 :     sub tex_ans_rule {
559 :     my $len = shift;
560 :     $len = 20 unless $len ;
561 :     my $name = NEW_ANS_NAME(++$main::ans_rule_count);
562 :     my $answer_rule = NAMED_ANS_RULE($name ,$len); # we don't want to create three answer rules in different modes.
563 :     my $out = MODES(
564 :     'TeX' => $answer_rule,
565 :     'Latex2HTML' => '\\fbox{Answer boxes cannot be placed inside typeset equations}',
566 :     'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
567 :     'HTML' => $answer_rule
568 :     );
569 :    
570 :     $out;
571 :     }
572 :     sub tex_ans_rule_extension {
573 :     my $len = shift;
574 :     $len = 20 unless $len ;
575 :     my $name = NEW_ANS_NAME($main::ans_rule_count);
576 :     my $answer_rule = NAMED_ANS_RULE($name ,$len); # we don't want to create three answer rules in different modes.
577 :     my $out = MODES(
578 :     'TeX' => $answer_rule,
579 :     'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}',
580 :     'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
581 :     'HTML' => $answer_rule
582 :     );
583 :    
584 :     $out;
585 :     }
586 : gage 5 # still needs some cleanup.
587 :     sub NAMED_TEX_ANS_RULE {
588 :     my $name = shift;
589 :     my $len = shift;
590 :     $len = 20 unless $len ;
591 :     my $answer_rule = NAMED_ANS_RULE($name ,$len); # we don't want to create three answer rules in different modes.
592 :     my $out = MODES(
593 :     'TeX' => $answer_rule,
594 :     'Latex2HTML' => '\\fbox{Answer boxes cannot be placed inside typeset equations}',
595 :     'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
596 :     'HTML' => $answer_rule
597 :     );
598 :    
599 :     $out;
600 :     }
601 :     sub NAMED_TEX_ANS_RULE_EXTENSION {
602 :     my $name = shift;
603 :     my $len = shift;
604 :     $len = 20 unless $len ;
605 :     my $answer_rule = NAMED_ANS_RULE_EXTENSION($name ,$len); # we don't want to create three answer rules in different modes.
606 :     my $out = MODES(
607 :     'TeX' => $answer_rule,
608 :     'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}',
609 :     'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
610 :     'HTML' => $answer_rule
611 :     );
612 :    
613 :     $out;
614 :     }
615 : sam 2 sub ans_box {
616 :     my $row = shift;
617 :     my $col =shift;
618 :     $row = 5 unless $row;
619 :     $col = 80 unless $col;
620 :     my $name = NEW_ANS_NAME(++$main::ans_rule_count);
621 :     NAMED_ANS_BOX($name ,$row,$col);
622 :     }
623 :    
624 :     #this is legacy code; use ans_checkbox instead
625 :     sub checkbox {
626 :     my %options = @_;
627 :     qq!<INPUT TYPE="checkbox" NAME="$options{'-name'}" VALUE="$options{'-value'}">$options{'-label'}!
628 :     }
629 :    
630 :    
631 :     sub NAMED_POP_UP_LIST {
632 :     my $name = shift;
633 :     my @list = @_;
634 :     $name = RECORD_ANS_NAME($name); # record answer name
635 :     my $answer_value = '';
636 :     $answer_value = ${$main::inputs_ref}{$name} if defined(${$main::inputs_ref}{$name});
637 :     my $out = "";
638 : gage 30 if ($displayMode eq "HTML" or $displayMode eq "HTML_tth") {
639 : sam 2 $out = qq!<SELECT NAME = "$name" SIZE=1> \n!;
640 :     my $i;
641 :     foreach ($i=0; $i< @list; $i=$i+2) {
642 :     my $select_flag = ($list[$i] eq $answer_value) ? "SELECTED" : "";
643 :     $out .= qq!<OPTION $select_flag VALUE ="$list[$i]" > $list[$i+1] </OPTION>\n!;
644 :     };
645 :     $out .= " </SELECT>\n";
646 : gage 30 } elsif ( $displayMode eq "Latex2HTML") {
647 : sam 2 $out = qq! \\begin{rawhtml}<SELECT NAME = "$name" SIZE=1> \\end{rawhtml} \n !;
648 :     my $i;
649 :     foreach ($i=0; $i< @list; $i=$i+2) {
650 :     my $select_flag = ($list[$i] eq $answer_value) ? "SELECTED" : "";
651 :     $out .= qq!\\begin{rawhtml}<OPTION $select_flag VALUE ="$list[$i]" > $list[$i+1] </OPTION>\\end{rawhtml}\n!;
652 :     };
653 :     $out .= " \\begin{rawhtml}</SELECT>\\end{rawhtml}\n";
654 : gage 30 } elsif ( $displayMode eq "TeX") {
655 : sam 2 $out .= "\\fbox{?}";
656 :     }
657 :    
658 :     }
659 :    
660 :     sub pop_up_list {
661 :     my @list = @_;
662 :     my $name = NEW_ANS_NAME(++$main::ans_rule_count); # get new answer name
663 :     NAMED_POP_UP_LIST($name, @list);
664 :     }
665 :    
666 :     # end answer blank macros
667 :    
668 :     =head2 Hints and solutions macros
669 :    
670 :     solution('text','text2',...);
671 :     SOLUTION('text','text2',...); # equivalent to TEXT(solution(...));
672 :    
673 :     hint('text', 'text2', ...);
674 : gage 30 HINT('text', 'text2',...); # equivalent to TEXT("$BR$HINT" . hint(@_) . "$BR") if hint(@_);
675 : sam 2
676 :     Solution prints its concatenated input when the check box named 'ShowSol' is set and
677 : apizer 37 the time is after the answer date. The check box 'ShowSol' is visible only after the
678 :     answer date or when the problem is viewed by a professor.
679 : sam 2
680 : apizer 37 $envir{'displaySolutionsQ'} is set to 1 when a solution is to be displayed.
681 : sam 2
682 : apizer 37 Hints are shown only after the number of attempts is greater than $:showHint
683 :     ($main::showHint defaults to 1) and the check box named 'ShowHint' is set. The check box
684 :     'ShowHint' is visible only after the number of attempts is greater than $main::showHint.
685 : sam 2
686 : apizer 37 $envir{'displayHintsQ'} is set to 1 when a hint is to be displayed.
687 :    
688 :    
689 : sam 2 =cut
690 :    
691 :    
692 :    
693 :     # solution prints its input when $displaySolutionsQ is set.
694 :     # use as TEXT(solution("blah, blah");
695 :     # \$solutionExists
696 :     # is passed to processProblem which displays a "show Solution" button
697 :     # when a solution is available for viewing
698 :    
699 :    
700 :     sub solution {
701 :     my @in = @_;
702 :     my $out = '';
703 : gage 36 $main::solutionExists =1;
704 : apizer 37 if ($envir{'displaySolutionsQ'}) {$out = join(' ',@in);}
705 : sam 2 $out;
706 :     }
707 :    
708 :    
709 :     sub SOLUTION {
710 :     TEXT( solution(@_)) ;
711 :     }
712 :    
713 :    
714 :    
715 :     sub hint {
716 :     my @in = @_;
717 :     my $out = '';
718 : apizer 37
719 :     $main::hintExists =1;
720 :     $main::numOfAttempts = 0 unless defined($main::numOfAttempts);
721 : sam 2
722 : apizer 37 if ($main::displayMode eq 'TeX') {
723 : sam 2 $out = ''; # do nothing since hints are not available for download
724 : apizer 37 } elsif (($envir{'displayHintsQ'}) and ($main::numOfAttempts >= $main::showHint))
725 :    
726 :     ## the second test above prevents a hint being shown if a doctored form is submitted
727 :    
728 :     {$out = join(' ',@in);} # show hint
729 :    
730 : sam 2 $out ;
731 :     }
732 :    
733 :    
734 :     sub HINT {
735 : apizer 37 TEXT("$main::BR" . hint(@_) . "$main::BR") if hint(@_);
736 : sam 2 }
737 :    
738 :    
739 :    
740 :     # End hints and solutions macros
741 :     #################################
742 :    
743 :     # Produces a random number between $begin and $end with increment 1.
744 :     # You do not have to worry about integer or floating point types.
745 :    
746 :     =head2 Pseudo-random number generator
747 :    
748 :     Usage:
749 :     random(0,5,.1) # produces a random number between 0 and 5 in increments of .1
750 :     non_zero_random(0,5,.1) # gives a non-zero random number
751 :    
752 :     SRAND(seed) # resets the main random generator -- use very cautiously
753 :    
754 :    
755 :     SRAND(time) will create a different problem everytime it is called. This makes it difficult
756 :     to check the answers :-).
757 :    
758 :     SRAND($envir{'inputs_ref'}->{'key'} ) will create a different problem for each login session.
759 :     This is probably what is desired.
760 :    
761 :     =cut
762 :    
763 :    
764 :     sub random {
765 :     my ($begin, $end, $incr) = @_;
766 :     $main::PG_random_generator->random($begin,$end,$incr);
767 :     }
768 :    
769 :    
770 :     sub non_zero_random { ##gives a non-zero random number
771 :     my (@arguments)=@_;
772 :     my $a=0;
773 :     my $i=100; #safety counter
774 :     while ($a==0 && ( 0 < $i-- ) ) {
775 :     $a=random(@arguments);
776 :     }
777 :     $a;
778 :     }
779 :    
780 :     sub SRAND { # resets the main random generator -- use cautiously
781 :     my $seed = shift;
782 :     $main::PG_random_generator -> srand($seed);
783 :     }
784 :    
785 :     # display macros
786 :    
787 :     =head2 Display Macros
788 :    
789 :     These macros produce different output depending on the display mode being used to show
790 :     the problem on the screen, or whether the problem is being converted to TeX to produce
791 :     a hard copy output.
792 :    
793 :     MODES ( TeX => "Output this in TeX mode",
794 :     HTML => "output this in HTML mode",
795 :     HTML_tth => "output this in HTML_tth mode",
796 :     Latex2HTML => "output this in Latex2HTML mode",
797 :     )
798 :    
799 :     TEX (tex_version, html_version) #obsolete
800 :    
801 :     M3 (tex_version, latex2html_version, html_version) #obsolete
802 :    
803 :    
804 :    
805 :     =cut
806 :    
807 :    
808 :     sub TEX {
809 :     my ($tex, $html ) = @_;
810 :     MODES(TeX => $tex, HTML => $html, HTML_tth => $html);
811 :     }
812 :    
813 :    
814 :     sub M3 {
815 :     my($tex,$l2h,$html) = @_;
816 :     MODES(TeX => $tex, Latex2HTML => $l2h, HTML => $html, HTML_tth => $html);
817 :     }
818 :    
819 :     # This replaces M3. You can add new modes at will to this one.
820 :    
821 :     sub MODES {
822 :     my %options = @_;
823 : gage 30 return $options{$displayMode}
824 :     if defined( $options{$displayMode} );
825 : sam 2
826 :     # default searches.
827 : gage 30 if ($displayMode eq "Latex2HTML") {
828 : sam 2 return $options{TeX}
829 :     if defined( $options{TeX} );
830 :     return $options{HTML}
831 :     if defined( $options{HTML} );
832 :     die " ERROR in using MODES: 'HTML' and 'TeX' options not defined for 'Latex2HTML'";
833 :     }
834 :    
835 : gage 30 if ($displayMode eq "HTML_tth") {
836 : sam 2 return $options{HTML}
837 :     if defined( $options{HTML} );
838 :     die " ERROR in using MODES: 'HTML' option not defined for HTML_tth";
839 :    
840 :     }
841 :    
842 :     # trap undefined errors
843 : gage 27 die "ERROR in defining MODES: Can't find |$displayMode| among
844 :     available options:" . join(" ", keys(%options) )
845 :     . " file " . __FILE__ ." line " . __LINE__."\n\n";
846 : sam 2
847 :     }
848 :    
849 :    
850 :     # end display macros
851 :    
852 :    
853 :     =head2 Display constants
854 :    
855 :     @ALPHABET ALPHABET() capital letter alphabet -- ALPHABET[0] = 'A'
856 :     $PAR PAR() paragraph character (\par or <p>)
857 :     $BR BR() line break character
858 :     $LQ LQ() left double quote
859 :     $RQ RQ() right double quote
860 :     $BM BM() begin math
861 :     $EM EM() end math
862 :     $BDM BDM() begin display math
863 :     $EDM EDM() end display math
864 :     $LTS LTS() strictly less than
865 :     $GTS GTS() strictly greater than
866 :     $LTE LTE() less than or equal
867 :     $GTE GTE() greater than or equal
868 :     $BEGIN_ONE_COLUMN BEGIN_ONE_COLUMN() begin one-column mode
869 :     $END_ONE_COLUMN END_ONE_COLUMN() end one-column mode
870 :     $SOL SOLUTION_HEADING() solution headline
871 : apizer 37 $SOLUTION SOLUTION_HEADING() solution headline
872 : sam 2 $HINT HINT_HEADING() hint headline
873 :     $US US() underscore character
874 :     $SPACE SPACE() space character (tex and latex only)
875 :     $BBOLD BBOLD() begin bold typeface
876 :     $EBOLD EBOLD() end bold typeface
877 : apizer 208 $BITALIC BITALIC() begin italic typeface
878 :     $EITALIC EITALIC() end italic typeface
879 :     $BCENTER BCENTER() begin centered environment
880 :     $ECENTER ECENTER() end centered environment
881 : sam 2 $HR HR() horizontal rule
882 :     $LBRACE LBRACE() left brace
883 :     $LB LB () left brace
884 :     $RBRACE RBRACE() right brace
885 :     $RB RB () right brace
886 :     $DOLLAR DOLLAR() a dollar sign
887 :     $PERCENT PERCENT() a percent sign
888 :     $CARET CARET() a caret sign
889 :     $PI PI() the number pi
890 :     $E E() the number e
891 :    
892 :     =cut
893 :    
894 :    
895 :    
896 : gage 30
897 :    
898 : sam 2 # A utility variable. Notice that "B"=$ALPHABET[1] and
899 :     # "ABCD"=@ALPHABET[0..3].
900 :    
901 :     sub ALPHABET {
902 :     ('A'..'ZZ')[@_];
903 :     }
904 :    
905 :     ###############################################################
906 :     # Some constants which are different in tex and in HTML
907 :     # The order of arguments is TeX, Latex2HTML, HTML
908 :     sub PAR { MODES( TeX => '\\par ',Latex2HTML => '\\par ',HTML => '<P>' ); };
909 :     sub BR { MODES( TeX => '\\par\\noindent ',Latex2HTML => '\\par\\noindent ',HTML => '<BR>'); };
910 :     sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); };
911 :     sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); };
912 :     sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode
913 :     sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode
914 :     sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode
915 :     sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode
916 :     sub LTS { MODES(TeX => ' < ', Latex2HTML => ' \\lt ', HTML => '&lt;'); };
917 :     sub GTS {MODES(TeX => ' > ', Latex2HTML => ' \\gt ', HTML => '&gt;'); };
918 :     sub LTE { MODES(TeX => ' \\le ', Latex2HTML => ' \\le ', HTML => '&lt;=' ); };
919 :     sub GTE { MODES(TeX => ' \\ge ', Latex2HTML => ' \\ge ', HTML => '&gt;'); };
920 :     sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); };
921 :     sub END_ONE_COLUMN { MODES(TeX =>
922 :     " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n",
923 :     Latex2HTML => ' ', HTML => ' ');
924 :    
925 :     };
926 :     sub SOLUTION_HEADING { MODES( TeX => '\\par {\\bf Solution:}',
927 :     Latex2HTML => '\\par {\\bf Solution:}',
928 :     HTML => '<P><B>Solution:</B>');
929 :     };
930 :     sub HINT_HEADING { MODES( TeX => "\\par {\\bf Hint:}", Latex2HTML => "\\par {\\bf Hint:}", HTML => "<P><B>Hint:</B>"); };
931 :     sub US { MODES(TeX => '\\_', Latex2HTML => '\\_', HTML => '_');}; # underscore, e.g. file${US}name
932 :     sub SPACE { MODES(TeX => '\\ ', Latex2HTML => '\\ ', HTML => '&nbsp;');}; # force a space in latex, doesn't force extra space in html
933 :     sub BBOLD { MODES(TeX => '{\\bf ', Latex2HTML => '{\\bf ', HTML => '<B>'); };
934 :     sub EBOLD { MODES( TeX => '}', Latex2HTML => '}',HTML => '</B>'); };
935 : apizer 208 sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); };
936 :     sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); };
937 :     sub BCENTER { MODES(TeX => '\\begin{center} ', Latex2HTML => ' \\begin{rawhtml} <div align="center"> ', HTML => '<div align="center">'); };
938 :     sub ECENTER { MODES(TeX => '\\end{center} ', Latex2HTML => ' </div> \\end{rawhtml} ', HTML => '</div>'); };
939 : sam 2 sub HR { MODES(TeX => '\\par\\hrulefill\\par ', Latex2HTML => '\\begin{rawhtml} <HR> \\end{rawhtml}', HTML => '<HR>'); };
940 :     sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); };
941 :     sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); };
942 :     sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); };
943 :     sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); };
944 :     sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); };
945 :     sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); };
946 :     sub CARET { MODES( TeX => '\\^', Latex2HTML => '\\^', HTML => '^' ); };
947 :     sub PI {4*atan2(1,1);};
948 :     sub E {exp(1);};
949 :    
950 :     ###############################################################
951 :     ## Evaluation macros
952 :    
953 :    
954 :     =head2 TEXT macros
955 :    
956 :     Usage:
957 :     TEXT(@text);
958 :    
959 :     This is the simplest way to print text from a problem. The strings in the array C<@text> are concatenated
960 :     with spaces between them and printed out in the text of the problem. The text is not processed in any other way.
961 :     C<TEXT> is defined in PG.pl.
962 :    
963 :     Usage:
964 :     BEGIN_TEXT
965 :     text.....
966 :     END_TEXT
967 :    
968 :     This is the most common way to enter text into the problem. All of the text between BEGIN_TEXT and END_TEXT
969 :     is processed by the C<EV3> macro described below and then printed using the C<TEXT> command. The two key words
970 :     must appear on lines by themselves. The preprocessing that makes this construction work is done in F<PGtranslator.pm>.
971 :     See C<EV3> below for details on the processing.
972 :    
973 :    
974 :     =cut
975 :    
976 :     =head2 Evaluation macros
977 :    
978 :     =head3 EV3
979 :    
980 :     TEXT(EV3("This is a formulat \( \int_0^5 x^2 \, dx \) ");
981 :     TEXT(EV3(@text));
982 :    
983 :     TEXT(EV3(<<'END_TEXT'));
984 :     text stuff...
985 :     END_TEXT
986 :    
987 :    
988 :     The BEGIN_TEXT/END_TEXT construction is translated into the construction above by PGtranslator.pm. END_TEXT must appear
989 :     on a line by itself and be left justified. (The << construction is known as a "here document" in UNIX and in PERL.)
990 :    
991 :     The single quotes around END_TEXT mean that no automatic interpolation of variables takes place in the text.
992 :     Using EV3 with strings which have been evaluated by double quotes may lead to unexpected results.
993 :    
994 :    
995 :     The evaluation macro E3 first evaluates perl code inside the braces: C<\{ code \}>.
996 :     Any perl statment can be put inside the braces. The
997 :     result of the evaluation (i.e. the last statement evaluated) replaces the C<\{ code \}> construction.
998 :    
999 :     Next interpolation of all variables (e.g. C<$var or @array> ) is performed.
1000 :    
1001 :     Then mathematical formulas in TeX are evaluated within the
1002 :     C<\( tex math mode \)> and
1003 :     C<\[ tex display math mode \] >
1004 :     constructions, in that order:
1005 :    
1006 :     =head3 FEQ
1007 :    
1008 :     FEQ($string); # processes and outputs the string
1009 :    
1010 :    
1011 :     The mathematical formulas are run through the macro C<FEQ> (Format EQuations) which performs
1012 :     several substitutions (see below).
1013 :     In C<HTML_tth> mode the resulting code is processed by tth to obtain an HTML version
1014 :     of the formula. (In the future processing by WebEQ may be added here as another option.)
1015 :     The Latex2HTML mode does nothing
1016 :     at this stage; it creates the entire problem before running it through
1017 :     TeX and creating the GIF images of the equations.
1018 :    
1019 :     The resulting string is output (and usually fed into TEXT to be printed in the problem).
1020 :    
1021 :     Usage:
1022 :    
1023 :     $string2 = FEQ($string1);
1024 :    
1025 :     This is a filter which is used to format equations by C<EV2> and C<EV3>, but can also be used on its own. It is best
1026 :     understood with an example.
1027 :    
1028 :     $string1 = "${a}x^2 + ${b}x + {$c:%.1f}"; $a = 3;, $b = -2; $c = -7.345;
1029 :    
1030 :     when interpolated becomes:
1031 :    
1032 :     $string1 = '3x^2 + -2x + {-7.345:%0.1f}
1033 :    
1034 :     FEQ first changes the number of decimal places displayed, so that the last term becomes -7.3 Then it removes the
1035 :     extraneous plus and minus signs, so that the final result is what you want:
1036 :    
1037 :     $string2 = '3x^2 - 2x -7.3';
1038 :    
1039 :     (The %0.1f construction
1040 :     is the same formatting convention used by Perl and nearly identical to the one used by the C printf statement. Some common
1041 :     usage: %0.3f 3 decimal places, fixed notation; %0.3e 3 significant figures exponential notation; %0.3g uses either fixed
1042 :     or exponential notation depending on the size of the number.)
1043 :    
1044 :     Two additional legacy formatting constructions are also supported:
1045 :    
1046 :     C<?{$c:%0.3f} > will give a number with 3 decimal places and a negative
1047 :     sign if the number is negative, no sign if the number is positive.
1048 :    
1049 :     C<!{$c:%0.3f}> determines the sign and prints it
1050 :     whether the number is positive or negative.
1051 :    
1052 :     =head3 EV2
1053 :    
1054 :     TEXT(EV2(@text));
1055 :    
1056 :     TEXT(EV2(<<END_OF_TEXT));
1057 :     text stuff...
1058 :     END_OF_TEXT
1059 :    
1060 :     This is a precursor to EV3. In this case the constants are interpolated first, before the evaluation of the \{ ...code...\}
1061 :     construct. This can lead to unexpected results. For example C<\{ join(" ", @text) \}> with C<@text = ("Hello","World);> becomes,
1062 :     after interpolation, C<\{ join(" ",Hello World) \}> which then causes an error when evaluated because Hello is a bare word.
1063 :     C<EV2> can still be useful if you allow for this, and in particular it works on double quoted strings, which lead to
1064 :     unexpected results with C<EV3>. Using single quoted strings with C<EV2> may lead to unexpected results.
1065 :    
1066 :     The unexpected results have to do with the number of times backslashed constructions have to be escaped. It's quite messy. For
1067 :     more details get a good Perl book and then read the code. :-)
1068 :    
1069 :    
1070 :    
1071 :    
1072 :     =cut
1073 :    
1074 :    
1075 :     sub ev_substring {
1076 :     my $string = shift;
1077 :     my $start_delim = shift;
1078 :     my $end_delim = shift;
1079 :     my $actionRef = shift;
1080 :     my ($eval_out,$PG_eval_errors,$PG_full_error_report)=();
1081 :     my $out = "";
1082 :     while ($string) {
1083 :     if ($string =~ /\Q$start_delim\E/s) {
1084 :     #print "$start_delim $end_delim evaluating_substring=$string<BR>";
1085 :     $string =~ s/^(.*?)\Q$start_delim\E//s; # get string up to next \{ ---treats string as a single line, ignoring returns
1086 :     $out .= $1;
1087 :     #print "$start_delim $end_delim substring_out=$out<BR>";
1088 :     $string =~ s/^(.*?)\Q$end_delim\E//s; # get perl code up to \} ---treats string as a single line, ignoring returns
1089 :     #print "$start_delim $end_delim evaluate_string=$1<BR>";
1090 :     ($eval_out,$PG_eval_errors,$PG_full_error_report) = &$actionRef($1);
1091 :     $eval_out = "$start_delim $eval_out $end_delim" if $PG_full_error_report;
1092 :     $out = $out . $eval_out;
1093 :     #print "$start_delim $end_delim new substring_out=$out<BR><p><BR>";
1094 :     $out .="$main::PAR ERROR $0 in ev_substring, PGbasicmacros.pl:$main::PAR <PRE> $@ </PRE>$main::PAR" if $@;
1095 :     }
1096 :     else {
1097 :     $out .= $string; # flush the last part of the string
1098 :     last;
1099 :     }
1100 :    
1101 :     }
1102 :     $out;
1103 :     }
1104 :     sub safe_ev {
1105 :     my ($out,$PG_eval_errors,$PG_full_error_report) = &old_safe_ev; # process input by old_safe_ev first
1106 :     $out =~s/\\/\\\\/g; # protect any new backslashes introduced.
1107 :     ($out,$PG_eval_errors,$PG_full_error_report)
1108 :     }
1109 :    
1110 :     sub old_safe_ev {
1111 :     my $in = shift;
1112 :     my ($out,$PG_eval_errors,$PG_full_error_report) = PG_restricted_eval("$in;");
1113 :     # the addition of the ; seems to provide better error reporting
1114 :     if ($PG_eval_errors) {
1115 :     my @errorLines = split("\n",$PG_eval_errors);
1116 :     #$out = "<PRE>$main::PAR % ERROR in $0:old_safe_ev, PGbasicmacros.pl: $main::PAR % There is an error occuring inside evaluation brackets \\{ ...code... \\} $main::BR % somewhere in an EV2 or EV3 or BEGIN_TEXT block. $main::BR % Code evaluated:$main::BR $in $main::BR % $main::BR % $errorLines[0]\n % $errorLines[1]$main::BR % $main::BR % $main::BR </PRE> ";
1117 :     warn " ERROR in old_safe_ev, PGbasicmacros.pl: <PRE>
1118 :     ## There is an error occuring inside evaluation brackets \\{ ...code... \\}
1119 :     ## somewhere in an EV2 or EV3 or BEGIN_TEXT block.
1120 :     ## Code evaluated:
1121 :     ## $in
1122 :     ##" .join("\n ", @errorLines). "
1123 :     ##</PRE>$main::BR
1124 :     ";
1125 :     $out ="$main::PAR $main::BBOLD $in $main::EBOLD $main::PAR";
1126 :    
1127 :    
1128 :     }
1129 :    
1130 :     ($out,$PG_eval_errors,$PG_full_error_report);
1131 :     }
1132 :    
1133 :     sub FEQ { # Format EQuations
1134 :     my $in = shift;
1135 :     # formatting numbers -- the ?{} and !{} constructions
1136 :     $in =~s/\?\s*\{([.\-\$\w\d]+):?([%.\da-z]*)\}/${ \( &sspf($1,$2) )}/g;
1137 :     $in =~s/\!\s*\{([.\-\$\w\d]+):?([%.\da-z]*)\}/${ \( &spf($1,$2) )}/g;
1138 :    
1139 :     # more formatting numbers -- {number:format} constructions
1140 :     $in =~ s/\{(\s*[\+\-\d\.]+[eE]*[\+\-]*\d*):(\%\d*.\d*\w)}/${ \( &spf($1,$2) )}/g;
1141 :     $in =~ s/\+\s*\-/ - /g;
1142 :     $in =~ s/\-\s*\+/ - /g;
1143 :     $in =~ s/\+\s*\+/ + /g;
1144 :     $in =~ s/\-\s*\-/ + /g;
1145 :     $in;
1146 :     }
1147 :    
1148 :     sub math_ev3 {
1149 :     my $in = shift; #print "in=$in<BR>";
1150 :     my ($out,$PG_eval_errors,$PG_full_error_report);
1151 :     $in = FEQ($in);
1152 :     $in =~ s/%/\\%/g; # % causes trouble in TeX and HTML_tth it usually (always?) indicates an error, not comment
1153 : gage 30 return("$main::BM $in $main::EM") unless ($displayMode eq 'HTML_tth');
1154 : sam 2 $in = "\\(" . $in . "\\)";
1155 :     $out = tth($in);
1156 :     ($out,$PG_eval_errors,$PG_full_error_report);
1157 :    
1158 :     }
1159 :    
1160 :     sub display_math_ev3 {
1161 :     my $in = shift; #print "in=$in<BR>";
1162 :     my ($out,$PG_eval_errors,$PG_full_error_report);
1163 :     $in = FEQ($in);
1164 :     $in =~ s/%/\\%/g;
1165 : gage 30 return("$main::BDM $in $main::EDM") unless $displayMode eq 'HTML_tth' ;
1166 : sam 2 $in = "\\[" . $in . "\\]";
1167 :     $out =tth($in);
1168 :     ($out,$PG_eval_errors,$PG_full_error_report);
1169 :     }
1170 :    
1171 :     sub EV2 {
1172 :     my $string = join(" ",@_);
1173 :     # evaluate code inside of \{ \} (no nesting allowed)
1174 :     $string = ev_substring($string,"\\{","\\}",\&old_safe_ev);
1175 :     $string = ev_substring($string,"\\<","\\>",\&old_safe_ev);
1176 :     $string = ev_substring($string,"\\(","\\)",\&math_ev3);
1177 :     $string = ev_substring($string,"\\[","\\]",\&display_math_ev3);
1178 :     # macros for displaying math
1179 :     $string =~ s/\\\(/$main::BM/g;
1180 :     $string =~ s/\\\)/$main::EM/g;
1181 :     $string =~ s/\\\[/$main::BDM/g;
1182 :     $string =~ s/\\\]/$main::EDM/g;
1183 :     $string;
1184 :     }
1185 :    
1186 :     sub EV3{
1187 :     my $string = join(" ",@_);
1188 :     # evaluate code inside of \{ \} (no nesting allowed)
1189 :     $string = ev_substring($string,"\\\\{","\\\\}",\&safe_ev); # handles \{ \} in single quoted strings of PG files
1190 :     # interpolate variables
1191 :     my ($evaluated_string,$PG_eval_errors,$PG_full_errors) = PG_restricted_eval("<<END_OF_EVALUATION_STRING\n$string\nEND_OF_EVALUATION_STRING\n");
1192 :     if ($PG_eval_errors) {
1193 :     my @errorLines = split("\n",$PG_eval_errors);
1194 :     $string =~ s/</&lt;/g; $string =~ s/>/&gt;/g;
1195 :     $evaluated_string = "<PRE>$main::PAR % ERROR in $0:EV3, PGbasicmacros.pl: $main::PAR % There is an error occuring in the following code:$main::BR $string $main::BR % $main::BR % $errorLines[0]\n % $errorLines[1]$main::BR % $main::BR % $main::BR </PRE> ";
1196 :     $@="";
1197 :     }
1198 :     $string = $evaluated_string;
1199 :     $string = ev_substring($string,"\\(","\\)",\&math_ev3);
1200 :     $string = ev_substring($string,"\\[","\\]",\&display_math_ev3);
1201 :     $string;
1202 :     }
1203 :    
1204 :     =head2 Formatting macros
1205 :    
1206 :     beginproblem() # generates text listing number and the point value of
1207 :     # the problem. It will also print the file name containing
1208 :     # the problem for users listed in the PRINT_FILE_NAMES_FOR PG_environment
1209 :     # variable.
1210 :     OL(@array) # formats the array as an Ordered List ( <OL> </OL> ) enumerated by letters.
1211 :    
1212 :     htmlLink($url, $text)
1213 :     # Places a reference to the URL with the specified text in the problem.
1214 :     # A common usage is \{ htmlLink(alias('prob1_help.html') \}, 'for help')
1215 :     # where alias finds the full address of the prob1_help.html file in the same directory
1216 :     # as the problem file
1217 :     appletLink($url, $parameters)
1218 :     # For example
1219 : gage 5 # appletLink(q! archive="http: //webwork.math.rochester.edu/gage/xFunctions/xFunctions.zip"
1220 :     code="xFunctionsLauncher.class" width=100 height=14!,
1221 : sam 2 " parameter text goes here")
1222 :     # will link to xFunctions.
1223 :    
1224 :     low level:
1225 :    
1226 :     spf($number, $format) # prints the number with the given format
1227 :     sspf($number, $format) # prints the number with the given format, always including a sign.
1228 :     protect_underbar($string) # protects the underbar (class_name) in strings which may have to pass through TeX.
1229 :    
1230 :     =cut
1231 :    
1232 :     sub beginproblem {
1233 :     my $out = "";
1234 :     my $TeXFileName = protect_underbar($main::fileName);
1235 :     my $l2hFileName = protect_underbar($main::fileName);
1236 :     my %inlist;
1237 :     my $points ='pts';
1238 :     $points = 'pt' if $main::problemValue == 1;
1239 :     ## Prepare header for the problem
1240 :     grep($inlist{$_}++,@{ $envir{'PRINT_FILE_NAMES_FOR'} });
1241 :     if ( defined($inlist{$main::studentLogin}) and ($inlist{$main::studentLogin} > 0) ) {
1242 :     $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${main::probNum}.{\\footnotesize ($main::problemValue $points) $TeXFileName}}\\newline ",
1243 :     " \\begin{rawhtml} ($main::problemValue $points) <B>$l2hFileName</B><BR>\\end{rawhtml}",
1244 :     "($main::problemValue $points) <B>$main::fileName</B><BR>"
1245 :     );
1246 :     } else {
1247 :     $out = &M3("\n\n\\smallskip\\hrule\\smallskip\\par{\\bf ${main::probNum}.}($main::problemValue $points) ",
1248 :     "($main::problemValue $points) ",
1249 :     "($main::problemValue $points) "
1250 :     );
1251 :     }
1252 :     $out;
1253 :    
1254 :     }
1255 :    
1256 :     # kludge to clean up path names
1257 :     ## allow underscore character in set and section names and also allows line breaks at /
1258 :     sub protect_underbar {
1259 :     my $in = shift;
1260 : gage 30 if ($displayMode eq 'TeX') {
1261 : sam 2
1262 :     $in =~ s|_|\\\_|g;
1263 :     $in =~ s|/|\\\-/|g; # allows an optional hyphenation of the path (in tex)
1264 :     }
1265 :     $in;
1266 :     }
1267 :    
1268 :    
1269 :     # An example of a macro which prints out a list (with letters)
1270 :     sub OL {
1271 :     my(@array) = @_;
1272 :     my $i = 0;
1273 :     my $out= &M3(
1274 :     "\\begin{enumerate}\n",
1275 :     " \\begin{rawhtml} <OL TYPE=\"A\" VALUE=\"1\"> \\end{rawhtml} ",
1276 :     "<OL TYPE=\"A\" VALUE=\"1\">\n"
1277 :     ) ;
1278 :     my $elem;
1279 :     foreach $elem (@array) {
1280 :     $out .= &M3(
1281 :     "\\item[$main::ALPHABET[$i].] $elem\n",
1282 :     " \\begin{rawhtml} <LI> \\end{rawhtml} $elem ",
1283 :     "<LI> $elem\n"
1284 :     ) ;
1285 :     $i++;
1286 :     }
1287 :     $out .= &M3(
1288 :     "\\end{enumerate}\n",
1289 :     " \\begin{rawhtml} </OL>\n \\end{rawhtml} ",
1290 :     "</OL>\n"
1291 :     ) ;
1292 :     }
1293 :    
1294 :     sub htmlLink {
1295 :     my $url = shift;
1296 :     my $text = shift;
1297 :     my $options = shift;
1298 :     $options = "" unless defined($options);
1299 : gage 28 return "${main::BBOLD}[ broken link: $text ] ${main::EBOLD}" unless defined($url);
1300 : sam 2 M3( "{\\bf \\underline{$text} }",
1301 :     "\\begin{rawhtml} <A HREF=\"$url\" $options> $text </A>\\end{rawhtml}",
1302 :     "<A HREF=\"$url\" $options> $text </A>"
1303 :     );
1304 :     }
1305 :     sub appletLink {
1306 :     my $url = shift;
1307 :     my $options = shift;
1308 :     $options = "" unless defined($options);
1309 :     M3( "{\\bf \\underline{APPLET} }",
1310 :     "\\begin{rawhtml} <APPLET $url> $options </APPLET>\\end{rawhtml}",
1311 :     "<APPLET $url> $options </APPLET>"
1312 :     );
1313 :     }
1314 :     sub spf {
1315 :     my($number,$format) = @_; # attention, the order of format and number are reversed
1316 :     $format = "%4.3g" unless $format; # default value for format
1317 :     sprintf($format, $number);
1318 :     }
1319 :     sub sspf {
1320 :     my($number,$format) = @_; # attention, the order of format and number are reversed
1321 :     $format = "%4.3g" unless $format; # default value for format
1322 :     my $sign = $number>=0 ? " + " : " - ";
1323 :     $number = $number>=0 ? $number : -$number;
1324 :     $sign .sprintf($format, $number);
1325 :     }
1326 :    
1327 :     =head2 Sorting and other list macros
1328 :    
1329 :    
1330 :    
1331 :     Usage:
1332 :     lex_sort(@list); # outputs list in lexigraphic (alphabetical) order
1333 :     num_sort(@list); # outputs list in numerical order
1334 :     uniq( @list); # outputs a list with no duplicates. Order is unspecified.
1335 :    
1336 :     PGsort( \&sort_subroutine, @list);
1337 :     # &sort_subroutine defines order. It's output must be -1,0 or 1.
1338 :    
1339 :     =cut
1340 :    
1341 :     # uniq gives unique elements of a list:
1342 :     sub uniq {
1343 :     my (@in) =@_;
1344 :     my %temp = ();
1345 :     while (@in) {
1346 :     $temp{shift(@in)}++;
1347 :     }
1348 :     my @out = keys %temp; # sort is causing trouble with Safe.??
1349 :     @out;
1350 :     }
1351 :    
1352 :     sub lex_sort {
1353 : gage 30 PGsort sub {$_[0] cmp $_[1]}, @_;
1354 : sam 2 }
1355 :     sub num_sort {
1356 :     PGsort sub {$_[0] <=> $_[1]}, @_;
1357 :     }
1358 :    
1359 :    
1360 :     =head2 Macros for handling tables
1361 :    
1362 :     Usage:
1363 :     begintable( number_of_columns_in_table)
1364 :     row(@dataelements)
1365 :     endtable()
1366 :    
1367 :     Example of useage:
1368 :    
1369 :     BEGIN_TEXT
1370 :     This problem tests calculating new functions from old ones:$BR
1371 :     From the table below calculate the quantities asked for:$BR
1372 :     \{begintable(scalar(@firstrow)+1)\}
1373 :     \{row(" \(x\) ",@firstrow)\}
1374 :     \{row(" \(f(x)\) ", @secondrow)\}
1375 :     \{row(" \(g(x)\) ", @thirdrow)\}
1376 :     \{row(" \(f'(x)\) ", @fourthrow)\}
1377 :     \{row(" \(g'(x)\) ", @fifthrow)\}
1378 :     \{endtable()\}
1379 :    
1380 :     (The arrays contain numbers which are placed in the table.)
1381 :    
1382 :     END_TEXT
1383 :    
1384 :     =cut
1385 :    
1386 :     sub begintable {
1387 :     my ($number)=shift; #number of columns in table
1388 :     my %options = @_;
1389 :     warn "begintable(cols) requires a number indicating the number of columns" unless defined($number);
1390 :     my $out = "";
1391 : gage 30 if ($displayMode eq 'TeX') {
1392 : sam 2 $out .= "\n\\par\\smallskip\\begin{center}\\begin{tabular}{" . "|c" x $number . "|} \\hline\n";
1393 :     }
1394 : gage 30 elsif ($displayMode eq 'Latex2HTML') {
1395 : sam 2 $out .= "\n\\begin{rawhtml} <TABLE , BORDER=1>\n\\end{rawhtml}";
1396 :     }
1397 : gage 30 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth') {
1398 : sam 2 $out .= "<TABLE BORDER=1>\n"
1399 :     }
1400 :     else {
1401 : gage 30 $out = "Error: PGchoicemacros: begintable: Unknown displayMode: $displayMode.\n";
1402 : sam 2 }
1403 :     $out;
1404 :     }
1405 :    
1406 :     sub endtable {
1407 :     my $out = "";
1408 : gage 30 if ($displayMode eq 'TeX') {
1409 : sam 2 $out .= "\n\\end {tabular}\\end{center}\\par\\smallskip\n";
1410 :     }
1411 : gage 30 elsif ($displayMode eq 'Latex2HTML') {
1412 : sam 2 $out .= "\n\\begin{rawhtml} </TABLE >\n\\end{rawhtml}";
1413 :     }
1414 : gage 30 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth') {
1415 : sam 2 $out .= "</TABLE>\n";
1416 :     }
1417 :     else {
1418 : gage 30 $out = "Error: PGchoicemacros: endtable: Unknown displayMode: $displayMode.\n";
1419 : sam 2 }
1420 :     $out;
1421 :     }
1422 :    
1423 :    
1424 :     sub row {
1425 :     my @elements = @_;
1426 :     my $out = "";
1427 : gage 30 if ($displayMode eq 'TeX') {
1428 : sam 2 while (@elements) {
1429 :     $out .= shift(@elements) . " &";
1430 :     }
1431 :     chop($out); # remove last &
1432 :     $out .= "\\\\ \\hline \n";
1433 :     # carriage returns must be added manually for tex
1434 :     }
1435 : gage 30 elsif ($displayMode eq 'Latex2HTML') {
1436 : sam 2 $out .= "\n\\begin{rawhtml}\n<TR>\n\\end{rawhtml}\n";
1437 :     while (@elements) {
1438 :     $out .= " \n\\begin{rawhtml}\n<TD> \n\\end{rawhtml}\n" . shift(@elements) . " \n\\begin{rawhtml}\n</TD> \n\\end{rawhtml}\n";
1439 :     }
1440 :     $out .= " \n\\begin{rawhtml}\n</TR> \n\\end{rawhtml}\n";
1441 :     }
1442 :     elsif ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
1443 :     $out .= "<TR>\n";
1444 :     while (@elements) {
1445 :     $out .= "<TD>" . shift(@elements) . "</TD>";
1446 :     }
1447 :     $out .= "\n</TR>\n";
1448 :     }
1449 :     else {
1450 :     $out = "Error: PGchoicemacros: row: Unknown displayMode: $main::displayMode.\n";
1451 :     }
1452 :     $out;
1453 :     }
1454 :    
1455 :     =head2 Macros for displaying static images
1456 :    
1457 :     Usage:
1458 :     $string = image($image, width => 100, height => 100, tex_size => 800)
1459 :     $string = image([$image1, $image2], width => 100, height => 100, tex_size => 800)
1460 :     $string = caption($string);
1461 :     $string = imageRow([$image1, $image2 ], [$caption1, $caption2]);
1462 :     # produces a complete table with rows of pictures.
1463 :    
1464 :    
1465 :     =cut
1466 :    
1467 :     # More advanced macros
1468 :     sub image {
1469 :     my $image_ref = shift;
1470 :     my @opt = @_;
1471 :     unless (scalar(@opt) % 2 == 0 ) {
1472 :     warn "ERROR in image macro. A list of macros must be inclosed in square brackets.";
1473 :     }
1474 :     my %in_options = @opt;
1475 :     my %known_options = ( width => 100,
1476 :     height => 100,
1477 :     tex_size => 800
1478 :     );
1479 :     # # handle options
1480 :     my %out_options = %known_options;
1481 :     foreach my $opt_name (keys %in_options) {
1482 :     if ( exists( $known_options{$opt_name} ) ) {
1483 :     $out_options{$opt_name} = $in_options{$opt_name} if exists( $in_options{$opt_name} ) ;
1484 :     } else {
1485 :     die "Option $opt_name not defined for image. " .
1486 :     "Default options are:<BR> ", display_options2(%known_options);
1487 :    
1488 :     }
1489 :     }
1490 :     my $width = $out_options{width};
1491 :     my $height = $out_options{height};
1492 :     my $tex_size = $out_options{tex_size};
1493 :     my $width_ratio = $tex_size*(.001);
1494 :     my @image_list = ();
1495 :    
1496 :     if (ref($image_ref) =~ /ARRAY/ ) {
1497 :     @image_list = @{$image_ref};
1498 :     } else {
1499 :     push(@image_list,$image_ref);
1500 :     }
1501 :     my @output_list = ();
1502 :     while(@image_list) {
1503 :    
1504 :     my $imageURL = alias(shift @image_list);
1505 :     my $out="";
1506 :    
1507 :    
1508 :     if ($main::displayMode eq 'TeX') {
1509 :     $out = qq!\\includegraphics[width=$width_ratio\\linewidth]{$imageURL}\n !
1510 :     }
1511 :     elsif ($main::displayMode eq 'Latex2HTML') {
1512 :     $out = qq!\\begin{rawhtml}\n<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A>\n
1513 :     \\end{rawhtml}\n !
1514 :     }
1515 :     elsif ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth') {
1516 :     $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A>
1517 :     !
1518 :     }
1519 :     else {
1520 :     $out = "Error: PGchoicemacros: image: Unknown displayMode: $main::displayMode.\n";
1521 :     }
1522 :     push(@output_list, $out);
1523 :     }
1524 :     wantarray ? @output_list : $output_list[0] ;
1525 :     }
1526 :    
1527 :     # This is legacy code.
1528 :     sub images {
1529 :     my @in = @_;
1530 :     my @outlist = ();
1531 :     while (@in) {
1532 :     push(@outlist,&image( shift(@in) ) );
1533 :     }
1534 :     @outlist;
1535 :     }
1536 :    
1537 :    
1538 :     sub caption {
1539 :     my ($out) = @_;
1540 :     $out = " $out \n" if $main::displayMode eq 'TeX';
1541 :     $out = " $out " if $main::displayMode eq 'HTML';
1542 :     $out = " $out " if $main::displayMode eq 'HTML_tth';
1543 :     $out = " $out " if $main::displayMode eq 'Latex2HTML';
1544 :     $out;
1545 :     }
1546 :    
1547 :     sub captions {
1548 :     my @in = @_;
1549 :     my @outlist = ();
1550 :     while (@in) {
1551 :     push(@outlist,&caption( shift(@in) ) );
1552 :     }
1553 :     @outlist;
1554 :     }
1555 :    
1556 :     sub imageRow {
1557 :    
1558 :     my $pImages = shift;
1559 :     my $pCaptions=shift;
1560 :     my $out = "";
1561 :     my @images = @$pImages;
1562 :     my @captions = @$pCaptions;
1563 :     my $number = @images;
1564 :     # standard options
1565 :     my %options = ( 'tex_size' => 200, # width for fitting 4 across
1566 :     'height' => 100,
1567 :     'width' => 100,
1568 :     @_ # overwrite any default options
1569 :     );
1570 :    
1571 :     if ($main::displayMode eq 'TeX') {
1572 :     $out .= "\n\\par\\smallskip\\begin{center}\\begin{tabular}{" . "|c" x $number . "|} \\hline\n";
1573 :     while (@images) {
1574 :     $out .= &image( shift(@images),%options ) . '&';
1575 :     }
1576 :     chop($out);
1577 :     $out .= "\\\\ \\hline \n";
1578 :     while (@captions) {
1579 :     $out .= &caption( shift(@captions) ) . '&';
1580 :     }
1581 :     chop($out);
1582 :     $out .= "\\\\ \\hline \n\\end {tabular}\\end{center}\\par\\smallskip\n";
1583 :     } elsif ($main::displayMode eq 'Latex2HTML'){
1584 :    
1585 :     $out .= "\n\\begin{rawhtml} <TABLE BORDER=1><TR>\n\\end{rawhtml}\n";
1586 :     while (@images) {
1587 :     $out .= "\n\\begin{rawhtml} <TD>\n\\end{rawhtml}\n" . &image( shift(@images),%options )
1588 :     . "\n\\begin{rawhtml} </TD>\n\\end{rawhtml}\n" ;
1589 :     }
1590 :    
1591 :     $out .= "\n\\begin{rawhtml}</TR><TR>\\end{rawhtml}\n";
1592 :     while (@captions) {
1593 :     $out .= "\n\\begin{rawhtml} <TH>\n\\end{rawhtml}\n".&caption( shift(@captions) )
1594 :     . "\n\\begin{rawhtml} </TH>\n\\end{rawhtml}\n" ;
1595 :     }
1596 :    
1597 :     $out .= "\n\\begin{rawhtml} </TR> </TABLE >\n\\end{rawhtml}";
1598 :     } elsif ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth'){
1599 :     $out .= "<P>\n <TABLE BORDER=2 CELLPADDING=3 CELLSPACING=2 ><TR ALIGN=CENTER VALIGN=MIDDLE>\n";
1600 :     while (@images) {
1601 :     $out .= " \n<TD>". &image( shift(@images),%options ) ."</TD>";
1602 :     }
1603 :     $out .= "</TR>\n<TR>";
1604 :     while (@captions) {
1605 :     $out .= " <TH>". &caption( shift(@captions) ) ."</TH>";
1606 :     }
1607 :     $out .= "\n</TR></TABLE></P>\n"
1608 :     }
1609 :     else {
1610 :     $out = "Error: PGchoicemacros: imageRow: Unknown languageMode: $main::displayMode.\n";
1611 :     warn $out;
1612 :     }
1613 :     $out;
1614 :     }
1615 :    
1616 :    
1617 :     ###########
1618 :     # Auxiliary macros
1619 :    
1620 :     sub display_options2{
1621 :     my %options = @_;
1622 :     my $out_string = "";
1623 :     foreach my $key (keys %options) {
1624 :     $out_string .= " $key => $options{$key},<BR>";
1625 :     }
1626 :     $out_string;
1627 :     }
1628 :    
1629 :    
1630 :     1;

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9