Saturday, May 23, 2009

announcing latex-table

Latex-table is a simple Common Lisp library for writing vectors and matrices into LaTeX tables. It won't allow you to do anything magical that you could not do in LaTeX otherwise, but it simplifies formatting (mostly numerical) tables. Floats are aligned on the decimal dot. Some examples:
(with-open-file (stream "/tmp/horizontal.table" :direction :output
   :if-exists :overwrite :if-does-not-exist :create)
  (labeled-vector-horizontal stream 
        (vector "foo" pi -42)
        (vector "$\\alpha$" "bar" "baz")
        :significant-digits 3))
(with-open-file (stream "/tmp/matrix.table" :direction :output
   :if-exists :overwrite :if-does-not-exist :create)
  (labeled-matrix stream #2A((11.1 112.55 3)
        (9 1345.79 14.72))
    (vector "foo" "bar" "baz")
    (vector "first" "second")
    :hlines '(1 2 -1 1)))
All of these functions use the "raw" interface below, which you can also use directly.
(with-open-file (stream "/tmp/raw.table" :direction :output
   :if-exists :overwrite :if-does-not-exist :create)
  (raw-tabular stream #2A(((:aligned "foo" ""))
     ((:aligned "bar" "baz"))
     ((:aligned "" ".19"))
     ((:left "left"))
     ((:right "right"))
     ((:center "center")))
        #(:aligned)  ; column types
        #(0 0)   ; vertical lines
        #(1 2 0 0 0 0 3))) ; horizontal lines

3 comments:

  1. How well does it work across page boundaries?

    ReplyDelete
  2. That you have to handle in LaTeX, by using packages that provide tabular environments that can split tables across pages, eg longtable, xtab. Look on CTAN.

    ReplyDelete
  3. Do you consider a support for multirow also?

    ReplyDelete