emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] showing image of latex code results produced from an R code block
@ 2010-05-13 22:10 Erik Iverson
  2010-05-14 19:23 ` Erik Iverson
  0 siblings, 1 reply; 2+ messages in thread
From: Erik Iverson @ 2010-05-13 22:10 UTC (permalink / raw)
  To: emacs-orgmode

Hello, consider the following org-mode file:

=================================================

* R returning LaTeX for display

I have an R function that generates LaTeX code.  I would like the 
resulting LaTeX to be displayed in an inline image in the org-buffer


#+begin_src R
lf <- function() {
     "\\LaTeX"
   }

lf()
#+end_src

#+results:
: \LaTeX

I want the above results to actually be just like below, i.e., process 
the results as LaTeX and include an image of the results.  I think 
org-babel can do this sort of thing, it's just escaping me how!

* If I just specify LaTeX as the input language, all works as I hope

#+begin_src latex :file latex-logo.png
   \LaTeX
#+end_src[$]

The LaTeX logo is displayed properly below on my screen with the latest 
inline image functions.

#+results:
[[file:latex-logo.png]]

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

* Re: [babel] showing image of latex code results produced from an R code block
  2010-05-13 22:10 [babel] showing image of latex code results produced from an R code block Erik Iverson
@ 2010-05-14 19:23 ` Erik Iverson
  0 siblings, 0 replies; 2+ messages in thread
From: Erik Iverson @ 2010-05-14 19:23 UTC (permalink / raw)
  To: emacs-orgmode

Solution below!

Erik Iverson wrote:
> Hello, consider the following org-mode file:
> 
> =================================================
> 
> * R returning LaTeX for display
> 
> I have an R function that generates LaTeX code.  I would like the 
> resulting LaTeX to be displayed in an inline image in the org-buffer
> 
> 
> #+begin_src R
> lf <- function() {
>     "\\LaTeX"
>   }
> 
> lf()
> #+end_src
> 
> #+results:
> : \LaTeX
> 
> I want the above results to actually be just like below, i.e., process 
> the results as LaTeX and include an image of the results.  I think 
> org-babel can do this sort of thing, it's just escaping me how!
> 
> * If I just specify LaTeX as the input language, all works as I hope
> 
> #+begin_src latex :file latex-logo.png
>   \LaTeX
> #+end_src[$]
> 
> The LaTeX logo is displayed properly below on my screen with the latest 
> inline image functions.
> 
> #+results:
> [[file:latex-logo.png]]


The solution is simply to give the R src block a name, then create a new 
src block of LaTeX code which calls the R src block using the noweb 
syntax.  Note that in my actual application the LaTeX returned is *not* 
an R object like in my example, it is actually just text written to 
stdout, so in my R source block I use :results output.

#+srcname: R-latex
#+begin_src R
lf <- function() {
     "\\LaTeX"
   }

lf()
#+end_src

#+begin_src latex :noweb yes :file latex-logo.png
<<R-latex()>>
#+end_src

Now I can preview tables produced by Hmisc's latex function in my 
org-mode buffer, very nice!

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

end of thread, other threads:[~2010-05-14 19:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-13 22:10 [babel] showing image of latex code results produced from an R code block Erik Iverson
2010-05-14 19:23 ` Erik Iverson

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