all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* adding attributes to tables in results
@ 2015-11-21 13:55 John Kitchin
  2015-11-21 17:40 ` Charles C. Berry
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2015-11-21 13:55 UTC (permalink / raw)
  To: Org Mode

Hi everyone,

I am trying to figure out a way to automatically add some attributes to
tables generated from code blocks.

These aren't the same all the time, but some typical things I would want
to do is specify some tables to be longtable, or set the placements,
alignments, etc...

I know of http://orgmode.org/manual/post.html#post which works for
non-table output well, but with tables, adding the text makes the output
not render as a table anymore.

For example:

#+name: attr_wrap
#+begin_src sh :var data=""  :results output
echo "#+ATTR_LATEX: :environment longtable"
echo $data
#+end_src

#+BEGIN_SRC emacs-lisp  :post attr_wrap(*this*)
(list (+ 2 4) 4 5)
#+END_SRC

#+RESULTS:
: #+ATTR_LATEX: :environment longtable
: 6 4 5


Does anyone know a way to have a code block output a table with
attributes (besides printing them as strings with raw output)?

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 13:55 adding attributes to tables in results John Kitchin
@ 2015-11-21 17:40 ` Charles C. Berry
  2015-11-21 18:04   ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Charles C. Berry @ 2015-11-21 17:40 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org Mode

On Sat, 21 Nov 2015, John Kitchin wrote:

> Hi everyone,
>
> I am trying to figure out a way to automatically add some attributes to
> tables generated from code blocks.
>

With ob-org loaded:

#+BEGIN_SRC emacs-lisp
(require 'ob-org)
#+END_SRC

this src block (n.b. there is a backslash escaped n in the #+HEADER line 
just before the #+ATTR - I hope it doesn't linewrap in email or gnus 
readers)

--8<---------------cut here---------------start------------->8---
#+HEADER: :wrap "src org :exports results :results replace \n#+ATTR_LATEX: :environment longtable"
#+BEGIN_SRC emacs-lisp :exports results
(list  (+ 2 4) 4 5)
#+END_SRC
--8<---------------cut here---------------end--------------->8---

exports as

--8<---------------cut here---------------start------------->8---

\begin{longtable}{rrr}
6 & 4 & 5\\
\end{longtable}
\end{document}

--8<---------------cut here---------------end--------------->8---


HTH,

Chuck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 17:40 ` Charles C. Berry
@ 2015-11-21 18:04   ` John Kitchin
  2015-11-21 18:09     ` Vikas Rawal
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2015-11-21 18:04 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: Org Mode

Thanks. That gets me pretty close to what I want.

Charles C. Berry writes:

> On Sat, 21 Nov 2015, John Kitchin wrote:
>
>> Hi everyone,
>>
>> I am trying to figure out a way to automatically add some attributes to
>> tables generated from code blocks.
>>
>
> With ob-org loaded:
>
> #+BEGIN_SRC emacs-lisp
> (require 'ob-org)
> #+END_SRC
>
> this src block (n.b. there is a backslash escaped n in the #+HEADER line
> just before the #+ATTR - I hope it doesn't linewrap in email or gnus
> readers)
>
> --8<---------------cut here---------------start------------->8---
> #+HEADER: :wrap "src org :exports results :results replace \n#+ATTR_LATEX: :environment longtable"
> #+BEGIN_SRC emacs-lisp :exports results
> (list  (+ 2 4) 4 5)
> #+END_SRC
> --8<---------------cut here---------------end--------------->8---
>
> exports as
>
> --8<---------------cut here---------------start------------->8---
>
> \begin{longtable}{rrr}
> 6 & 4 & 5\\
> \end{longtable}
> \end{document}
>
> --8<---------------cut here---------------end--------------->8---
>
>
> HTH,
>
> Chuck

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 18:04   ` John Kitchin
@ 2015-11-21 18:09     ` Vikas Rawal
  2015-11-21 18:52       ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Vikas Rawal @ 2015-11-21 18:09 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode mailing list, Charles C. Berry

John,

Just curious. What advantage do you see in adding these attributes to the code block, and not directly to the result?

Vikas



> On 21-Nov-2015, at 11:34 pm, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
> 
> Thanks. That gets me pretty close to what I want.
> 
> Charles C. Berry writes:
> 
>> On Sat, 21 Nov 2015, John Kitchin wrote:
>> 
>>> Hi everyone,
>>> 
>>> I am trying to figure out a way to automatically add some attributes to
>>> tables generated from code blocks.
>>> 
>> 
>> With ob-org loaded:
>> 
>> #+BEGIN_SRC emacs-lisp
>> (require 'ob-org)
>> #+END_SRC
>> 
>> this src block (n.b. there is a backslash escaped n in the #+HEADER line
>> just before the #+ATTR - I hope it doesn't linewrap in email or gnus
>> readers)
>> 
>> --8<---------------cut here---------------start------------->8---
>> #+HEADER: :wrap "src org :exports results :results replace \n#+ATTR_LATEX: :environment longtable"
>> #+BEGIN_SRC emacs-lisp :exports results
>> (list  (+ 2 4) 4 5)
>> #+END_SRC
>> --8<---------------cut here---------------end--------------->8---
>> 
>> exports as
>> 
>> --8<---------------cut here---------------start------------->8---
>> 
>> \begin{longtable}{rrr}
>> 6 & 4 & 5\\
>> \end{longtable}
>> \end{document}
>> 
>> --8<---------------cut here---------------end--------------->8---
>> 
>> 
>> HTH,
>> 
>> Chuck
> 
> --
> Professor John Kitchin
> Doherty Hall A207F
> Department of Chemical Engineering
> Carnegie Mellon University
> Pittsburgh, PA 15213
> 412-268-7803
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 18:09     ` Vikas Rawal
@ 2015-11-21 18:52       ` John Kitchin
  2015-11-21 20:04         ` Charles C. Berry
  0 siblings, 1 reply; 7+ messages in thread
From: John Kitchin @ 2015-11-21 18:52 UTC (permalink / raw)
  To: Vikas Rawal; +Cc: org-mode mailing list, Charles C. Berry

I am running a search committee of 5 people. As applications come in, an
org heading is created for each application, and I run a command to send
one of the committee an email with a review rubric in it, and this
command creates a subheading to put their review. We have 275
applications so far, so I am using code to aggregate results into tables.

Now, I am generating reports that show what each person has reviewed. In
the report, I make a table for each person in a code block that
constructs the data for that person. I don't want to manually modify the
results because there will be a lot of tables, and I have to update this
reasonably often.

HEre is what generates the table, it is a function that returns a list
of results which on its own renders as a table just fine.

#+BEGIN_SRC emacs-lisp :exports results
(happ-reviewer-table "jkitchin@andrew.cmu.edu")
#+END_SRC

would ideally output something like:

#+RESULTS:
#+tblname: kitchin-reviews
#+attr_latex: :environment longtable
#+caption: Reviews by Kitchin
| the | table | I | generated|

from a data result from my function that looked like:

(table
 '("#+tblname: kitchin-reviews" "#+attr_latex: :environment longtable"
 "#+caption: Reviews by Kitchin")
 '(the table I generated))

i.e. of the form (table attrs data)

And even better, on rerunning the code it would correctly replace it. I
usually accomplish this with :results raw and some tedious printing to
get what I want. That way is annoying to rerun because of the manual
removal of the output.

I just made up the syntax, and no doubt there are many other ways to
achieve it. That is what I had in mind though.

The tip Charles gave works for export, but the tables do not look too
good for me in the org-document unless I run C-c ' on them to get them
in org, and I also want them functional in the org-buffer too.






Vikas Rawal writes:

> John,
>
> Just curious. What advantage do you see in adding these attributes to the code block, and not directly to the result?
>
> Vikas
>
>
>
>> On 21-Nov-2015, at 11:34 pm, John Kitchin <jkitchin@andrew.cmu.edu> wrote:
>>
>> Thanks. That gets me pretty close to what I want.
>>
>> Charles C. Berry writes:
>>
>>> On Sat, 21 Nov 2015, John Kitchin wrote:
>>>
>>>> Hi everyone,
>>>>
>>>> I am trying to figure out a way to automatically add some attributes to
>>>> tables generated from code blocks.
>>>>
>>>
>>> With ob-org loaded:
>>>
>>> #+BEGIN_SRC emacs-lisp
>>> (require 'ob-org)
>>> #+END_SRC
>>>
>>> this src block (n.b. there is a backslash escaped n in the #+HEADER line
>>> just before the #+ATTR - I hope it doesn't linewrap in email or gnus
>>> readers)
>>>
>>> --8<---------------cut here---------------start------------->8---
>>> #+HEADER: :wrap "src org :exports results :results replace \n#+ATTR_LATEX: :environment longtable"
>>> #+BEGIN_SRC emacs-lisp :exports results
>>> (list  (+ 2 4) 4 5)
>>> #+END_SRC
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>> exports as
>>>
>>> --8<---------------cut here---------------start------------->8---
>>>
>>> \begin{longtable}{rrr}
>>> 6 & 4 & 5\\
>>> \end{longtable}
>>> \end{document}
>>>
>>> --8<---------------cut here---------------end--------------->8---
>>>
>>>
>>> HTH,
>>>
>>> Chuck
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu
>>

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 18:52       ` John Kitchin
@ 2015-11-21 20:04         ` Charles C. Berry
  2015-11-21 21:45           ` John Kitchin
  0 siblings, 1 reply; 7+ messages in thread
From: Charles C. Berry @ 2015-11-21 20:04 UTC (permalink / raw)
  To: John Kitchin; +Cc: org-mode mailing list, Vikas Rawal

On Sat, 21 Nov 2015, John Kitchin wrote:

> I am running a search committee of 5 people. As applications come in, an
> org heading is created for each application, and I run a command to send
> one of the committee an email with a review rubric in it, and this
> command creates a subheading to put their review. We have 275
> applications so far, so I am using code to aggregate results into tables.

Ouch! That is serious work!

[snip]
>
> The tip Charles gave works for export, but the tables do not look too
> good for me in the org-document unless I run C-c ' on them to get them
> in org, and I also want them functional in the org-buffer too.
>
>

Use a different wrapper for executing src block outside of exports.

Something like this (with suitable tuning) should work:

#+BEGIN_SRC emacs-lisp
   (defun ex-aware-wrap ()
       (if org-export-current-backend
 	  (concat "src org :exports results "
 		  ":results  replace "
 		  "\n#+ATTR_LATEX: "
 		  ":environment longtable")
 	"example"))
#+END_SRC

#+BEGIN_SRC emacs-lisp :exports results :wrap (ex-aware-wrap)
(list (+ 1 2) 3 4)
#+END_SRC

HTH,

Chuck

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: adding attributes to tables in results
  2015-11-21 20:04         ` Charles C. Berry
@ 2015-11-21 21:45           ` John Kitchin
  0 siblings, 0 replies; 7+ messages in thread
From: John Kitchin @ 2015-11-21 21:45 UTC (permalink / raw)
  To: Charles C. Berry; +Cc: org-mode mailing list, Vikas Rawal

Also an interesting approach!

I never execute src blocks on export though (old habit of having
expensive blocks, and the desire to know what the export looks like).

This is close to what I want:

#+name: el_attr
#+BEGIN_SRC emacs-lisp :var data='(1 2 3)
(org-babel-format-result
 (concat
  "#+tblname: test\n"
  "#+ATTR_LATEX: :environment longtable\n"
  (orgtbl-to-generic  (list data) (list :lstart "|" :lend "|"  :sep "|" :fmt "%s"))))
#+END_SRC

#+RESULTS: el_attr
: #+tblname: test
: |1|2|3|


#+BEGIN_SRC emacs-lisp  :exports results :post el_attr(*this*)
(list (+ 1 2) 3 3)
#+END_SRC

#+RESULTS:
: #+tblname: test
: #+ATTR_LATEX: :environment longtable
: |3|3|3|


But I cannot figure out how to get the results in org format. If I put
:results org or raw in I get this output:

#+RESULTS:
#+tblname: test
#+ATTR_LATEX: :environment longtable
|40|51|32|51|32|51|41|



Charles C. Berry writes:

> On Sat, 21 Nov 2015, John Kitchin wrote:
>
>> I am running a search committee of 5 people. As applications come in, an
>> org heading is created for each application, and I run a command to send
>> one of the committee an email with a review rubric in it, and this
>> command creates a subheading to put their review. We have 275
>> applications so far, so I am using code to aggregate results into tables.
>
> Ouch! That is serious work!
>
> [snip]
>>
>> The tip Charles gave works for export, but the tables do not look too
>> good for me in the org-document unless I run C-c ' on them to get them
>> in org, and I also want them functional in the org-buffer too.
>>
>>
>
> Use a different wrapper for executing src block outside of exports.
>
> Something like this (with suitable tuning) should work:
>
> #+BEGIN_SRC emacs-lisp
>    (defun ex-aware-wrap ()
>        (if org-export-current-backend
>         (concat "src org :exports results "
>                 ":results  replace "
>                 "\n#+ATTR_LATEX: "
>                 ":environment longtable")
>       "example"))
> #+END_SRC
>
> #+BEGIN_SRC emacs-lisp :exports results :wrap (ex-aware-wrap)
> (list (+ 1 2) 3 4)
> #+END_SRC
>
> HTH,
>
> Chuck

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-11-21 21:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-21 13:55 adding attributes to tables in results John Kitchin
2015-11-21 17:40 ` Charles C. Berry
2015-11-21 18:04   ` John Kitchin
2015-11-21 18:09     ` Vikas Rawal
2015-11-21 18:52       ` John Kitchin
2015-11-21 20:04         ` Charles C. Berry
2015-11-21 21:45           ` John Kitchin

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.