在编译为 PDF 和 HTML 的 R 降价文件中使用高级引用命令(例如,citetitle、citeauthor、footcite from biblatex/natbib)

mav*_*cks 7 latex bibtex citations biblatex r-markdown

双方natbibbiblatex提供种类繁多的命令中插入引用。

但是,在R markdown 中似乎只有少数可用:

描述 R降价 natbib 命令 biblatex 命令
经典引文:作者、年份和括号(根据引文风格使用圆括号或方括号) [@key] \citep{key} \parencite[Prefix][Suffix]{key}
文本内引用:作者(年份)(不带方括号或带括号,具体取决于引用样式) @key \citet{key} \cite[Prefix][Suffix]{key}
仅年份/抑制作者:(年份) [-@key] \citeyear{key} \citeyear[Prefix][Suffix]{key}
在参考书目中包含项目而不在文档中引用它 未使用的参考文献(nocite) \nocite{key} \nocite{key}

通常人们想使用更高级的命令,例如只引用作者并隐藏年份。

有没有办法在 R markdown 文档中添加和使用以下 cite 命令以多种输出格式编译,特别是 PDF 和 HTML?

\citetitle{key} Returns the title of the source.
\citeauthor{key} Returns the author(s) of the cited source.
\footcite{key} Creates a footnote within the document.
\fullcite{key} Creates a complete quote like in the bibliography
\footfullcite{key} Creates a complete citation, as in the bibliography, in a footnote.
Run Code Online (Sandbox Code Playgroud)

相关 SO Q: 仅作者并在文本引用中添加所有格更灵活的引文格式

tar*_*leb 3

依靠。如果你只是制作PDF文档,那么你可以直接使用natbib或biblatex并使用原始的LaTeX命令。

---
output:
  pdf_document:
    citation_package: biblatex
---

Show just the author of citation with ID "rick": \citeauthor{rick}
Run Code Online (Sandbox Code Playgroud)

但这适用于 PDF 输出。


其他格式则很棘手。R Markdown 使用citeproc处理器,该处理器根据以引文样式语言 (CSL)编写的定义来处理引文并设置引文样式。有些事情可以通过这种方式进行控制,例如一致使用脚注作为参考。CSL 不支持其他选项,例如仅作者引用。

理论上,您可以使用pandocfiltersLua 过滤器来破解您自己的插件,扩展引用语法。但这可能带来的麻烦大于其价值。