[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 1267 Revision 1483
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 $PAR = PAR(); 90 $main::PAR = PAR();
89 $BR = BR(); 91 $main::BR = BR();
90 $main::LQ = LQ(); 92 $main::LQ = LQ();
91 $main::RQ = RQ(); 93 $main::RQ = RQ();
92 $BM = BM(); 94 $main::BM = BM();
93 $EM = EM(); 95 $main::EM = EM();
94 $main::BDM = BDM(); 96 $main::BDM = BDM();
95 $main::EDM = EDM(); 97 $main::EDM = EDM();
96 $main::LTS = LTS(); 98 $main::LTS = LTS();
97 $main::GTS = GTS(); 99 $main::GTS = GTS();
98 $main::LTE = LTE(); 100 $main::LTE = LTE();
102 $main::SOL = SOLUTION_HEADING(); 104 $main::SOL = SOLUTION_HEADING();
103 $main::SOLUTION = SOLUTION_HEADING(); 105 $main::SOLUTION = SOLUTION_HEADING();
104 $main::HINT = HINT_HEADING(); 106 $main::HINT = HINT_HEADING();
105 $main::US = US(); 107 $main::US = US();
106 $main::SPACE = SPACE(); 108 $main::SPACE = SPACE();
107 $BBOLD = BBOLD(); 109 $main::BBOLD = BBOLD();
108 $EBOLD = EBOLD(); 110 $main::EBOLD = EBOLD();
109 $main::BITALIC = BITALIC(); 111 $main::BITALIC = BITALIC();
110 $main::EITALIC = EITALIC(); 112 $main::EITALIC = EITALIC();
111 $main::BCENTER = BCENTER(); 113 $main::BCENTER = BCENTER();
112 $main::ECENTER = ECENTER(); 114 $main::ECENTER = ECENTER();
113 $main::HR = HR(); 115 $main::HR = HR();
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
132 134
133 $PAR = $PAR; 135 $PAR = PAR();
134 $BR = $BR; 136 $BR = BR();
135 $LQ = $main::LQ; 137 $LQ = LQ();
136 $RQ = $main::RQ; 138 $RQ = RQ();
137 $BM = $BM; 139 $BM = BM();
138 $EM = $EM; 140 $EM = EM();
139 $BDM = $main::BDM; 141 $BDM = BDM();
140 $EDM = $main::EDM; 142 $EDM = EDM();
141 $LTS = $main::LTS; 143 $LTS = LTS();
142 $GTS = $main::GTS; 144 $GTS = GTS();
143 $LTE = $main::LTE; 145 $LTE = LTE();
144 $GTE = $main::GTE; 146 $GTE = GTE();
145 $BEGIN_ONE_COLUMN = $main::BEGIN_ONE_COLUMN; 147 $BEGIN_ONE_COLUMN = BEGIN_ONE_COLUMN();
146 $END_ONE_COLUMN = $main::END_ONE_COLUMN; 148 $END_ONE_COLUMN = END_ONE_COLUMN();
147 $SOL = $main::SOLUTION_HEADING; 149 $SOL = SOLUTION_HEADING();
148 $SOLUTION = $main::SOLUTION_HEADING; 150 $SOLUTION = SOLUTION_HEADING();
149 $HINT = $main::HINT_HEADING; 151 $HINT = HINT_HEADING();
150 $US = $main::US; 152 $US = US();
151 $SPACE = $main::SPACE; 153 $SPACE = SPACE();
152 $BBOLD = $BBOLD; 154 $BBOLD = BBOLD();
153 $EBOLD = $EBOLD; 155 $EBOLD = EBOLD();
156 $BITALIC = BITALIC();
157 $EITALIC = EITALIC();
158 $BCENTER = BCENTER();
159 $ECENTER = ECENTER();
154 $HR = $main::HR; 160 $HR = HR();
155 $LBRACE = $main::LBRACE; 161 $LBRACE = LBRACE();
156 $RBRACE = $main::RBRACE; 162 $RBRACE = RBRACE();
157 $LB = $main::LB; 163 $LB = LB();
158 $RB = $main::RB; 164 $RB = RB();
159 $DOLLAR = $main::DOLLAR; 165 $DOLLAR = DOLLAR();
160 $PERCENT = $main::PERCENT; 166 $PERCENT = PERCENT();
161 $CARET = $main::CARET; 167 $CARET = CARET();
162 $PI = $main::PI; 168 $PI = PI();
163 $E = $main::E; 169 $E = E();
164 @ALPHABET = ('A'..'ZZ'); 170 @ALPHABET = ('A'..'ZZ');
165
166# We initialize a local reference to the environment hash rather than transfer the entire hash
167# This way is slightly more efficient.
168 171
169 $envir = PG_restricted_eval(q!\%main::envir!); 172 $envir = PG_restricted_eval(q!\%main::envir!);
170 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!); 173 $PG_random_generator = PG_restricted_eval(q!$main::PG_random_generator!);
171 $inputs_ref = $envir{inputs_ref}; 174 $inputs_ref = $envir{inputs_ref};
172 175 $rh_sticky_answers = PG_restricted_eval(q!\%main::STICKY_ANSWERS!);
176 $r_ans_rule_count = PG_restricted_eval(q!\$ans_rule_count!);
173} 177}
174 178
175=head2 Answer blank macros: 179=head2 Answer blank macros:
176 180
177These 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.
267 my $answer_value = ''; 271 my $answer_value = '';
268 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 272 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
269 if ($answer_value =~ /\0/ ) { 273 if ($answer_value =~ /\0/ ) {
270 my @answers = split("\0", $answer_value); 274 my @answers = split("\0", $answer_value);
271 $answer_value = shift(@answers); # use up the first answer 275 $answer_value = shift(@answers); # use up the first answer
272 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 276 $rh_sticky_answers->{$name}=\@answers;
273 # store the rest -- beacuse this stores to a main:; variable 277 # store the rest -- beacuse this stores to a main:; variable
274 # it must be evaluated at run time 278 # it must be evaluated at run time
275 $answer_value= '' unless defined($answer_value); 279 $answer_value= '' unless defined($answer_value);
276 } elsif (ref($answer_value) eq 'ARRAY') { 280 } elsif (ref($answer_value) eq 'ARRAY') {
277 my @answers = @{ $answer_value}; 281 my @answers = @{ $answer_value};
278 $answer_value = shift(@answers); # use up the first answer 282 $answer_value = shift(@answers); # use up the first answer
279 PG_restricted_eval(q!$main::rh_sticky_answers{$name}=\@answers;!); 283 $rh_sticky_answers->{$name}=\@answers;
280 # store the rest -- beacuse this stores to a main:; variable 284 # store the rest -- beacuse this stores to a main:; variable
281 # it must be evaluated at run time 285 # it must be evaluated at run time
282 $answer_value= '' unless defined($answer_value); 286 $answer_value= '' unless defined($answer_value);
283 } 287 }
284 288
285 $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
286 $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
287 MODES( 298 MODES(
288 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 299 TeX => "\\mbox{\\parbox[t]{${tcol}ex}{\\hrulefill}}",
289 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}!,
290 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n" 301 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">"
291 ); 302 );
292} 303}
293 304
294sub NAMED_ANS_RULE_OPTION { # deprecated 305sub NAMED_ANS_RULE_OPTION { # deprecated
295 &NAMED_ANS_RULE_EXTENSION; 306 &NAMED_ANS_RULE_EXTENSION;
298sub NAMED_ANS_RULE_EXTENSION { 309sub NAMED_ANS_RULE_EXTENSION {
299 my($name,$col) = @_; 310 my($name,$col) = @_;
300 my $len = 0.07*$col; 311 my $len = 0.07*$col;
301 my $answer_value = ''; 312 my $answer_value = '';
302 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 313 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
303 if ( defined(PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)) ) { 314 if ( defined( $rh_sticky_answers->{$name} ) ) {
304 $answer_value = shift( @{PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)}); 315 $answer_value = shift( @{ $rh_sticky_answers->{$name} });
305 $answer_value = '' unless defined($answer_value); 316 $answer_value = '' unless defined($answer_value);
306 } 317 }
307 $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
308 MODES( 319 MODES(
309 TeX => '\\hrulefill\\quad ', 320 TeX => '\\hrulefill\\quad ',
310 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!,
311 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!
312 ); 323 );
326 $name = RECORD_ANS_NAME($name); 337 $name = RECORD_ANS_NAME($name);
327 my $len = 0.07*$col; 338 my $len = 0.07*$col;
328 my $height = .07*$row; 339 my $height = .07*$row;
329 my $answer_value = ''; 340 my $answer_value = '';
330 $answer_value = $inputs_ref->{$name} if defined( $inputs_ref->{$name} ); 341 $answer_value = $inputs_ref->{$name} if defined( $inputs_ref->{$name} );
331 $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
332 my $out = M3( 343 my $out = M3(
333 qq!\\vskip $height in \\hrulefill\\quad !, 344 qq!\\vskip $height in \\hrulefill\\quad !,
334 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 345 qq!\\begin{rawhtml}<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
335 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!, 346 WRAP="VIRTUAL">$answer_value</TEXTAREA>\\end{rawhtml}!,
336 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col" 347 qq!<TEXTAREA NAME="$name" ROWS="$row" COLS="$col"
570 NAMED_ANS_RULE($name ,$len); 581 NAMED_ANS_RULE($name ,$len);
571} 582}
572sub ans_rule_extension { 583sub ans_rule_extension {
573 my $len = shift; 584 my $len = shift;
574 $len = 20 unless $len ; 585 $len = 20 unless $len ;
575 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
576 NAMED_ANS_RULE($name ,$len); 587 NAMED_ANS_RULE($name ,$len);
577} 588}
578sub ans_radio_buttons { 589sub ans_radio_buttons {
579 my $name = NEW_ANS_NAME(inc_ans_rule_count()); 590 my $name = NEW_ANS_NAME(inc_ans_rule_count());
580 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_); 591 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_);
621 $out; 632 $out;
622} 633}
623sub tex_ans_rule_extension { 634sub tex_ans_rule_extension {
624 my $len = shift; 635 my $len = shift;
625 $len = 20 unless $len ; 636 $len = 20 unless $len ;
626 my $name = NEW_ANS_NAME(PG_restricted_eval(q!$main::ans_rule_count!)); 637 my $name = NEW_ANS_NAME($$r_ans_rule_count);
627 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.
628 my $out = MODES( 639 my $out = MODES(
629 'TeX' => $answer_rule, 640 'TeX' => $answer_rule,
630 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}', 641 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}',
631 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}', 642 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',
721 732
722 733
723=head5 answer_matrix 734=head5 answer_matrix
724 735
725 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \] 736 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \]
726 737
727 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
728 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
729 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.
730 (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
731 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
732 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.)
733 744
734 The options are passed on to display_matrix. 745 The options are passed on to display_matrix.
735 746
736 747
737=cut 748=cut
738 749
744 my @options = @_; 755 my @options = @_;
745 my @array=(); 756 my @array=();
746 for( my $i = 0; $i < $m; $i+=1) 757 for( my $i = 0; $i < $m; $i+=1)
747 { 758 {
748 my @row_array = (); 759 my @row_array = ();
749 760
750 for( my $i = 0; $i < $n; $i+=1) 761 for( my $i = 0; $i < $n; $i+=1)
751 { 762 {
752 push @row_array, ans_rule($width); 763 push @row_array, ans_rule($width);
753 } 764 }
754 my $r_row_array = \@row_array; 765 my $r_row_array = \@row_array;
755 push @array, $r_row_array; 766 push @array, $r_row_array;
756 } 767 }
757 # display_matrix hasn't been loaded into the cache safe compartment 768 # display_matrix hasn't been loaded into the cache safe compartment
758 # 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
759 # sure that main is defined correctly. 770 # sure that main is defined correctly.
760 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!);
761 &$ra_local_display_matrix( \@array, @options ); 772 &$ra_local_display_matrix( \@array, @options );
762 773
763} 774}
764 775
765sub NAMED_ANS_ARRAY_EXTENSION{ 776sub NAMED_ANS_ARRAY_EXTENSION{
766 777
767 my $name = shift; 778 my $name = shift;
768 my $col = shift; 779 my $col = shift;
769 $col = 20 unless $col; 780 $col = 20 unless $col;
770 my $answer_value = ''; 781 my $answer_value = '';
771 782
772 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 783 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
773 if ($answer_value =~ /\0/ ) { 784 if ($answer_value =~ /\0/ ) {
774 my @answers = split("\0", $answer_value); 785 my @answers = split("\0", $answer_value);
775 $answer_value = shift(@answers); 786 $answer_value = shift(@answers);
776 $answer_value= '' unless defined($answer_value); 787 $answer_value= '' unless defined($answer_value);
777 } elsif (ref($answer_value) eq 'ARRAY') { 788 } elsif (ref($answer_value) eq 'ARRAY') {
778 my @answers = @{ $answer_value}; 789 my @answers = @{ $answer_value};
779 $answer_value = shift(@answers); 790 $answer_value = shift(@answers);
780 $answer_value= '' unless defined($answer_value); 791 $answer_value= '' unless defined($answer_value);
781 } 792 }
782 793
783 $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
784 MODES( 795 MODES(
785 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ", 796 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ",
786 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!,
787 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"
788 ); 799 );
797 my $name = NEW_ANS_ARRAY_NAME($num,0,0); 808 my $name = NEW_ANS_ARRAY_NAME($num,0,0);
798 my @options = @_; 809 my @options = @_;
799 my @array=(); 810 my @array=();
800 my $string; 811 my $string;
801 my $answer_value = ""; 812 my $answer_value = "";
802 813
803 $array[0][0] = NAMED_ANS_RULE($name,$col); 814 $array[0][0] = NAMED_ANS_RULE($name,$col);
804 815
805 for( my $i = 1; $i < $n; $i+=1) 816 for( my $i = 1; $i < $n; $i+=1)
806 { 817 {
807 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i); 818 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i);
808 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 819 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
809 820
810 } 821 }
811 822
812 for( my $j = 1; $j < $m; $j+=1 ){ 823 for( my $j = 1; $j < $m; $j+=1 ){
813 824
814 for( my $i = 0; $i < $n; $i+=1) 825 for( my $i = 0; $i < $n; $i+=1)
815 { 826 {
816 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 827 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
817 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 828 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
818 829
819 } 830 }
820 831
821 } 832 }
822 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!);
823 &$ra_local_display_matrix( \@array, @options ); 834 &$ra_local_display_matrix( \@array, @options );
824 835
825} 836}
826 837
827sub ans_array_extension{ 838sub ans_array_extension{
828 my $m = shift; 839 my $m = shift;
829 my $n = shift; 840 my $n = shift;
833 my @options = @_; 844 my @options = @_;
834 my $name; 845 my $name;
835 my @array=(); 846 my @array=();
836 my $string; 847 my $string;
837 my $answer_value = ""; 848 my $answer_value = "";
838 849
839 for( my $j = 0; $j < $m; $j+=1 ){ 850 for( my $j = 0; $j < $m; $j+=1 ){
840 851
841 for( my $i = 0; $i < $n; $i+=1) 852 for( my $i = 0; $i < $n; $i+=1)
842 { 853 {
843 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i); 854 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
844 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col); 855 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
845 856
846 } 857 }
847 858
848 } 859 }
849 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!);
850 &$ra_local_display_matrix( \@array, @options ); 861 &$ra_local_display_matrix( \@array, @options );
851 862
852} 863}
853 864
854 865
855# end answer blank macros 866# end answer blank macros
856 867
909 $main::numOfAttempts = 0 unless defined($main::numOfAttempts); 920 $main::numOfAttempts = 0 unless defined($main::numOfAttempts);
910 !); 921 !);
911 922
912 if ($displayMode eq 'TeX') { 923 if ($displayMode eq 'TeX') {
913 $out = ''; # do nothing since hints are not available for download 924 $out = ''; # do nothing since hints are not available for download
914 } elsif (($envir->{'displayHintsQ'}) and 925 } elsif (($envir->{'displayHintsQ'}) and
915 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!)) 926 PG_restricted_eval(q!($main::numOfAttempts >= $main::showHint)!))
916 927
917 ## 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
918 929
919 {$out = join(' ',@in);} # show hint 930 {$out = join(' ',@in);} # show hint
976 return $li[random(1,scalar(@li))-1]; 987 return $li[random(1,scalar(@li))-1];
977} 988}
978 989
979sub SRAND { # resets the main random generator -- use cautiously 990sub SRAND { # resets the main random generator -- use cautiously
980 my $seed = shift; 991 my $seed = shift;
981 PG_random_generator -> srand($seed); 992 $PG_random_generator -> srand($seed);
982} 993}
983 994
984# display macros 995# display macros
985 996
986=head2 Display Macros 997=head2 Display Macros
1119} 1130}
1120 1131
1121############################################################### 1132###############################################################
1122# Some constants which are different in tex and in HTML 1133# Some constants which are different in tex and in HTML
1123# 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
1124sub PAR { MODES( TeX => '\\par ',Latex2HTML => '\\par ',HTML => '<P>' ); }; 1136sub PAR { MODES( TeX => '\\par ', Latex2HTML => '\\begin{rawhtml}<P>\\end{rawhtml}', HTML => '<P>'); };
1125sub 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>'); };
1126sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); }; 1141sub LQ { MODES( TeX => "``", Latex2HTML => '"', HTML => '&quot;' ); };
1127sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); }; 1142sub RQ { MODES( TeX => "''", Latex2HTML => '"', HTML => '&quot;' ); };
1128sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode 1143sub BM { MODES(TeX => '\\(', Latex2HTML => '\\(', HTML => ''); }; # begin math mode
1129sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode 1144sub EM { MODES(TeX => '\\)', Latex2HTML => '\\)', HTML => ''); }; # end math mode
1130sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode 1145sub BDM { MODES(TeX => '\\[', Latex2HTML => '\\[', HTML => '<P ALIGN=CENTER>'); }; #begin displayMath mode
1131sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode 1146sub EDM { MODES(TeX => '\\]', Latex2HTML => '\\]', HTML => '</P>'); }; #end displayMath mode
1132sub LTS { MODES(TeX => ' < ', Latex2HTML => ' \\lt ', HTML => '&lt;'); }; 1147sub LTS { MODES(TeX => '<', Latex2HTML => '\\lt ', HTML => '&lt;', HTML_tth => '<' ); };
1133sub GTS {MODES(TeX => ' > ', Latex2HTML => ' \\gt ', HTML => '&gt;'); }; 1148sub GTS { MODES(TeX => '>', Latex2HTML => '\\gt ', HTML => '&gt;', HTML_tth => '>' ); };
1134sub LTE { MODES(TeX => ' \\le ', Latex2HTML => ' \\le ', HTML => '&lt;=' ); }; 1149sub LTE { MODES(TeX => '\\le ', Latex2HTML => '\\le ', HTML => '<U>&lt;</U>', HTML_tth => '\\le ' ); };
1135sub GTE { MODES(TeX => ' \\ge ', Latex2HTML => ' \\ge ', HTML => '&gt;'); }; 1150sub GTE { MODES(TeX => '\\ge ', Latex2HTML => '\\ge ', HTML => '<U>&gt;</U>', HTML_tth => '\\ge ' ); };
1136sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); }; 1151sub BEGIN_ONE_COLUMN { MODES(TeX => " \\end{multicols}\n", Latex2HTML => " ", HTML => " "); };
1137sub END_ONE_COLUMN { MODES(TeX => 1152sub END_ONE_COLUMN { MODES(TeX =>
1138 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n", 1153 " \\begin{multicols}{2}\n\\columnwidth=\\linewidth\n",
1139 Latex2HTML => ' ', HTML => ' '); 1154 Latex2HTML => ' ', HTML => ' ');
1140 1155
1151sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); }; 1166sub BITALIC { MODES(TeX => '{\\it ', Latex2HTML => '{\\it ', HTML => '<I>'); };
1152sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); }; 1167sub EITALIC { MODES(TeX => '} ', Latex2HTML => '} ', HTML => '</I>'); };
1153sub 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">'); };
1154sub 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>'); };
1155sub 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>'); };
1156sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1171sub LBRACE { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1157sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1172sub RBRACE { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1158sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '\{' , HTML_tth=> '\\lbrace' ); }; 1173sub LB { MODES( TeX => '\{', Latex2HTML => '\\lbrace', HTML => '{' , HTML_tth=> '\\lbrace' ); };
1159sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '\}' , HTML_tth=> '\\rbrace',); }; 1174sub RB { MODES( TeX => '\}', Latex2HTML => '\\rbrace', HTML => '}' , HTML_tth=> '\\rbrace',); };
1160sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); }; 1175sub DOLLAR { MODES( TeX => '\\$', Latex2HTML => '\\$', HTML => '$' ); };
1161sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); }; 1176sub PERCENT { MODES( TeX => '\\%', Latex2HTML => '\\%', HTML => '%' ); };
1162sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); }; 1177sub CARET { MODES( TeX => '\\verb+^+', Latex2HTML => '\\verb+^+', HTML => '^' ); };
1163sub PI {4*atan2(1,1);}; 1178sub PI {4*atan2(1,1);};
1164sub E {exp(1);}; 1179sub E {exp(1);};
1293 my $start_delim = shift; 1308 my $start_delim = shift;
1294 my $end_delim = shift; 1309 my $end_delim = shift;
1295 my $actionRef = shift; 1310 my $actionRef = shift;
1296 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=(); 1311 my ($eval_out,$PG_eval_errors,$PG_full_error_report)=();
1297 my $out = ""; 1312 my $out = "";
1313 #
1314 # DPVC -- 2001/12/07
1315 # original "while ($string)" fails to process the string "0" correctly
1316 #
1298 while ($string) { 1317 while ($string ne "") {
1318 #
1319 # end DPVC
1320 #
1299 if ($string =~ /\Q$start_delim\E/s) { 1321 if ($string =~ /\Q$start_delim\E/s) {
1300 #print "$start_delim $end_delim evaluating_substring=$string<BR>"; 1322 #print "$start_delim $end_delim evaluating_substring=$string<BR>";
1301 $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
1302 $out .= $1; 1324 $out .= $1;
1303 #print "$start_delim $end_delim substring_out=$out<BR>"; 1325 #print "$start_delim $end_delim substring_out=$out<BR>";
1398 my $in = shift; 1420 my $in = shift;
1399 my $mode = shift || "inline"; 1421 my $mode = shift || "inline";
1400 1422
1401 $in = FEQ($in); # Format EQuations 1423 $in = FEQ($in); # Format EQuations
1402 $in =~ s/%/\\%/g; # avoid % becoming TeX comments 1424 $in =~ s/%/\\%/g; # avoid % becoming TeX comments
1403 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
1404 # some modes want the delimiters, some don't 1431 # some modes want the delimiters, some don't
1405 my $in_delim = $mode eq "inline" 1432 my $in_delim = $mode eq "inline"
1406 ? "\\($in\\)" 1433 ? "\\($in\\)"
1407 : "\\[$in\\]"; 1434 : "\\[$in\\]";
1408 1435
1409 my $out; 1436 my $out;
1410 if($displayMode eq "HTML_tth") { 1437 if($displayMode eq "HTML_tth") {
1411 $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+$//;
1412 } elsif ($displayMode eq "HTML_dpng") { 1442 } elsif ($displayMode eq "HTML_dpng") {
1413 # for jj's version of ImageGenerator 1443 # for jj's version of ImageGenerator
1414 $out = $envir->{'imagegen'}->add($in_delim); 1444 $out = $envir->{'imagegen'}->add($in_delim);
1415 # for my version of ImageGenerator 1445 # for my version of ImageGenerator
1416 #$out = $envir->{'imagegen'}->add($in, $mode); 1446 #$out = $envir->{'imagegen'}->add($in, $mode);
1454 $string = ev_substring($string,"\\(","\\)",\&math_ev3); 1484 $string = ev_substring($string,"\\(","\\)",\&math_ev3);
1455 $string = ev_substring($string,"\\[","\\]",\&display_math_ev3); 1485 $string = ev_substring($string,"\\[","\\]",\&display_math_ev3);
1456 $string; 1486 $string;
1457} 1487}
1458 1488
1489sub EV4{
1490 if ($displayMode eq "HTML_dpng") {
1491 my $string = join(" ",@_);
1492 my ($evaluated_string,$PG_eval_errors,$PG_full_errors) = PG_restricted_eval("<<END_OF_EVALUATION_STRING\n$string\nEND_OF_EVALUATION_STRING\n");
1493 if ($PG_eval_errors) {
1494 my @errorLines = split("\n",$PG_eval_errors);
1495 $string =~ s/</&lt;/g; $string =~ s/>/&gt;/g;
1496 $evaluated_string = "<PRE>$PAR % ERROR in $0:EV3, PGbasicmacros.pl:".
1497 "$PAR % There is an error occuring in the following code:$BR ".
1498 "$string $BR % $mBR % $errorLines[0]\n % $errorLines[1]$BR ".
1499 "% $BR % $BR </PRE> ";
1500 }
1501 $string = $evaluated_string;
1502 $string = $envir{'imagegen'}->add($string);
1503 $string;
1504 } else {
1505 EV3(@_);
1506 }
1507}
1508
1509
1459=head2 Formatting macros 1510=head2 Formatting macros
1460 1511
1461 beginproblem() # generates text listing number and the point value of 1512 beginproblem() # generates text listing number and the point value of
1462 # the problem. It will also print the file name containing 1513 # the problem. It will also print the file name containing
1463 # the problem for users listed in the PRINT_FILE_NAMES_FOR PG_environment 1514 # the problem for users listed in the PRINT_FILE_NAMES_FOR PG_environment
1485=cut 1536=cut
1486 1537
1487sub beginproblem { 1538sub beginproblem {
1488 my $out = ""; 1539 my $out = "";
1489 my $problemValue = $envir->{problemValue}; 1540 my $problemValue = $envir->{problemValue};
1490 my $fileName = $envir->{problemValue}; 1541 my $fileName = $envir->{fileName};
1491 my $probNum = $envir->{probNum}; 1542 my $probNum = $envir->{probNum};
1492 my $TeXFileName = protect_underbar($envir->{fileName}); 1543 my $TeXFileName = protect_underbar($envir->{fileName});
1493 my $l2hFileName = protect_underbar($envir->{fileName}); 1544 my $l2hFileName = protect_underbar($envir->{fileName});
1494 my %inlist; 1545 my %inlist;
1495 my $points ='pts'; 1546 my $points ='pts';
1496 1547
1497 $points = 'pt' if $problemValue == 1; 1548 $points = 'pt' if $problemValue == 1;
1498 ## Prepare header for the problem 1549 ## Prepare header for the problem
1499 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} }); 1550 grep($inlist{$_}++,@{ $envir->{'PRINT_FILE_NAMES_FOR'} });
1500 if ( defined($inlist{$envir->{studentLogin}}) and ($inlist{$envir->{studentLogin}} > 0) ) { 1551 if ( defined($inlist{$envir->{studentLogin}}) and ($inlist{$envir->{studentLogin}} > 0) ) {
1501 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${probNum}.{\\footnotesize ($problemValue $points) $TeXFileName}}\\newline ", 1552 $out = &M3("\n\n\\medskip\\hrule\\smallskip\\par{\\bf ${probNum}.{\\footnotesize ($problemValue $points) $TeXFileName}}\\newline ",
1657 } 1708 }
1658 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1709 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1659 $out .= "<TABLE BORDER=1>\n" 1710 $out .= "<TABLE BORDER=1>\n"
1660 } 1711 }
1661 else { 1712 else {
1662 $out = "Error: PGchoicemacros: begintable: Unknown displayMode: $displayMode.\n"; 1713 $out = "Error: PGbasicmacros: begintable: Unknown displayMode: $displayMode.\n";
1663 } 1714 }
1664 $out; 1715 $out;
1665 } 1716 }
1666 1717
1667sub endtable { 1718sub endtable {
1674 } 1725 }
1675 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') { 1726 elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' ||$displayMode eq 'HTML_img') {
1676 $out .= "</TABLE>\n"; 1727 $out .= "</TABLE>\n";
1677 } 1728 }
1678 else { 1729 else {
1679 $out = "Error: PGchoicemacros: endtable: Unknown displayMode: $displayMode.\n"; 1730 $out = "Error: PGbasicmacros: endtable: Unknown displayMode: $displayMode.\n";
1680 } 1731 }
1681 $out; 1732 $out;
1682 } 1733 }
1683 1734
1684 1735
1706 $out .= "<TD>" . shift(@elements) . "</TD>"; 1757 $out .= "<TD>" . shift(@elements) . "</TD>";
1707 } 1758 }
1708 $out .= "\n</TR>\n"; 1759 $out .= "\n</TR>\n";
1709 } 1760 }
1710 else { 1761 else {
1711 $out = "Error: PGchoicemacros: row: Unknown displayMode: $displayMode.\n"; 1762 $out = "Error: PGbasicmacros: row: Unknown displayMode: $displayMode.\n";
1712 } 1763 }
1713 $out; 1764 $out;
1714} 1765}
1715 1766
1716=head2 Macros for displaying static images 1767=head2 Macros for displaying static images
1791 \\end{rawhtml}\n ! 1842 \\end{rawhtml}\n !
1792 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') { 1843 } elsif ($displayMode eq 'HTML' || $displayMode eq 'HTML_tth' || $displayMode eq 'HTML_dpng' || $displayMode eq 'HTML_img') {
1793 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A> 1844 $out = qq!<A HREF= "$imageURL" TARGET="ZOOM"><IMG SRC="$imageURL" WIDTH="$width" HEIGHT="$height"></A>
1794 ! 1845 !
1795 } else { 1846 } else {
1796 $out = "Error: PGchoicemacros: image: Unknown displayMode: $displayMode.\n"; 1847 $out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
1797 } 1848 }
1798 push(@output_list, $out); 1849 push(@output_list, $out);
1799 } 1850 }
1800 return wantarray ? @output_list : $output_list[0]; 1851 return wantarray ? @output_list : $output_list[0];
1801} 1852}
1883 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>"; 1934 $out .= " <TH>". &caption( shift(@captions) ) ."</TH>";
1884 } 1935 }
1885 $out .= "\n</TR></TABLE></P>\n" 1936 $out .= "\n</TR></TABLE></P>\n"
1886 } 1937 }
1887 else { 1938 else {
1888 $out = "Error: PGchoicemacros: imageRow: Unknown languageMode: $displayMode.\n"; 1939 $out = "Error: PGbasicmacros: imageRow: Unknown languageMode: $displayMode.\n";
1889 warn $out; 1940 warn $out;
1890 } 1941 }
1891 $out; 1942 $out;
1892} 1943}
1893 1944

Legend:
Removed from v.1267  
changed lines
  Added in v.1483

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9