傻瓜的 Makefile 吗? Mac OS X

发布于 2024-10-16 04:10:03 字数 489 浏览 8 评论 0原文

我无法理解我在 stackoverflow 上提出的上一个问题的答案,该问题位于:

更高效的 R / Sweave / TeXShop 工作流程?

答案特别来自于用户:las3rjock,他建议创建一个“makefile”并运行该 makefile 以在 R(Sweave)中自动编译 .Rnw,然后在乳胶中。我不知道 makefile 是什么,也不知道如何在 Mac OS X 上的终端 (?) 中使用它。我的互联网搜索返回的内容超出了我的知识水平。我想我需要一些帮助来创建和运行 makefile。

任何人都可以提供有关如何创建 makefile 来运行 Sweave / LaTeX 的“虚拟”说明,或者更重要的是,利用上一个问题中 las3rjock 的答案吗? 谢谢!

I am having trouble understanding an answer to a previous question I asked here on stackoverflow located at:

More efficient R / Sweave / TeXShop work-flow?

The answer in particular is from user: las3rjock who suggests creating a "makefile" and running the makefile to automate compilation of a .Rnw in R (Sweave) and then in LaTeX. I don't know what a makefile is, or how to use it in Terminal (?) on Mac OS X. My internet searching has returned things above my knowledge level. I guess I need some hand holding to create and run a makefile.

Could anyone give "dummy" instructions on how to create a makefile to run Sweave / LaTeX, or more to the point, utilize the answer from las3rjock in the previous question? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

静若繁花 2024-10-23 04:10:03

我写了一篇文章,其中包含关于 Sweave 的 makefile 入门< /a>.

摘自帖子:

我还发布了四个示例 Sweave 文档。
每一个都在 github 上提供了完整的源代码。
每个都使用一个 makefile。
在前两个教程中,描述了 makefile 的详细信息:

I wrote a post with links on getting started with makefiles for Sweave.

From the post:

I also posted four sample Sweave documents.
Each one has full source code available on github.
Each one uses a makefile.
In the first two tutorials, details of the makefile are described:

十二 2024-10-23 04:10:03

makefile 是一个纯文本文件,它指定如何通过一系列操作在给定一组“依赖项”的情况下创建“目标”。目标是左侧后面带有“:”的内容,依赖项位于该行的其余部分。随后的缩进行是应该成为目标的操作。

例如,在您的 LaTeX 案例中,.pdf 文件是您的最终目标,这取决于您的 .tex 文件。所以有一个运行 pdflatex 的操作。 .tex 本身是从 .Rnw 文件创建的,因此还有另一个规则可以通过运行 Sweave 从 foo.Rnw 生成 foo.tex。

make 的美妙之处在于它检查依赖项的时间戳。它最初是为了编译大型 C 程序,分为很多文件。编译最终程序时,没有必要重新编译所有未更改的 .C 文件,因此您的 Makefile 只会编译更改的 .C 文件并将所有 .o 文件链接到可执行文件中。

Make 的利用远远超出了最初的方案,以至于可以使用更新的自动化构建解决方案,因此您可能会看到提到 cmake、ant、maven 和许多其他东西。我不知道其中一半是哪一半。

A makefile is a plain text file that specifies how to make 'targets' given a set of 'dependencies' via a bunch of actions. The targets are the things on the left with ":" after them, the dependencies are on the rest of that line. Subsequent indented lines are the actions that should make the target.

So for example in your LaTeX case, the .pdf file is your final target, and that depends on your .tex file. So there's a an action that runs pdflatex. The .tex itself is created from the .Rnw file, so there's another rule to make foo.tex from foo.Rnw by running Sweave.

The beauty of make is that it checks the timestamps on dependencies. It was originally meant for compiling large C programs, divided up into lots of files. When compiling the final program there's no point recompiling all the .C that you've not changed, so your Makefile would just compile the changed .C files and link all the .o files into an executable.

Make has been leveraged way beyond that original scheme, to the point that newer automated build solutions are available, so you may see mentions of cmake, ant, maven, and a bunch of other things. I don't know what half of them are.

哆兒滾 2024-10-23 04:10:03

我刚刚阅读了上一个问题和这个问题,但这是我为 Mac OS X 编写的一个小 shell 脚本。我不确定这是否正是您想要的,但也许您可以从中学习:

#!/bin/sh
R CMD Sweave yourfile.Rnw
for file in `ls pdfs`;
do pdfcrop "$file" pdfs/"$file"
done
pdflatex yourfile.tex
open yourfile.pdf

如果您不这样做知道:您可以通过 chmod +x yourscriptfile.sh 使该脚本可执行,然后通过 ./yourscript 运行它。第一行开始 Sweave 创建 .tex 文件。 for 循环是可选的:它用于将 .pdf 图形裁剪到子文件夹中。我发现这比处理 R 绘图中的边距容易得多——特别是如果我想优化 .pdf 报告中的位置。

在工作流程方面,我执行以下操作: 1. 存储打印到 R 对象中的所有内容(例如函数结果和图形)。 2. 只需在 Sweave 中使用一小行即可获取整个分析。这样我的 Sweave 文档几乎不包含任何非 LaTeX 代码并且仍然很方便。每当我编辑文本时,我只需要编辑 sweave 文件(或者如果我不需要刷新计算,甚至只需要 .tex 文件)

HTH

I just read the previous question and this one, but here is a little shell script that I wrote for Mac OS X. I am not sure if that is exactly what you want, but maybe you can learn from this:

#!/bin/sh
R CMD Sweave yourfile.Rnw
for file in `ls pdfs`;
do pdfcrop "$file" pdfs/"$file"
done
pdflatex yourfile.tex
open yourfile.pdf

In case you do not know: you can make this script executable by chmod +x yourscriptfile.sh and then run it by ./yourscript.The first line starts your Sweave creation of .tex file. The for loop is optional: it's used to crop .pdf graphics to a subfolder. I found this much easier than handling the margin within R's plotting – in particular if I want to optimize the position in your .pdf report.

Workflow-wise I do the following: 1. store everything that is printed into R objects (such as function results and graphics). 2. Just use a little line in Sweave that sources the whole analysis. That way my Sweave document contains hardly any non LaTeX code and remains handy. Whenever I edit the text I just need to edit the sweave file (or if I do not need the calculations to be refreshed or even need only the .tex file)

HTH

紫轩蝶泪 2024-10-23 04:10:03

创建一个名为 Makefile 的文件来存储您的文档并打开它。

复制/粘贴他在 Makefile 中输入的代码(并记住将 myfile 替换为您要生成的文件的名称)

在文档目录中打开控制台并输入制作pdf

create a file named Makefile where your documents are stored and open it.

Copy/paste the code he typed in your Makefile (and remember to replace myfile by the name of the file you want to generate)

Open a console in your documents directory and type make pdf

浪漫之都 2024-10-23 04:10:03

我来到这里是为了寻找一个简单的 Makefile 示例。所以这里有一个:

# Makefile

showme:
        ls

重要请注意,这一行 ls 上的间隙实际上是按一下选项卡按钮。它不能是空格,因为独特的奇怪原因。如果您确实使用空格,您将收到此错误:“Makefile:4: *** 缺少分隔符。停止。”。

一旦您有了一个名为 Makefile 的文件,其中包含上面的一小段代码,请在终端中输入 make showme 来运行它。您应该会看到打印到终端的目录内容。

I arrived here looking for a simple example of a Makefile. So here's one:

# Makefile

showme:
        ls

important note that the gap on this line ls is actually 1 single press of the tab button. It cannot be spaces for weird reasons unique to make. If you do use spaces you'll get this error: "Makefile:4: *** missing separator. Stop.".

Once you have a file called Makefile with the above tiny snippet of code in it, in your terminal type make showme to run it. You should see the contents of the directory printed to the terminal.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文