【问题标题】:Bibliography in knitr child documentsknitr 子文档中的参考书目
【发布时间】:2015-06-25 23:07:00
【问题描述】:

我无法在knitr 子文档中包含参考书目。我希望能够在子文档中引用我的主要参考书目中的文章,但参考书目出现在主文档之后,而不是在子文档之后。如果我只在主文档中包含\bibliography 命令,则无法正确解析子文档中的引用。示例:

main.Rnw:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\begin{document}
This is the main doc.

<<child-demo, child='child.Rnw'>>=
@
\bibliography{mylib}
\end{document}

child.Rnw:

This is the child \cite{myref}.

mylib.bib:

@article{myref,
 title = {frobnosticating froo filters}
 volume = {21},
 journal = {Frobnification},
 author = {John Q. Smith}
 month = jan,
 year = {2004}
}

我的compile 脚​​本包含:

#!/usr/bin/env Rscript
library(knitr)
knit('main.Rnw', tangle=TRUE)
knit('main.Rnw', tangle=FALSE)
for ( i in c(1,2,3)) {
  system('pdflatex main')
  system('bibtex main')
}

运行compile 产生:

如何使子文档包含主要参考书目中的参考文献?

【问题讨论】:

  • 这不是 Latex 问题;这是一个编织问题。 stackoverflow 上有成千上万个标记为“knitr”的问题。
  • 你是如何编译主文档的?要解析引用,通常你必须经历 pdflatex & bibtex & pdflatex & pdflatex 的无聊过程,除非你使用足够聪明的工具来解析引用。
  • @Yihui--将我的编译脚本添加到问题中。
  • 原来它一个LaTeX问题...

标签: r knitr bibtex bibliography


【解决方案1】:

首先,您在mylib.bib 中遗漏了几个逗号:

@article{myref,
 title = {frobnosticating froo filters},
 volume = {21},
 journal = {Frobnification},
 author = {John Q. Smith},
 month = {jan},
 year = {2004}
}

那么您没有指定参考书目样式:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\begin{document}
This is the main doc.

<<child-demo, child='child.Rnw'>>=
@
\bibliography{mylib}
\bibliographystyle{plain}
\end{document}

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-20
    • 2016-01-01
    • 2019-05-16
    • 1970-01-01
    • 2020-08-10
    相关资源
    最近更新 更多