尝试了解 Latex、Sweave 和 R 之间的工作流程

发布于 2024-12-07 06:41:15 字数 973 浏览 0 评论 0原文

假设我编写了以下微小的 .Rnw 文件:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{Sweave}
\usepackage{tikz}
\usepackage{pgf}
\begin{document}

<<>>=
sessionInfo()
@ 

\end{document}

然后我可以转到 R 并使用 sweave 将 .Rnw 文件转换为 .tex 文件 一旦完成,就可以调用乳胶解释器,因为我使用了 \usepackage{Sweave} Latex 知道如何处理 sweave 特定的代码标签。 当我第一次执行此过程时,我遇到了 Sweave.sty 文件可能会出现的常见错误 找不到。我用谷歌搜索并可以通过输入以下命令解决问题 进入 Mac OS 终端:

mkdir -p ~/Library/texmf/tex/latex 
cd ~/Library/texmf/tex/latex 
ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave 

我现在不明白的是 Latex 包 \usepackage{Sweave} 是如何知道它的 必须查看 ~/Library/texmf/tex/latex 才能找到 Sweave.sty 文件的符号链接? 如果我更改以下行会发生什么:

ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave

ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave_Link

在 .Rnw 中我必须使用文件 \usepackage{Sweave_Link} 吗?

Let's say I have written the following tiny .Rnw file:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{Sweave}
\usepackage{tikz}
\usepackage{pgf}
\begin{document}

<<>>=
sessionInfo()
@ 

\end{document}

I then can go to R and use sweave to translate the .Rnw file into a .tex file
Once this is done the latex interpreter can be called and because I used
\usepackage{Sweave} Latex knows how to handle the sweave specific code tags.
When I first did this procedure I got the common error that the Sweave.sty file could
not be found. I googled and could solve the problem by typing the following command
into the Mac OS Terminal:

mkdir -p ~/Library/texmf/tex/latex 
cd ~/Library/texmf/tex/latex 
ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave 

What I don't understand now is how does the latex package \usepackage{Sweave} know that it
has to look at ~/Library/texmf/tex/latex to find the symbolic link to the Sweave.sty file?
What happens if I change the following line:

ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave

to

ln -s /Library/Frameworks/R.framework/Resources/share/texmf Sweave_Link

In the .Rnw file do I have to use then \usepackage{Sweave_Link}?

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

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

发布评论

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

评论(1

じ违心 2024-12-14 06:41:15

当你安装 LaTeX 时,该路径会自动设置;这是您个人的 texmf 树,您可以将任何您希望 LaTeX 找到的样式或类文件放在那里。目录名称并不重要,它会在其中递归搜索 Sweave.sty。因此,将目录链接更改为 Sweave_Link 应该没有关系。

您可以通过运行 kpsewhich Sweave.sty 来测试它,它会在所有 texmf 树中查找所需的文件。

另外,您不需要在 Rnw 文件中包含 \usepackage{Sweave}; Sweave 会自动添加它。

That path is set automatically when you install LaTeX; it's your personal texmf tree and you can put any style or class files you want LaTeX to find there. The directory names don't matter, it searches recursively in them for Sweave.sty. So changing the directory link to Sweave_Link shouldn't matter.

You can test this by running kpsewhich Sweave.sty which looks in all the texmf trees for the desired file.

Also, you don't need to have \usepackage{Sweave} in the Rnw file; Sweave will add it automatically.

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