ESS/AucTeX/Sweave 集成
我正在使用 GNU/Linux 发行版(Arch,如果相关的话)、Emacs v23.2.1、ESS v5.9 和 AucTeX v11.86。
我想设置 AucTeX 来识别 .Rnw 文件,这样我就可以使用 .Rnw 文件在 .Rnw 文件上运行 LaTeX code>Cc Cc 并自动获取.dvi 文件。我认为通过编辑 .emacs 文件就可以很好地管理它,但我仍然没有牢牢掌握 Elisp。
还有一个问题非常烦人 - 不知何故,LaTeX 无法识别序言中的 \usepackage{Sweave}
,所以我实际上需要复制 Sweave.sty
> 文件(在我的情况下位于 /usr/share/R/texmf/Sweave.sty
中)到 .Rnw 文件所在的目录(而且我变得越来越这是 Windows 平台上常见的错误,这让我很沮丧!)
我的问题归结为两个问题:
- 如何让 LaTeX 识别
\usepackage{Sweave}
(不复制 <每次代码>Sweave.sty到“home”文件夹)[编辑:设法做到这一点;请参阅 Dirk 的回答后的评论] - 如何设置 AucTeX 将 .Rnw 文件编译为 .dvi
I'm using GNU/Linux distro (Arch, if that's relevant), Emacs v23.2.1, ESS v5.9 and AucTeX v11.86.
I want to setup AucTeX to recognize .Rnw files, so I can run LaTeX on .Rnw files with C-c C-c
and get .dvi file automatically. I reckon it's quite manageable by editing .emacs file, but I still haven't got a firm grasp on Elisp.
Yet another problem is quite annoying - somehow, LaTeX is not recognizing \usepackage{Sweave}
in preambule, so I actually need to copy Sweave.sty
file (in my case located in /usr/share/R/texmf/Sweave.sty
) to directory where .Rnw file is located (and I'm becoming more frustrated by the fact that this is common bug on Windows platforms!)
My question boils down to two problems:
- how to make LaTeX recognize
\usepackage{Sweave}
(without copyingSweave.sty
to "home" folder each time) [Edit: managed to do this; see comment after Dirk's answer] - how to setup AucTeX to compile .Rnw files to .dvi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是两个不同的问题。
对于第一个,我的 Debian R 软件包确保有一个从
$RHOME/share/texmf/
目录到 TeX 文件系统树的软链接,例如/usr/share /texmf/tex/latex/R
。对于第二个问题:不知道。我倾向于通过几年前编写的一个小型 shell 脚本来运行 Sweave,尽管所有编辑工作都是在 Emacs 中完成的。
几个月后编辑:使用 ESS,而不是 AucTeX。然后,
Mn s
(即 Alt-n 后接 s)运行 Sweave 步骤,Mn P
运行 LaTeX 编译,并在需要时调用 Bibtex。That's two different questions.
For the first one, my Debian R packages make sure that there is a soft link from the
$RHOME/share/texmf/
directory into the TeX file system tree, e.g. as/usr/share/texmf/tex/latex/R
.For the second question: dunno. I tend to run Sweave via a small shell script I crafted years ago even though I do all the editing in Emacs.
Edit, a few months later: Use ESS, rather than AucTeX. Then
M-n s
(i.e Alt-n followed by s) runs the Sweave step andM-n P
runs the LaTeX compilation, with a call to Bibtex if needed.经过简短而高效的谷歌搜索后,我找到了此链接,乍一看,一切看起来都不错,但是 pdf 文件在 Sweaving 后变得乱码......所以我用另一种方式解决了这个问题:当有疑问时,去bash!我无耻地从 Dirk 的 Sweave bash 脚本中窃取了错误检查功能,此处。基本上,这是一种解决方法:
R CMD Sweave
在 .Rnw 文件上执行,因此 latex 出现,pdflatex 之后...我将发布一个为我完成这项工作的 bash 脚本。我必须声明,我不是一个高级的 bash 程序员,而且我什至不是一个职业程序员,所以这个脚本很有可能被正确地优化/编写。如下:
然后将此脚本保存/复制/移动到任何
echo $PATH
文件夹中(我将我的保存在/usr/bin/
中),并确保它已命名sweave,或选择您喜欢的任何名称,然后将这些行放入 .emacs 文件中:当然,您可以更改键绑定以满足您的需要,并且一定要更改sweave,脚本名称放置在
/usr/bin/
中。请记住,这不是答案,而是解决方法。如果您找到了处理 AucTeX/ESS/Sweave 集成的方法,请发布它,我会给它一个复选标记。
在此解决方法之前,我必须对 Sweave 执行
Mn s
,然后执行Cc Cc
,这是 AucTeX 中用于 LaTeX 文件编译的默认键绑定。生成的文件是错误的,所以我不得不用 bash 尝试一下。它对我有用,如果您有任何建议,请告诉我。亲切的问候,
aL3xa
编辑:
已插入
cd $FILEPATH
After brief and efficient Googling, I've found this link, and at first glance, everything seems OK, but pdf file gets garbled after Sweaving... So I tackled this problem another way around: when in doubt, go bash! I've shamelessly stolen error checking function from Dirk's Sweave bash script available here. Basically, this is a workaround:
R CMD Sweave
gets executed on .Rnw file, hence latex comes in, and pdflatex after that...I'll post a bash script that does the job for me. I must state that I'm not an advanced bash programmer, moreover I'm not even a programmer by vocation, so there's a great chance that this script can be optimized/written properly. Here goes:
Then save/copy/move this script in any of
echo $PATH
folders (I keep mine in/usr/bin/
), and make sure that it's named sweave, or choose whatever name you like, then put these lines in your .emacs file:Of course, you can change keybinding to suite your needs, and be sure to change sweave with script name placed in
/usr/bin/
.Bare in mind that this is not an answer, but a workaround. If you have found a way to deal with AucTeX/ESS/Sweave integration, post it, and I'll give it a checkmark.
Prior to this workaround, I had to do
M-n s
to Sweave, followed byC-c C-c
which is default keybind in AucTeX for LaTeX file compilation. Produced file is erroneous, so I had to give it a try with bash. It works for me, if you have any suggestions, please let me know.Kind regards,
aL3xa
EDIT:
Inserted
cd $FILEPATH