如何Sweave 多文件项目?
我正在用 LaTeX 写论文,因为内容有点长,不合我的口味,我把它分成了几个文件。我们将它们称为 thesis.tex
、intro.tex
、mat_n_met.tex
、rslts.tex
和 Discsn.tex
。我已通过 链接了
与 intro.tex
、mat_n_met.tex
、rslts.tex
和 discsn.tex
thesis.tex\include{intro}
(等等...)。 我还创建了一个名为 r_crunching.Rnw 的单独文件(我通过 Sweave 运行),其中包含一个运行 R 脚本并进行数据分析的块,以及生成我通过 < 嵌入的图形的 pdf 输出的块。 code>\includegraphics(例如,rslts.tex
)。还在关注吗?
如果我运行 Rnw(即我将 rslts.tex
重命名为 rslts.Rnw
),而没有使用 R 脚本指向该块的“链接”,您将得到一个 Sweave()
错误,表示 \Sexpr{}
中的引用不存在。有没有办法在不将所有文件合并到单个 .Rnw 中的情况下,在 rslts.Rnw
中调用 \Sexpr{}
?
欢迎使用其他方法来实现这一点。
I am writing my thesis in LaTeX and because things got a bit long for my taste, I had split it into several files. Let's call them thesis.tex
, intro.tex
, mat_n_met.tex
, rslts.tex
and discsn.tex
. I have linked intro.tex
, mat_n_met.tex
, rslts.tex
and discsn.tex
through thesis.tex
with \include{intro}
(and so on...).
I have also created a separate file called r_crunching.Rnw
(that I run through Sweave) that holds a chunk that runs the R script with data analysis and chunks that produce pdf outputs of graphs that I embed via \includegraphics
(in e.g., rslts.tex
). Still following?
If I run a Rnw (i.e. I renamed rslts.tex
to rslts.Rnw
) without "a link" to the chunk with the R script, you will get a Sweave()
error saying the reference in \Sexpr{}
doesn't exist. Is there a way, without merging all the files into a single .Rnw, to call \Sexpr{}
in say rslts.Rnw
?
Other methods how to accomplish this are welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议使用 RStudio (http://www.rstudio.com/ide/)。 Sweave 很好地集成到该 IDE 中,并且支持多文件文档。在处理多文件文档时,甚至 Synctex 和 TeX 错误日志导航仍然有效。
在主文件中,您可以使用以下命令包含子文件
包含指令来将子文件链接回主文件
。您可以通过在子文件中 。这样,当处理子文件并排版时,RStudio 就知道要排版主文件。
有关详细信息,请参阅 RStudio 文档,网址为 http://www.rstudio.com/ide/文档/创作/multiple_rnw_files
I recommend using RStudio (http://www.rstudio.com/ide/). Sweave is nicely integrated into that IDE and it supports multi-file documents. Even Synctex and TeX error log navigation still work when working with multi-file documents.
From the master file you can include child files using
You can link a child file back to the master file by including the directive
in the child file. That way when working on a child file and typesetting it, RStudio know to typeset the master file.
The details are explained in the RStudio documentation at http://www.rstudio.com/ide/docs/authoring/multiple_rnw_files
暂时忘记您正在处理 Sweave,只需考虑乳胶问题 -
\include
和\includeonly
提供了解决方案。使用一些简单的测试文件尝试一下。一旦你弄清楚了这一点,将 Sweave 重新融入到混合中,它就可以像 Sweave 那样工作,因为 Sweave “仅仅”是一个预处理步骤,尽管这是一个非常聪明的步骤。
Forget for a second that you are dealing with Sweave and just think of the latex problem -- for which
\include
and\includeonly
offer solutions. Try that with a few simple test files.Once you have that figured out, fold Sweave back into the mix and it just work as Sweave is after 'merely' a pre-processing step, albeit a very clever one.
为了扩展 Dirk 和 mjm 的答案,我建议使用
\include
和 Makefiles。假设您有一个主文件:
master.tex
。在该文件中,您包含一些.tex
和.Rnw
文件,即现在以下 Makefile 提供了用于创建
.tex
、的函数>.R
和.pdf
文件:本质上,
.SUFFIXES
提供了一组从一种文件格式转换为另一种文件格式的规则。例如,要将.Rnw
转换为.R
,我们使用命令To expand Dirk's and mjm's answer, I would suggest using
\include
's and Makefiles.Suppose you have a master file:
master.tex
. In that file, you include some.tex
and.Rnw
files, i.e.Now the following Makefile provides functions for creating the
.tex
,.R
and.pdf
files:Essentially, the
.SUFFIXES
provide a set of rules for convert from one file format to another. For example, to convert from.Rnw
to.R
, we use the command一个相当明显的答案是使用 makefile(可能使用包 cachesweave)以正确的顺序处理相关文件。
one fairly obvious answer is to use a makefile, possibly using package cachesweave, to process the relevant files in the right order.
我对 Sweave(在 Rstudio 下)中的多文件项目的解决方案如下:
1) 创建一个主文件,例如
master.Rnw
,在其中调用子文件intro。 Rnw
、matmet.Rnw
等:2) 创建子文件。我在这里只给出第一个,
intro.Rnw
。请注意,在子文件中,您不要使用序言命令,例如\documentclass
或\begin{document}
3) 将修改保存在 ' intro.Rnw',只需转到“master.Rnw”并使用 Ctrl+Shift+K 进行编译,然后...瞧:
上述命令创建的文件的屏幕截图。
My solution to multi-file projects in Sweave (under Rstudio) is the following:
1) Create a master file, say
master.Rnw
, in which you have the calls to the subfilesintro.Rnw
,matmet.Rnw
, etc:2) Create the subfiles. I'm giving here only the first one,
intro.Rnw
. Please note that in the subfiles you do not use preambular commands such as\documentclass
or\begin{document}
3) After saving modifications in 'intro.Rnw', simply go to 'master.Rnw' and compile it using Ctrl+Shift+K and... voilá:
Screenshot of the file created by the above command.