[system] / trunk / pg / lib / Value / AnswerChecker.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Value/AnswerChecker.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3272 Revision 3273
293 return $self->format_matrix_HTML(@_); 293 return $self->format_matrix_HTML(@_);
294} 294}
295 295
296sub format_matrix_tex { 296sub format_matrix_tex {
297 my $self = shift; my $array = shift; 297 my $self = shift; my $array = shift;
298 my %options = {open=>'',close=>'',sep=>'',@_}; 298 my %options = (open=>'.',close=>'.',sep=>'',@_);
299 $self->{format_options} = [%options] unless $self->{format_options}; 299 $self->{format_options} = [%options] unless $self->{format_options};
300 my ($open,$close,$sep) = ($options{open},$options{close},$options{sep}); 300 my ($open,$close,$sep) = ($options{open},$options{close},$options{sep});
301 my ($rows,$cols) = (scalar(@{$array}),scalar(@{$array->[0]})); 301 my ($rows,$cols) = (scalar(@{$array}),scalar(@{$array->[0]}));
302 my $tex = ""; 302 my $tex = "";
303 $open = '\\'.$open if $open =~ m/[{}]/; $close = '\\'.$close if $close =~ m/[{}]/;
304 $tex .= '\(\left'.$open;
305 $tex .= '\setlength{\arraycolsep}{2pt}', $sep = '\,'.$sep if $sep;
303 $tex .= '\left'.$open.'\begin{array}{'.('c'x$cols).'}'; 306 $tex .= '\begin{array}{'.('c'x$cols).'}';
304 foreach my $i (0..$rows-1) {$tex .= join('&',@{$array->[$i]}).'\\'."\n"} 307 foreach my $i (0..$rows-1) {$tex .= join($sep.'&',@{$array->[$i]}).'\cr'."\n"}
305 $tex .= '\end{array}\right'.$close; 308 $tex .= '\end{array}\right'.$close.'\)';
306 return $tex; 309 return $tex;
307} 310}
308 311
309sub format_matrix_HTML { 312sub format_matrix_HTML {
310 my $self = shift; my $array = shift; 313 my $self = shift; my $array = shift;
334 } 337 }
335 return '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" CLASS="ArrayLayout"' 338 return '<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" CLASS="ArrayLayout"'
336 . ' STYLE="display:inline;vertical-align:-'.(1.1*$rows-.6).'em">' 339 . ' STYLE="display:inline;vertical-align:-'.(1.1*$rows-.6).'em">'
337 . $HTML 340 . $HTML
338 . '</TABLE>'; 341 . '</TABLE>';
342}
343
344sub VERBATIM {
345 my $string = shift;
346 my $displayMode = Value->getPG('$displayMode');
347 $string = '\end{verbatim}'.$string.'\begin{verbatim}' if $displayMode eq 'TeX';
348 return $string;
339} 349}
340 350
341# 351#
342# Create a tall delimiter to match the line height 352# Create a tall delimiter to match the line height
343# 353#
587} 597}
588 598
589sub correct_ans { 599sub correct_ans {
590 my $self = shift; 600 my $self = shift;
591 return $self->SUPER::correct_ans unless $self->{ans_name}; 601 return $self->SUPER::correct_ans unless $self->{ans_name};
592 return $self->format_matrix([[@{$self->{data}}]],@{$self->{format_options}},tth_delims=>1); 602 Value::VERBATIM($self->format_matrix([[@{$self->{data}}]],@{$self->{format_options}},tth_delims=>1));
593} 603}
594 604
595sub ANS_MATRIX { 605sub ANS_MATRIX {
596 my $self = shift; 606 my $self = shift;
597 my $extend = shift; my $name = shift; 607 my $extend = shift; my $name = shift;
654} 664}
655 665
656sub correct_ans { 666sub correct_ans {
657 my $self = shift; 667 my $self = shift;
658 return $self->SUPER::correct_ans unless $self->{ans_name}; 668 return $self->SUPER::correct_ans unless $self->{ans_name};
659 return $self->format_matrix([[$self->value]],@{$self->{format_options}},tth_delims=>1) 669 return Value::VERBATIM($self->format_matrix([[$self->value]],@{$self->{format_options}},tth_delims=>1))
660 unless $self->{ColumnVector}; 670 unless $self->{ColumnVector};
661 my @array = (); foreach my $x ($self->value) {push(@array,[$x])} 671 my @array = (); foreach my $x ($self->value) {push(@array,[$x])}
662 return $self->format_matrix([@array],@{$self->{format_options}},tth_delims=>1); 672 return Value::VERBATIM($self->format_matrix([@array],@{$self->{format_options}},tth_delims=>1));
663} 673}
664 674
665sub ANS_MATRIX { 675sub ANS_MATRIX {
666 my $self = shift; 676 my $self = shift;
667 my $extend = shift; my $name = shift; 677 my $extend = shift; my $name = shift;
720 730
721sub correct_ans { 731sub correct_ans {
722 my $self = shift; 732 my $self = shift;
723 return $self->SUPER::correct_ans unless $self->{ans_name}; 733 return $self->SUPER::correct_ans unless $self->{ans_name};
724 my @array = $self->value; @array = ([@array]) if $self->isRow; 734 my @array = $self->value; @array = ([@array]) if $self->isRow;
725 return $self->format_matrix([$self->value],@{$self->{format_options}},tth_delims=>1); 735 Value::VERBATIM($self->format_matrix([$self->value],@{$self->{format_options}},tth_delims=>1));
726} 736}
727 737
728sub ANS_MATRIX { 738sub ANS_MATRIX {
729 my $self = shift; 739 my $self = shift;
730 my $extend = shift; my $name = shift; 740 my $extend = shift; my $name = shift;
1197 } else { 1207 } else {
1198 foreach my $x (@{$self->{tree}{coords}}) {push(@array,$x->string)} 1208 foreach my $x (@{$self->{tree}{coords}}) {push(@array,$x->string)}
1199 if ($self->{tree}{ColumnVector}) {foreach my $x (@array) {$x = [$x]}} 1209 if ($self->{tree}{ColumnVector}) {foreach my $x (@array) {$x = [$x]}}
1200 else {@array = [@array]} 1210 else {@array = [@array]}
1201 } 1211 }
1202 return $self->format_matrix([@array],@{$self->{format_options}},tth_delims=>1); 1212 Value::VERBATIM($self->format_matrix([@array],@{$self->{format_options}},tth_delims=>1));
1203} 1213}
1204 1214
1205# 1215#
1206# Get the size of the array and create the appropriate answer array 1216# Get the size of the array and create the appropriate answer array
1207# 1217#

Legend:
Removed from v.3272  
changed lines
  Added in v.3273

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9