[system] / trunk / webwork / system / courseScripts / PGmatrixmacros.pl Repository:
ViewVC logotype

Diff of /trunk/webwork/system/courseScripts/PGmatrixmacros.pl

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

Revision 845 Revision 846
192 $entry = "#" unless defined($entry); 192 $entry = "#" unless defined($entry);
193 push @{ $myRows[$i] }, $entry; 193 push @{ $myRows[$i] }, $entry;
194 } 194 }
195 } 195 }
196 } else { # matrix is input at [ [1,2,3],[4,5,6]] 196 } else { # matrix is input at [ [1,2,3],[4,5,6]]
197 $numCols = 0;
197 @myRows = @{$ra_matrix}; 198 @myRows = @{$ra_matrix};
198 $numRows = scalar(@myRows); 199 $numRows = scalar(@myRows); # counts horizontal rules too
200 my $tmp;
201 for $tmp (@myRows) {
202 if($tmp ne 'hline') {
199 my @arow = @{$myRows[0]}; 203 my @arow = @{$tmp};
200 $numCols= scalar(@arow); #number of columns in table 204 $numCols= scalar(@arow); #number of columns in table
205 last;
206 }
207 }
201 } 208 }
202 my $out; 209 my $out;
203 my $j; 210 my $j;
204 my $alignString=''; # alignment as a string for dvi/pdf 211 my $alignString=''; # alignment as a string for dvi/pdf
205 my $alignList; # alignment as a list 212 my $alignList; # alignment as a list
218 } 225 }
219 } 226 }
220 227
221 $out .= dm_begin_matrix($alignString, %opts); 228 $out .= dm_begin_matrix($alignString, %opts);
222 $out .= dm_mat_left($numRows, %opts); 229 $out .= dm_mat_left($numRows, %opts);
230 # vertical lines put in with first row
231 $j = shift @myRows;
232 $out .= dm_mat_row($j, $alignList, %opts, 'isfirst'=>$numRows);
223 for $j (@myRows) { 233 for $j (@myRows) {
224 $out .= dm_mat_row($j, $alignList, %opts); 234 $out .= dm_mat_row($j, $alignList, %opts, 'isfirst'=>0);
225 } 235 }
226 $out .= dm_mat_right($numRows, %opts); 236 $out .= dm_mat_right($numRows, %opts);
227 $out .= dm_end_matrix(%opts); 237 $out .= dm_end_matrix(%opts);
228 $out; 238 $out;
229} 239}
377 my $tmp = shift; 387 my $tmp = shift;
378 my @align = @{$tmp} ; 388 my @align = @{$tmp} ;
379 my %opts = @_; 389 my %opts = @_;
380 my @elements = @{$elements}; 390 my @elements = @{$elements};
381 my $out = ""; 391 my $out = "";
392 my ($brh, $erh) = ("",""); # Start and end raw html
393 if($main::displayMode eq 'Latex2HTML') {
394 $brh = " \n\\begin{rawhtml}\n";
395 $erh = " \n\\end{rawhtml}\n";
396 }
382 if ($main::displayMode eq 'TeX' or $opts{'force_tex'}) { 397 if ($main::displayMode eq 'TeX' or $opts{'force_tex'}) {
383 while (@elements) { 398 while (@elements) {
384 $out .= shift(@elements) . " &"; 399 $out .= shift(@elements) . " &";
385 } 400 }
386 chop($out); # remove last & 401 chop($out); # remove last &
387 $out .= "\\cr \n"; 402 $out .= "\\cr \n";
388 # carriage returns must be added manually for tex 403 # carriage returns must be added manually for tex
389 } 404 } elsif ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth'
405 || $main::displayMode eq 'HTML_dpng'
390 elsif ($main::displayMode eq 'Latex2HTML') { 406 || $main::displayMode eq 'Latex2HTML') {
391 $out .= "\n\\begin{rawhtml}\n<TR>\n\\end{rawhtml}\n";
392 while (@elements) {
393 $out .= " \n\\begin{rawhtml}\n<TD> \n\\end{rawhtml}\n" . shift(@elements) . " \n\\begin{rawhtml}\n</TD> \n\\end{rawhtml}\n";
394 }
395 $out .= " \n\\begin{rawhtml}\n</TR> \n\\end{rawhtml}\n";
396 }
397 elsif ($main::displayMode eq 'HTML' || $main::displayMode eq 'HTML_tth' || $main::displayMode eq 'HTML_dpng') {
398 $out .= "<TR><td nowrap=\"nowrap\">\n"; 407 $out .= "$brh<TR><td nowrap=\"nowrap\">\n$erh";
399 while (@elements) { 408 while (@elements) {
400 my $myalign; 409 my $myalign;
401 #do {$myalign = shift @align;} until($myalign ne "|");
402 $myalign = shift @align; 410 $myalign = shift @align;
403 if($myalign eq "|") { 411 if($myalign eq "|") {
412 if($opts{'isfirst'} && $main::displayMode ne 'HTML_tth') {
413 $out .= $brh.'<td rowspan="'.$opts{'isfirst'}.'">'.$erh;
414 $out .= dm_image_delimeter($opts{'isfirst'}, "|");
415 } elsif($main::displayMode eq 'HTML_tth') {
404 $out .= '<td> | </td>'; 416 $out .= '<td> | </td>';
417 }
405 } else { 418 } else {
406 if($myalign eq "c") { $myalign = "center";} 419 if($myalign eq "c") { $myalign = "center";}
407 if($myalign eq "l") { $myalign = "left";} 420 if($myalign eq "l") { $myalign = "left";}
408 if($myalign eq "r") { $myalign = "right";} 421 if($myalign eq "r") { $myalign = "right";}
409 $out .= "<TD nowrap=\"nowrap\" align=\"$myalign\">" . shift(@elements) . "</TD>"; 422 $out .= "$brh<TD nowrap=\"nowrap\" align=\"$myalign\">$erh" . shift(@elements) . "$brh</TD>$erh";
410 } 423 }
411 } 424 }
412 $out .= "<td>\n</TR>\n"; 425 $out .= "$brh<td>\n</TR>\n$erh";
413 } 426 }
414 else { 427 else {
415 $out = "Error: dm_mat_row: Unknown displayMode: $main::displayMode.\n"; 428 $out = "Error: dm_mat_row: Unknown displayMode: $main::displayMode.\n";
416 } 429 }
417 $out; 430 $out;
426 'valign' => 'middle', 439 'valign' => 'middle',
427 'allowbreaks' => 'no', 440 'allowbreaks' => 'no',
428 'allow_unknown_options'=> 0); 441 'allow_unknown_options'=> 0);
429 my $out = ""; 442 my $out = "";
430 my $j; 443 my $j;
444 my $l2h = ($main::displayMode eq 'Latex2HTML') ? 1 : 0;
431 my @hlist = @{$inList}; 445 my @hlist = @{$inList};
432 if($main::displayMode eq 'TeX') { 446 if($main::displayMode eq 'TeX') {
433 for $j (@hlist) { $out .= $j;} 447 for $j (@hlist) { $out .= $j;}
434 } else { 448 } else {
449 $out .= $l2h ? "\n\\begin{rawhtml}\n" : '';
435 $out = qq!<table><tr valign="$opts{'valign'}">!; 450 $out .= qq!<table><tr valign="$opts{'valign'}">!;
436 for $j (@hlist) { $out .= "<td>$j</td>";} 451 $out .= $l2h ? "\n\\end{rawhtml}\n" : '';
452 for $j (@hlist) {
453 $out .= $l2h ? "\n\\begin{rawhtml}\n<td>\n\\end{rawhtml}\n" : "<td>";
454 $out .= "$j";
455 $out .= $l2h ? "\n\\begin{rawhtml}\n</td>\n\\end{rawhtml}\n" : "</td>";
456 }
457 $out .= $l2h ? "\n\\begin{rawhtml}\n" : '';
437 $out .= "</table>"; 458 $out .= "</table>";
459 $out .= $l2h ? "\n\\end{rawhtml}\n" : '';
438 } 460 }
439 return $out; 461 return $out;
440} 462}
441 463
442 464

Legend:
Removed from v.845  
changed lines
  Added in v.846

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9