Rentrop
Rentrop

Reputation: 21497

R bookdown - math in table-header not working

After cloning the bookdown-demo i tried to get a table with some math in the header. In the html-output everything works fine. In the PDF output it is broken:

Chunk:

```{r}
knitr::kable(
  head(cars),
  col.names = c("$y_{speed}$", "$y_{dist}$")
)
```

Bookdown - PDF: (Here you can see the wrong output)

enter image description here

Rmarkdown - PDF: (Result as expected)

enter image description here

Bookdown - HTML: (Result as expected)

enter image description here

This is the Latex-Code bookdown produces:

\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{knitr::}\KeywordTok{kable}\NormalTok{(}
  \KeywordTok{head}\NormalTok{(cars),}
  \DataTypeTok{col.names =} \KeywordTok{c}\NormalTok{(}\StringTok{"$y_\{speed\}$"}\NormalTok{, }\StringTok{"$y_\{dist\}$"}\NormalTok{)}
\NormalTok{)}
\end{Highlighting}
\end{Shaded}

\begin{tabular}{r|r}
\hline
\$y\_\{speed\}\$ & \$y\_\{dist\}\$\\
\hline
4 & 2\\
\hline
4 & 10\\
\hline
7 & 4\\
\hline
7 & 22\\
\hline
8 & 16\\
\hline
9 & 10\\
\hline
\end{tabular}

Upvotes: 3

Views: 407

Answers (1)

Martin Schmelzer
Martin Schmelzer

Reputation: 23889

Just use the argument escape = F for kable since there seems to be a double escaping of special characters in bookdown.

Upvotes: 2

Related Questions