r - 编织 R-Markdown 文档会导致“!未定义的控制序列”。错误
问题描述
我正在创建一个 R Markdown 文档,并在尝试打印出数学公式时不断出错。我认为错误在标题中的某个地方,但我不能完全确定。这是该文档的简化版本:
---
output:
pdf_document:
keep_tex: yes
latex_engine: xelatex
header-includes: |
\usepackage{nath}
\usepackage{amsmath}
title: "Test Report"
toc: true
number_sections: true
graphics: yes
toc_depth: 2
df_print: kable
fontsize: 13pt
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
**`r 5 * 20`** entries in the dataset;
Testing mathematical symbols, $\varepsilon _{u,i}$.
The formula used for this is:
$$ Y_{u,i} = \mu + \varepsilon _{u,i} $$
Where $\Y_{u,i}$ is the predicted rating per user, per movie and $\mu$ is the "true" rating for all movies. Mu-hat -> $\hat{mu}$ .
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
这是错误消息:
output file: final_testing.knit.md
! Undefined control sequence.
\mathop ...\o@mathop {#1}} \else \def \mathop@arg
{#1} \def \afterparse@ {\m...
l.112 \begin{document}
Error: LaTeX failed to compile final_testing.tex. See https://yihui.org/tinytex/r/#debugging for debugging tips. See final_testing.log for more info.
Execution halted
任何使这种情况发生的输入都非常感谢。TIA
解决方案
我做了以下事情:
- 注释掉了latex引擎(可能是让Rmarkdown自己做选择)
- 删除
|
后header-includes:
-
之前插入\usepackage{}
- 注释掉包
nath
,因为它似乎没有加载 - 改变
fontsize: 12pt
,因为没有13pt
- 删除公式中的空格和几个反斜杠
现在对我有用,对你也有希望吗?
---
output:
pdf_document:
keep_tex: yes
# latex_engine: xelatex
header-includes:
# - \usepackage{nath}
- \usepackage{amsmath}
title: "Test Report"
toc: true
number_sections: true
graphics: yes
toc_depth: 2
df_print: kable
fontsize: 12pt
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r cars}
summary(cars)
```
**`r 5 * 20`** entries in the dataset;
Testing mathematical symbols, $\varepsilon_{u,i}$.
The formula used for this is:
$$Y_{u,i} = \mu + \varepsilon_{u,i}$$
Where $Y_{u,i}$ is the predicted rating per user, per movie and $\mu$ is the "true" rating for all movies. Mu-hat -> $\hat{mu}$.
## Including Plots
You can also embed plots, for example:
```{r pressure, echo=FALSE}
plot(pressure)
```
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.
推荐阅读
- android - Android Emulator UI 在方向更改时中断
- ios - SwiftUI:在 iOS 14 上点击返回时导航链接崩溃,但在 iOS 13 上没有
- telegram - 可以电报 Bot 以管理员身份创建聊天(组)并通过链接授予访问权限吗?
- android - Android Emulator UI 在方向更改时中断
- .net-core - 如何解决实体模型定义中的错误?
- reactjs - React Pluggable - 卸载插件时组件不会从 DOM 中删除
- javascript - 如何在触摸屏上跟踪/跟踪用户输入以匹配屏幕上的图像
- reactjs - React API this.props.message.map 不是函数
- python - 在 Python 中计算 CSV 中唯一值的最佳方法?
- google-dfp - Google 广告管理器广告位尺寸默认行为