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

Diff of /trunk/pg/macros/PGbasicmacros.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1298 Revision 1462
64 $E, 64 $E,
65 @ALPHABET, 65 @ALPHABET,
66 $envir, 66 $envir,
67 $PG_random_generator, 67 $PG_random_generator,
68 $inputs_ref, 68 $inputs_ref,
69 $rh_sticky_answers,
70 $r_ans_rule_count,
69 ); 71 );
70 72
71sub _PGbasicmacros_init { 73sub _PGbasicmacros_init {
72 74
73 # The big problem is that at compile time in the cached Safe compartment 75 # The big problem is that at compile time in the cached Safe compartment
74 # main:: has one definition, probably Safe::Root1:: 76 # main:: has one definition, probably Safe::Root1::
75 # At runtime main has another definition Safe::Rootx:: where x is > 1 77 # At runtime main has another definition Safe::Rootx:: where x is > 1
76 78
77 # It is important to 79 # It is important to
78 # initialize the my variable version of $displayMode from the "runtime" version 80 # initialize the my variable version of $displayMode from the "runtime" version
79 # of main::displayMode 81 # of main::displayMode
80 82
81 $displayMode = main::PG_restricted_eval(q!$main::displayMode!); 83 $displayMode = main::PG_restricted_eval(q!$main::displayMode!);
82 84
83# This is initializes the remaining variables in the runtime main:: compartment. 85# This is initializes the remaining variables in the runtime main:: compartment.
84 86
85main::PG_restricted_eval( <<'EndOfFile'); 87main::PG_restricted_eval( <<'EndOfFile');
86 $displayMode = $displayMode; 88 $displayMode = $displayMode;
87 89
88 $main::PAR = PAR(); 90 $main::PAR = PAR();
89 $main::BR = BR(); 91 $main::BR = BR();
119 $main::PERCENT = PERCENT(); 121 $main::PERCENT = PERCENT();
120 $main::CARET = CARET(); 122 $main::CARET = CARET();
121 $main::PI = PI(); 123 $main::PI = PI();
122 $main::E = E(); 124 $main::E = E();
123 @main::ALPHABET = ('A'..'ZZ'); 125 @main::ALPHABET = ('A'..'ZZ');
126 %main::STICKY_ANSWERS = ();
124 127
125 128
126
127EndOfFile 129EndOfFile
128 130
129# Next we transfer the correct definitions in the main:: compartment to the local my variables 131# Next we transfer the correct definitions in the main:: compartment to the local my variables
130# This can't be done inside the eval above because my variables seem to be invisible inside the eval 132# This can't be done inside the eval above because my variables seem to be invisible inside the eval
131 133
168 @ALPHABET = ('A'..'ZZ'); 170 @ALPHABET = ('A'..'ZZ');
169 171
170 $envir = PG_restricted_eval(q!\%main::envir!); 172 $envir = PG_restricted_eval(q!\%main::envir!);
171 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!); 173 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!);
172 $inputs_ref = $envir{inputs_ref}; 174 $inputs_ref = $envir{inputs_ref};
173 175 $rh_sticky_answers = PG_restricted_eval(q!\%main::STICKY_ANSWERS!);
176 $r_ans_rule_count = PG_restricted_eval(q!\$ans_rule_count!);
174} 177}
175 178
176=head2 Answer blank macros: 179=head2 Answer blank macros:
177 180
178These produce answer blanks of various sizes or pop up lists or radio answer buttons. 181These produce answer blanks of various sizes or pop up lists or radio answer buttons.
268 my $answer_value = ''; 271 my $answer_value = '';
269 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 272 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
270 if ($answer_value =~ /\0/ ) { 273 if ($answer_value =~ /\0/ ) {
271 my @answers = split("\0", $answer_value); 274 my @answers = split("\0", $answer_value);
272 $answer_value = shift(@answers); # use up the first answer 275 $answer_value = shift(@answers); # use up the first answer
273 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 276 $rh_sticky_answers->{$name}=\@answers;
274 # store the rest -- beacuse this stores to a main:; variable 277 # store the rest -- beacuse this stores to a main:; variable
275 # it must be evaluated at run time 278 # it must be evaluated at run time
276 $answer_value= '' unless defined($answer_value); 279 $answer_value= '' unless defined($answer_value);
277 } elsif (ref($answer_value) eq 'ARRAY') { 280 } elsif (ref($answer_value) eq 'ARRAY') {
278 my @answers = @{ $answer_value}; 281 my @answers = @{ $answer_value};
279 $answer_value = shift(@answers); # use up the first answer 282 $answer_value = shift(@answers); # use up the first answer
280 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 283 $rh_sticky_answers->{$name}=\@answers;
281 # store the rest -- beacuse this stores to a main:; variable 284 # store the rest -- beacuse this stores to a main:; variable
282 # it must be evaluated at run time 285 # it must be evaluated at run time
283 $answer_value= '' unless defined($answer_value); 286 $answer_value= '' unless defined($answer_value);
284 } 287 }
285 288
286 $answer_value =~ tr/$@`//d; ## make sure student answers can not be interpolated by e.g. EV3 289 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
287 $name = RECORD_ANS_NAME($name); 290 $name = RECORD_ANS_NAME($name);
291
292 # incorporated Davide Cervone's changes
293 # removed newlines from around <INPUT> tags
294 # made TeX rule be based on specified width rather than varying size.
295 my $tcol = $col/2 > 3 ? $col/2 : 3; ## get max
296 $tcol = $tcol < 40 ? $tcol : 40; ## get min
297
288 MODES( 298 MODES(
289 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 299 TeX => "\\mbox{\\parbox[t]{${tcol}ex}{\\hrulefill}}",
290 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 300 Latex2HTML => qq!\\begin{rawhtml}<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\\end{rawhtml}!,
291 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n" 301 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">"
292 ); 302 );
293} 303}
294 304
295sub NAMED_ANS_RULE_OPTION { # deprecated 305sub NAMED_ANS_RULE_OPTION { # deprecated
296 &NAMED_ANS_RULE_EXTENSION; 306 &NAMED_ANS_RULE_EXTENSION;
299sub NAMED_ANS_RULE_EXTENSION { 309sub NAMED_ANS_RULE_EXTENSION {
300 my($name,$col) = @_; 310 my($name,$col) = @_;
301 my $len = 0.07*$col; 311 my $len = 0.07*$col;
302 my $answer_value = ''; 312 my $answer_value = '';
303 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 313 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
304 if ( defined(PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)) ) { 314 if ( defined( $rh_sticky_answers->{$name} ) ) {
305 $answer_value = shift( @{PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)}); 315 $answer_value = shift( @{ $rh_sticky_answers->{$name} });
306 $answer_value = '' unless defined($answer_value); 316 $answer_value = '' unless defined($answer_value);
307 } 317 }
308 $answer_value =~ tr/$@//d; ## make sure student answers can not be interpolated by e.g. EV3 318 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
309 MODES( 319 MODES(
310 TeX => '\\hrulefill\\quad ', 320 TeX => '\\hrulefill\\quad ',
311 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 321 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
312 HTML => qq!<INPUT TYPE=TEXT SIZE=$col NAME = "$name" VALUE = "$answer_value">\n! 322 HTML => qq!<INPUT TYPE=TEXT SIZE=$col NAME = "$name" VALUE = "$answer_value">\n!
313 ); 323 );
327 $name = RECORD_ANS_NAME($name); 337 $name = RECORD_ANS_NAME($name);
328 my $len = 0.07*$col; 338 my $len = 0.07*$col;
329 my $height = .07*$row; 339 my $height = .07*$row;
330 my $answer_value = ''; 340 my $answer_value = '';
331 $answer_value = $inputs_ref->{$name} if defined( $inputs_ref->{$name} ); 341 $answer_value = $inputs_ref->{$name} if defined( $inputs_ref->{$name} );
332 $answer_value =~ tr/$@//d; ## make sure student answers can not be interpolated by e.g. EV3 342 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
333 my $out = M3( 343 my $out = M3(
334 qq!\\vskip $height in \\hrulefill\\quad !, 344 qq!\\vskip $height in \\hrulefill\\quad !,
335 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 345 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
336 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!, 346 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!,
337 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 347 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
571 NAMED_ANS_RULE($name ,$len); 581 NAMED_ANS_RULE($name ,$len);
572} 582}
573sub ans_rule_extension { 583sub ans_rule_extension {
574 my $len = shift; 584 my $len = shift;
575 $len = 20 unless $len ; 585 $len = 20 unless $len ;
576 my $name = NEW_ANS_NAME(PG_restricted_eval(q!$main::ans_rule_count!)); # don't update the answer name 586 my $name = NEW_ANS_NAME($$r_ans_rule_count); # don't update the answer name
577 NAMED_ANS_RULE($name ,$len); 587 NAMED_ANS_RULE($name ,$len);
578} 588}
579sub ans_radio_buttons { 589sub ans_radio_buttons {
580 my $name = NEW_ANS_NAME(inc_ans_rule_count()); 590 my $name = NEW_ANS_NAME(inc_ans_rule_count());
581 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_); 591 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_);
622 $out; 632 $out;
623} 633}
624sub tex_ans_rule_extension { 634sub tex_ans_rule_extension {
625 my $len = shift; 635 my $len = shift;
626 $len = 20 unless $len ; 636 $len = 20 unless $len ;
627 my $name = NEW_ANS_NAME(PG_restricted_eval(q!$main::ans_rule_count!)); 637 my $name = NEW_ANS_NAME($$r_ans_rule_count);
628 my $answer_rule = NAMED_ANS_RULE($name ,$len); # we don't want to create three answer rules in different modes. 638 my $answer_rule = NAMED_ANS_RULE($name ,$len); # we don't want to create three answer rules in different modes.
629 my $out = MODES( 639 my $out = MODES(
630 'TeX' => $answer_rule, 640 'TeX' => $answer_rule,
631 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}', 641 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}',
632 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}', 642 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
722 732
723 733
724=head5 answer_matrix 734=head5 answer_matrix
725 735
726 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \] 736 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \]
727 737
728 Creates an array of answer blanks and passes it to display_matrix which returns 738 Creates an array of answer blanks and passes it to display_matrix which returns
729 text which represents the matrix in TeX format used in math display mode. Answers 739 text which represents the matrix in TeX format used in math display mode. Answers
730 are then passed back to whatever answer evaluators you write at the end of the problem. 740 are then passed back to whatever answer evaluators you write at the end of the problem.
731 (note, if you have an m x n matrix, you will need mn answer evaluators, and they will be 741 (note, if you have an m x n matrix, you will need mn answer evaluators, and they will be
732 returned to the evaluaters starting in the top left hand corner and proceed to the left 742 returned to the evaluaters starting in the top left hand corner and proceed to the left
733 and then at the end moving down one row, just as you would read them.) 743 and then at the end moving down one row, just as you would read them.)
734 744
735 The options are passed on to display_matrix. 745 The options are passed on to display_matrix.
736 746
737 747
738=cut 748=cut
739 749
745 my @options = @_; 755 my @options = @_;
746 my @array=(); 756 my @array=();
747 for( my $i = 0; $i < $m; $i+=1) 757 for( my $i = 0; $i < $m; $i+=1)
748 { 758 {
749 my @row_array = (); 759 my @row_array = ();
750 760
751 for( my $i = 0; $i < $n; $i+=1) 761 for( my $i = 0; $i < $n; $i+=1)
752 { 762 {
753 push @row_array, ans_rule($width); 763 push @row_array, ans_rule($width);
754 } 764 }
755 my $r_row_array = \@row_array; 765 my $r_row_array = \@row_array;
756 push @array, $r_row_array; 766 push @array, $r_row_array;
757 } 767 }
758 # display_matrix hasn't been loaded into the cache safe compartment 768 # display_matrix hasn't been loaded into the cache safe compartment
759 # so we need to refer to the subroutine in this way to make 769 # so we need to refer to the subroutine in this way to make
760 # sure that main is defined correctly. 770 # sure that main is defined correctly.
761 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 771 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
762 &$ra_local_display_matrix( \@array, @options ); 772 &$ra_local_display_matrix( \@array, @options );
763 773
764} 774}
765 775
766sub NAMED_ANS_ARRAY_EXTENSION{ 776sub NAMED_ANS_ARRAY_EXTENSION{
767 777
768 my $name = shift; 778 my $name = shift;
769 my $col = shift; 779 my $col = shift;
770 $col = 20 unless $col; 780 $col = 20 unless $col;
771 my $answer_value = ''; 781 my $answer_value = '';
772 782
773 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 783 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
774 if ($answer_value =~ /\0/ ) { 784 if ($answer_value =~ /\0/ ) {
775 my @answers = split("\0", $answer_value); 785 my @answers = split("\0", $answer_value);
776 $answer_value = shift(@answers); 786 $answer_value = shift(@answers);
777 $answer_value= '' unless defined($answer_value); 787 $answer_value= '' unless defined($answer_value);
778 } elsif (ref($answer_value) eq 'ARRAY') { 788 } elsif (ref($answer_value) eq 'ARRAY') {
779 my @answers = @{ $answer_value}; 789 my @answers = @{ $answer_value};
780 $answer_value = shift(@answers); 790 $answer_value = shift(@answers);
781 $answer_value= '' unless defined($answer_value); 791 $answer_value= '' unless defined($answer_value);
782 } 792 }
783 793
784 $answer_value =~ tr/$@`//d; ## make sure student answers can not be interpolated by e.g. EV3 794 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
785 MODES( 795 MODES(
786 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 796 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ",
787 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 797 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
788 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n" 798 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n"
789 ); 799 );
798 my $name = NEW_ANS_ARRAY_NAME($num,0,0); 808 my $name = NEW_ANS_ARRAY_NAME($num,0,0);
799 my @options = @_; 809 my @options = @_;
800 my @array=(); 810 my @array=();
801 my $string; 811 my $string;
802 my $answer_value = ""; 812 my $answer_value = "";
803 813
804 $array[0][0] = NAMED_ANS_RULE($name,$col); 814 $array[0][0] = NAMED_ANS_RULE($name,$col);
805 815
806 for( my $i = 1; $i < $n; $i+=1) 816 for( my $i = 1; $i < $n; $i+=1)
807 { 817 {
808 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i); 818 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i);
809 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 819 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
810 820
811 } 821 }
812 822
813 for( my $j = 1; $j < $m; $j+=1 ){ 823 for( my $j = 1; $j < $m; $j+=1 ){
814 824
815 for( my $i = 0; $i < $n; $i+=1) 825 for( my $i = 0; $i < $n; $i+=1)
816 { 826 {
817 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 827 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
818 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 828 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
819 829
820 } 830 }
821 831
822 } 832 }
823 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 833 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
824 &$ra_local_display_matrix( \@array, @options ); 834 &$ra_local_display_matrix( \@array, @options );
825 835
826} 836}
827 837
828sub ans_array_extension{ 838sub ans_array_extension{
829 my $m = shift; 839 my $m = shift;
830 my $n = shift; 840 my $n = shift;
834 my @options = @_; 844 my @options = @_;
835 my $name; 845 my $name;
836 my @array=(); 846 my @array=();
837 my $string; 847 my $string;
838 my $answer_value = ""; 848 my $answer_value = "";
839 849
840 for( my $j = 0; $j < $m; $j+=1 ){ 850 for( my $j = 0; $j < $m; $j+=1 ){
841 851
842 for( my $i = 0; $i < $n; $i+=1) 852 for( my $i = 0; $i < $n; $i+=1)
843 { 853 {
844 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 854 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
845 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 855 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
846 856
847 } 857 }
848 858
849 } 859 }
850 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 860 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
851 &$ra_local_display_matrix( \@array, @options ); 861 &$ra_local_display_matrix( \@array, @options );
852 862
853} 863}
854 864
855 865
856# end answer blank macros 866# end answer blank macros
857 867
910 $main::numOfAttempts = 0 unless defined($main::numOfAttempts); 920 $main::numOfAttempts = 0 unless defined($main::numOfAttempts);
911 !); 921 !);
912 922
913 if ($displayMode eq 'TeX') { 923 if ($displayMode eq 'TeX') {
914 $out = ''; # do nothing since hints are not available for download 924 $out = ''; # do nothing since hints are not available for download
915 } elsif (($envir->{'displayHintsQ'}) and 925 } elsif (($envir->{'displayHintsQ'}) and
916 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!)) 926 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!))
917 927
918 ## the second test above prevents a hint being shown if a doctored form is submitted 928 ## the second test above prevents a hint being shown if a doctored form is submitted
919 929
920 {$out = join(' ',@in);} # show hint 930 {$out = join(' ',@in);} # show hint
977 return $li[random(1,scalar(@li))-1]; 987 return $li[random(1,scalar(@li))-1];
978} 988}
979 989
980sub SRAND { # resets the main random generator -- use cautiously 990sub SRAND { # resets the main random generator -- use cautiously
981 my $seed = shift; 991 my $seed = shift;
982 PG_random_generator -> srand($seed); 992 $PG_random_generator -> srand($seed);
983} 993}
984 994
985# display macros 995# display macros
986 996
987=head2 Display Macros 997=head2 Display Macros
1120} 1130}
1121 1131
1122############################################################### 1132###############################################################
1123# Some constants which are different in tex and in HTML 1133# Some constants which are different in tex and in HTML
1124# The order of arguments is TeX, Latex2HTML, HTML 1134# The order of arguments is TeX, Latex2HTML, HTML
1135# Adopted Davide Cervone's improvements to PAR, LTS, GTS, LTE, GTE, LBRACE, RBRACE, LB, RB. 7-14-03 AKP
1125sub PAR { MODES( TeX => '\\par ',Latex2HTML => '\\par ',HTML => '<P>' ); }; 1136sub PAR { MODES( TeX => '\\par ', Latex2HTML => '\\begin{rawhtml}<P>\\end{rawhtml}', HTML => '<P>'); };
1126sub BR { MODES( TeX => '\\par\\noindent ',Latex2HTML => '\\par\\noindent ',HTML => '<BR>'); }; 1137sub BR { MODES( TeX => '\\par\\noindent ', Latex2HTML => '\\begin{rawhtml}<BR>\\end{rawhtml}', HTML => '<BR>'); };
1138# Alternate definition of BR which is slightly more flexible and gives more white space in printed output
1139# which looks better but kills more trees.
1140#sub BR { MODES( TeX => '\\\\', Latex2HTML => '\\begin{rawhtml}<BR>\\end{rawhtml}', HTML => '<BR>'); };
1127sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); }; 1141sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); };
1128sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); }; 1142sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); };
1129sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode 1143sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode
1130sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode 1144sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode
1131sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode 1145sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode
1132sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode 1146sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode
1133sub LTS { MODES(TeX => ' < ', Latex2HTML => ' \\lt ', HTML => '&lt;'); }; 1147sub LTS { MODES(TeX => '<', Latex2HTML => '\\lt ', HTML => '&lt;', HTML_tth => '<' ); };
1134sub GTS {MODES(TeX => ' > ', Latex2HTML => ' \\gt ', HTML => '&gt;'); }; 1148sub GTS { MODES(TeX => '>', Latex2HTML => '\\gt ', HTML => '&gt;', HTML_tth => '>' ); };
1135sub LTE { MODES(TeX => ' \\le ', Latex2HTML => ' \\le ', HTML => '&lt;=' ); }; 1149sub LTE { MODES(TeX => '\\le ', Latex2HTML => '\\le ', HTML => '<U>&lt;</U>', HTML_tth => '\\le ' ); };
1136sub GTE { MODES(TeX => ' \\ge ', Latex2HTML => ' \\ge ', HTML => '&gt;'); }; 1150sub GTE { MODES(TeX => '\\ge ', Latex2HTML => '\\ge ', HTML => '<U>&gt;</U>', HTML_tth => '\\ge ' ); };
1137sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); }; 1151sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); };
1138sub END_ONE_COLUMN { MODES(TeX => 1152sub END_ONE_COLUMN { MODES(TeX =>
1139 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n", 1153 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n",
1140 Latex2HTML => ' ', HTML => ' '); 1154 Latex2HTML => ' ', HTML => ' ');
1141 1155
1152sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); }; 1166sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); };
1153sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); }; 1167sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); };
1154sub BCENTER { MODES(TeX => '\\begin{center} ', Latex2HTML => ' \\begin{rawhtml} <div align="center"> \\end{rawhtml} ', HTML => '<div align="center">'); }; 1168sub BCENTER { MODES(TeX => '\\begin{center} ', Latex2HTML => ' \\begin{rawhtml} <div align="center"> \\end{rawhtml} ', HTML => '<div align="center">'); };
1155sub ECENTER { MODES(TeX => '\\end{center} ', Latex2HTML => ' \\begin{rawhtml} </div> \\end{rawhtml} ', HTML => '</div>'); }; 1169sub ECENTER { MODES(TeX => '\\end{center} ', Latex2HTML => ' \\begin{rawhtml} </div> \\end{rawhtml} ', HTML => '</div>'); };
1156sub HR { MODES(TeX => '\\par\\hrulefill\\par ', Latex2HTML => '\\begin{rawhtml} <HR> \\end{rawhtml}', HTML => '<HR>'); }; 1170sub HR { MODES(TeX => '\\par\\hrulefill\\par ', Latex2HTML => '\\begin{rawhtml} <HR> \\end{rawhtml}', HTML => '<HR>'); };
1157sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1171sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1158sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1172sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1159sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1173sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1160sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1174sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1161sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); }; 1175sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); };
1162sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); }; 1176sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); };
1163sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); }; 1177sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); };
1164sub PI {4*atan2(1,1);}; 1178sub PI {4*atan2(1,1);};
1165sub E {exp(1);}; 1179sub E {exp(1);};
1294 my $start_delim = shift; 1308 my $start_delim = shift;
1295 my $end_delim = shift; 1309 my $end_delim = shift;
1296 my $actionRef = shift; 1310 my $actionRef = shift;
1297 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=(); 1311 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=();
1298 my $out = ""; 1312 my $out = "";
1313 #
1314 # DPVC -- 2001/12/07
1315 # original "while ($string)" fails to process the string "0" correctly
1316 #
1299 while ($string) { 1317 while ($string ne "") {
1318 #
1319 # end DPVC
1320 #
1300 if ($string =~ /\Q$start_delim\E/s) { 1321 if ($string =~ /\Q$start_delim\E/s) {
1301 #print "$start_delim $end_delim evaluating_substring=$string<BR>"; 1322 #print "$start_delim $end_delim evaluating_substring=$string<BR>";
1302 $string =~ s/^(.*?)\Q$start_delim\E//s; # get string up to next \{ ---treats string as a single line, ignoring returns 1323 $string =~ s/^(.*?)\Q$start_delim\E//s; # get string up to next \{ ---treats string as a single line, ignoring returns
1303 $out .= $1; 1324 $out .= $1;
1304 #print "$start_delim $end_delim substring_out=$out<BR>"; 1325 #print "$start_delim $end_delim substring_out=$out<BR>";
1399 my $in = shift; 1420 my $in = shift;
1400 my $mode = shift || "inline"; 1421 my $mode = shift || "inline";
1401 1422
1402 $in = FEQ($in); # Format EQuations 1423 $in = FEQ($in); # Format EQuations
1403 $in =~ s/%/\\%/g; # avoid % becoming TeX comments 1424 $in =~ s/%/\\%/g; # avoid % becoming TeX comments
1404 1425
1426 ## remove leading and trailing spaces so that HTML mode will
1427 ## not include unwanted spaces as per Davide Cervone.
1428 $in =~ s/^\s+//;
1429 $in =~ s/\s+$//;
1430
1405 # some modes want the delimiters, some don't 1431 # some modes want the delimiters, some don't
1406 my $in_delim = $mode eq "inline" 1432 my $in_delim = $mode eq "inline"
1407 ? "\\($in\\)" 1433 ? "\\($in\\)"
1408 : "\\[$in\\]"; 1434 : "\\[$in\\]";
1409 1435
1410 my $out; 1436 my $out;
1411 if($displayMode eq "HTML_tth") { 1437 if($displayMode eq "HTML_tth") {
1412 $out = tth($in_delim); 1438 $out = tth($in_delim);
1439 ## remove leading and trailing spaces as per Davide Cervone.
1440 $in =~ s/^\s+//;
1441 $in =~ s/\s+$//;
1413 } elsif ($displayMode eq "HTML_dpng") { 1442 } elsif ($displayMode eq "HTML_dpng") {
1414 # for jj's version of ImageGenerator 1443 # for jj's version of ImageGenerator
1415 $out = $envir->{'imagegen'}->add($in_delim); 1444 $out = $envir->{'imagegen'}->add($in_delim);
1416 # for my version of ImageGenerator 1445 # for my version of ImageGenerator
1417 #$out = $envir->{'imagegen'}->add($in, $mode); 1446 #$out = $envir->{'imagegen'}->add($in, $mode);
1492 my $probNum = $envir->{probNum}; 1521 my $probNum = $envir->{probNum};
1493 my $TeXFileName = protect_underbar($envir->{fileName}); 1522 my $TeXFileName = protect_underbar($envir->{fileName});
1494 my $l2hFileName = protect_underbar($envir->{fileName}); 1523 my $l2hFileName = protect_underbar($envir->{fileName});
1495 my %inlist; 1524 my %inlist;
1496 my $points ='pts'; 1525 my $points ='pts';
1497 1526
1498 $points = 'pt' if $problemValue == 1; 1527 $points = 'pt' if $problemValue == 1;
1499 ## Prepare header for the problem 1528 ## Prepare header for the problem
1500 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} }); 1529 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} });
1501 if ( defined($inlist{$envir->{studentLogin}}) and ($inlist{$envir->{studentLogin}} > 0) ) { 1530 if ( defined($inlist{$envir->{studentLogin}}) and ($inlist{$envir->{studentLogin}} > 0) ) {
1502 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${probNum}.{\\footnotesize ($problemValue $points) $TeXFileName}}\\newline ", 1531 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${probNum}.{\\footnotesize ($problemValue $points) $TeXFileName}}\\newline ",
1658 } 1687 }
1659 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1688 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1660 $out .= "<TABLE BORDER=1>\n" 1689 $out .= "<TABLE BORDER=1>\n"
1661 } 1690 }
1662 else { 1691 else {
1663 $out = "Error: PGchoicemacros: begintable: Unknown displayMode: $displayMode.\n"; 1692 $out = "Error: PGbasicmacros: begintable: Unknown displayMode: $displayMode.\n";
1664 } 1693 }
1665 $out; 1694 $out;
1666 } 1695 }
1667 1696
1668sub endtable { 1697sub endtable {
1675 } 1704 }
1676 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') { 1705 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') {
1677 $out .= "</TABLE>\n"; 1706 $out .= "</TABLE>\n";
1678 } 1707 }
1679 else { 1708 else {
1680 $out = "Error: PGchoicemacros: endtable: Unknown displayMode: $displayMode.\n"; 1709 $out = "Error: PGbasicmacros: endtable: Unknown displayMode: $displayMode.\n";
1681 } 1710 }
1682 $out; 1711 $out;
1683 } 1712 }
1684 1713
1685 1714
1707 $out .= "<TD>" . shift(@elements) . "</TD>"; 1736 $out .= "<TD>" . shift(@elements) . "</TD>";
1708 } 1737 }
1709 $out .= "\n</TR>\n"; 1738 $out .= "\n</TR>\n";
1710 } 1739 }
1711 else { 1740 else {
1712 $out = "Error: PGchoicemacros: row: Unknown displayMode: $displayMode.\n"; 1741 $out = "Error: PGbasicmacros: row: Unknown displayMode: $displayMode.\n";
1713 } 1742 }
1714 $out; 1743 $out;
1715} 1744}
1716 1745
1717=head2 Macros for displaying static images 1746=head2 Macros for displaying static images
1792 \\end{rawhtml}\n ! 1821 \\end{rawhtml}\n !
1793 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1822 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1794 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A> 1823 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A>
1795 ! 1824 !
1796 } else { 1825 } else {
1797 $out = "Error: PGchoicemacros: image: Unknown displayMode: $displayMode.\n"; 1826 $out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
1798 } 1827 }
1799 push(@output_list, $out); 1828 push(@output_list, $out);
1800 } 1829 }
1801 return wantarray ? @output_list : $output_list[0]; 1830 return wantarray ? @output_list : $output_list[0];
1802} 1831}
1884 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>"; 1913 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>";
1885 } 1914 }
1886 $out .= "\n</TR></TABLE></P>\n" 1915 $out .= "\n</TR></TABLE></P>\n"
1887 } 1916 }
1888 else { 1917 else {
1889 $out = "Error: PGchoicemacros: imageRow: Unknown languageMode: $displayMode.\n"; 1918 $out = "Error: PGbasicmacros: imageRow: Unknown languageMode: $displayMode.\n";
1890 warn $out; 1919 warn $out;
1891 } 1920 }
1892 $out; 1921 $out;
1893} 1922}
1894 1923

Legend:
Removed from v.1298  
changed lines
  Added in v.1462

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9