#! /usr/bin/perl

# Read in a .csv (comma separated variable) spreadsheet, write it out 
# STDOUT in TeXmacs format.
#
# This is a quick hack and not intended to solve all of the world's 
# table conversion problems.
#
# Typical usage
# $ csv2texmacs table filename.csv > filename.tm
#
# Use Emacs or a similar text editor to include it into a TeXmacs file.

printf("<block");
printf("|<tformat");
printf("|<table");

while ($line = <>) {
    chomp($line); # get rid of training newline character
    @row = split(",", $line);

    printf("|<row");

    foreach $cell (@row) {
        printf("|<cell|%s>", $cell);
    }

    printf(">"); # row

}

printf(">"); # table 
printf(">"); # tformat
printf(">"); # block

printf("\n\n"); # put an empty line after the table
