Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve as_latex rendering, courtesy of a patch from Xavier Taixés. F…

…ixes #1
  • Loading branch information...
commit 30a89d227896b835c9d95eb34b2800e713e29cfc 1 parent a9d3f98
@leto authored
Showing with 20 additions and 16 deletions.
  1. +16 −12 lib/Math/MatrixReal.pm
  2. +4 −4 t/latex.t
View
28 lib/Math/MatrixReal.pm
@@ -2666,23 +2666,22 @@ sub as_yacas{
return $s;
}
-#TODO: any ideas for a good test?
+
sub as_latex{
my ($m) = shift;
- my %args = (
- format => "%s",
- name => "",
- align => "c",
- @_);
+ my %args = (
+ format => "%s",
+ name => "",
+ align => "c",
+ display_math => 0,
+ @_);
my ($row,$col) = $m->dim;
my $inside;
my $s = <<LATEX;
-\$
\\left( \\begin{array}{%COLS%}
%INSIDE%\\end{array} \\right)
-\$
LATEX
$args{align} = lc $args{align};
if( $args{align} !~ m/^(c|l|r)$/ ){
@@ -2692,11 +2691,11 @@ LATEX
$s =~ s/%COLS%/$args{align} x $col/em;
if( $args{name} ){
- $s = "\$$args{name} = \$ " . $s;
+ $s = "$args{name} = $s";
}
$m->each(
- sub { my($x,$i,$j)=@_;
-
+ sub {
+ my ($x,$i,$j) = @_;
$x = sprintf($args{format},$x);
# last element in each row gets a \\
@@ -2710,6 +2709,11 @@ LATEX
}
}
);
+ if($args{displaymath}){
+ $s = "\\[$s\\]";
+ } else {
+ $s = "\$$s\$";
+ }
$s =~ s/%INSIDE%/$inside/gm;
return $s;
}
@@ -3197,7 +3201,7 @@ sub _clone
$temp->_undo_LR();
return $temp;
}
-42;
+{ no warnings; 42 }
__END__
View
8 t/latex.t
@@ -8,14 +8,14 @@ do 'funcs.pl';
{
my $latex1=<<'LATEX';
-$
-\left( \begin{array}{cc}
+$\left( \begin{array}{cc}
1.41e-05&1 \\
6.82e-06&3 \\
3.18e-06&4
\end{array} \right)
$
LATEX
+chomp $latex1;
my $a = Math::MatrixReal->new_from_cols([[ 1.41E-05, 6.82E-06, 3.18E-06 ],[1,3,4]]);
@@ -23,14 +23,14 @@ LATEX
}
{
my $latex2=<<'LATEX';
-$A = $ $
-\left( \begin{array}{ll}
+$A = \left( \begin{array}{ll}
1.23&1.00 \\
5.68&2.00 \\
9.10&3.00
\end{array} \right)
$
LATEX
+chomp $latex2;
my $b = Math::MatrixReal->new_from_cols([[ 1.234, 5.678, 9.1011],[1,2,3]] );
my $s = $b->as_latex( ( format => "%.2f", align => "l",name => "A" ) );
Please sign in to comment.
Something went wrong with that request. Please try again.