[TxMt] LaTeX (Sweave)/HTML/Markdown and Rdaemon (R)

Hans-Joerg Bibiko bibiko at eva.mpg.de
Fri Jul 4 11:37:57 UTC 2008


while developing the Rdaemon I had one single question in my mind. How  
can you integrate Rdaemon in documents like LaTeX, HTML, Markdown etc.

Up to now I fiddled around with automatically copy&pasting R stuff,  
thought about modifying Sweave etc.

But I believe I found hopefully a very easy solution.
One only has to use TextMate's wondrous facilities. ;P

Everybody knows, e.g. if one writes an HTML doc you have the HTML  
scope with all commands behind it. Then one inserts a new CSS  
declaration. If you are inside of such a CSS tag you have all CSS  
features available. This is done in the Language setting for HTML.  
This led me to an idea.

E.g. LaTeX:
If I'm writing an article or paper about my analyses of a topic, and I  
did this by using R; then I usually explain how I did this with R.
Or if you give a R course and you want to document it, or if you write  
a book about R, ...
One can use Sweave to typeset it. Fine.

BUT, my idea was to combine LaTeX and Rdaemon. I wrote a new Language  
for LaTeX called "LaTeX Rdaemon". The only thing I did is to insert an  
include statement

include = 'source.rd.console'

within the 'verbatim' environment.

OK. How does this work now?
You can start the Rdaemon and close that window. Then you open a LaTeX  
file, set the language to "LaTeX Rdaemon".
Now you can write your LaTeX stuff, but if you declare a  
\begin{verbatim} block AND within that block a line begins with "> "  
then you are talking with the Rdaemon with all features coming from R  
and Rdaemon. Press RETURN and the line will be executed and the result  
will be written into the TeX document. (Remember the Rdaemon runs  
further in the background)

I recorded a very tiny movie to illustrate that.


And this is only a test without fine-tuning! One can think about to  
write some code to automate some things like:

- if a line starts with "> " within a tex document this line and the  
output will wrapped automatically by a verbatim block after pressing  
- if one plots something and the Rdaemon recognizes that the command  
is coming from a tex document which is saved in a certain folder then  
the Rdaemon will plot this image using a Quartz device, dev.copy2eps(/ 
TEX_FOLDER/THE_NAME) [the Quartz is still open for further stuff!],  
and return something like:

\caption{Scatter Plot with Regression Line}

[FOO could be calcualted, I guess]


By using this approach one could do this also with Markdown or HTML  
etc. The only thing is to expand the Language syntax, and to fine-tune  
the Rdaemon.

Are there any comments about my approach? What kind of side-effects  
could be expected?
Would this be useful at all?

Kind regards,


More information about the textmate mailing list