[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 1314
71sub _PGbasicmacros_init { 71sub _PGbasicmacros_init {
72 72
73 # The big problem is that at compile time in the cached Safe compartment 73 # The big problem is that at compile time in the cached Safe compartment
74 # main:: has one definition, probably Safe::Root1:: 74 # main:: has one definition, probably Safe::Root1::
75 # At runtime main has another definition Safe::Rootx:: where x is > 1 75 # At runtime main has another definition Safe::Rootx:: where x is > 1
76 76
77 # It is important to 77 # It is important to
78 # initialize the my variable version of $displayMode from the "runtime" version 78 # initialize the my variable version of $displayMode from the "runtime" version
79 # of main::displayMode 79 # of main::displayMode
80 80
81 $displayMode = main::PG_restricted_eval(q!$main::displayMode!); 81 $displayMode = main::PG_restricted_eval(q!$main::displayMode!);
82 82
83# This is initializes the remaining variables in the runtime main:: compartment. 83# This is initializes the remaining variables in the runtime main:: compartment.
84 84
85main::PG_restricted_eval( <<'EndOfFile'); 85main::PG_restricted_eval( <<'EndOfFile');
86 $displayMode = $displayMode; 86 $displayMode = $displayMode;
87 87
88 $main::PAR = PAR(); 88 $main::PAR = PAR();
89 $main::BR = BR(); 89 $main::BR = BR();
121 $main::PI = PI(); 121 $main::PI = PI();
122 $main::E = E(); 122 $main::E = E();
123 @main::ALPHABET = ('A'..'ZZ'); 123 @main::ALPHABET = ('A'..'ZZ');
124 124
125 125
126 126
127EndOfFile 127EndOfFile
128 128
129# Next we transfer the correct definitions in the main:: compartment to the local my variables 129# 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 130# This can't be done inside the eval above because my variables seem to be invisible inside the eval
131 131
168 @ALPHABET = ('A'..'ZZ'); 168 @ALPHABET = ('A'..'ZZ');
169 169
170 $envir = PG_restricted_eval(q!\%main::envir!); 170 $envir = PG_restricted_eval(q!\%main::envir!);
171 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!); 171 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!);
172 $inputs_ref = $envir{inputs_ref}; 172 $inputs_ref = $envir{inputs_ref};
173 173
174} 174}
175 175
176=head2 Answer blank macros: 176=head2 Answer blank macros:
177 177
178These produce answer blanks of various sizes or pop up lists or radio answer buttons. 178These produce answer blanks of various sizes or pop up lists or radio answer buttons.
268 my $answer_value = ''; 268 my $answer_value = '';
269 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 269 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
270 if ($answer_value =~ /\0/ ) { 270 if ($answer_value =~ /\0/ ) {
271 my @answers = split("\0", $answer_value); 271 my @answers = split("\0", $answer_value);
272 $answer_value = shift(@answers); # use up the first answer 272 $answer_value = shift(@answers); # use up the first answer
273 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 273 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!);
274 # store the rest -- beacuse this stores to a main:; variable 274 # store the rest -- beacuse this stores to a main:; variable
275 # it must be evaluated at run time 275 # it must be evaluated at run time
276 $answer_value= '' unless defined($answer_value); 276 $answer_value= '' unless defined($answer_value);
277 } elsif (ref($answer_value) eq 'ARRAY') { 277 } elsif (ref($answer_value) eq 'ARRAY') {
278 my @answers = @{ $answer_value}; 278 my @answers = @{ $answer_value};
279 $answer_value = shift(@answers); # use up the first answer 279 $answer_value = shift(@answers); # use up the first answer
280 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 280 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!);
281 # store the rest -- beacuse this stores to a main:; variable 281 # store the rest -- beacuse this stores to a main:; variable
282 # it must be evaluated at run time 282 # it must be evaluated at run time
283 $answer_value= '' unless defined($answer_value); 283 $answer_value= '' unless defined($answer_value);
284 } 284 }
285 285
286 $answer_value =~ tr/$@`//d; ## make sure student answers can not be interpolated by e.g. EV3 286 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
287 $name = RECORD_ANS_NAME($name); 287 $name = RECORD_ANS_NAME($name);
288 MODES( 288 MODES(
289 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 289 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ",
290 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 290 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
291 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n" 291 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n"
303 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 303 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
304 if ( defined(PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)) ) { 304 if ( defined(PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)) ) {
305 $answer_value = shift( @{PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)}); 305 $answer_value = shift( @{PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)});
306 $answer_value = '' unless defined($answer_value); 306 $answer_value = '' unless defined($answer_value);
307 } 307 }
308 $answer_value =~ tr/$@//d; ## make sure student answers can not be interpolated by e.g. EV3 308 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
309 MODES( 309 MODES(
310 TeX => '\\hrulefill\\quad ', 310 TeX => '\\hrulefill\\quad ',
311 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!, 311 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! 312 HTML => qq!<INPUT TYPE=TEXT SIZE=$col NAME = "$name" VALUE = "$answer_value">\n!
313 ); 313 );
327 $name = RECORD_ANS_NAME($name); 327 $name = RECORD_ANS_NAME($name);
328 my $len = 0.07*$col; 328 my $len = 0.07*$col;
329 my $height = .07*$row; 329 my $height = .07*$row;
330 my $answer_value = ''; 330 my $answer_value = '';
331 $answer_value = $inputs_ref->{$name} if defined( $inputs_ref->{$name} ); 331 $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 332 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
333 my $out = M3( 333 my $out = M3(
334 qq!\\vskip $height in \\hrulefill\\quad !, 334 qq!\\vskip $height in \\hrulefill\\quad !,
335 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 335 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
336 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!, 336 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!,
337 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 337 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
722 722
723 723
724=head5 answer_matrix 724=head5 answer_matrix
725 725
726 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \] 726 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \]
727 727
728 Creates an array of answer blanks and passes it to display_matrix which returns 728 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 729 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. 730 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 731 (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 732 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.) 733 and then at the end moving down one row, just as you would read them.)
734 734
735 The options are passed on to display_matrix. 735 The options are passed on to display_matrix.
736 736
737 737
738=cut 738=cut
739 739
745 my @options = @_; 745 my @options = @_;
746 my @array=(); 746 my @array=();
747 for( my $i = 0; $i < $m; $i+=1) 747 for( my $i = 0; $i < $m; $i+=1)
748 { 748 {
749 my @row_array = (); 749 my @row_array = ();
750 750
751 for( my $i = 0; $i < $n; $i+=1) 751 for( my $i = 0; $i < $n; $i+=1)
752 { 752 {
753 push @row_array, ans_rule($width); 753 push @row_array, ans_rule($width);
754 } 754 }
755 my $r_row_array = \@row_array; 755 my $r_row_array = \@row_array;
756 push @array, $r_row_array; 756 push @array, $r_row_array;
757 } 757 }
758 # display_matrix hasn't been loaded into the cache safe compartment 758 # 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 759 # so we need to refer to the subroutine in this way to make
760 # sure that main is defined correctly. 760 # sure that main is defined correctly.
761 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 761 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
762 &$ra_local_display_matrix( \@array, @options ); 762 &$ra_local_display_matrix( \@array, @options );
763 763
764} 764}
765 765
766sub NAMED_ANS_ARRAY_EXTENSION{ 766sub NAMED_ANS_ARRAY_EXTENSION{
767 767
768 my $name = shift; 768 my $name = shift;
769 my $col = shift; 769 my $col = shift;
770 $col = 20 unless $col; 770 $col = 20 unless $col;
771 my $answer_value = ''; 771 my $answer_value = '';
772 772
773 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 773 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
774 if ($answer_value =~ /\0/ ) { 774 if ($answer_value =~ /\0/ ) {
775 my @answers = split("\0", $answer_value); 775 my @answers = split("\0", $answer_value);
776 $answer_value = shift(@answers); 776 $answer_value = shift(@answers);
777 $answer_value= '' unless defined($answer_value); 777 $answer_value= '' unless defined($answer_value);
778 } elsif (ref($answer_value) eq 'ARRAY') { 778 } elsif (ref($answer_value) eq 'ARRAY') {
779 my @answers = @{ $answer_value}; 779 my @answers = @{ $answer_value};
780 $answer_value = shift(@answers); 780 $answer_value = shift(@answers);
781 $answer_value= '' unless defined($answer_value); 781 $answer_value= '' unless defined($answer_value);
782 } 782 }
783 783
784 $answer_value =~ tr/$@`//d; ## make sure student answers can not be interpolated by e.g. EV3 784 $answer_value =~ tr/\\$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
785 MODES( 785 MODES(
786 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 786 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!, 787 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" 788 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n"
789 ); 789 );
798 my $name = NEW_ANS_ARRAY_NAME($num,0,0); 798 my $name = NEW_ANS_ARRAY_NAME($num,0,0);
799 my @options = @_; 799 my @options = @_;
800 my @array=(); 800 my @array=();
801 my $string; 801 my $string;
802 my $answer_value = ""; 802 my $answer_value = "";
803 803
804 $array[0][0] = NAMED_ANS_RULE($name,$col); 804 $array[0][0] = NAMED_ANS_RULE($name,$col);
805 805
806 for( my $i = 1; $i < $n; $i+=1) 806 for( my $i = 1; $i < $n; $i+=1)
807 { 807 {
808 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i); 808 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i);
809 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 809 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
810 810
811 } 811 }
812 812
813 for( my $j = 1; $j < $m; $j+=1 ){ 813 for( my $j = 1; $j < $m; $j+=1 ){
814 814
815 for( my $i = 0; $i < $n; $i+=1) 815 for( my $i = 0; $i < $n; $i+=1)
816 { 816 {
817 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 817 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
818 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 818 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
819 819
820 } 820 }
821 821
822 } 822 }
823 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 823 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
824 &$ra_local_display_matrix( \@array, @options ); 824 &$ra_local_display_matrix( \@array, @options );
825 825
826} 826}
827 827
828sub ans_array_extension{ 828sub ans_array_extension{
829 my $m = shift; 829 my $m = shift;
830 my $n = shift; 830 my $n = shift;
834 my @options = @_; 834 my @options = @_;
835 my $name; 835 my $name;
836 my @array=(); 836 my @array=();
837 my $string; 837 my $string;
838 my $answer_value = ""; 838 my $answer_value = "";
839 839
840 for( my $j = 0; $j < $m; $j+=1 ){ 840 for( my $j = 0; $j < $m; $j+=1 ){
841 841
842 for( my $i = 0; $i < $n; $i+=1) 842 for( my $i = 0; $i < $n; $i+=1)
843 { 843 {
844 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 844 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
845 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 845 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
846 846
847 } 847 }
848 848
849 } 849 }
850 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!); 850 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
851 &$ra_local_display_matrix( \@array, @options ); 851 &$ra_local_display_matrix( \@array, @options );
852 852
853} 853}
854 854
855 855
856# end answer blank macros 856# end answer blank macros
857 857
910 $main::numOfAttempts = 0 unless defined($main::numOfAttempts); 910 $main::numOfAttempts = 0 unless defined($main::numOfAttempts);
911 !); 911 !);
912 912
913 if ($displayMode eq 'TeX') { 913 if ($displayMode eq 'TeX') {
914 $out = ''; # do nothing since hints are not available for download 914 $out = ''; # do nothing since hints are not available for download
915 } elsif (($envir->{'displayHintsQ'}) and 915 } elsif (($envir->{'displayHintsQ'}) and
916 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!)) 916 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!))
917 917
918 ## the second test above prevents a hint being shown if a doctored form is submitted 918 ## the second test above prevents a hint being shown if a doctored form is submitted
919 919
920 {$out = join(' ',@in);} # show hint 920 {$out = join(' ',@in);} # show hint
1399 my $in = shift; 1399 my $in = shift;
1400 my $mode = shift || "inline"; 1400 my $mode = shift || "inline";
1401 1401
1402 $in = FEQ($in); # Format EQuations 1402 $in = FEQ($in); # Format EQuations
1403 $in =~ s/%/\\%/g; # avoid % becoming TeX comments 1403 $in =~ s/%/\\%/g; # avoid % becoming TeX comments
1404 1404
1405 # some modes want the delimiters, some don't 1405 # some modes want the delimiters, some don't
1406 my $in_delim = $mode eq "inline" 1406 my $in_delim = $mode eq "inline"
1407 ? "\\($in\\)" 1407 ? "\\($in\\)"
1408 : "\\[$in\\]"; 1408 : "\\[$in\\]";
1409 1409
1410 my $out; 1410 my $out;
1411 if($displayMode eq "HTML_tth") { 1411 if($displayMode eq "HTML_tth") {
1412 $out = tth($in_delim); 1412 $out = tth($in_delim);
1413 } elsif ($displayMode eq "HTML_dpng") { 1413 } elsif ($displayMode eq "HTML_dpng") {
1414 # for jj's version of ImageGenerator 1414 # for jj's version of ImageGenerator
1492 my $probNum = $envir->{probNum}; 1492 my $probNum = $envir->{probNum};
1493 my $TeXFileName = protect_underbar($envir->{fileName}); 1493 my $TeXFileName = protect_underbar($envir->{fileName});
1494 my $l2hFileName = protect_underbar($envir->{fileName}); 1494 my $l2hFileName = protect_underbar($envir->{fileName});
1495 my %inlist; 1495 my %inlist;
1496 my $points ='pts'; 1496 my $points ='pts';
1497 1497
1498 $points = 'pt' if $problemValue == 1; 1498 $points = 'pt' if $problemValue == 1;
1499 ## Prepare header for the problem 1499 ## Prepare header for the problem
1500 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} }); 1500 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} });
1501 if ( defined($inlist{$envir->{studentLogin}}) and ($inlist{$envir->{studentLogin}} > 0) ) { 1501 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 ", 1502 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${probNum}.{\\footnotesize ($problemValue $points) $TeXFileName}}\\newline ",

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9