简体   繁体   English

RStudio 编织到 pdf 书籍的文章在交叉引用方程时失败

[英]RStudio rticles knit to pdf book fails when cross-referencing equations

Ramping up for a new conference article, I want to use rticles and make use of the cross-referencing features of bookdown.准备一篇新的会议文章,我想使用 rticles 并利用 bookdown 的交叉引用功能。 This originally failed when using the standard equation and cross-referencing example (eg compare for https://bookdown.org/yihui/bookdown/cross-references.html ).这最初在使用标准方程和交叉引用示例时失败(例如,比较https://bookdown.org/yihui/bookdown/cross-references.html )。

The original error message read:原始错误消息如下:

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

Eliminating the cross-reference pointer \@ref(eq:linear) made knit complete.消除交叉引用指针\@ref(eq:linear)使 knit 完成。 However, I - obviously - lost the cross-reference to the equation.然而,我 - 显然 - 失去了对等式的交叉引用。

following an update of all R packages, the Rmd is knitted without throwing an error.在更新所有 R 包之后,Rmd 被编织而不会引发错误。 However, the cross-reference is not automatically inserted, instead the \@ref(eq:linear) is printed.但是,不会自动插入交叉引用,而是打印\@ref(eq:linear)

I assume the issue is related how such references (aka control sequences) are processed during the knitting.我认为这个问题与在编织过程中如何处理这些引用(又名控制序列)有关。 :( I have no idea how to handle this. :( 我不知道如何处理这个。

This SO-question Cross-referencing in rticles provides pointers to the official documentation from which the example is taken over.这个 SO-question Cross-reference in rticles提供了指向官方文档的指针,该示例从中被接管。

Thanks for shedding some light on me how to format the equation reference.感谢您让我了解如何格式化方程式参考。

---
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.

Referencing equation with \eqref requires the amsmath Tex package.使用\eqref引用方程需要amsmath Tex package。

For this specific format ieee_article , the use of amsmath is conditional to a pandoc variable.对于这种特定格式ieee_article , amsmath 的使用amsmath变量。 You need to add this in your yaml header您需要将此添加到您的 yaml header

with_amsmath: true

You can add any Tex packages for any rmarkdown format using the extra_dependencies argument in the format output.您可以使用格式为 output 的extra_dependencies参数为任何 rmarkdown 格式添加任何 Tex 包。

Here it could also works like this在这里它也可以这样工作

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

(but it is not recommended to comply with IEEE requirements here, as the template includes a configuration for amsmath ) (但这里不建议遵守 IEEE 要求,因为模板包含amsmath的配置)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM