我的纯乳胶demo.tex
如下:
\documentclass{article}
\usepackage[hidelinks]{hyperref}
\usepackage[numbers,super,square,sort&compress]{natbib}
\begin{document}
statistics \cite{anderson2003introduction,efron2004least,hastie2009elements}
\bibliographystyle{unsrtnat}
\nocite{*}
\bibliography{ref}
\addcontentsline{toc}{section}{References}
\end{document}
它运行良好,其中ref.bib
包含
@Book{anderson2003introduction,
author = {Anderson, Theodore Wilbur},
publisher = {Wiley},
title = {An introduction to multivariate statistical analysis},
year = {2003},
address = {New Jersey},
edition = {3},
}
@Article{efron2004least,
author = {Efron, Bradley and Hastie, Trevor and Johnstone, Iain and Tibshirani, Robert},
title = {Least angle regression},
journal = {The Annals of Statistics},
year = {2004},
volume = {32},
number = {2},
pages = {407--499},
}
@Book{hastie2009elements,
author = {Hastie, Trevor and Tibshirani, Robert and Friedman, Jerome},
publisher = {Springer},
title = {The elements of statistical learning: {Data} mining, inference, and prediction},
year = {2009},
address = {New York},
edition = {2},
}
@Book{fan2020statistical,
author = {Fan, Jianqing and Li, Runze and Zhang, Cun-Hui and Zou, Hui},
publisher = {CRC},
title = {Statistical foundations of data science},
year = {2020},
address = {Boca Raton},
}
我想将demo.tex
转换为rmarkdown文件tex2rmd.rmd
,并尝试
---
output:
pdf_document:
keep_tex: yes
citation_package: natbib
natbiboptions: "numbers,super,square,sort&compress"
# natbiboptions: "numbers,super,square" #test
biblio-style: unsrtnat
nocite: '@*'
bibliography: ref.bib
link-citations: yes
colorlinks: no
---
statistics [@anderson2003introduction; @efron2004least; @hastie2009elements]
# References
这会产生如下错误
! Missing \endcsname inserted.
<to be read again>
\&
l.351 \newcommand
\NAT@aysep{,} \newcommand\NAT@yrsep{,}
然后,我从keep_tex: yes
功能检查tex2rmd.tex
文件,发现问题发生在
\usepackage[numbers,super,square,sort\&compress]{natbib}
其中存在sort\&compress
而不是sort&compress
。如何修复此问题?
此外,我使用natbiboptions: "numbers,super,square"
代替测试目的,发现nocite: '@*'
也不工作(它应该显示所有4项,而不是引用的3项)。我忽略了什么吗?
2条答案
按热度按时间n9vozmp41#
将
sort&compress
中的&
替换为,
解决了sort&compress
的问题。当你使用
natbib
或biblatex
作为引用包时,nocite
YAML键似乎不起作用,因为nocite
键被pandoc-citeproc
过滤器使用,但当natbib
或biblatex
作为引用方法时(默认为citeproc
),pandoc-citeproc
不起作用,nocite
也不起作用。在这种情况下,您需要使用原始LaTeX命令
\nocite
(如下所述)lymnna712#
为了避免rmarkdown解析的所有问题并给予您更多的自由,您可以直接在rmarkdown中使用latex代码: