[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 1390 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
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');
124 126 %main::STICKY_ANSWERS = ();
125 127
126 128
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
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
306sub NAMED_ANS_RULE_EXTENSION { 309sub NAMED_ANS_RULE_EXTENSION {
307 my($name,$col) = @_; 310 my($name,$col) = @_;
308 my $len = 0.07*$col; 311 my $len = 0.07*$col;
309 my $answer_value = ''; 312 my $answer_value = '';
310 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name}); 313 $answer_value = ${$inputs_ref}{$name} if defined(${$inputs_ref}{$name});
311 if ( defined(PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)) ) { 314 if ( defined( $rh_sticky_answers->{$name} ) ) {
312 $answer_value = shift( @{PG_restricted_eval(q!$main::rh_sticky_answers{$name}!)}); 315 $answer_value = shift( @{ $rh_sticky_answers->{$name} });
313 $answer_value = '' unless defined($answer_value); 316 $answer_value = '' unless defined($answer_value);
314 } 317 }
315 $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
316 MODES( 319 MODES(
317 TeX => '\\hrulefill\\quad ', 320 TeX => '\\hrulefill\\quad ',
578 NAMED_ANS_RULE($name ,$len); 581 NAMED_ANS_RULE($name ,$len);
579} 582}
580sub ans_rule_extension { 583sub ans_rule_extension {
581 my $len = shift; 584 my $len = shift;
582 $len = 20 unless $len ; 585 $len = 20 unless $len ;
583 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
584 NAMED_ANS_RULE($name ,$len); 587 NAMED_ANS_RULE($name ,$len);
585} 588}
586sub ans_radio_buttons { 589sub ans_radio_buttons {
587 my $name = NEW_ANS_NAME(inc_ans_rule_count()); 590 my $name = NEW_ANS_NAME(inc_ans_rule_count());
588 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_); 591 my @radio_buttons = NAMED_ANS_RADIO_BUTTONS($name, @_);
629 $out; 632 $out;
630} 633}
631sub tex_ans_rule_extension { 634sub tex_ans_rule_extension {
632 my $len = shift; 635 my $len = shift;
633 $len = 20 unless $len ; 636 $len = 20 unless $len ;
634 my $name = NEW_ANS_NAME(PG_restricted_eval(q!$main::ans_rule_count!)); 637 my $name = NEW_ANS_NAME($$r_ans_rule_count);
635 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.
636 my $out = MODES( 639 my $out = MODES(
637 'TeX' => $answer_rule, 640 'TeX' => $answer_rule,
638 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}', 641 'Latex2HTML' => '\fbox{Answer boxes cannot be placed inside typeset equations}',
639 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}', 642 'HTML_tth' => '\\begin{rawhtml} '. $answer_rule.'\\end{rawhtml}',

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9