leto/math--matrixreal — Issue #1: displaymath mode for as_latex
Author: leto
Created: 2011-10-31 16:42:33+00:00
State: open

Here is a new feature suggestion + patch from Xavier Taixés

```perl
Hi,

I modified slightly the funcion as_latex to add a new possibiliy: having the matrix in a displaymath mode. You can check it's a small change, just change \$ with \\[, when the value displaymath is 1.

Perhaps you want to include this modification in your package...

Wishes,

Xavier

sub as_latex{
my ($m) = shift;
my %args = (
format => "%s",
name => "",
align => "c",
displaymath => "0",
@_);

my ($row,$col) = $m->dim;
my $inside;
my $s = <each(
sub { my($x,$i,$j)=@_;

$x = sprintf($args{format},$x);

# last element in each row gets a \\
if ($j == $col && $i != $row){
$inside .= "$x \\\\"."\n";
# the annoying last line has neither
} elsif( $j == $col && $i == $row){
$inside .= "$x\n";
} else {
$inside .= "$x&";
}
}
);
if($args{displaymath}){
$s = "\\[".$s."\\]";
} else {
$s = "\$".$s."\$";
}
$s =~ s/%INSIDE%/$inside/gm;
return $s;
}
```