[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 1250 Revision 1251
19 19
20=cut 20=cut
21 21
22# this is equivalent to use strict, but can be used within the Safe compartment. 22# this is equivalent to use strict, but can be used within the Safe compartment.
23BEGIN{ 23BEGIN{
24 be_strict; 24 main::be_strict;
25} 25}
26 26
27 27
28my $displayMode=$main::displayMode; 28my $displayMode;
29 29
30my ($PAR, 30my ($PAR,
31 $BR, 31 $BR,
32 $LQ, 32 $LQ,
33 $RQ, 33 $RQ,
61 $PERCENT, 61 $PERCENT,
62 $CARET, 62 $CARET,
63 $PI, 63 $PI,
64 $E, 64 $E,
65 @ALPHABET, 65 @ALPHABET,
66 $envir,
66 ); 67 );
67 68
68sub _PGbasicmacros_init { 69sub _PGbasicmacros_init {
70
71 # The big problem is that at compile time in the cached Safe compartment
72 # main:: has one definition, probably Safe::Root1::
73 # At runtime main has another definition Safe::Rootx:: where x is > 1
74
75 # It is important to
76 # initialize the my variable version of $displayMode from the "runtime" version
77 # of main::displayMode
78
79 $displayMode = main::PG_restricted_eval(q!$main::displayMode!);
80
81# This is initializes the remaining variables in the runtime main:: compartment.
82
83main::PG_restricted_eval( <<'EndOfFile');
69 $displayMode =$main::displayMode; 84 $displayMode = $main::displayMode;
85
70 $main::PAR = PAR(); 86 $main::PAR = PAR();
71 $main::BR = BR(); 87 $main::BR = BR();
72 $main::LQ = LQ(); 88 $main::LQ = LQ();
73 $main::RQ = RQ(); 89 $main::RQ = RQ();
74 $main::BM = BM(); 90 $main::BM = BM();
102 $main::CARET = CARET(); 118 $main::CARET = CARET();
103 $main::PI = PI(); 119 $main::PI = PI();
104 $main::E = E(); 120 $main::E = E();
105 @main::ALPHABET = ('A'..'ZZ'); 121 @main::ALPHABET = ('A'..'ZZ');
106 122
107 $PAR = PAR(); 123
108 $BR = BR(); 124
109 $LQ = LQ(); 125EndOfFile
110 $RQ = RQ(); 126
111 $BM = BM(); 127# Next we transfer the correct definitions in the main:: compartment to the local my variables
112 $EM = EM(); 128# This can't be done inside the eval above because my variables seem to be invisible inside the eval
129
130
131 $PAR = $main::PAR;
132 $BR = $main::BR;
133 $LQ = $main::LQ;
134 $RQ = $main::RQ;
135 $BM = $main::BM;
136 $EM = $main::EM;
113 $BDM = BDM(); 137 $BDM = $main::BDM;
114 $EDM = EDM(); 138 $EDM = $main::EDM;
115 $LTS = LTS(); 139 $LTS = $main::LTS;
116 $GTS = GTS(); 140 $GTS = $main::GTS;
117 $LTE = LTE(); 141 $LTE = $main::LTE;
118 $GTE = GTE(); 142 $GTE = $main::GTE;
119 $BEGIN_ONE_COLUMN = BEGIN_ONE_COLUMN(); 143 $BEGIN_ONE_COLUMN = $main::BEGIN_ONE_COLUMN;
120 $END_ONE_COLUMN = END_ONE_COLUMN(); 144 $END_ONE_COLUMN = $main::END_ONE_COLUMN;
121 $SOL = SOLUTION_HEADING(); 145 $SOL = $main::SOLUTION_HEADING;
122 $SOLUTION = SOLUTION_HEADING(); 146 $SOLUTION = $main::SOLUTION_HEADING;
123 $HINT = HINT_HEADING(); 147 $HINT = $main::HINT_HEADING;
124 $US = US(); 148 $US = $main::US;
125 $SPACE = SPACE(); 149 $SPACE = $main::SPACE;
126 $BBOLD = BBOLD(); 150 $BBOLD = $main::BBOLD;
127 $EBOLD = EBOLD(); 151 $EBOLD = $main::EBOLD;
128 $HR = HR(); 152 $HR = $main::HR;
129 $LBRACE = LBRACE(); 153 $LBRACE = $main::LBRACE;
130 $RBRACE = RBRACE(); 154 $RBRACE = $main::RBRACE;
131 $LB = LB(); 155 $LB = $main::LB;
132 $RB = RB(); 156 $RB = $main::RB;
133 $DOLLAR = DOLLAR(); 157 $DOLLAR = $main::DOLLAR;
134 $PERCENT = PERCENT(); 158 $PERCENT = $main::PERCENT;
135 $CARET = CARET(); 159 $CARET = $main::CARET;
136 $PI = PI(); 160 $PI = $main::PI;
137 $E = E(); 161 $E = $main::E;
138 @ALPHABET = ('A'..'ZZ'); 162 @ALPHABET = ('A'..'ZZ');
139 163
164# We initialize a local reference to the environment hash rather than transfer the entire hash
165# This way is slightly more efficient.
140 166
141 167 $envir = PG_restricted_eval(q!\%main::envir!);
168
142} 169}
143 170
144=head2 Answer blank macros: 171=head2 Answer blank macros:
145 172
146These produce answer blanks of various sizes or pop up lists or radio answer buttons. 173These produce answer blanks of various sizes or pop up lists or radio answer buttons.
715 push @row_array, ans_rule($width); 742 push @row_array, ans_rule($width);
716 } 743 }
717 my $r_row_array = \@row_array; 744 my $r_row_array = \@row_array;
718 push @array, $r_row_array; 745 push @array, $r_row_array;
719 } 746 }
747 # display_matrix hasn't been loaded into the cache safe compartment
748 # so we need to refer to the subroutine in this way to make
749 # sure that main is defined correctly.
750 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
720 display_matrix( \@array, @options ); 751 &$ra_local_display_matrix( \@array, @options );
721 752
722} 753}
723 754
724sub NAMED_ANS_ARRAY_EXTENSION{ 755sub NAMED_ANS_ARRAY_EXTENSION{
725 756
776 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 807 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
777 808
778 } 809 }
779 810
780 } 811 }
812 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
781 display_matrix( \@array, @options ); 813 &$ra_local_display_matrix( \@array, @options );
782 814
783} 815}
784 816
785sub ans_array_extension{ 817sub ans_array_extension{
786 my $m = shift; 818 my $m = shift;
802 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 834 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
803 835
804 } 836 }
805 837
806 } 838 }
839 my $ra_local_display_matrix=PG_restricted_eval(q!\&main::display_matrix!);
807 display_matrix( \@array, @options ); 840 &$ra_local_display_matrix( \@array, @options );
808 841
809} 842}
810 843
811 844
812# end answer blank macros 845# end answer blank macros
821 854
822Solution prints its concatenated input when the check box named 'ShowSol' is set and 855Solution prints its concatenated input when the check box named 'ShowSol' is set and
823the time is after the answer date. The check box 'ShowSol' is visible only after the 856the time is after the answer date. The check box 'ShowSol' is visible only after the
824answer date or when the problem is viewed by a professor. 857answer date or when the problem is viewed by a professor.
825 858
826$envir{'displaySolutionsQ'} is set to 1 when a solution is to be displayed. 859$main::envir{'displaySolutionsQ'} is set to 1 when a solution is to be displayed.
827 860
828Hints are shown only after the number of attempts is greater than $:showHint 861Hints are shown only after the number of attempts is greater than $:showHint
829($main::showHint defaults to 1) and the check box named 'ShowHint' is set. The check box 862($main::showHint defaults to 1) and the check box named 'ShowHint' is set. The check box
830'ShowHint' is visible only after the number of attempts is greater than $main::showHint. 863'ShowHint' is visible only after the number of attempts is greater than $main::showHint.
831 864
832$envir{'displayHintsQ'} is set to 1 when a hint is to be displayed. 865$main::envir{'displayHintsQ'} is set to 1 when a hint is to be displayed.
833 866
834 867
835=cut 868=cut
836 869
837 870
845 878
846sub solution { 879sub solution {
847 my @in = @_; 880 my @in = @_;
848 my $out = ''; 881 my $out = '';
849 $main::solutionExists =1; 882 $main::solutionExists =1;
850 if ($envir{'displaySolutionsQ'}) {$out = join(' ',@in);} 883 if ($main::envir{'displaySolutionsQ'}) {$out = join(' ',@in);}
851 $out; 884 $out;
852} 885}
853 886
854 887
855sub SOLUTION { 888sub SOLUTION {
865 $main::hintExists =1; 898 $main::hintExists =1;
866 $main::numOfAttempts = 0 unless defined($main::numOfAttempts); 899 $main::numOfAttempts = 0 unless defined($main::numOfAttempts);
867 900
868 if ($main::displayMode eq 'TeX') { 901 if ($main::displayMode eq 'TeX') {
869 $out = ''; # do nothing since hints are not available for download 902 $out = ''; # do nothing since hints are not available for download
870 } elsif (($envir{'displayHintsQ'}) and ($main::numOfAttempts >= $main::showHint)) 903 } elsif (($main::envir{'displayHintsQ'}) and ($main::numOfAttempts >= $main::showHint))
871 904
872 ## the second test above prevents a hint being shown if a doctored form is submitted 905 ## the second test above prevents a hint being shown if a doctored form is submitted
873 906
874 {$out = join(' ',@in);} # show hint 907 {$out = join(' ',@in);} # show hint
875 908
902 935
903 936
904SRAND(time) will create a different problem everytime it is called. This makes it difficult 937SRAND(time) will create a different problem everytime it is called. This makes it difficult
905to check the answers :-). 938to check the answers :-).
906 939
907SRAND($envir{'inputs_ref'}->{'key'} ) will create a different problem for each login session. 940SRAND($envir->{'inputs_ref'}->{'key'} ) will create a different problem for each login session.
908This is probably what is desired. 941This is probably what is desired.
909 942
910=cut 943=cut
911 944
912 945
1364 my $out; 1397 my $out;
1365 if($displayMode eq "HTML_tth") { 1398 if($displayMode eq "HTML_tth") {
1366 $out = tth($in_delim); 1399 $out = tth($in_delim);
1367 } elsif ($displayMode eq "HTML_dpng") { 1400 } elsif ($displayMode eq "HTML_dpng") {
1368 # for jj's version of ImageGenerator 1401 # for jj's version of ImageGenerator
1369 $out = $envir{'imagegen'}->add($in_delim); 1402 $out = $envir->{'imagegen'}->add($in_delim);
1370 # for my version of ImageGenerator 1403 # for my version of ImageGenerator
1371 #$out = $envir{'imagegen'}->add($in, $mode); 1404 #$out = $envir->{'imagegen'}->add($in, $mode);
1372 } elsif ($displayMode eq "HTML_img") { 1405 } elsif ($displayMode eq "HTML_img") {
1373 $out = math2img($in, $mode); 1406 $out = math2img($in, $mode);
1374 } else { 1407 } else {
1375 $out = "\\($in\\)" if $mode eq "inline"; 1408 $out = "\\($in\\)" if $mode eq "inline";
1376 $out = "\\[$in\\]" if $mode eq "display"; 1409 $out = "\\[$in\\]" if $mode eq "display";
1445 my $l2hFileName = protect_underbar($main::fileName); 1478 my $l2hFileName = protect_underbar($main::fileName);
1446 my %inlist; 1479 my %inlist;
1447 my $points ='pts'; 1480 my $points ='pts';
1448 $points = 'pt' if $main::problemValue == 1; 1481 $points = 'pt' if $main::problemValue == 1;
1449 ## Prepare header for the problem 1482 ## Prepare header for the problem
1450 grep($inlist{$_}++,@{ $envir{'PRINT_FILE_NAMES_FOR'} }); 1483 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} });
1451 if ( defined($inlist{$main::studentLogin}) and ($inlist{$main::studentLogin} > 0) ) { 1484 if ( defined($inlist{$main::studentLogin}) and ($inlist{$main::studentLogin} > 0) ) {
1452 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${main::probNum}.{\\footnotesize ($main::problemValue $points) $TeXFileName}}\\newline ", 1485 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${main::probNum}.{\\footnotesize ($main::problemValue $points) $TeXFileName}}\\newline ",
1453 " \\begin{rawhtml} ($main::problemValue $points) <B>$l2hFileName</B><BR>\\end{rawhtml}", 1486 " \\begin{rawhtml} ($main::problemValue $points) <B>$l2hFileName</B><BR>\\end{rawhtml}",
1454 "($main::problemValue $points) <B>$main::fileName</B><BR>" 1487 "($main::problemValue $points) <B>$main::fileName</B><BR>"
1455 ); 1488 );
1715 my $imageURL = alias(shift @image_list); 1748 my $imageURL = alias(shift @image_list);
1716 my $out=""; 1749 my $out="";
1717 1750
1718 if ($main::displayMode eq 'TeX') { 1751 if ($main::displayMode eq 'TeX') {
1719 my $imagePath = $imageURL; # in TeX mode, alias gives us a path, not a URL 1752 my $imagePath = $imageURL; # in TeX mode, alias gives us a path, not a URL
1720 if ($envir{texDisposition} eq "pdf") { 1753 if ($envir->{texDisposition} eq "pdf") {
1721 # We're going to create PDF files with our TeX (using pdflatex), so 1754 # We're going to create PDF files with our TeX (using pdflatex), so
1722 # alias should have given us the path to a PNG image. What we need 1755 # alias should have given us the path to a PNG image. What we need
1723 # to do is find out the dimmensions of this image, since pdflatex 1756 # to do is find out the dimmensions of this image, since pdflatex
1724 # is too dumb to live. 1757 # is too dumb to live.
1725 1758

Legend:
Removed from v.1250  
changed lines
  Added in v.1251

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9