2
votes

I'm compiling a report using Papaja and Rmarkdown, and I want to highlight various text throughout. Doing so with latex or pure Rmarkdown is easy, but I'm receiving an "undefined control sequence" error when I compile the report to PDF using Papaja's application of Knitr.

A similar question about text highlighting within a single Rmarkdown file was answered here: RMarkdown / pandoc fails to knit Pdf with latex color commands. I'd like to know if an answer exists for multiple Rmarkdown files using Papaja.

I'll include a minimal example below.

1) File called papaja_file.Rmd

---

# https://crsh.github.io/papaja_man/index.html

title             : "Some Title"
shorttitle        : "HEADER"

author: 
  - name          : "Name R Here"
    affiliation   : "1"
    corresponding : yes    # Define only one corresponding author
    address       : "Include addresss"
    email         : "[email protected]"

affiliation:
  - id            : "1"
    institution   : "Any University"



author_note: |
  ....

abstract: |
  Text here for abstract. 

keywords          : "Keyword1, keyword2, keyword3"
bibliography      : ["references.bib"]

figsintext        : no
figurelist        : no
tablelist         : no
footnotelist      : no
lineno            : yes

lang              : "english"
class             : "man"
output            : papaja::apa6_pdf
---

```{r load_packages, include = FALSE}
library("papaja")
```

```{r analysis_preferences}
# Seed for random number generation
set.seed(42)
```

```{r global_options, include=FALSE}
knitr::opts_chunk$set(fig.path = 'figures/', echo = TRUE, warning = FALSE, message = FALSE)
```


```{r child = 'child_document.Rmd'}
```


\newpage

# References
```{r create_references, echo = F}
r_refs(file = "references.bib")
```

\setlength{\parindent}{-0.5in}
\setlength{\leftskip}{0.5in}

Notice that it references a single child Rmarkdown document.

2) The child document with text, called child_document.Rmd

---
output: 
  pdf_document:
      includes:
          in_header: preamble.tex
---

One sentence without highlighting. \hl{Another with highlighting.}

3) The preamble, called preamble.tex

\usepackage{color}
\usepackage{soul}
\definecolor{lightblue}{rgb}{0.90, 0.95, 1}
\sethlcolor{lightblue}

Knitting the main papaja file produces the error. Removing the \hl command within the child document allows the pdf to compile without issue.

Result after putting YAML header within the main papaja document rather than the child:

enter image description here

1
You YAML header does not look like from a normal papaja file. Please provide a minimal reproducible example.Ralf Stubner
Ok I have edited the question to include a minimal example.Topher

1 Answers

2
votes

The YAML header in your child document is not evaluated, c.f.

The master document, for example, consists of the YAML front matter and includes the children, which are themselves R Markdown documents without a YAML front matter.

https://crsh.github.io/papaja_man/tips-and-tricks.html#splitting-an-r-markdown-document

But you can include your preamble.tex in you master file using:

output: 
  papaja::apa6_pdf:
    includes:
      in_header: preamble.tex

c.f. https://github.com/rstub/stackoverflow/commit/a92a67d4721ee9c06e995b08adbf8cb89daebcb4

Result:

enter image description here