emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* inline src_R also in latex src block
@ 2011-12-30 18:13 Michael Bach
  2012-01-02 17:49 ` Eric Schulte
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Bach @ 2011-12-30 18:13 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

I am using org-mode version 7.8.02

I can successfully do inline `src_R' e.g. via

--8<---------------cut here---------------start------------->8---
\begin{equation}
  src_R{4 + 4}
\end{equation}
--8<---------------cut here---------------end--------------->8---

where `8' is put into the equation environment on export.  Sadly, there
is no LaTeX font lock in the org file this way.  But when I do it inside
a latex src block providing font lock, e.g.

--8<---------------cut here---------------start------------->8---
#+name: test
#+begin_src latex
  \begin{equation}
    src_R{4 + 4}
  \end{equation}
#+end_src
--8<---------------cut here---------------end--------------->8---

the `src_R' is put in literally on latex export.

Is there a way of preprocessing this latex src block with babel for R
prior to exporting?

Thanks in advance,
Michael

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

* Re: inline src_R also in latex src block
  2011-12-30 18:13 inline src_R also in latex src block Michael Bach
@ 2012-01-02 17:49 ` Eric Schulte
  2012-01-10 12:25   ` Michael Bach
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Schulte @ 2012-01-02 17:49 UTC (permalink / raw)
  To: Michael Bach; +Cc: emacs-orgmode

Michael Bach <phaebz@gmail.com> writes:

> Hello,
>
> I am using org-mode version 7.8.02
>
> I can successfully do inline `src_R' e.g. via
>
> \begin{equation}
>   src_R{4 + 4}
> \end{equation}
>
> where `8' is put into the equation environment on export.  Sadly, there
> is no LaTeX font lock in the org file this way.  But when I do it inside
> a latex src block providing font lock, e.g.
>
> #+name: test
> #+begin_src latex
>   \begin{equation}
>     src_R{4 + 4}
>   \end{equation}
> #+end_src
>
> the `src_R' is put in literally on latex export.
>
> Is there a way of preprocessing this latex src block with babel for R
> prior to exporting?
>

I don't know of a way to evaluate inline code blocks which are already
inside of regular code blocks.  You could try direct begin_latex code
blocks, but in-buffer font lock support may simply not be possible in
this situation.

Best,

>
> Thanks in advance,
> Michael
>
>

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

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

* Re: inline src_R also in latex src block
  2012-01-02 17:49 ` Eric Schulte
@ 2012-01-10 12:25   ` Michael Bach
  2012-01-10 13:00     ` Andreas Leha
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Bach @ 2012-01-10 12:25 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric Schulte <eric.schulte@gmx.com> writes:


> I don't know of a way to evaluate inline code blocks which are already
> inside of regular code blocks.  

Thanks for your thoughts on this, Eric.  This would be *really*
convenient for me.  Too bad the christmas wishlist was processed
already.

> You could try direct begin_latex code blocks, but in-buffer font lock
> support may simply not be possible in this situation.
>

Sadly, direct begin_latex code blocks get fontified with `org-block' and
also export the inline `src_R' snippets literally.

What I was looking for is latex code fontified as AUCTeX and inline
`src_R' snippets evaluated prior to exporting.  The only working
combination I got right now is inline `src_R' evaluation and no AUCTeX
font-lock.  This is only a minor itch and not too bad considering what
org-mode already does for me.

Best Regards,
Michael

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

* Re: inline src_R also in latex src block
  2012-01-10 12:25   ` Michael Bach
@ 2012-01-10 13:00     ` Andreas Leha
  2012-01-10 23:25       ` Michael Bach
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Leha @ 2012-01-10 13:00 UTC (permalink / raw)
  To: emacs-orgmode

Michael Bach <phaebz@gmail.com> writes:

> Eric Schulte <eric.schulte@gmx.com> writes:
>
>
>> I don't know of a way to evaluate inline code blocks which are already
>> inside of regular code blocks.  
>
> Thanks for your thoughts on this, Eric.  This would be *really*
> convenient for me.  Too bad the christmas wishlist was processed
> already.
>
>> You could try direct begin_latex code blocks, but in-buffer font lock
>> support may simply not be possible in this situation.
>>
>
> Sadly, direct begin_latex code blocks get fontified with `org-block' and
> also export the inline `src_R' snippets literally.
>
> What I was looking for is latex code fontified as AUCTeX and inline
> `src_R' snippets evaluated prior to exporting.  The only working
> combination I got right now is inline `src_R' evaluation and no AUCTeX
> font-lock.  This is only a minor itch and not too bad considering what
> org-mode already does for me.
>
> Best Regards,
> Michael


Hi Michael,

would this noweb-based approach work for you:

#+name: inner_test
#+begin_src R
  4 + 4
#+end_src

#+name: test
#+begin_src latex :noweb yes
  \begin{equation}
    <<inner_test()>>
  \end{equation}
#+end_src

Cheers,
Andreas

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

* Re: inline src_R also in latex src block
  2012-01-10 13:00     ` Andreas Leha
@ 2012-01-10 23:25       ` Michael Bach
  2012-01-11  7:54         ` Sebastien Vauban
  2012-01-11  8:41         ` Andreas Leha
  0 siblings, 2 replies; 9+ messages in thread
From: Michael Bach @ 2012-01-10 23:25 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> would this noweb-based approach work for you:
>
> #+name: inner_test
> #+begin_src R
>   4 + 4
> #+end_src
>
> #+name: test
> #+begin_src latex :noweb yes
>   \begin{equation}
>     <<inner_test()>>
>   \end{equation}
> #+end_src
>

Yes, that works.  Thanks for your thoughts on this, Andreas.

I am just thinking of another benefit:  Is it correct that I can use
caching with this approach?  So that the call to <<inner_test()>> does
not evaluate the `inner_test' block but instead takes its results
directly from the cached `#+results[6099...]: inner_test' block?  This
would be speedier than src_R usage...

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

* Re: inline src_R also in latex src block
  2012-01-10 23:25       ` Michael Bach
@ 2012-01-11  7:54         ` Sebastien Vauban
  2012-01-12 11:57           ` Michael Bach
  2012-01-11  8:41         ` Andreas Leha
  1 sibling, 1 reply; 9+ messages in thread
From: Sebastien Vauban @ 2012-01-11  7:54 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hi Michael,

Michael Bach wrote:
> Andreas Leha <andreas.leha-A1rZ2h3LdSKGMSlLMZIubhS11BummzK+@public.gmane.org> writes:
>
>> would this noweb-based approach work for you:
>>
>> #+name: inner_test
>> #+begin_src R
>>   4 + 4
>> #+end_src
>>
>> #+name: test
>> #+begin_src latex :noweb yes
>>   \begin{equation}
>>     <<inner_test()>>
>>   \end{equation}
>> #+end_src
>
> Yes, that works.  Thanks for your thoughts on this, Andreas.
>
> I am just thinking of another benefit: Is it correct that I can use caching
> with this approach? So that the call to <<inner_test()>> does not evaluate
> the `inner_test' block but instead takes its results directly from the
> cached `#+results[6099...]: inner_test' block? This would be speedier than
> src_R usage...

That's perfectly correct: as long as your input code block does not change
(options on the "meta" line and/or contents), your results will be taken "as
is", instead of being recomputed every time.

Best regards,
  Seb

-- 
Sebastien Vauban

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

* Re: inline src_R also in latex src block
  2012-01-10 23:25       ` Michael Bach
  2012-01-11  7:54         ` Sebastien Vauban
@ 2012-01-11  8:41         ` Andreas Leha
  2012-01-12 12:00           ` Michael Bach
  1 sibling, 1 reply; 9+ messages in thread
From: Andreas Leha @ 2012-01-11  8:41 UTC (permalink / raw)
  To: emacs-orgmode

Michael Bach <phaebz@gmail.com> writes:

> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> would this noweb-based approach work for you:
>>
>> #+name: inner_test
>> #+begin_src R
>>   4 + 4
>> #+end_src
>>
>> #+name: test
>> #+begin_src latex :noweb yes
>>   \begin{equation}
>>     <<inner_test()>>
>>   \end{equation}
>> #+end_src
>>
>
> Yes, that works.  Thanks for your thoughts on this, Andreas.
>
> I am just thinking of another benefit:  Is it correct that I can use
> caching with this approach?  So that the call to <<inner_test()>> does
> not evaluate the `inner_test' block but instead takes its results
> directly from the cached `#+results[6099...]: inner_test' block?  This
> would be speedier than src_R usage...

yes, that should work.  Try to export the following several times.  The
first number should not change.
(note: maybe you'd have to execute the inner_test_cached once on your
system)

#+name: inner_test_cached
#+begin_src R :cache yes :exports none
  rnorm(1)
#+end_src

#+results[dbeb7280be41fdc949815808cf601a6d01a400bb]: inner_test_cached
: 1.12399967834262

#+name: inner_test_not_cached
#+begin_src R :exports none
  rnorm(1)
#+end_src

#+results: inner_test_not_cached
: -0.562660468468834

#+name: test
#+begin_src latex :noweb yes
  \begin{equation}
    <<inner_test_cached()>>
    !=
    <<inner_test_not_cached()>>
  \end{equation}
#+end_src

Cheers,
Andreas

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

* Re: inline src_R also in latex src block
  2012-01-11  7:54         ` Sebastien Vauban
@ 2012-01-12 11:57           ` Michael Bach
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Bach @ 2012-01-12 11:57 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: public-emacs-orgmode-mXXj517/zsQ




"Sebastien Vauban"
<wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org> writes:

> That's perfectly correct: as long as your input code block does not change
> (options on the "meta" line and/or contents), your results will be taken "as
> is", instead of being recomputed every time.

Very nice, Thanks for confirmation!  

Michael

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

* Re: inline src_R also in latex src block
  2012-01-11  8:41         ` Andreas Leha
@ 2012-01-12 12:00           ` Michael Bach
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Bach @ 2012-01-12 12:00 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> yes, that should work.  Try to export the following several times.  The
> first number should not change.
> (note: maybe you'd have to execute the inner_test_cached once on your
> system)
>
> #+name: inner_test_cached
> #+begin_src R :cache yes :exports none
>   rnorm(1)
> #+end_src
>
> #+results[dbeb7280be41fdc949815808cf601a6d01a400bb]: inner_test_cached
> : 1.12399967834262
>
> #+name: inner_test_not_cached
> #+begin_src R :exports none
>   rnorm(1)
> #+end_src
>
> #+results: inner_test_not_cached
> : -0.562660468468834
> #+name: test
> #+begin_src latex :noweb yes
>   \begin{equation}
>     <<inner_test_cached()>>
>     !=
>     <<inner_test_not_cached()>>
>   \end{equation}
> #+end_src

Thanks for the testing code.  Having R and LaTeX inside org this way is
just pure fun.

Michael

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

end of thread, other threads:[~2012-01-12 11:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-30 18:13 inline src_R also in latex src block Michael Bach
2012-01-02 17:49 ` Eric Schulte
2012-01-10 12:25   ` Michael Bach
2012-01-10 13:00     ` Andreas Leha
2012-01-10 23:25       ` Michael Bach
2012-01-11  7:54         ` Sebastien Vauban
2012-01-12 11:57           ` Michael Bach
2012-01-11  8:41         ` Andreas Leha
2012-01-12 12:00           ` Michael Bach

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).