I am using bookdown in RStudio to compile a series of lecture notes into a single manuscript. I have a custom block that has within it an enumerated list.
```{r, echo=FALSE}
instructorVersion<-TRUE
```
What is 1+1?
```{block, type='ANSWER', echo=instructorVersion, purl=FALSE}
1. This answer is easy
2. Yes, really, that's all that I was asking.
```
What is the meaning of life?
```{block, type='ANSWER', echo=instructorVersion, purl=FALSE}
The Answer is only for Instructor's Eyes
1. The answer is hard
2. You won't get it right
3. But try anyway
```
The first block turns out fine in latex:
\begin{ANSWER}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
This answer is easy
\item
Yes, really, that's all that I was asking.
\end{enumerate}
\end{ANSWER}
but for some reason, the second block has a different latex code that creates a problem in compiling
\begin{ANSWER}
The Answer is only for Instructor's Eyes
\begin{enumerate}
\def\arabic{enumi}.{\arabic{enumi}.} %%% This line is different
\tightlist
\item
The answer is hard
\item
You won't get it right
\item
But try anyway
\end{enumerate}
\end{ANSWER}
I get the following error:
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.181 T
he answer is hard
Deleting the line marked above (with %%%) or replacing it with the version in the first block allows the latex to compile fine.
I don't have the problem if I use the ::: Div blocks (the latex code looks like the first one above that compiles correctly).
```{r, echo=FALSE}
instructorVersion<-TRUE
```
What is 1+1?
::: {.ANSWER}
1. This answer is easy
2. Yes, really, that's all that I was asking.
:::
What is the meaning of life?
::: {.ANSWER}
The Answer is only for Instructor's Eyes
1. The answer is hard
2. You won't get it right
3. But try anyway
:::
But I am using the ```block style rather than ::: .{ANSWER} because I want to be able to toggle on and off whether to have the text appear, as I showed above. I don't know that I can do that with the ::: format. (I would be happy with an answer that showed me how to use the ::: version but with a toggle on/off like what I have now.)
Here is my environment command in latex, which basically makes the text red (I don't think it matters, and I've made it just an empty environment and gotten the same thing, but just for completeness)
\newenvironment{ANSWER}{%
\envspace\itshape\color{red}
}
{}
Also, I am running this in RStudio, with the following command:
render_book('index.Rmd',envir=new.env(),clean=FALSE,output_dir='test', output_format=c('bookdown::pdf_book') )
R Studio 1.3.959,
> sessionInfo()
R version 4.0.1 (2020-06-06)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.4
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bookdown_0.20
loaded via a namespace (and not attached):
[1] compiler_4.0.1 magrittr_1.5 htmltools_0.5.0 tools_4.0.1
[5] rstudioapi_0.11 yaml_2.2.1 tinytex_0.24 stringi_1.4.6
[9] rmarkdown_2.3 highr_0.8 knitr_1.29 stringr_1.4.0
[13] xfun_0.15 digest_0.6.25 rlang_0.4.7 evaluate_0.14