* Library of Babel function
@ 2011-08-27 18:33 Thomas S. Dye
2011-08-28 14:44 ` Eric Schulte
0 siblings, 1 reply; 6+ messages in thread
From: Thomas S. Dye @ 2011-08-27 18:33 UTC (permalink / raw
To: Org-mode
Hi Eric,
The booktabs-notes function, below, is based on the booktabs function in
the library of Babel. It takes a second table and adds it to the bottom
of the main table. I use it to add multicolumn footnotes to the bottom
of the table. There is also a switch that adds a linespace between the
main table and the notes table. I think the function might be a useful
addition to the library of Babel.
I tried to design it to be a functional replacement for the booktabs
function, but don't trust my emacs-lisp (or other) programming skills.
All the best,
Tom
#+srcname: booktabs-notes
#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
(flet ((to-tab (tab)
(orgtbl-to-generic
(mapcar (lambda (lis)
(if (listp lis)
(mapcar (lambda (el)
(if (stringp el)
el
(format "%S" el))) lis)
lis)) tab)
(list :lend " \\\\" :sep " & " :hline "\\hline"))))
(org-fill-template
"
\\begin{%env}%width%align
\\toprule
%table
\\bottomrule%spacer
%notes
\\end{%env}\n"
(list
(cons "env" (or env "table"))
(cons "width" (if width (format "{%s}" width) ""))
(cons "align" (if align (format "{%s}" align) ""))
(cons "spacer" (if lspace "\\addlinespace" ""))
(cons "table"
;; only use \midrule if it looks like there are column headers
(if (equal 'hline (second table))
(concat (to-tab (list (first table)))
"\n\\midrule\n"
(to-tab (cddr table)))
(to-tab table)))
(cons "notes" (if notes (to-tab notes) ""))
)))
#+end_src
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Library of Babel function
2011-08-27 18:33 Library of Babel function Thomas S. Dye
@ 2011-08-28 14:44 ` Eric Schulte
2011-08-28 17:11 ` [PATCH] Library of Babel source block Thomas S. Dye
0 siblings, 1 reply; 6+ messages in thread
From: Eric Schulte @ 2011-08-28 14:44 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org-mode
Hi Tom,
This sounds great, would you mind submitting this as a patch to the
library-of-babel.org file in the git repository, with some included
usage instructions in the same subtree as the code block?
Thanks! -- Eric
tsd@tsdye.com (Thomas S. Dye) writes:
> Hi Eric,
>
> The booktabs-notes function, below, is based on the booktabs function in
> the library of Babel. It takes a second table and adds it to the bottom
> of the main table. I use it to add multicolumn footnotes to the bottom
> of the table. There is also a switch that adds a linespace between the
> main table and the notes table. I think the function might be a useful
> addition to the library of Babel.
>
> I tried to design it to be a functional replacement for the booktabs
> function, but don't trust my emacs-lisp (or other) programming skills.
>
> All the best,
> Tom
>
> #+srcname: booktabs-notes
> #+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
> (flet ((to-tab (tab)
> (orgtbl-to-generic
> (mapcar (lambda (lis)
> (if (listp lis)
> (mapcar (lambda (el)
> (if (stringp el)
> el
> (format "%S" el))) lis)
> lis)) tab)
> (list :lend " \\\\" :sep " & " :hline "\\hline"))))
> (org-fill-template
> "
> \\begin{%env}%width%align
> \\toprule
> %table
> \\bottomrule%spacer
> %notes
> \\end{%env}\n"
> (list
> (cons "env" (or env "table"))
> (cons "width" (if width (format "{%s}" width) ""))
> (cons "align" (if align (format "{%s}" align) ""))
> (cons "spacer" (if lspace "\\addlinespace" ""))
> (cons "table"
> ;; only use \midrule if it looks like there are column headers
> (if (equal 'hline (second table))
> (concat (to-tab (list (first table)))
> "\n\\midrule\n"
> (to-tab (cddr table)))
> (to-tab table)))
> (cons "notes" (if notes (to-tab notes) ""))
> )))
> #+end_src
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] Library of Babel source block
2011-08-28 14:44 ` Eric Schulte
@ 2011-08-28 17:11 ` Thomas S. Dye
2011-08-28 18:16 ` Eric Schulte
2011-08-28 18:20 ` Pieter Praet
0 siblings, 2 replies; 6+ messages in thread
From: Thomas S. Dye @ 2011-08-28 17:11 UTC (permalink / raw
To: Eric Schulte; +Cc: Org-mode
[-- Attachment #1: Type: text/plain, Size: 3049 bytes --]
Eric Schulte <schulte.eric@gmail.com> writes:
> Hi Tom,
>
> This sounds great, would you mind submitting this as a patch to the
> library-of-babel.org file in the git repository, with some included
> usage instructions in the same subtree as the code block?
>
> Thanks! -- Eric
>
> tsd@tsdye.com (Thomas S. Dye) writes:
>
>> Hi Eric,
>>
>> The booktabs-notes function, below, is based on the booktabs function in
>> the library of Babel. It takes a second table and adds it to the bottom
>> of the main table. I use it to add multicolumn footnotes to the bottom
>> of the table. There is also a switch that adds a linespace between the
>> main table and the notes table. I think the function might be a useful
>> addition to the library of Babel.
>>
>> I tried to design it to be a functional replacement for the booktabs
>> function, but don't trust my emacs-lisp (or other) programming skills.
>>
>> All the best,
>> Tom
>>
>> #+srcname: booktabs-notes
>> #+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
>> (flet ((to-tab (tab)
>> (orgtbl-to-generic
>> (mapcar (lambda (lis)
>> (if (listp lis)
>> (mapcar (lambda (el)
>> (if (stringp el)
>> el
>> (format "%S" el))) lis)
>> lis)) tab)
>> (list :lend " \\\\" :sep " & " :hline "\\hline"))))
>> (org-fill-template
>> "
>> \\begin{%env}%width%align
>> \\toprule
>> %table
>> \\bottomrule%spacer
>> %notes
>> \\end{%env}\n"
>> (list
>> (cons "env" (or env "table"))
>> (cons "width" (if width (format "{%s}" width) ""))
>> (cons "align" (if align (format "{%s}" align) ""))
>> (cons "spacer" (if lspace "\\addlinespace" ""))
>> (cons "table"
>> ;; only use \midrule if it looks like there are column headers
>> (if (equal 'hline (second table))
>> (concat (to-tab (list (first table)))
>> "\n\\midrule\n"
>> (to-tab (cddr table)))
>> (to-tab table)))
>> (cons "notes" (if notes (to-tab notes) ""))
>> )))
>> #+end_src
Hi Eric,
Here is the patch that adds the booktabs-notes source block. I took the
liberty of editing the description of the booktabs source block, which
contained a contradiction about the number of required and optional
arguments. Take a look to make sure I resolved the contradiction
correctly.
I tried to follow Bastien's suggestion about adding a change log to the
commit message, but ended up with something that looks different than
his example. I'm not sure why--perhaps Bastien is not working in magit,
so his instructions apply to some other context?
All the best,
Tom
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Source block for Library of Babel --]
[-- Type: text/x-patch, Size: 4449 bytes --]
From ebc18deea7958cf70f761b1fff8134c1e0a35288 Mon Sep 17 00:00:00 2001
From: Tom Dye <tsd@tsdye.com>
Date: Sun, 28 Aug 2011 07:00:32 -1000
Subject: [PATCH] * contrib/babel/library-of-babel.org: 2011-08-28 Thomas Dye <tsd@tsdye.com>
* Add booktabs-notes source block to the Library of Babel. Minor
edits to booktabs documentation.
---
contrib/babel/library-of-babel.org | 74 +++++++++++++++++++++++++++++++++---
1 files changed, 68 insertions(+), 6 deletions(-)
diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org
index e76b313..c3b000c 100644
--- a/contrib/babel/library-of-babel.org
+++ b/contrib/babel/library-of-babel.org
@@ -194,18 +194,26 @@ plot(data)
* Tables
-** LaTeX Table export
+** LaTeX Table Export
*** booktabs
-This block can be used to wrap a table in the latex =booktabs=
-environment, it takes the following arguments -- all but the first two
-are optional.
+This source block can be used to wrap a table in the latex =booktabs=
+environment. The source block adds a =toprule= and =bottomrule= (so
+don't use =hline= at the top or bottom of the table). The =hline=
+after the header is replaced with a =midrule=.
+
+Note that this function bypasses the Org-mode LaTeX exporter and calls
+=orgtbl-to-generic= to create the output table. This means that the
+entries in the table are not translated from Org-mode to LaTeX.
+
+It takes the following arguments -- all but the first two are
+optional.
| arg | description |
|-------+--------------------------------------------|
| table | a reference to the table |
-| align | optional alignment string |
+| align | alignment string |
| env | optional environment, default to "tabular" |
| width | optional width specification string |
@@ -241,7 +249,7 @@ are optional.
(to-tab table))))))
#+end_src
-*** Longtable
+*** longtable
This block can be used to wrap a table in the latex =longtable=
environment, it takes the following arguments -- all but the first two
@@ -288,6 +296,60 @@ are optional.
(list :lend " \\\\" :sep " & " :hline hline)))))
#+end_src
+
+*** booktabs-notes
+
+This source block builds on [[booktabs]]. It accepts two additional
+arguments, both of which are optional.
+
+#+tblname: arguments
+| arg | description |
+|--------+------------------------------------------------------|
+| notes | an org-mode table with footnotes |
+| lspace | if non-nil, insert =addlinespace= after =bottomrule= |
+
+An example footnote to the =arguments= table specifies the column
+span. Note the use of LaTeX, rather than Org-mode, markup.
+
+#+tblname: arguments-notes
+| \multicolumn{2}{l}{This is a footnote to the \emph{arguments} table.} |
+
+#+srcname: booktabs-notes
+#+begin_src emacs-lisp :var table='((:head) hline (:body)) :var notes='() :var align='() :var env="tabular" :var width='() :var lspace='() :noweb yes :results latex
+ (flet ((to-tab (tab)
+ (orgtbl-to-generic
+ (mapcar (lambda (lis)
+ (if (listp lis)
+ (mapcar (lambda (el)
+ (if (stringp el)
+ el
+ (format "%S" el))) lis)
+ lis)) tab)
+ (list :lend " \\\\" :sep " & " :hline "\\hline"))))
+ (org-fill-template
+ "
+ \\begin{%env}%width%align
+ \\toprule
+ %table
+ \\bottomrule%spacer
+ %notes
+ \\end{%env}\n"
+ (list
+ (cons "env" (or env "table"))
+ (cons "width" (if width (format "{%s}" width) ""))
+ (cons "align" (if align (format "{%s}" align) ""))
+ (cons "spacer" (if lspace "\\addlinespace" ""))
+ (cons "table"
+ ;; only use \midrule if it looks like there are column headers
+ (if (equal 'hline (second table))
+ (concat (to-tab (list (first table)))
+ "\n\\midrule\n"
+ (to-tab (cddr table)))
+ (to-tab table)))
+ (cons "notes" (if notes (to-tab notes) ""))
+ )))
+#+end_src
+
** Elegant lisp for transposing a matrix.
#+tblname: transpose-example
--
1.7.1
[-- Attachment #3: Type: text/plain, Size: 40 bytes --]
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] Library of Babel source block
2011-08-28 17:11 ` [PATCH] Library of Babel source block Thomas S. Dye
@ 2011-08-28 18:16 ` Eric Schulte
2011-08-28 18:20 ` Pieter Praet
1 sibling, 0 replies; 6+ messages in thread
From: Eric Schulte @ 2011-08-28 18:16 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org-mode
>
> Here is the patch that adds the booktabs-notes source block.
Applied, thanks.
> I took the liberty of editing the description of the booktabs source
> block, which contained a contradiction about the number of required
> and optional arguments. Take a look to make sure I resolved the
> contradiction correctly.
>
This looks good to me.
>
> I tried to follow Bastien's suggestion about adding a change log to the
> commit message, but ended up with something that looks different than
> his example. I'm not sure why--perhaps Bastien is not working in magit,
> so his instructions apply to some other context?
>
To easily add a changelog entry from within Magit, I do the following
1. from within magit view the diff of the current changes (often this
can be done through pressing TAB with the cursor on the "Modified"
line in the magit buffer)
2. from within the diff view press capital c "C" with the cursor on
either a green or white line (e.g., not a red line). This will pop
to the commit log buffer with an appropriately formatted changelog
entry. Do this for every portion of the diff.
Hope this helps, thanks for the contribution -- Eric
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Library of Babel source block
2011-08-28 17:11 ` [PATCH] Library of Babel source block Thomas S. Dye
2011-08-28 18:16 ` Eric Schulte
@ 2011-08-28 18:20 ` Pieter Praet
2011-08-28 19:03 ` Thomas S. Dye
1 sibling, 1 reply; 6+ messages in thread
From: Pieter Praet @ 2011-08-28 18:20 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org-mode
On Sun, 28 Aug 2011 07:11:36 -1000, tsd@tsdye.com (Thomas S. Dye) wrote:
> [...]
> I tried to follow Bastien's suggestion about adding a change log to the
> commit message, but ended up with something that looks different than
> his example. I'm not sure why--perhaps Bastien is not working in magit,
> so his instructions apply to some other context?
> [...]
Bastien was referring to `add-change-log-entry{,-other-window}', which is
part of Emacs [1], and is mainly intended to add entries to a dedicated
ChangeLog file (when this file isn't present, it'll open a new buffer
for the entry). While it *does* most definitely produce properly formatted
entries when called with point on a diff hunk, it always requires the extra
step of yanking the entry into your commit message buffer.
When using Magit (which I highly recommend) however, you can add properly
formatted entries *much* faster by positioning point on a (staged) diff
hunk in the status buffer, and calling `magit-add-log' (bound to 'C') [2].
If you don't already have a commit buffer ('*magit-edit-log*'), it will
create one for you, so you don't even need to call `magit-log-edit'
(bound to 'c') in advance anymore. :)
Peace
--
Pieter
[1] [[info:emacs#Change Log]]
[2] [[info:magit#Staging and Committing]]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Library of Babel source block
2011-08-28 18:20 ` Pieter Praet
@ 2011-08-28 19:03 ` Thomas S. Dye
0 siblings, 0 replies; 6+ messages in thread
From: Thomas S. Dye @ 2011-08-28 19:03 UTC (permalink / raw
To: Pieter Praet; +Cc: Org-mode
Pieter Praet <pieter@praet.org> writes:
> On Sun, 28 Aug 2011 07:11:36 -1000, tsd@tsdye.com (Thomas S. Dye) wrote:
>> [...]
>> I tried to follow Bastien's suggestion about adding a change log to the
>> commit message, but ended up with something that looks different than
>> his example. I'm not sure why--perhaps Bastien is not working in magit,
>> so his instructions apply to some other context?
>> [...]
>
> Bastien was referring to `add-change-log-entry{,-other-window}', which is
> part of Emacs [1], and is mainly intended to add entries to a dedicated
> ChangeLog file (when this file isn't present, it'll open a new buffer
> for the entry). While it *does* most definitely produce properly formatted
> entries when called with point on a diff hunk, it always requires the extra
> step of yanking the entry into your commit message buffer.
>
>
> When using Magit (which I highly recommend) however, you can add properly
> formatted entries *much* faster by positioning point on a (staged) diff
> hunk in the status buffer, and calling `magit-add-log' (bound to 'C') [2].
>
> If you don't already have a commit buffer ('*magit-edit-log*'), it will
> create one for you, so you don't even need to call `magit-log-edit'
> (bound to 'c') in advance anymore. :)
>
>
> Peace
Thanks Pieter. Your instructions cut through a lot of the complexity.
All the best,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-08-28 19:03 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-27 18:33 Library of Babel function Thomas S. Dye
2011-08-28 14:44 ` Eric Schulte
2011-08-28 17:11 ` [PATCH] Library of Babel source block Thomas S. Dye
2011-08-28 18:16 ` Eric Schulte
2011-08-28 18:20 ` Pieter Praet
2011-08-28 19:03 ` Thomas S. Dye
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.