emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Add tikzDevice support to ob-R
@ 2011-11-27  7:32 Thomas S. Dye
  2011-11-27 12:18 ` Rasmus Pank Roulund
  2011-11-28  7:08 ` Eric Schulte
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas S. Dye @ 2011-11-27  7:32 UTC (permalink / raw)
  To: Org-mode

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

Aloha all,

The attached patch adds tikzDevice support to ob-R.  It requires that
the tikzDevice package be available to R, so it must be installed and
loaded.  Something like the following code in .Rprofile will load the
package by default:

old <- getOption("defaultPackages")
options(defaultPackages = c(old, "tikzDevice"))

Then, specify a .tex file in the :file header argument of the R source
code block, e.g., :file intervals.tex, and the graphic will be produced
by tikzDevice.

The advantage of this for LaTeX export is that the resulting file will
be set with the fonts of its surrounding document.

Something like this works for me, where the \sffamily command uses the
document's sans serif font and the file is called intervals.tex:

\begin{figure}[htb!]
  \centering
  \sffamily
  \input{../figure/intervals}
  \caption[Elapsed time between Polynesian colonization of Hawai`i and fire-pit use]{Elapsed time between Polynesian colonization of Hawai`i and fire-pit use.}
  \label{fig:elapsed-time}
\end{figure}
 
All the best,
Tom


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Add tikzDevice support to ob-R --]
[-- Type: text/x-patch, Size: 994 bytes --]

From 7f144d05f898565be0c3e17c8417ce81d01442b3 Mon Sep 17 00:00:00 2001
From: Thomas Dye <dk@poto.local>
Date: Sat, 26 Nov 2011 21:17:00 -1000
Subject: [PATCH] * lisp/ob-R.el: Added tikzDevice support.

---
 lisp/ob-R.el |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/lisp/ob-R.el b/lisp/ob-R.el
index 79cc0be..d8c3d6b 100644
--- a/lisp/ob-R.el
+++ b/lisp/ob-R.el
@@ -197,6 +197,7 @@ current code buffer."
 	 '((:bmp . "bmp")
 	   (:jpg . "jpeg")
 	   (:jpeg . "jpeg")
+	   (:tex . "tikz")
 	   (:tiff . "tiff")
 	   (:png . "png")
 	   (:svg . "svg")
@@ -214,7 +215,7 @@ current code buffer."
     (setq device (or (and device (cdr (assq (intern (concat ":" device))
 					    devices))) "png"))
     (setq filearg
-	  (if (member device '("pdf" "postscript" "svg")) "file" "filename"))
+	  (if (member device '("pdf" "postscript" "svg" "tikz")) "file" "filename"))
     (setq args (mapconcat
 		(lambda (pair)
 		  (if (member (car pair) allowed-args)
-- 
1.7.5.4


[-- Attachment #3: Type: text/plain, Size: 146 bytes --]


-- 
T.S. Dye & Colleagues, Archaeologists
735 Bishop St, Suite 315, Honolulu, HI 96813
Tel: 808-529-0866, Fax: 808-529-0884
http://www.tsdye.com

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

* Re: [PATCH] Add tikzDevice support to ob-R
  2011-11-27  7:32 [PATCH] Add tikzDevice support to ob-R Thomas S. Dye
@ 2011-11-27 12:18 ` Rasmus Pank Roulund
  2011-11-28  7:08 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Pank Roulund @ 2011-11-27 12:18 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org-mode


Aloha Thomas,

> The attached patch adds tikzDevice support to ob-R.  It requires that
> the tikzDevice package be available to R, so it must be installed and
> loaded.  Something like the following code in .Rprofile will load the
> package by default:

Thanks a bunch.  I always use pgfSweave and thus I haven't really
managed to move from Rnw (LaTeX + R files) to Org file.

Are you aware of the very handy pgfsweave bin?  In the Arch R package it
is located in

 /usr/lib/R/bin/pgfsweave

First, you don't have to load tikzDevice. Second, It makes this very
nice notation valid in Rnw files:

#+begin_src latex
\begin{figure}[tbh]
\caption{Time series $x$ and $y$}\label{fig:ts1}
<<ts3xy-plot, echo=FALSE, fig=T, tikz=T, external=T, cache=F, echo=F, width=7, height=3, sanitize=T>>=
plot(x.ts)
lines(y.ts)
#abline(lm(y.fil~x.fil))
@
\end{figure}
#+end_latex

which translates to the following automatically:
#+begin_src latex
\begin{figure}[tbh]
\caption{Time series $x$ and $y$}\label{fig:ts1}
\tikzsetnextfilename{class3-ts3xy-plot}
\tikzexternalfiledependsonfile{class3-ts3xy-plot}{class3-ts3xy-plot.tikz}
\input{class3-ts3xy-plot.tikz}
\end{figure}
#+end_src

It also adds nice formatting of R chucks without the need other R
packages.

Thus, using pgfSweave over regular Sweave is just wonderful.  However, I
don't know whether it can integrate with Babel.

Thanks again.

–Rasmus

-- 
Sent from my Emacs

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

* Re: [PATCH] Add tikzDevice support to ob-R
  2011-11-27  7:32 [PATCH] Add tikzDevice support to ob-R Thomas S. Dye
  2011-11-27 12:18 ` Rasmus Pank Roulund
@ 2011-11-28  7:08 ` Eric Schulte
  1 sibling, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2011-11-28  7:08 UTC (permalink / raw)
  To: Thomas S. Dye; +Cc: Org-mode

Applied, Thanks -- Eric

tsd@tsdye.com (Thomas S. Dye) writes:

> Aloha all,
>
> The attached patch adds tikzDevice support to ob-R.  It requires that
> the tikzDevice package be available to R, so it must be installed and
> loaded.  Something like the following code in .Rprofile will load the
> package by default:
>
> old <- getOption("defaultPackages")
> options(defaultPackages = c(old, "tikzDevice"))
>
> Then, specify a .tex file in the :file header argument of the R source
> code block, e.g., :file intervals.tex, and the graphic will be produced
> by tikzDevice.
>
> The advantage of this for LaTeX export is that the resulting file will
> be set with the fonts of its surrounding document.
>
> Something like this works for me, where the \sffamily command uses the
> document's sans serif font and the file is called intervals.tex:
>
> \begin{figure}[htb!]
>   \centering
>   \sffamily
>   \input{../figure/intervals}
>   \caption[Elapsed time between Polynesian colonization of Hawai`i and
> fire-pit use]{Elapsed time between Polynesian colonization of Hawai`i
> and fire-pit use.}
>   \label{fig:elapsed-time}
> \end{figure}
>  
> All the best,
> Tom

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

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

end of thread, other threads:[~2011-11-28  7:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-27  7:32 [PATCH] Add tikzDevice support to ob-R Thomas S. Dye
2011-11-27 12:18 ` Rasmus Pank Roulund
2011-11-28  7:08 ` Eric Schulte

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