在将r-markdown编入PDF时,是否有办法将LaTeX引用键保存在.tex文件中
我正在用r-markdown写一篇文章,希望保留.tex文件,以便通过在将r-markdown编入PDF时,是否有办法将LaTeX引用键保存在.tex文件中,r,latex,r-markdown,knitr,R,Latex,R Markdown,Knitr,我正在用r-markdown写一篇文章,希望保留.tex文件,以便通过 title: "My title" author: "My name" date: "`r format(Sys.time(), '%d %B, %Y')`" abstract: "My abstract" output: html_document: df_print: paged word_document: default
title: "My title"
author: "My name"
date: "`r format(Sys.time(), '%d %B, %Y')`"
abstract: "My abstract"
output:
html_document:
df_print: paged
word_document: default
pdf_document:
keep_tex: yes
bibliography: bibfile.bib
在PDF中一切都很好,甚至.tex文件看起来也不错,但是参考键消失了。
是否有一种方法可以自动将引用密钥从r标记文件(如[@smith1995]
转换为.tex文件(如\cite{smith1995}
)并创建相应的引用
我正在x86_64-pc-linux-gnu(64位)
所有R软件包均更新至最新版本:
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] texreg_1.37.5
loaded via a namespace (and not attached):
[1] httr_1.4.2 viridis_0.5.1 tidyr_1.1.2 tidygraph_1.2.0 viridisLite_0.3.0 splines_4.0.3
[7] foreach_1.5.1 ggraph_2.0.3 network_1.16.1 assertthat_0.2.1 yaml_2.2.1 robustbase_0.93-6
[13] ggrepel_0.8.2 backports_1.2.1 pillar_1.5.0 lattice_0.20-41 quantreg_5.85 glue_1.4.2
[19] digest_0.6.27 polyclip_1.10-0 colorspace_1.4-1 htmltools_0.5.1.1 cowplot_1.1.1 Matrix_1.3-2
[25] plyr_1.8.6 conquer_1.0.2 lpSolve_5.6.15 pkgconfig_2.0.3 broom_0.7.5 SparseM_1.78
[31] purrr_0.3.4 ergm_3.11.0 scales_1.1.1 tweenr_1.0.1 sna_2.6 MatrixModels_0.4-1
[37] ggforce_0.3.2 tibble_3.0.6 mgcv_1.8-33 generics_0.1.0 farver_2.0.3 ggplot2_3.3.3
[43] ellipsis_0.3.1 cli_2.3.1 splitstackshape_1.4.8 magrittr_1.5 crayon_1.3.4 statnet.common_4.4.1
[49] evaluate_0.14 mcmc_0.9-7 fansi_0.4.1 doParallel_1.0.16 nlme_3.1-152 MASS_7.3-53
[55] rem_1.3.1 vegan_2.5-6 tools_4.0.3 data.table_1.14.0 lifecycle_0.2.0 matrixStats_0.58.0
[61] stringr_1.4.0 MCMCpack_1.5-0 trust_0.1-8 munsell_0.5.0 cluster_2.1.0 compiler_4.0.3
[67] rlang_0.4.10 grid_4.0.3 iterators_1.0.13 rstudioapi_0.11 igraph_1.2.6 rmarkdown_2.7
[73] gtable_0.3.0 codetools_0.2-18 DBI_1.1.1 reshape2_1.4.4 graphlayouts_0.7.1 rDNA_2.1.18
[79] R6_2.5.0 gridExtra_2.3 rle_0.9.2 knitr_1.31 dplyr_1.0.4 utf8_1.1.4
[85] permute_0.9-5 rJava_0.9-13 stringi_1.5.3 parallel_4.0.3 Rcpp_1.0.6 vctrs_0.3.6
[91] xfun_0.21 DEoptimR_1.0-8 tidyselect_1.1.0 coda_0.19-4
我找到了解决办法。。。更改引文包起了作用。默认的
pandoc citeproc
似乎不会在.tex文件中创建引用键,但natbib
会创建引用键。我只是简单地用:
pdf_document:
keep_tex: yes
latex_engine: xelatex
citation_package: natbib
现在.Rmd引用,如[@Smith1995]
,在相应的.tex文件中转换为\citep{Smith1995}
。
另一个选项可能是
biblatex
是否在YAML部分添加参考书目
键@CarlosLuisRivera是的,我做了,pdf(以及.html甚至.docx)输出看起来不错,并且有正确的引用。在.tex文件中没有引用键。这里的引文是纯文本,比如(Smith 1995)而不是\cite{Smith 1995}
你介意编辑这篇文章并添加YAML的完整规范和R的版本信息、其软件包和Pandoc吗?最新的Pandoc版本是2021/02/27。您的可能太老了,无法获得LaTeX的引用命令(我认为Pandoc版本2.5使用了Pandoc citeproc
,这是不推荐使用的,如果我正确理解的话,在从[R]md生成.tex时标记为@提及
)。指导您使用未与RStudio IDE捆绑的Pandoc版本。即使升级Pandoc后问题仍然存在,您是否可以报告?遗憾的是,问题仍然存在。。。我也试过Xeletex和lualatex,但没有区别