通过 org-mode 在 Latex 中嵌入 R 绘图
我刚刚开始使用 org-mode,到目前为止我很喜欢它。我已经看到可以将 R 插入到 org-mode 文件中并在导出时执行它。但是我在让 org-babel (代码嵌入)生成我感兴趣的图并嵌入生成的图像而不是代码或运行代码的输出时遇到了一些麻烦。
到目前为止,我已经做到了这一点:
#+BABEL: :session *R* :results output graphics :exports both
#+begin_src R :file img.pdf :results output graphics :session *R*
hist(rnorm(100))
#+end_src
#\includegraphics{img.pdf}
但它并没有想象的那么好。首先,它总是提示我是否要执行 R 代码,其次,我想消除 \includegraphics
指令。
这有可能吗?
I'm just getting started with org-mode and so far I love it. I've seen that it is possible to insert R in the org-mode file and execute it upon export. But I have some trouble getting org-babel (the code embedding) to generate the plot I'm interested in and embed the resulting image instead of the code or the output from running the code.
So far I've got this to work:
#+BABEL: :session *R* :results output graphics :exports both
#+begin_src R :file img.pdf :results output graphics :session *R*
hist(rnorm(100))
#+end_src
#\includegraphics{img.pdf}
But it's not as nice as it could be. First it always prompts me whether I do want to execute the R code and secondly I would like to eliminate the \includegraphics
instruction.
Is this possible at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有几件事:1) Org 模式最近发生了很大变化,特别是 wrt Babel 和 src 块 - 从他们的 git 存储库获取最新版本(查看常见问题解答以了解如何做到这一点的详细信息)。 2) 我们不再使用
#+BABEL
行,现在使用#+PROPERTY
行完成,3) 图形的包含是自动完成的。人们根本不需要执行\includegraphics{}
(除非您想调整默认行为,例如标题放置)。例如,以下是您的示例的简单版本在最新版本的 Org 模式下的样子:
我刚刚在我的机器上进行了测试,它的工作方式非常出色。最后一件事 - 我强烈建议您订阅 Org 模式邮件列表,因为您将在其中看到有关 BABEL、PROPERTY 和一大堆其他内容的持续讨论。
顺便说一句,
#+PROPERTY: results output
行并不重要,这只是我通常所做的,因为它更像是我对 Sweave 的期望。Few things: 1) Org mode has changed a lot recently, especially w.r.t. Babel and src blocks - get the latest version from their git repository (check the FAQ for details how to do that). 2) We don't use
#+BABEL
line any more, those are now done with#+PROPERTY
lines, 3) The inclusion of graphics is done automatically. A person shouldn't need to do an\includegraphics{}
at all (unless you want to tweak the default behavior, say, for caption placement).For instance, here's what a simple version of your example would look like under a recent version of Org mode:
I just tested on my machine and it works like a charm. One last thing - I highly recommend you subscribe to the Org mode mailing list, because that's the place you'll see the ongoing discussions about the BABEL, PROPERTY, and a whole bunch of other stuff.
By the way, the
#+PROPERTY: results output
line isn't critical, it's just what I usually do because it's more like what I expect from Sweave.