Yaml 在编织PDF时,如何让amsmath在RMarkdown中工作?

Yaml 在编织PDF时,如何让amsmath在RMarkdown中工作?,yaml,r-markdown,knitr,bookdown,tinytex,Yaml,R Markdown,Knitr,Bookdown,Tinytex,在RMarkdown中,我有一个文档要编织成pdf。文件中有我需要自动编号的方程式。我一直在使用$$1+1=2\tag{1}$约定来编写方程,但现在想切换到\begin{equation}1+1=2\eq:this_eq\end{equation}约定,这样我就可以对方程进行自动编号和轻松的交叉引用。我发现的少数在线资源让我觉得这应该是相当简单的。例如或。然而,在尝试这样做的过程中,我遇到了无尽的心碎 我将3.4.3版与tinytex发行版RStudio一起使用,并安装了bookdown(我仍然

在RMarkdown中,我有一个文档要编织成pdf。文件中有我需要自动编号的方程式。我一直在使用
$$1+1=2\tag{1}$
约定来编写方程,但现在想切换到
\begin{equation}1+1=2\eq:this_eq\end{equation}
约定,这样我就可以对方程进行自动编号和轻松的交叉引用。我发现的少数在线资源让我觉得这应该是相当简单的。例如或。然而,在尝试这样做的过程中,我遇到了无尽的心碎

我将3.4.3版与tinytex发行版RStudio一起使用,并安装了bookdown(我仍然不确定是否真的需要它来实现我的目标)。这里有一个重复:

---
title: This title
author: "This guy"
date: "This date"
header-includes:
   - \usepackage{amsmath}
output:
  pdf_document:
    toc: yes
    toc_depth: '4'
    df_print: kable
    fig_caption: yes
    latex_engine: xelatex
mainfont: Calibri Light
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction

blah blah...

\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}

## Later on

blah blah \@ref(eq:signals)
当我尝试“编织到PDF”时,我遇到了错误

! Package mathspec Error: `amsmath' must be loaded earlier than `mathspec'.
这已被报告为一个错误和“修复”,但我无法理解修复或遵循其指示。我所要求的是一套非常清晰的步骤,让我可以毫无意外地运行上面的repex

我尝试过的一些事情:

当我用
bookdown::pdf\u document2
替换
pdf\u document
时,也会发生相同的错误。或者当我移除

header-includes:
   - \usepackage{amsmath}
而是把

includes:
  in_header: preamble.tex
在第
行latex\u engine:xelatex
之后,其中“preamble.tex”是一个记事本文件,其中包含第
\usepack{amsmath}

中的评论似乎表明,甚至没有必要在YAML选项中提及amsmath,这让我更加困惑。当我从YAML选项中删除对amsmath的任何提及时,我会收到错误,指出mathjax脚本无法识别,例如:

! Package amsmath Error: \bar allowed only in math mode.

当我尝试你的例子时,方程没有成功地标记

然后我将输出设置替换为
bookdown::pdf\u book
。它起作用了

---
title: This title
author: "This guy"
date: "This date"
output:
  bookdown::pdf_book
mainfont: Calibri Light
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```

## Introduction

blah blah...

\begin{equation}
  S = X \bar{P}
  (\#eq:signals)
\end{equation}

## Later on

blah blah \@ref(eq:signals)