微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

来自 .Rnw 文件的 knitr 章节参考书目?

如何解决来自 .Rnw 文件的 knitr 章节参考书目?

可以使用 BiblateX 和直接的 .tex 文件创建章节参考书目,如本 MWE 所示:

% main.tex
\documentclass{report}
\usepackage{natbib}
\usepackage{chapterbib}

\begin{document}

\include{chap1}
\include{chap2}

\end{document}


% chap1.tex
\chapter{one chapter}

text~\cite{paper1}
text~\cite{paper2}

\bibliographystyle{plainnat}
\bibliography{biblio}


% chap2.tex
\chapter{another chapter}

text~\cite{paper2,paper3}

\bibliographystyle{plainnat}
\bibliography{biblio}


% biblio.bib
@Article{paper1,author =       {John Smith},title =        {A title},journal =      {A Journal},year =         {2010}
}
@Article{paper2,author =       {John Doe},title =        {A paper},journal =      {Another journal},year =         {2009}
}
@Article{paper3,author =       {Yuppie Networking},title =        {My paper},journal =      {The best journal},year =         {2000}
}

使用以下脚本可以成功编译以上文件

% compile.bash
#!/bin/bash
pdflatex main.tex
for auxfile in chaP*.aux
do
    bibtex `basename $auxfile .aux`
done
pdflatex main.tex
pdflatex main.tex

我希望使用 knitr、BiblateX 和 .Rnw 文件(不是 .tex 文件)重新创建上述功能。这是一个小的非工作示例。 (我知道这个例子缺少 R 代码块,但我的用例会有 R 代码块。)

% main.Rnw
\documentclass{report}
\usepackage{natbib}
\usepackage{chapterbib}

\begin{document}

\Sexpr{knitr::knit_child("chap1.Rnw")}
\Sexpr{knitr::knit_child("chap2.Rnw")}

\end{document}


% chap1.Rnw
\chapter{one chapter}

text~\cite{paper1}
text~\cite{paper2}

\bibliographystyle{plainnat}
\bibliography{biblio}


% chap2.Rnw
\chapter{another chapter}

text~\cite{paper2,paper3}

\bibliographystyle{plainnat}
\bibliography{biblio}


% knit_script.R
knitr::knit(input = "main.Rnw")


% compileRnw.bash
/usr/local/bin/Rscript knit_script.R

pdflatex main.tex
for auxfile in chaP*.aux
do
    bibtex `basename $auxfile .aux`
done
pdflatex main.tex
pdflatex main.tex

当我运行 compileRnw.bash 脚本时,生成的文档缺少参考书目。

从 .Rnw 文件创建包含章节参考书目的文档时,main.RnwcompileRnw.bash 应该是什么样的?

在此先感谢您的帮助!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?