简体   繁体   English

使用 RStudio 和 natbib 进行引用时出现参考书目样式的问题

[英]Problems doing citations using RStudio with natbib with a bibliography style

Consider the following:考虑以下:

test.rnw测试.rnw

\documentclass[12pt]{article}
\usepackage{natbib}
\usepackage[margin=1in]{geometry}

\begin{document}
<<setup, include = FALSE,  echo = FALSE>>=
Sys.setenv(TEXINPUTS = getwd(),
           BIBINPUTS = getwd(),
           BSTINPUTS = getwd())
@

Some text \citet{brockwelldavis}
\newpage 
\nocite{*}
\bibliographystyle{jasa}
\bibliography{test}
\end{document}

test.bib测试.bib

@book{brockwelldavis,
  author = {Brockwell, Peter J. and Davis, Richard A.},
  year = 2016,
  title = "Introduction to Time Series and Forecasting",
  editor = "",
  publisher = "Springer International Publishing",
  address = "Switzerland"
}

jasa.bst jasa.bst

This file can be found at either https://github.com/merliseclyde/AAIS/blob/master/jasa.bst or https://github.com/auk12/MSc-Thesis-backup/blob/master/Bibliography/jasa.bst .该文件可在https://github.com/merliseclyde/AAIS/blob/master/jasa.bsthttps://github.com/auk12/MSc-Thesis-backup/blob/master/Bibliography/ja中找到.bst

Problem Description问题描述

In RStudio, when I hit "Compile PDF" using test.rnw , I get在 RStudio 中,当我使用test.rnw点击“编译 PDF”时,我得到

output file: test.tex

[1] "test.tex"
Running pdflatex.exe on test.tex...failed

Issues: 2 warnings

and from the log file:并从日志文件中:

Package natbib Warning: Citation `brockwelldavis' on page 1 undefined on input 
line 58.

[1

{C:/Users/[my name]/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}]

No file test.bbl.

Package natbib Warning: There were undefined citations.

So, I run test.tex created from test.rnw using pdfLaTeX + MakeIndex + BibTeX in TeXworks, and test.bbl is created.因此,我在test.rnw中使用 pdfLaTeX + MakeIndex + BibTeX 运行从test.tex创建的 test.tex,并创建了test.bbl Interestingly, test.pdf compiles correctly and can be viewed through TeXworks.有趣的是, test.pdf编译正确,可以通过 TeXworks 查看。 I can clearly both the.bbl and.pdf files using Windows Explorer.我可以使用 Windows Explorer 清楚地看到 .bbl 和 .pdf 文件。

But when I hit "Compile PDF" in RStudio after compiling through TeXworks, I still get the same warning as above.但是当我通过 TeXworks 编译后在 RStudio 中点击“编译 PDF”时,我仍然收到与上述相同的警告。 Anyone have any insight as to how to fix this?任何人都知道如何解决这个问题?

Additional Note附加说明

What's also baffling is that on my old computer, test.rnw compiles fine without having to use TeXworks as an intermediate step and on my new computer, it does not.同样令人困惑的是,在我的旧计算机上, test.rnw编译得很好,而无需使用 TeXworks 作为中间步骤,而在我的新计算机上却没有。 The only difference I can think of is that perhaps my new computer has more updated versions of R and MikTeX.我能想到的唯一区别是,也许我的新电脑有更多更新版本的 R 和 MikTeX。 I also tried uninstalling and reinstalling MikTeX on my new computer and still ran into the same problem.我还尝试在我的新计算机上卸载并重新安装 MikTeX,但仍然遇到了同样的问题。

New Computer setup:新电脑设置:

From R (using RStudio 1.2.5033):从 R(使用 RStudio 1.2.5033):

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.3 tools_3.6.3   

Through the Windows command prompt:通过 Windows 命令提示符:

> pdftex --version
MiKTeX-pdfTeX 2.9.7338 (1.40.21) (MiKTeX 2.9.7380 64-bit)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2020 Han The Thanh
TeX is a trademark of the American Mathematical Society.
using bzip2 version 1.0.6, 6-Sept-2010
compiled with curl version 7.61.1; using libcurl/7.61.1 WinSSL
compiled with expat version 2.2.6; using expat_2.2.6
compiled with jpeg version 9.3
compiled with liblzma version 50020042; using 50020042
compiled with libpng version 1.6.37; using 1.6.37
compiled with libressl version LibreSSL 2.8.2; using LibreSSL 2.8.2
compiled with MiKTeX Application Framework version 4.7348; using 4.7348
compiled with MiKTeX Core version 16.7375; using 16.7375
compiled with MiKTeX Archive Extractor version 1.6882; using 1.6882
compiled with MiKTeX Package Manager version 9.7364; using 9.7364
compiled with poppler version 0.60.1
compiled with uriparser version 0.9.2
compiled with zlib version 1.2.11; using 1.2.11

Old Computer setup:旧电脑设置:

From R (using RStudio 1.2.5001):从 R(使用 RStudio 1.2.5001):

> sessionInfo()
R version 3.6.2 (2019-12-12)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_3.6.2 tools_3.6.2   

Through the Windows command prompt:通过 Windows 命令提示符:

> pdftex --version
MiKTeX-pdfTeX 2.9.6050 (1.40.17) (MiKTeX 2.9 64-bit)
Copyright (C) 1982 D. E. Knuth, (C) 1996-2016 Han The Thanh
TeX is a trademark of the American Mathematical Society.
compiled with zlib version 1.2.8; using 1.2.8
compiled with libpng version 1.6.24; using 1.6.24
compiled with poppler version 0.46.0
compiled with jpeg version 8.4

Both are using knitr and pdfLaTeX based on Tools > Global Options > Sweave in RStudio.两者都基于 RStudio 中的工具 > 全局选项 > Sweave 使用 knitr 和 pdfLaTeX。

This has finally be resolved in the RStudio IDE, and the fix will appear in the patch release after RStudio 1.4, which is not available yet.这个问题终于在RStudio IDE中得到解决,修复会出现在RStudio 1.4之后的补丁发布中,目前还没有。 Currently you have to use the daily build of RStudio: https://dailies.rstudio.com目前您必须使用 RStudio 的每日构建: https://dailies.rstudio.Z4D236D9A50D102C5ZFE6BAD1

In Tools -> Global Options , you can check the box "Use tinytex when compiling.tex files":Tools -> Global Options中,您可以选中“编译时使用 tinytex 文件”框:

在 RStudio 中使用 tinytex 编译 .tex

Then the bibliography should be compiled correctly.然后应该正确编译参考书目。

I had a similar problem, on Windows.我在 Windows 上遇到了类似的问题。 I tried to use R-studio and Miktex, but bibliographic citations were not generated.我尝试使用 R-studio 和 Miktex,但没有生成书目引文。 I installed TinyTex but it was in conflict with Texmaker.我安装了 TinyTex,但它与 Texmaker 冲突。 Solution: I installed the full Texlive.解决方案:我安装了完整的 Texlive。 Everything working now.现在一切正常。

RStudio (1.3.959), R (4.0.2), Texlive (2020-r55535), Texmaker 5.0.4, Windows 10 x64 single language. RStudio (1.3.959), R (4.0.2), Texlive (2020-r55535), Texmaker 5.0.4, ZAEA234820864AA9B4406CD1 8640A 单一语言。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM