r markdown不编译

时间:2018-09-21 04:49:06

标签: r latex r-markdown pandoc

所以我已经使用R Markdown已有一段时间了,但是现在当我尝试编织文档时,它失败了。出现以下错误消息:

  

LaTeX错误:孤独的\ item-也许缺少列表   环境。

我不确定为什么会发生这种情况,因为它以前对我有用。我的文档序言中有两个快捷方式:

  1. \newcommand{\benum}{\begin{enumerate}}

  2. \newcommand{\eenum}{\end{enumerate}}

我觉得这可能是造成我问题的原因,但是令人沮丧的是,在此之前我已经使用了很长时间,没有遇到任何麻烦。

任何帮助将不胜感激!

编辑:

这是我制作的最小文件。此小文档将不会编织,并且出现与上述相同的错误消息。

---
title: "Minimal Document"
author: Aiden Kenny
date: Friday, 09/21/2018
header-includes: 
  - #\usepackage{setspace}\doublespacing
  - \newcommand{\benum}{\begin{enumerate}}
  - \newcommand{\eenum}{\end{enumerate}}
  - \usepackage{xcolor}
fontsize: 12pt
geometry: margin=1in 
output: pdf_document
---

\newpage

```{r setup, include = FALSE}
knitr::opts_chunk$set(fig.width = 10, fig.height = 5, echo = TRUE)
library(mosaic)
library(knitr)
library(scatterplot3d)
```

1. Here is a sample of some code I found online. The code chunk by 
itself will run fine, so that is not the issue.


```{r, echp=FALSE}
require(stats); require(graphics)
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)",
 las = 1)
lines(lowess(cars$speed, cars$dist, f = 2/3, iter = 3), col = "red")
title(main = "cars data")
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)",
     las = 1, log = "xy")
title(main = "cars data (logarithmic scales)")
lines(lowess(cars$speed, cars$dist, f = 2/3, iter = 3), col = "red")
summary(fm1 <- lm(log(dist) ~ log(speed), data = cars))
opar <- par(mfrow = c(2, 2), oma = c(0, 0, 1.1, 0),
            mar = c(4.1, 4.1, 2.1, 1.1))
plot(fm1)
par(opar)
```

编辑:  我一直在玩这个,这似乎是问题的一部分:

\begin{enumerate}

\item Using the default enumerate/itemize commands

\item DO work!

\end{enumerate}

但是...

\benum

\item Using the shortcut commands I made

\item DO NOT work!

\eenum

当我尝试单独运行代码块时,它们可以正常编译并生成所需的图形,因此我怀疑这是LaTeX的问题。但是我不是特克斯人,所以我不确定。

最初创建这些快捷键命令的原因是,我可以在这种类型的环境中使用大块R代码(请参见https://tex.stackexchange.com/questions/210003/how-can-i-nest-a-code-chunk-within-an-enumerate-environment-when-using-r-markdow)。

如以下某人所述,这可能与Pandoc有关吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

不需要原始LaTeX。以下内容可以很好地产生您认为要达到的结果:

---
title: "Minimal Document"
author: Aiden Kenny
date: Friday, 09/21/2018
header-includes: 
  - \usepackage{xcolor}
fontsize: 12pt
geometry: margin=1in 
output: 
  pdf_document:
    keep_tex: yes
---

\newpage

```{r setup, include = FALSE}
knitr::opts_chunk$set(fig.width = 10, fig.height = 5, echo = TRUE)
library(knitr)
```

1. Here is a sample of some code I found online. The code chunk by 
itself will run fine, so that is not the issue.


```{r}
require(stats); require(graphics)
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)",
 las = 1)
lines(lowess(cars$speed, cars$dist, f = 2/3, iter = 3), col = "red")
title(main = "cars data")
plot(cars, xlab = "Speed (mph)", ylab = "Stopping distance (ft)",
     las = 1, log = "xy")
title(main = "cars data (logarithmic scales)")
lines(lowess(cars$speed, cars$dist, f = 2/3, iter = 3), col = "red")
summary(fm1 <- lm(log(dist) ~ log(speed), data = cars))
opar <- par(mfrow = c(2, 2), oma = c(0, 0, 1.1, 0),
            mar = c(4.1, 4.1, 2.1, 1.1))
plot(fm1)
par(opar)
```

2. Thanks for the help. This document will not knit!

您也可以使用完整的命令:\begin{enumerate}\end{enumerate}。我不确定为什么pandoc会将您的缩写从TeX文件中删除。