emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* inline Babel calls in math environments and table cells
@ 2013-03-11 20:54 Jay Kerns
  2013-03-11 21:08 ` Jay Kerns
  2013-03-11 21:26 ` Eric Schulte
  0 siblings, 2 replies; 7+ messages in thread
From: Jay Kerns @ 2013-03-11 20:54 UTC (permalink / raw)
  To: Org Mode List

Greetings,

I am in the process of updating materials to the new exporter in
anticipation of Org 8.0.  It appears that inline SRC blocks are not
being evaluated in table cells and math environments in the new
exporter, for instance, something like this:

\( SRC_R[:exports results]{2+3} \)

or like this:

| SRC_R[:exports results]{2+3} |

Is the above intentional?  I am reading the Org Syntax document and it
looks like inline Babel calls are "objects".  It also looks like the
pair \(...\) is a "LaTeX fragment" (also an object).  At the beginning
of the section it says, "Most objects cannot contain objects."  And it
also says right above that, "Objects can be found in... table cells."
If my reading of the syntax is correct then it would look like the
latter example is meant to be supported while the former example is
not.

Am I reading that correctly?

Thank you,

-- 
Jay

P.S. I've tried all possible settings of #+OPTIONS and of :mode
settings in the #+attr_latex line for the table.

P.P.S. Best-case scenario for me would be both examples supported, but
if not then I am willing to live with it or try to write something
that will support it.

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

* Re: inline Babel calls in math environments and table cells
  2013-03-11 20:54 inline Babel calls in math environments and table cells Jay Kerns
@ 2013-03-11 21:08 ` Jay Kerns
  2013-03-11 21:26 ` Eric Schulte
  1 sibling, 0 replies; 7+ messages in thread
From: Jay Kerns @ 2013-03-11 21:08 UTC (permalink / raw)
  To: Org Mode List

Let me make clear: I'm talking about on export to LaTeX the code
blocks aren't evaluated.  I can execute in the buffer and everything
works fine.

-- 
Jay

On Mon, Mar 11, 2013 at 4:54 PM, Jay Kerns <gjkernsysu@gmail.com> wrote:
> Greetings,
>
> I am in the process of updating materials to the new exporter in

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

* Re: inline Babel calls in math environments and table cells
  2013-03-11 20:54 inline Babel calls in math environments and table cells Jay Kerns
  2013-03-11 21:08 ` Jay Kerns
@ 2013-03-11 21:26 ` Eric Schulte
  2013-03-11 23:10   ` Jay Kerns
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Schulte @ 2013-03-11 21:26 UTC (permalink / raw)
  To: Jay Kerns; +Cc: Org Mode List

Jay Kerns <gjkernsysu@gmail.com> writes:

> Greetings,
>
> I am in the process of updating materials to the new exporter in
> anticipation of Org 8.0.  It appears that inline SRC blocks are not
> being evaluated in table cells and math environments in the new
> exporter, for instance, something like this:
>
> \( SRC_R[:exports results]{2+3} \)
>
> or like this:
>
> | SRC_R[:exports results]{2+3} |
>
> Is the above intentional?  I am reading the Org Syntax document and it
> looks like inline Babel calls are "objects".  It also looks like the
> pair \(...\) is a "LaTeX fragment" (also an object).  At the beginning
> of the section it says, "Most objects cannot contain objects."  And it
> also says right above that, "Objects can be found in... table cells."
> If my reading of the syntax is correct then it would look like the
> latter example is meant to be supported while the former example is
> not.
>
> Am I reading that correctly?
>
> Thank you,

Hi Jay,

This sounds like a question about the new exporter which is beyond my
ken.

However, code blocks may be called from Org-mode tables, using the `sbe'
[1] macro.

Hope this helps,

Footnotes: 
[1]  
,----[sbe]
| sbe is a Lisp macro in `ob-table.el'.
| 
| (sbe SOURCE-BLOCK &rest VARIABLES)
| 
| Return the results of calling SOURCE-BLOCK with VARIABLES.
| Each element of VARIABLES should be a two
| element list, whose first element is the name of the variable and
| second element is a string of its value.  The following call to
| `sbe' would be equivalent to the following source code block.
| 
|  (sbe 'source-block (n $2) (m 3))
| 
| #+begin_src emacs-lisp :var results=source-block(n=val_at_col_2, m=3) :results silent
| results
| #+end_src
| 
| NOTE: by default string variable names are interpreted as
| references to source-code blocks, to force interpretation of a
| cell's value as a string, prefix the identifier a "$" (e.g.,
| "$$2" instead of "$2" or "$@2$2" instead of "@2$2").
| 
| NOTE: it is also possible to pass header arguments to the code
| block.  In this case a table cell should hold the string value of
| the header argument which can then be passed before all variables
| as shown in the example below.
| 
| | 1 | 2 | :file nothing.png | nothing.png |
| #+TBLFM: @1$4='(sbe test-sbe $3 (x $1) (y $2))
| 
| [back]
`----


-- 
Eric Schulte
http://cs.unm.edu/~eschulte

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

* Re: inline Babel calls in math environments and table cells
  2013-03-11 21:26 ` Eric Schulte
@ 2013-03-11 23:10   ` Jay Kerns
  2013-03-12 15:35     ` Jay Kerns
  0 siblings, 1 reply; 7+ messages in thread
From: Jay Kerns @ 2013-03-11 23:10 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Org Mode List

Hello there,

On Mon, Mar 11, 2013 at 5:26 PM, Eric Schulte <schulte.eric@gmail.com> wrote:

> Hi Jay,
>
> This sounds like a question about the new exporter which is beyond my
> ken.
>
> However, code blocks may be called from Org-mode tables, using the `sbe'
> [1] macro.
>
> Hope this helps,


Thank you.  Yes, it definitely helps; I hadn't heard about sbe - very
cool!  I played with your suggestion and here is a working example
(for the archives):

#+BEGIN_SRC R :session *R*
A <- matrix(sample(100, size = 6), nrow = 2)
#+END_SRC

#+RESULTS:
| 51 | 77 | 63 |
| 65 | 20 | 56 |

#+name: foo
#+BEGIN_SRC R :session *R*
A[m,n]
#+END_SRC

|   |    | 63 |
|   |    |    |
#+TBLFM: @1$3='(sbe foo (m "1") (n "3"))

Now I can frame my question better about the new exporter: what I am
asking about is whether it is planned to ever be possible to do
something like this (and get the same exported results):

#PROPERTY: :exports results
#PROPERTY: :results output

|   |    | SRC_R{A[1,3]} |
|   |    |                       |


-- 
Jay

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

* Re: inline Babel calls in math environments and table cells
  2013-03-11 23:10   ` Jay Kerns
@ 2013-03-12 15:35     ` Jay Kerns
  2013-03-13  2:31       ` Charles Berry
  0 siblings, 1 reply; 7+ messages in thread
From: Jay Kerns @ 2013-03-12 15:35 UTC (permalink / raw)
  To: Org Mode List

Hello,

I went back and spent some time to rethink how I was approaching my
problem.  Instead of inline src blocks like this:

\( SRC_R{blah} \)

or this

| SRC_R{blah} |

or even this

\begin{equation}
SRC_R{blah}
\end{equation}

I could get by doing noweb substitution like this:

#+NAME: foo
#+BEGIN_SRC R
blah
#+END_SRC

then elsewhere

#+BEGIN_SRC latex :noweb yes
Here is a bunch <<foo()>> of LaTeX markup
#+END_SRC

This method works. I think it would be cool if it were possible to
evaluate inline src blocks all over the place but on the other hand
there are other tools which might be better suited for that kind of
work. At least for the time being.  :-)

-- 
Jay

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

* Re: inline Babel calls in math environments and table cells
  2013-03-12 15:35     ` Jay Kerns
@ 2013-03-13  2:31       ` Charles Berry
  2013-03-13  3:02         ` Jay Kerns
  0 siblings, 1 reply; 7+ messages in thread
From: Charles Berry @ 2013-03-13  2:31 UTC (permalink / raw)
  To: emacs-orgmode

Jay Kerns <gjkernsysu <at> gmail.com> writes:

> 
> Hello,
> 
> I went back and spent some time to rethink how I was approaching my
> problem.  Instead of inline src blocks like this:
> 
> \( SRC_R{blah} \)
> 
> or this
> 
> | SRC_R{blah} |

[deleted noweb stuff]

> This method works. I think it would be cool if it were possible to
> evaluate inline src blocks all over the place but on the other hand
> there are other tools which might be better suited for that kind of
> work. At least for the time being.  
> 


Jay,

It seems unlikely that inline src blocks will be allowed in table cells.

In org-element.el, there is this in org-element-object-restrictions - the 
alist of objects restrictions:

,----
|   ;; Ignore inline babel call and inline src block as formulas are
|   ;; possible.  Also ignore line breaks and statistics cookies.
|     (table-cell export-snippet footnote-reference latex-or-entity link macro
| 	  radio-target sub/superscript target text-markup timestamp)
`----
  

Another way to get where you want to go is to use the =brew= R package. The
markup is very simple - use <%= code %> in place of src_R{ code }.

Example:

,----
| #+DRAWERS: TABLEDRAWER
|
| * jay's query
|   :PROPERTIES:
|   :session:  *R:2*
|   :exports:  both
|   :END:
| 
| #+BEGIN_SRC R :results value
| A <- matrix(sample(100, size = 6), nrow = 2)
| #+END_SRC
| 
| #+RESULTS:
| | 51 | 77 | 63 |
| | 65 | 20 | 56 |
| 
| Put a table with brew markup in an example block in a drawer, so it
| will not appear in the output.
| 
| :TABLEDRAWER:
| #+NAME: src-blk-out
| #+BEGIN_EXAMPLE
| | a | b | <%= A[1,3] %> |
| | c | d | eeeee         |
| #+END_EXAMPLE
| :END:
| 
| Then use a call to ~brew()~ to run it. Note =:results output raw=
| #+NAME: test-src-blk-out 
| #+BEGIN_SRC R :results output raw :var tab=src-blk-out
| require(brew)
| brew(text=tab)
| #+END_SRC
`----

With point in or below the headline,

  C-c C-e C-s C-b l L 

exports the above as 

,----
| \begin{verbatim}
| A <- matrix(sample(100, size = 6), nrow = 2)
| \end{verbatim}
| 
| \begin{center}
| \begin{tabular}{rrr}
| 2 & 16 & 30\\
| 11 & 81 & 86\\
| \end{tabular}
| \end{center}
| 
| Put a table with brew markup in an example block in a drawer, so it
| will not appear in the output.
| 
| Then use a call to \verb~brew()~ to run it. Note \texttt{:results output raw}
| \label{test-src-blk-out}
| \begin{verbatim}
| require(brew)
| brew(text=tab)
| \end{verbatim}
| 
| \begin{center}
| \begin{tabular}{llr}
| a & b & 30\\
| c & d & eeeee\\
| \end{tabular}
| \end{center}
`----

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

* Re: inline Babel calls in math environments and table cells
  2013-03-13  2:31       ` Charles Berry
@ 2013-03-13  3:02         ` Jay Kerns
  0 siblings, 0 replies; 7+ messages in thread
From: Jay Kerns @ 2013-03-13  3:02 UTC (permalink / raw)
  To: Charles Berry; +Cc: emacs-orgmode

Dear Chuck,

On Tue, Mar 12, 2013 at 10:31 PM, Charles Berry <ccberry@ucsd.edu> wrote:

[snip extended brew example]
>
>

Whoa. That opens up a lot of possibilities I really hadn't thought
about before. *Thank you*.

-- 
Jay

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

end of thread, other threads:[~2013-03-13  3:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-11 20:54 inline Babel calls in math environments and table cells Jay Kerns
2013-03-11 21:08 ` Jay Kerns
2013-03-11 21:26 ` Eric Schulte
2013-03-11 23:10   ` Jay Kerns
2013-03-12 15:35     ` Jay Kerns
2013-03-13  2:31       ` Charles Berry
2013-03-13  3:02         ` Jay Kerns

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).