Ragnar Beer <[EMAIL PROTECTED]> writes:

> Howdy again!
> 

> I need to create a 20x20 correlation table. Last time I did this
> with cuts and pastes. (That was a smaller table in case you question
> my IQ ;) I wonder if there is an easier way to get the table if I've
> got a file with the coefficients in a tab delimited form anyway.

This shoud convert you file in a latex tabular environment:

#!/usr/bin/perl
# mkltxtab: converts an IFS-delimited file into a LaTeX tabular
# usage: IFS='\s+' mkltxtab mytable.dat > mytable.tex
$max = 0;
while(<>) {
    chomp;
    @row = split /$ENV{IFS}/;
    push @data, [ @row ];
    $max = @row if @row > $max;
}
print STDERR "Read ".(scalar @data)." rows with at most $max elements\n";
print "\\begin{tabular}{" . ("c"x$max) . "}\n";
for (@data) {
    print join " & ", @{$_};
    print "&"x($max-@{$_});
    print "\\\\\n";
}
print "\\end{tabular}\n";

Save it into a file and make that executable, then run the program as
in the `usage` line above. The IFS bit tells the program what to use
to separate fields (rows are assumed to be separated by newline).
It is a Perl regex. For instance:
  IFS=' ' a space
  IFS=',\s*' comma followed by 0 or more spaces
  IFS='\t' a tab
and so on...

Then you need to make the file available from within LyX. The easiest
way is to use the include feature (Insert > Include File).

I only have tested the program on a simple file but it appears to
work. You can also have different numbers of entries on each line.

-- 
Stefano Ghirlanda, Zoologiska Institutionen, Stockholms Universitet
  email: you know it already, tel: +46-8-164055, fax:+46-8-167715
 the free science campaign: http://ethology.zool.su.se/freescience

Reply via email to