Browse Source

library-of-babel: adding function for LaTeX Table export

* contrib/babel/library-of-babel.org (Write): support for LaTeX table export
Eric Schulte 14 years ago
parent
commit
5461d3e605
1 changed files with 48 additions and 2 deletions
  1. 48 2
      contrib/babel/library-of-babel.org

+ 48 - 2
contrib/babel/library-of-babel.org

@@ -96,9 +96,55 @@ plot(data)
 
 ** Gnuplot
 
-* Table/Matrix manipulation
+* Tables
+** LaTeX Table export
+This block can be used to wrap a table in the latex =longtable=
+environment, it takes the following arguments -- all but the first
+three are optional.
+| arg       | description                                                 |
+|-----------+-------------------------------------------------------------|
+| table     | a reference to the table                                    |
+| env       | table environment, e.g. longtable, tablex, etc...           |
+| align     | optional alignment string                                   |
+| width     | optional width specification string                         |
+| hline     | the string to use as hline separator, defaults to "\\hline" |
+| head      | optional "head" string                                      |
+| firsthead | optional "firsthead" string                                 |
+| foot      | optional "foot" string                                      |
+| lastfoot  | optional "lastfoot" string                                  |
+
+#+srcname: table
+#+begin_src emacs-lisp :var table='((:table)) :var env="table" :var align='() :var width='() :var hline="\\hline" :var firsthead='() :var head='() :var foot='() :var lastfoot='() :noweb yes :results latex
+  (org-fill-template
+   "
+  \\begin{%env}%width%align
+  %firsthead
+  %head
+  %foot
+  %lastfoot
+  
+  %table
+  \\end{%env}\n"
+   (list
+    (cons "env"       env)
+    (cons "width"     (if width (format "{%s}" width) ""))
+    (cons "align"     (if align (format "{%s}" align) ""))
+    (cons "firsthead" (if firsthead (concat firsthead "\n\\endfirsthead\n") ""))
+    (cons "head"      (if head (concat head "\n\\endhead\n") ""))
+    (cons "foot"      (if foot (concat foot "\n\\endfoot\n") ""))
+    (cons "lastfoot"  (if lastfoot (concat lastfoot "\n\\endlastfoot\n") ""))
+    (cons "table" (orgtbl-to-generic
+                   (mapcar (lambda (lis)
+                             (if (listp lis)
+                                 (mapcar (lambda (el)
+                                           (if (stringp el)
+                                               el
+                                             (format "%S" el))) lis)
+                               lis)) table)
+                   (list :lend " \\\\" :sep " & " :hline hline)))))
+#+end_src
 
-Elegant lisp code for transposing a matrix.
+** Elegant lisp for transposing a matrix.
 
 #+tblname: transpose-example
 | 1 | 2 | 3 |