如何解决来自 .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.Rnw
和 compileRnw.bash
应该是什么样的?
在此先感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。