Mikhail Titov <mlt <at> gmx.us> writes:

> 
> Hello!
> 
> First of all I’m not good at lisp as of now. I’d like to have an extra 
> export option when I press C-c C-e that
> would create <dot>Rnw file instead of <dot>tex, pass it through pgfSweave 
> in running R session.

Mikhail,

For vanilla Sweave, use the LaTeX style syntax (vs noweb style) to create an
Rtex file. Typing 'C-c C-e l' causes the following *.org to produce  *.Rtex
which R CMD Sweave will turn to *.tex and R CMD pdflatex will turn into a 
*.pdf. 

Note this this will break ordinary R code export in latex, so be sure it 
is not invoked when you want to go from *.org to *.pdf via 'C-c C-e d'

The trick is mainly to get the latex exporter to drop the verbatim wrapper.


-------8<--------------------------------------------------------------->8----
* Retooling org-babel to accept Rtex

Run this subtree once to start or put these blocks in your =~/.emacs=

Either way, run the elisp in this subtree once to start a session


** Nullify =\begin{verbatim}= ... =\end{verbatim}=

Under standard latex export, the code blocks get wrapped in verbatim
environments. To Sweave the resulting code as =*.Rtex= it is necessary
to unplug this behavior. 'Advising'
=org-export-format-source-code-or-example= like this has the desired
effect on =R= src blocks , but leaves others alone.


#+begin_src emacs-lisp :exports code
  (defadvice
    org-export-format-source-code-or-example
    (around no-verbatim (lang code &optional opts indent caption))
    "dont wrap R code in verbatim"
    ( let
        (( old-verb-wrap org-export-latex-verbatim-wrap))
      (if (equal lang "R") (setq org-export-latex-verbatim-wrap nil))
      ad-do-it
      (setq org-export-latex-verbatim-wrap old-verb-wrap)))


  (ad-activate 'org-export-format-source-code-or-example)

#+end_src

#+results:
: org-export-format-source-code-or-example


** after processing convert =*.tex= to =*.Rtex=


Adding the commands to run Sweave and pdflatex to this hook function
is left as an exercise...

#+begin_src emacs-lisp :results silent
  (add-hook
   'org-export-latex-after-save-hook
   (lambda ()
     (rename-file (buffer-file-name)
                  (concat (file-name-sans-extension
                           (buffer-file-name)) ".Rtex") t )
     ))

#+end_src


* SRC BLOCKS

Two simple examples

** R graphics

A simple scatterplot. Here we want the verbatim omitted:


\begin{Scode}{fig=T}
#+begin_src R  :eval never :exports code :results raw
plot(rnorm(10))
#+end_src
\end{Scode}

** shell script

Here we want to execute the shell script and pass it to the =*.Rtex= file

#+begin_src sh :eval t :results output verbatim :exports both
ls | wc
#+end_src


-------8<--------------------------------------------------------------->8---

HTH,

Chuck

[rest deleted]



Reply via email to