首页 > 解决方案 > 交叉引用方程时,RStudio rticles knit to pdf book 失败

问题描述

准备一篇新的会议文章,我想使用 rticles 并利用 bookdown 的交叉引用功能。这最初在使用标准方程和交叉引用示例时失败(例如比较https://bookdown.org/yihui/bookdown/cross-references.html)。

原始错误消息如下:

! Undefined control sequence.
l.430 See equation \eqref
                         {eq:linear} for more insights. 

消除交叉引用指针\@ref(eq:linear)使编织完成。然而,我 - 显然 - 失去了对等式的交叉引用。

在更新所有 R 包之后,Rmd 被编织而不会引发错误。但是,不会自动插入交叉引用,而是\@ref(eq:linear)打印出来。

我认为这个问题与在编织过程中如何处理这些引用(又名控制序列)有关。:( 我不知道如何处理这个。

这个 SO-question Cross-reference in rticles提供了指向官方文档的指针,该示例从中被接管。

感谢您让我了解如何格式化方程式参考。

---
title: "rticles fails knitting equation references"
keywords: ["keyword 1", "keyword 2"]
abstract: |
  The abstract goes here.
  On multiple lines eventually.
## hook up rticles as base format with bookdown for referencing, etc
output:
  bookdown::pdf_book:
    base_format: rticles::ieee_article
---

Introduction
=============

To add math, I do the following

See equation \@ref(eq:linear) for more insights.

\begin{equation}
a + bx = c  (\#eq:linear)
\end{equation}

More cool text.

标签: rr-markdowncross-reference

解决方案


引用方程式\eqref需要amsmathTex 包。

对于这种特定格式ieee_article,使用amsmath是有条件的 pandoc 变量。您需要将其添加到您的 yaml 标头中

with_amsmath: true

extra_dependencies您可以使用格式输出中的参数为任何 rmarkdown 格式添加任何 Tex 包。

在这里它也可以这样工作

output:
  bookdown::pdf_book:
    base_format: rticles::ieee_article
    extra_dependencies: amsmath

(但这里不建议遵守 IEEE 要求,因为模板包含用于 的配置amsmath


推荐阅读