【问题标题】:Mixing R and LaTeX code in an Rnw file在 Rnw 文件中混合 R 和 LaTeX 代码
【发布时间】:2014-05-04 16:46:15
【问题描述】:

在使用 knitr 将 .Rnw 文件转换为 .tex 文件时,我尝试将科学名称用斜体表示。运行 knit 时出现错误。这是我的 .Rnw 文件中包含的代码(需要运行 taxizestringr 库):

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum \Sexpr{str_c("Collared Flycatchers (\\textit{", comm2sci(commnames='Collared Flycatcher', db="itis")[[1]], "})")[1]}

.tex 文件中的输出应该是:

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum Collared Flycatchers (\textit{Ficedula semitorquata})

如何在 .tex 文件中获取此输出?

【问题讨论】:

标签: r latex knitr ropensci


【解决方案1】:

这对我有用

\documentclass{article}
\begin{document}
<<message=FALSE>>=
library("taxize")
@
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum \textit{\Sexpr{comm2sci(commnames='Collared Flycatcher', db="itis")[[1]][2]}}
\end{document}

这能满足您的需求吗?在我的输出 pdf 中看起来很正确。

【讨论】:

    猜你喜欢
    • 2018-09-07
    • 1970-01-01
    • 2023-03-27
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    相关资源
    最近更新 更多