ods2latex convert OpenDocument Spreadsheet to LaTeX tables
doc generated from the script with gendoc
ruby script, version=1.00

Synopsis

ods2latex [options] odsfile [outputfile]

Options:

-f,--format=STR
output format, one of:
ctable longtable longtablex |tabs| is the default.
-s,--specs=STR
column specs, space separated, last one repeated
as needed. default: C for tabulary, else X, if possible, else c.
-c,--caption=STR
set caption to STR
-l,--label=STR
set label to STR
-i,--info=CODE
CODE=clfs12 says: caption, label, format and specs
in row 12 (default 1), in that order
-a,--article
create compilable article document
-r,--rotate
rotate the printing page to landscape
-t,--thinrules
separate rows with thin rules
-h,--help
print this help and exit
-v,--verbose
set verbosity one level higher
-V,--version
print version and exit

Description

ods2latex considers each sheet of an Open Document Spreadsheet to be a table, which is associated with four parameters:

caption
a caption to be placed on top of the table
label
a label used to reference the table.
specs
column specifications for the table (c l r et cetera)
format
format of the table (tabular, ctable, longtable and more,
see --help)

Using these parameters, ods2latex converts each sheet into a LaTeX table. The output appears on standard output or on the specified output file and can optionally be surrounded by a preamble and a postamble such that the result can be compiled with LaTeX.

Multiline cells

Lines in multiline cells are joined to a single line. For the tabs format, a bar (|) is used as a separator between the lines, for LaTeX formats the string \\ is used, and the resulting line is surrounded by \Tbl{...}. For proper compilation, the macro \Tbl should be defined as:
  \def\Tbl#1{\begin{tabular}[t]{@{}l@{}}#1\end{tabular}}

X Columns

If more than one of the X columns are detected in the column specification, then the X‘s will be prefixed with >{\H{0.nnn}}X, where 0.nnn is the reciprocal of the number of X-columns. This is to make it easy to adapt the width of each X-column by manual editing. Note that the sum of all 0.nnn should be (about) 1. For proper compilation, the \H macro must be defined as:

   \def\H#1{\hsize=#1\hsize\raggedright}

Option specification

The most important formatting options mentioned above that is: those having an argument named STR, can be specified in two different ways:

Options

--format=STR
STR specifies the LaTeX table that will be produced. The section Option specification is applicable for this option. Choices are:
  tabs
This is the only non-LaTeX format: it simply outputs a tab- separated file. Although the other options have no meaning for this format, they may be used to remove formatting rows from the table.
  tabular
Generates the simplest LaTeX table: a tabular environment. The default is to have a c column specification for all colomns. Other specifier can be used, as long as the specifier does not itself contain a space, such as in @{␣}: remember that the space would make this two specifiers: @{ and }. If you want such specifiers, you will have to edit the output. For more information see
http://mirror.ctan.org/help/Catalogue/entries/array.html
  tabularx
Generates a table in a tabularx environment. Its width is set to \textwidth. This width is reached by making the last column wider than needed, unless X columns are specified. You will have to adjust the X column width manually by adjusting their >{\H{0.nnn}} prefixes. For more information, see the tabularx documentation:
http://mirror.ctan.org/help/Catalogue/entries/tabularx.html
  tabulary
Generates a table in a tabulary environment. Its width is set to \textwidth. This width is reached by automatic adjustment of any C, L, R, and J columns, depending on the contents of the table. For more information, see the tabulary documentation:
http://mirror.ctan.org/help/Catalogue/entries/tabulary.html
  longtable
Generates a multipage table in a longtable environment. No X xolumns allowed. For more information see:
http://mirror.ctan.org/help/Catalogue/entries/longtable.html
  longtablex
Generates a multipage table in a longtablex environment: the same as longtable, but X columns can be used. For more information see:
mirror.ctan.org/help/Catalogue/entries/longtablex.html
      ctable
A ctable-command is generated, which is, effectively, a floating tabular or tabularx. If X column specifiers are detected, the ctable-option width=\textwidth will be added. See the ctable documentation for more information:
http://mirror.ctan.org/macros/latex/contrib/ctable/ctable.pdf
--specs=STR
The section Option specification is applicable for this option. STR must contain space-separated column specifiers, one for each column or less. If there are less specifiers than columns, the last specifier is repeated. More specifiers than column result in an error.
--label=STR
The section Option specification is applicable for this option. If this option is set, a \label{...} statement will appear in the output.
--caption=STR
The section Option specification is applicable for this option. If this option is set, a \caption{...} statement will appear in the output for floats and longtables. In other cases, the string will be centered on the page, just before the table.
--info=CODE
When your formatting specifiers are in your ods-file, and you are tired of specifying many options like -c␣1,2, then this your rescue. An option like -i␣clsf12 is equivalent to -c␣12,1␣-l 12,2␣-s␣12,3␣-f␣12,4. That is, the values for the options caption, label, specs, format are found in the first four cells of row 12.
--article
Output an article containing all tables, ready for compilation by pdfLaTeX.
--rotate
Rotate the paper so that the table is printed in landscape direction. In your final document you can, of course, rotate the table, but rotating the paper is more useful for demonstration purposes.
--thinrules
Draw thin rules between rows that would otherwise not be separated with a rule. Useful for tables with many multiline cells.
--help
Print this help, then exit.
--verbose
Set verbositiy level one higher.
--Version
Print version, then exit.

Examples

Suppose we have an OpenDocument Spreadsheet test.ods with these contents:

   ┌─────────┬───────────┬────────┬────────┐
   │ mylabel │ mycaption │ ctable │ l X    │
   ├─────────┼───────────┼────────┼────────┤
   │ l       │ X         │ X      │ X      │
   ├─────────┼───────────┼────────┼────────┤
   │         │ head2a    │ head3a │        │
   │ head1   │ head2b    │ head3b │ head4  │
   ├─────────┼───────────┼────────┼────────┤
   │         │ row12a    │ row13a │        │
   │ row11   │ row12b    │ row13b │ row14  │
   ├─────────┼───────────┼────────┼────────┤
   │ row21a  │           │        │ row24a │
   │ row21b  │ row22     │ row23  │ row23b │
   └─────────┴───────────┴────────┴────────┘

ods2latex will, without any options, produce tab-separated ASCII output:

   $ ods2latex test
   %====== Sheet: Sheet1 5 rows, 4 columns =======
   mylabel      mycaption       ctable  l X
   l    X       X       X
   head1        head2a|head2b   head3a|head3b   head4
   row11        row12a|row12b   row13a|row13b   row14
   row21a|row21b        row22   row23   row24a|row24b

The output is not easily readable, as severall cells are wider than than the 8 spaces for a tab. This cn be solved by piping the output through expand:

   $ ods2latex test |expand -20
   %====== Sheet: Sheet1 5 rows, 4 columns =======
   mylabel             mycaption           ctable              l X
   l                   X                   X                   X
   head1               head2a|head2b       head3a|head3b       head4
   row11               row12a|row12b       row13a|row13b       row14
   row21a|row21b       row22               row23               row24a|row24b

Apparently, label, caption, table format and colspecs are in the first row of the table. For testing purposes, the colspecs are repeated in the second row, one spec per column. The most complex way to use the information in the first row would be:

   $ ods2latex --label=1,1 --caption=1,2 --format=1,3 --specs=1,4 test

However, as the second row is not used, it would appear in the output. So it‘s better to specify the colspecs to be in the second row. Also, the output not be compilable with pdflatex, so it‘s better to add the --article option:

   $ ods2latex --label=1,1 --caption=1,2 --format=1,3 --specs=2 --article test

   Skipping rows 1,2
   %====== Sheet: Sheet1 3 rows, 4 columns =======
   \documentclass[english]{article}
   \usepackage{ucs}\usepackage[utf8x]{inputenc}
   \usepackage[a4paper,margin=20mm,noheadfoot]{geometry}
   \usepackage{ctable}
   \usepackage{babel}
   \def\Tbl#1{\begin{tabular}[t]{@{}l@{}}#1\end{tabular}}
   \def\H#1{\hsize=#1\hsize\raggedright}
   \pagestyle{empty}
   \begin{document}
   \ctable[
     caption={mycaption},
       label={mylabel},
       width=\textwidth
   ]{
     l
     >{\H{0.333}}X
     >{\H{0.333}}X
     >{\H{0.333}}X
   }{}{
     \FL
       head1
       & \Tbl{head2a\\head2b}
       & \Tbl{head3a\\head3b}
       & head4
     \ML
       row11
       & \Tbl{row12a\\row12b}
       & \Tbl{row13a\\row13b}
       & row14
     \NN
       \Tbl{row21a\\row21b}
       & row22
       & row23
       & \Tbl{row24a\\row24b}
     \LL
   }
   \clearpage
   \end{document}

Using short options would make easier typing:

   $ ods2latex -l 1,1 -c 1,2 -f 1,3 -s 2 -a test

But it can be done shorter, by using the --info (shorter: -i) option:

   $ ods2latex -a -i lcf -s 2 test

If the second row would not be there (you would not normally specify things twice) this could become (note that short options without arguments can be combined):

   $ ods2latex -ai lcf -s 2 test

The argument of -i (here lcf) should normally be suffixed with the row number, but since its default is 1, it can be left out here.

If one often makes use of ods2latex, then it would be wise to adhere to a standard way of placing formatting specifications in the OpenDocument spreadsheet and define an alias. For eample, if label, caption, colspecs and table format are always in the first row, in that order, then add the following line to your .bashrc file:

    alias co="ods2latex --info=lcsf"

and run:

    $ source  ~/.bashrc

(or log out and in again). Now a simple

    $ co test -a >test.tex

would be enough to generate a complete latex source.

Finally: one can also refrain from adding extra‘s to the spreadsheet and do it all on the command line:

    $ ods2latex --caption='My caption' --label=mylabel --format=ctable \
        --specs='l X' --article test

or, shorter:

    $ ods2latex c 'My caption' -l mylabel -f ctable -s 'l X' test

Author

Wybo Dekker

Copyright

Released under the GNU General Public License