Search code examples
rlatexr-markdownbookdown

Bookdown to PDF Theorem Environment Duplicate


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?


Solution

  • 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