Logo
IT Dienstleistungen

CSV2latex

Ever wanted to use OpenOffice calc sheets as a table in a latex document? Here's the KDE4 variant of an older script from here

#!/bin/bash
# calc2latex: Clipboard format exchange KDE SC 4 version 
# Manuel Krischer, March 2010 
# (kde3 original http://www.molspaces.com/d_misc1.php)
# Pere Constans, Mar 6 2004 (uses csv2latex, by Benoit Rouits)
# http://dries.ulyssis.org/rpm/packages/csv2latex/info.html
# with help from
# http://milianw.de/code-snippets/access-klipper-clipboard-on-cli-under-kde4
 
# catch csv table from kde4 klipper and make tmp file
dbus-send --print-reply --dest=org.kde.klipper /klipper org.kde.klipper.klipper.getClipboardContents | awk '
      BEGIN { output = ""; }
      {
        if ( NR > 1 ) {
          output = output $0 "\n";
        }
      }
      END {
        print substr(output, 12, length(output) - 13);
      }' | sed 's%\t%;%g' > /tmp/csv2latex.tmp
 
# convert csv table to latex
TABLE=`csv2latex --nohead --separator s /tmp/csv2latex.tmp | grep -v "\end{document}"`
 
# remove tmp file
rm /tmp/csv2latex.tmp
 
# post latex to klipper
dbus-send --type=method_call --dest=org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents string:"$TABLE"
 
# notify user
notify-send "calc2latex" "converted clipboard to a latex table, paste it now."
echo calc2latex: converted clipboard to a latex table, paste it now.
  • 2010/03/03 14:08 Seems not to work right now as a whole but with single steps. debug later

Seiten-Werkzeuge