RMarkdown / pandoc fails to knit Pdf with latex color commands
RMarkdown fails to knit PDF when latex commands such as:
textcolor{blue}{Character String}
are present in the .rmd file. The error output is:
/usr/local/bin/pandoc +RTS -K512m -RTS test.utf8.md --to latex --from markdown+autolink_bare_uris+ascii_identifiers+tex_math_single_backslash --output test.pdf --template ~/R/3.3/library/rmarkdown/rmd/latex/default-1.17.0.2.tex --highlight-style tango --latex-engine /Library/TeX/texbin/pdflatex --variable graphics=yes --variable 'geometry:margin=1in' ! Undefined control sequence. l.105 textcolor
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43
Execution halted
Inclusion of an r code chunk with echo = TRUE such as:
```{r, echo = TRUE}
# I am a glitch
```
in the .rmd file allows for the successful creation of the PDF document.
If all r code chunks in the .rmd file are set with echo = FALSE or equivalent statements, the PDF file will not knit regardless of latex engine used if latex commands such as /textcolor are present. If only latex commands such as begin{tabular}, many, etc… are used the error is not present.
Addition of “header-includes: usepackage{color}” to the YAML header, as seen below, addresses the issue. However, it is unclear why insertion of an “echo = TRUE” R-code chunk also resolves the issue.
---
title: "test"
output: pdf_document
header-includes: usepackage{color}
---
Interestingly, with a previous version of the R-Studio suite, as see below, inclusion of “header-includes: usepackage{color}” in the YAML header, did not appear necessary prior to use of commands such as "textcolor{blue}{Character String}" in the .rmd file.