9

Suddenly, I run into an error when knitting to PDF in Markdown/Bookdown. Nothing about my system has changed.

The error is being caused by a 'horzontal rule' i.e. --- or *** anywhere in markdown, despite line spaces either side.

I include a simplistic exmaple of the offending --- that will not knit to PDF.

Incidentally, knitting to another format does not cause problems and knitting to PDF without a horizontal rule does not generate an error. Also, swapped --- for *** to explore if this stapped the error. It did not.

Can anyone offer any insight, please?

Using TinyTex and MikteX separately (not installed together). Neither solve the problem. Only just encountered this problem. Files that previously knitted without issue now fail when they encounter --- or ***.


## R Markdown

Some text, then I want horizontal rule

---

Some text after the horizonatal rule.



! Missing number, treated as zero.
<to be read again> 
                   \protect 
l.146 ...nter}\rule{0.5\linewidth}{\linethickness}
                                                  \end{center} 

Error: Failed to compile K.tex. See https://yihui.name/tinytex/r/#debugging for debugging tips. See K.log for more info.
Execution halted
Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
stats4ever
  • 431
  • 1
  • 3
  • 5
  • 1
    FYI I just fixed this issue in **rmarkdown**: https://github.com/rstudio/rmarkdown/commit/2faf16a8bc4755569250fd426b0c5080888de2a0. The problem should go away if you install the dev version of **rmarkdown**, or wait for the next CRAN release of **rmarkdown**. Thanks! – Yihui Xie Jan 17 '20 at 04:46

2 Answers2

9

Update: this issue has been fixed in rmarkdown v2.1, and should disappear if you (re)install the latest version of rmarkdown from CRAN.


This is a known and fixed bug now in pandoc. https://github.com/jgm/pandoc/issues/5801

it happened with newer version of TexLive.

This will be fixed in next pandoc version. You'll have to wait or use the nightly build.

you can also use a trick for now by adding this in the header of tex document.

\renewcommand{\linethickness}{0.05em}

With rmarkdown you can do

---
title: "Untitled"
output: 
  pdf_document:
    keep_tex: true
    includes:
      in_header: header.tex
---

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


```{cat, engine.opts = list(file = "header.tex")}
\renewcommand{\linethickness}{0.05em}
```


lalalala

---

lilili

you can also write the header.tex file manually, or add it to your template.

This works for me.

Yihui Xie
  • 28,913
  • 23
  • 193
  • 419
cderv
  • 6,272
  • 1
  • 21
  • 31
2

So, a temporary solution, that worked for me, until a more permanent solution is found is:

\begin{center}\rule{3in}{0.4pt}\end{center}

Used this instead of --- or ***

stats4ever
  • 431
  • 1
  • 3
  • 5