[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 1119 Revision 1120
679 my @list = @_; 679 my @list = @_;
680 my $name = NEW_ANS_NAME(++$main::ans_rule_count); # get new answer name 680 my $name = NEW_ANS_NAME(++$main::ans_rule_count); # get new answer name
681 NAMED_POP_UP_LIST($name, @list); 681 NAMED_POP_UP_LIST($name, @list);
682} 682}
683 683
684
685
686=head5 answer_matrix
687
688 Usage \[ \{ answer_matrix(rows,columns,width_of_ans_rule, @options) \} \]
689
690 Creates an array of answer blanks and passes it to display_matrix which returns
691 text which represents the matrix in TeX format used in math display mode. Answers
692 are then passed back to whatever answer evaluators you write at the end of the problem.
693 (note, if you have an m x n matrix, you will need mn answer evaluators, and they will be
694 returned to the evaluaters starting in the top left hand corner and proceed to the left
695 and then at the end moving down one row, just as you would read them.)
696
697 The options are passed on to display_matrix.
698
699
700=cut
701
702
703sub answer_matrix{
704 my $m = shift;
705 my $n = shift;
706 my $width = shift;
707 my @options = @_;
708 my @array=();
709 for( my $i = 0; $i < $m; $i+=1)
710 {
711 my @row_array = ();
712
713 for( my $i = 0; $i < $n; $i+=1)
714 {
715 push @row_array, ans_rule($width);
716 }
717 my $r_row_array = \@row_array;
718 push @array, $r_row_array;
719 }
720 display_matrix( \@array, @options );
721
722}
723
724sub NAMED_ANS_ARRAY_EXTENSION{
725
726 my $name = shift;
727 my $col = shift;
728 $col = 20 unless $col;
729 my $answer_value = '';
730
731 $answer_value = ${$main::inputs_ref}{$name} if defined(${$main::inputs_ref}{$name});
732 if ($answer_value =~ /\0/ ) {
733 my @answers = split("\0", $answer_value);
734 $answer_value = shift(@answers);
735 $answer_value= '' unless defined($answer_value);
736 } elsif (ref($answer_value) eq 'ARRAY') {
737 my @answers = @{ $answer_value};
738 $answer_value = shift(@answers);
739 $answer_value= '' unless defined($answer_value);
740 }
741
742 $answer_value =~ tr/$@`//d; ## make sure student answers can not be interpolated by e.g. EV3
743 MODES(
744 TeX => "\\mbox{\\parbox[t]{10pt}{\\hrulefill}}\\hrulefill\\quad ",
745 Latex2HTML => qq!\\begin{rawhtml}\n<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"\">\n\\end{rawhtml}\n!,
746 HTML => "<INPUT TYPE=TEXT SIZE=$col NAME=\"$name\" VALUE = \"$answer_value\">\n"
747 );
748}
749
750sub ans_array{
751 my $m = shift;
752 my $n = shift;
753 my $col = shift;
754 $col = 20 unless $col;
755 my $num = ++$main::ans_rule_count ;
756 my $name = NEW_ANS_ARRAY_NAME($num,0,0);
757 my @options = @_;
758 my @array=();
759 my $string;
760 my $answer_value = "";
761
762 $array[0][0] = NAMED_ANS_RULE($name,$col);
763
764 for( my $i = 1; $i < $n; $i+=1)
765 {
766 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,0,$i);
767 $array[0][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
768
769 }
770
771 for( my $j = 1; $j < $m; $j+=1 ){
772
773 for( my $i = 0; $i < $n; $i+=1)
774 {
775 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
776 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
777
778 }
779
780 }
781 display_matrix( \@array, @options );
782
783}
784
785sub ans_array_extension{
786 my $m = shift;
787 my $n = shift;
788 my $col = shift;
789 $col = 20 unless $col;
790 my $num = $main::ans_rule_count;
791 my @options = @_;
792 my $name;
793 my @array=();
794 my $string;
795 my $answer_value = "";
796
797 for( my $j = 0; $j < $m; $j+=1 ){
798
799 for( my $i = 0; $i < $n; $i+=1)
800 {
801 $name = NEW_ANS_ARRAY_NAME_EXTENSION($num,$j,$i);
802 $array[$j][$i] = NAMED_ANS_ARRAY_EXTENSION($name,$col);
803
804 }
805
806 }
807 display_matrix( \@array, @options );
808
809}
810
811
684# end answer blank macros 812# end answer blank macros
685 813
686=head2 Hints and solutions macros 814=head2 Hints and solutions macros
687 815
688 solution('text','text2',...); 816 solution('text','text2',...);

Legend:
Removed from v.1119  
changed lines
  Added in v.1120

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9