2

I am working on a bookdown project and ran into a problem with the theorem environment. It works when I compile to gitbook, epub_book, or tufte_html_book but not to pdf_book. The following is what I have on my index.Rmd file

--- 
title: "Blah Blah"
author: "Me"
date: "`r Sys.Date()`"
site: bookdown::bookdown_site
documentclass: krantz
bibliography: [book.bib, packages.bib]
biblio-style: apalike
link-citations: yes
description: "This is a minimal example of using the bookdown package to write a book. The output format for this example is bookdown::gitbook."
header-includes:
- \usepackage{amsthm}
- \newtheorem{definition}{Definition}
- \newtheorem{lemma}{Lemma}
- \newtheorem{theorem}{Theorem}
- \newtheorem{example}{Example}
---

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

# First Chapter

The content of Preface. [@xie2015]

```{theorem, name="Infinite Group"}
A group having an infinite number of elements.
```

```{example}
The set $(\mathbb{Z}, +)$ is an infinite group.
```

This is what I have on my _output.yml file (the relevant part):

bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  keep_tex: yes
  pandoc_args: --top-level-division=chapter

The preamble.tex simply has \usepackage{booktabs}

This is what I get when I compile: enter image description here

It seems that the name of the theorem and the actual content are being treated as two different theorems, as well as the example. This is the same with respect to definition and lemma. Even if I remove

header-includes:
    - \usepackage{amsthm}
    - \newtheorem{definition}{Definition}
    - \newtheorem{lemma}{Lemma}
    - \newtheorem{theorem}{Theorem}
    - \newtheorem{example}{Example}

from the yaml header, I still get the same problem. Any ideas on how to fix this?

Phil
  • 7,287
  • 3
  • 36
  • 66
Yocoxcanemitia
  • 265
  • 1
  • 4
  • 9

1 Answers1

2

This is a known bug, and has been fixed in the development version of knitr. You may try:

remotes::install_github('yihui/knitr')
install.packages('bookdown')  # update bookdown
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
  • Dear @YihuiXie, this did not fix it for me - I am still getting the issue.. I clicked your link, pointing to your GitHub and if I am not mistaken, it seems that the issue is that I am not using the most recent version of Pandoc, correct? The reason I am stuck on an old version of Pandoc is [this unsolved SO post](https://stackoverflow.com/questions/57614387/pandoc-4317-forces-content-under-title-slides-to-be-included-in-a-frame-in-pand). Would it be possible to make your solution Pandoc 2.6 friendly? Many thanks, thomas – tchevrier Jun 18 '20 at 19:48
  • @tchevrier Please see https://github.com/rstudio/bookdown/issues/883#issuecomment-647184411 – Yihui Xie Jun 21 '20 at 21:33